|
|||||||||||
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".
JndiObjectFactoryBean
,
SimpleNamingContextBuilder
,
BasicDataSource
Field Summary |
Fields inherited from class org.springframework.jdbc.datasource.AbstractDataSource |
logger |
Constructor Summary | |
DriverManagerDataSource()
Constructor for bean-style configuration. |
|
DriverManagerDataSource(String driverClassName,
String url,
String username,
String password)
Create a new SingleConnectionDataSource with the given standard DriverManager parameters. |
Method Summary | |
Connection |
getConnection()
|
Connection |
getConnection(String username,
String password)
|
protected Connection |
getConnectionFromDriverManager()
Get a new Connection from DriverManager, with the connection properties of this DataSource. |
protected Connection |
getConnectionFromDriverManager(String url,
String username,
String password)
Getting a connection using the nasty static from DriverManager is extracted into a protected method to allow for easy unit testing. |
String |
getDriverClassName()
|
String |
getPassword()
|
String |
getUrl()
|
String |
getUsername()
|
void |
setDriverClassName(String driverClassName)
|
void |
setPassword(String password)
|
void |
setUrl(String url)
|
void |
setUsername(String username)
|
boolean |
shouldClose(Connection con)
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(String driverClassName, String url, String username, String password) throws CannotGetJdbcConnectionException
Method Detail |
public void setDriverClassName(String driverClassName) throws CannotGetJdbcConnectionException
CannotGetJdbcConnectionException
public String getDriverClassName()
public void setUrl(String url)
public String getUrl()
public void setUsername(String username)
public String getUsername()
public void setPassword(String password)
public String getPassword()
public boolean shouldClose(Connection con)
shouldClose
in interface SmartDataSource
con
- connection, which should have been obtained
from this data source, to check closure status of
public Connection getConnection() throws SQLException
getConnection
in interface DataSource
SQLException
public Connection getConnection(String username, String password) throws SQLException
getConnection
in interface DataSource
SQLException
protected Connection getConnectionFromDriverManager() throws SQLException
SQLException
protected Connection getConnectionFromDriverManager(String url, String username, String password) throws SQLException
SQLException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |