com.interface21.jdbc.datasource
Class DriverManagerDataSource

java.lang.Object
  |
  +--com.interface21.jdbc.datasource.AbstractDataSource
        |
        +--com.interface21.jdbc.datasource.DriverManagerDataSource
All Implemented Interfaces:
javax.sql.DataSource, SmartDataSource
Direct Known Subclasses:
SingleConnectionDataSource

public class DriverManagerDataSource
extends AbstractDataSource
implements SmartDataSource

Implementation of SmartDataSource that configures a plain old JDBC Driver via bean properties, and returns a new connection every time.

Useful for test or standalone environments outside of a J2EE container, either as a DataSource bean in a respective ApplicationContext, or in conjunction with a mock JNDI InitialContext. Pool-assuming Connection.close() calls will simply close the connection, so any DataSource-aware persistence code should work.

In a J2EE container, it is recommended to use a JNDI DataSource provided by the container. Such a DataSource can be exported as a DataSource bean in an ApplicationContext via JndiObjectFactoryBean, for seamless switching to and from a local DataSource bean like this class.

If you need a "real" connection pool outside of a container, consider Apache's Jakarta Commons DBCP. Its BasicDataSource is a full connection pool bean, supporting the same basic properties as this class + specific settings. It can be used as a replacement for an instance of this class just by exchanging the class name of the bean definition.

Since:
14.03.2003
Version:
$Id: DriverManagerDataSource.java,v 1.4 2003/05/28 11:21:35 jhoeller Exp $
Author:
Juergen Hoeller
See Also:
MockInitialContextFactoryBuilder, JndiObjectFactoryBean

Fields inherited from class com.interface21.jdbc.datasource.AbstractDataSource
logger
 
Constructor Summary
DriverManagerDataSource()
           
DriverManagerDataSource(java.lang.String driverName, java.lang.String url, java.lang.String user, java.lang.String password)
           
 
Method Summary
 java.sql.Connection getConnection()
           
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
           
 java.lang.String getDriverClassName()
           
 java.lang.String getPassword()
           
 java.lang.String getUrl()
           
 java.lang.String getUsername()
           
 void setDriverClassName(java.lang.String driverClassName)
           
 void setPassword(java.lang.String password)
           
 void setUrl(java.lang.String url)
           
 void setUsername(java.lang.String username)
           
 boolean shouldClose(java.sql.Connection conn)
          This returns a new connection every time: Close it when returning one to the "pool".
 
Methods inherited from class com.interface21.jdbc.datasource.AbstractDataSource
getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.sql.DataSource
getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter
 

Constructor Detail

DriverManagerDataSource

public DriverManagerDataSource()

DriverManagerDataSource

public DriverManagerDataSource(java.lang.String driverName,
                               java.lang.String url,
                               java.lang.String user,
                               java.lang.String password)
                        throws CannotGetJdbcConnectionException
Method Detail

setDriverClassName

public void setDriverClassName(java.lang.String driverClassName)
                        throws CannotGetJdbcConnectionException

getDriverClassName

public java.lang.String getDriverClassName()

setUrl

public void setUrl(java.lang.String url)

getUrl

public java.lang.String getUrl()

setUsername

public void setUsername(java.lang.String username)

getUsername

public java.lang.String getUsername()

setPassword

public void setPassword(java.lang.String password)

getPassword

public java.lang.String getPassword()

shouldClose

public boolean shouldClose(java.sql.Connection conn)
This returns a new connection every time: Close it when returning one to the "pool".
Specified by:
shouldClose in interface SmartDataSource
Following copied from interface: com.interface21.jdbc.datasource.SmartDataSource
Parameters:
conn - connection, which should have been obtained from this data source, to check closure status of

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Specified by:
getConnection in interface javax.sql.DataSource

getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Specified by:
getConnection in interface javax.sql.DataSource


Rod Johnson and Spring contributors 2001-2003.