|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.jdbc.datasource.AbstractDataSource org.springframework.jdbc.datasource.DriverManagerDataSource
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 simple JNDI environment. 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 J2EE container, consider Apache's Jakarta Commons DBCP. Its BasicDataSource is a full connection pool bean, supporting the same basic properties as this class plus specific settings. It can be used as a replacement for an instance of this class just by changing the class name of the bean definition to "org.apache.commons.dbcp.BasicDataSource".
SimpleNamingContextBuilder
,
JndiObjectFactoryBean
,
BasicDataSource
Field Summary |
Fields inherited from class org.springframework.jdbc.datasource.AbstractDataSource |
logger |
Constructor Summary | |
DriverManagerDataSource()
Constructor for bean-style configuration. |
|
DriverManagerDataSource(java.lang.String driverClassName,
java.lang.String url,
java.lang.String username,
java.lang.String password)
Create a new SingleConnectionDataSource with the given standard DriverManager parameters. |
Method Summary | |
java.sql.Connection |
getConnection()
|
java.sql.Connection |
getConnection(java.lang.String username,
java.lang.String password)
|
protected java.sql.Connection |
getConnectionFromDriverManager()
Get a new Connection from DriverManager, with the connection properties of this DataSource. |
protected java.sql.Connection |
getConnectionFromDriverManager(java.lang.String url,
java.lang.String username,
java.lang.String password)
Getting a connection using the nasty static from DriverManager is extracted into a protected method to allow for easy unit testing. |
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 DataSource returns a new connection every time: Close it when returning one to the "pool". |
Methods inherited from class org.springframework.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 |
public DriverManagerDataSource()
public DriverManagerDataSource(java.lang.String driverClassName, java.lang.String url, java.lang.String username, java.lang.String password) throws CannotGetJdbcConnectionException
Method Detail |
public void setDriverClassName(java.lang.String driverClassName) throws CannotGetJdbcConnectionException
CannotGetJdbcConnectionException
public java.lang.String getDriverClassName()
public void setUrl(java.lang.String url)
public java.lang.String getUrl()
public void setUsername(java.lang.String username)
public java.lang.String getUsername()
public void setPassword(java.lang.String password)
public java.lang.String getPassword()
public boolean shouldClose(java.sql.Connection conn)
shouldClose
in interface SmartDataSource
conn
- connection, which should have been obtained
from this data source, to check closure status ofpublic java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
java.sql.SQLException
public java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException
getConnection
in interface javax.sql.DataSource
java.sql.SQLException
protected java.sql.Connection getConnectionFromDriverManager() throws java.sql.SQLException
java.sql.SQLException
protected java.sql.Connection getConnectionFromDriverManager(java.lang.String url, java.lang.String username, java.lang.String password) throws java.sql.SQLException
java.sql.SQLException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |