org.springframework.jdbc.datasource
Class AbstractDriverBasedDataSource

java.lang.Object
  extended by org.springframework.jdbc.datasource.AbstractDataSource
      extended by org.springframework.jdbc.datasource.AbstractDriverBasedDataSource
All Implemented Interfaces:
java.sql.Wrapper, javax.sql.CommonDataSource, javax.sql.DataSource
Direct Known Subclasses:
DriverManagerDataSource, SimpleDriverDataSource

public abstract class AbstractDriverBasedDataSource
extends AbstractDataSource

Abstract base class for JDBC DataSource implementations that operate on a JDBC Driver.

Since:
2.5.5
Author:
Juergen Hoeller
See Also:
SimpleDriverDataSource, DriverManagerDataSource

Field Summary
private  java.util.Properties connectionProperties
           
private  java.lang.String password
           
private  java.lang.String url
           
private  java.lang.String username
           
 
Fields inherited from class org.springframework.jdbc.datasource.AbstractDataSource
logger
 
Constructor Summary
AbstractDriverBasedDataSource()
           
 
Method Summary
 java.sql.Connection getConnection()
          This implementation delegates to getConnectionFromDriver, using the default username and password of this DataSource.
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
          This implementation delegates to getConnectionFromDriver, using the given username and password.
protected abstract  java.sql.Connection getConnectionFromDriver(java.util.Properties props)
          Obtain a Connection using the given properties.
protected  java.sql.Connection getConnectionFromDriver(java.lang.String username, java.lang.String password)
          Build properties for the Driver, including the given username and password (if any), and obtain a corresponding Connection.
 java.util.Properties getConnectionProperties()
          Return the connection properties to be passed to the Driver, if any.
 java.lang.String getPassword()
          Return the JDBC password to use for connecting through the Driver.
 java.lang.String getUrl()
          Return the JDBC URL to use for connecting through the Driver.
 java.lang.String getUsername()
          Return the JDBC username to use for connecting through the Driver.
 void setConnectionProperties(java.util.Properties connectionProperties)
          Specify arbitrary connection properties as key/value pairs, to be passed to the Driver.
 void setPassword(java.lang.String password)
          Set the JDBC password to use for connecting through the Driver.
 void setUrl(java.lang.String url)
          Set the JDBC URL to use for connecting through the Driver.
 void setUsername(java.lang.String username)
          Set the JDBC username to use for connecting through the Driver.
 
Methods inherited from class org.springframework.jdbc.datasource.AbstractDataSource
getLoginTimeout, getLogWriter, getParentLogger, isWrapperFor, setLoginTimeout, setLogWriter, unwrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

url

private java.lang.String url

username

private java.lang.String username

password

private java.lang.String password

connectionProperties

private java.util.Properties connectionProperties
Constructor Detail

AbstractDriverBasedDataSource

public AbstractDriverBasedDataSource()
Method Detail

setUrl

public void setUrl(java.lang.String url)
Set the JDBC URL to use for connecting through the Driver.

See Also:
Driver.connect(String, java.util.Properties)

getUrl

public java.lang.String getUrl()
Return the JDBC URL to use for connecting through the Driver.


setUsername

public void setUsername(java.lang.String username)
Set the JDBC username to use for connecting through the Driver.

See Also:
Driver.connect(String, java.util.Properties)

getUsername

public java.lang.String getUsername()
Return the JDBC username to use for connecting through the Driver.


setPassword

public void setPassword(java.lang.String password)
Set the JDBC password to use for connecting through the Driver.

See Also:
Driver.connect(String, java.util.Properties)

getPassword

public java.lang.String getPassword()
Return the JDBC password to use for connecting through the Driver.


setConnectionProperties

public void setConnectionProperties(java.util.Properties connectionProperties)
Specify arbitrary connection properties as key/value pairs, to be passed to the Driver.

Can also contain "user" and "password" properties. However, any "username" and "password" bean properties specified on this DataSource will override the corresponding connection properties.

See Also:
Driver.connect(String, java.util.Properties)

getConnectionProperties

public java.util.Properties getConnectionProperties()
Return the connection properties to be passed to the Driver, if any.


getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
This implementation delegates to getConnectionFromDriver, using the default username and password of this DataSource.

Throws:
java.sql.SQLException
See Also:
getConnectionFromDriver(String, String), setUsername(java.lang.String), setPassword(java.lang.String)

getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
This implementation delegates to getConnectionFromDriver, using the given username and password.

Throws:
java.sql.SQLException
See Also:
getConnectionFromDriver(String, String)

getConnectionFromDriver

protected java.sql.Connection getConnectionFromDriver(java.lang.String username,
                                                      java.lang.String password)
                                               throws java.sql.SQLException
Build properties for the Driver, including the given username and password (if any), and obtain a corresponding Connection.

Parameters:
username - the name of the user
password - the password to use
Returns:
the obtained Connection
Throws:
java.sql.SQLException - in case of failure
See Also:
Driver.connect(String, java.util.Properties)

getConnectionFromDriver

protected abstract java.sql.Connection getConnectionFromDriver(java.util.Properties props)
                                                        throws java.sql.SQLException
Obtain a Connection using the given properties.

Template method to be implemented by subclasses.

Parameters:
props - the merged connection properties
Returns:
the obtained Connection
Throws:
java.sql.SQLException - in case of failure