org.pfsw.db.util
Class DataSourceProxy

java.lang.Object
  extended by org.pfsw.db.util.DataSourceProxy
All Implemented Interfaces:
java.sql.Wrapper, javax.sql.CommonDataSource, javax.sql.DataSource

public class DataSourceProxy
extends java.lang.Object
implements javax.sql.DataSource

This class is a datasource wrapper for other datasources or simple connections. It allows to pass simple connection information such as url, userid, password as a datasource to other objects that require a javax.sql.DataSource rather than java.sql.Connection as input. In addition the wrapping of other datasource objects plus their associated userid/password data is supported. That allows to pass around just one object that can be asked to return a connection via getConnection().


Constructor Summary
DataSourceProxy(java.sql.Connection conn)
          Initialize the new instance with a ready-to-use connection.
DataSourceProxy(javax.sql.DataSource dataSource)
           
DataSourceProxy(javax.sql.DataSource dataSource, java.lang.String username, java.lang.String password)
           
DataSourceProxy(java.lang.String url)
          Initialize the new instance with an URL for the database connection.
DataSourceProxy(java.lang.String url, java.lang.String username, java.lang.String password)
          Initialize the new instance with all necessary connection information.
 
Method Summary
 java.sql.Connection getConnection()
          Attempt to establish a database connection
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
          Attempt to establish a database connection
protected  javax.sql.DataSource getDataSource()
           
protected  java.sql.Connection getDataSourceConnection()
          Attempt to establish a database connection using the wrapped datasource
protected  java.sql.Connection getDbConnection()
           
 java.lang.String getDbPassword()
           
 java.lang.String getDbUrl()
           
 java.lang.String getDbUserid()
           
 int getLoginTimeout()
          Returns the maximum time in seconds that this data source can wait while attempting to connect to a database.
 java.io.PrintWriter getLogWriter()
          Returns the log writer for this data source
protected  boolean hasConnection()
           
protected  boolean hasDataSource()
           
 boolean isWrapperFor(java.lang.Class<?> iface)
          Always returns false.
protected  void setDataSource(javax.sql.DataSource newValue)
           
protected  void setDbConnection(java.sql.Connection newValue)
           
 void setDbPassword(java.lang.String password)
           
 void setDbUrl(java.lang.String url)
           
 void setDbUserid(java.lang.String userId)
           
 void setDriverClassName(java.lang.String driverClassName)
          Creates an instance of the given class name in order to register the database driver.
 void setLoginTimeout(int timeout)
          Sets the maximum time in seconds that this data source can wait while attempting to connect to a database.
 void setLogWriter(java.io.PrintWriter writer)
          Sets the log writer for this data source
<T> T
unwrap(java.lang.Class<T> iface)
          Always throws SQLException, becaus eno interfaces are supported.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataSourceProxy

public DataSourceProxy(java.sql.Connection conn)
Initialize the new instance with a ready-to-use connection.


DataSourceProxy

public DataSourceProxy(java.lang.String url,
                       java.lang.String username,
                       java.lang.String password)
Initialize the new instance with all necessary connection information.


DataSourceProxy

public DataSourceProxy(java.lang.String url)
Initialize the new instance with an URL for the database connection.


DataSourceProxy

public DataSourceProxy(javax.sql.DataSource dataSource,
                       java.lang.String username,
                       java.lang.String password)

DataSourceProxy

public DataSourceProxy(javax.sql.DataSource dataSource)
Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Attempt to establish a database connection

Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Attempt to establish a database connection

Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

isWrapperFor

public boolean isWrapperFor(java.lang.Class<?> iface)
                     throws java.sql.SQLException
Always returns false.

Specified by:
isWrapperFor in interface java.sql.Wrapper
Throws:
java.sql.SQLException

unwrap

public <T> T unwrap(java.lang.Class<T> iface)
         throws java.sql.SQLException
Always throws SQLException, becaus eno interfaces are supported.

Specified by:
unwrap in interface java.sql.Wrapper
Throws:
java.sql.SQLException

getDbUrl

public java.lang.String getDbUrl()

setDbUrl

public void setDbUrl(java.lang.String url)

getDbUserid

public java.lang.String getDbUserid()

setDbUserid

public void setDbUserid(java.lang.String userId)

getDbPassword

public java.lang.String getDbPassword()

setDbPassword

public void setDbPassword(java.lang.String password)

getLoginTimeout

public int getLoginTimeout()
                    throws java.sql.SQLException
Returns the maximum time in seconds that this data source can wait while attempting to connect to a database.

Specified by:
getLoginTimeout in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

getLogWriter

public java.io.PrintWriter getLogWriter()
                                 throws java.sql.SQLException
Returns the log writer for this data source

Specified by:
getLogWriter in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

setLoginTimeout

public void setLoginTimeout(int timeout)
                     throws java.sql.SQLException
Sets the maximum time in seconds that this data source can wait while attempting to connect to a database.

Specified by:
setLoginTimeout in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

setLogWriter

public void setLogWriter(java.io.PrintWriter writer)
                  throws java.sql.SQLException
Sets the log writer for this data source

Specified by:
setLogWriter in interface javax.sql.CommonDataSource
Throws:
java.sql.SQLException

setDriverClassName

public void setDriverClassName(java.lang.String driverClassName)
Creates an instance of the given class name in order to register the database driver.


hasDataSource

protected boolean hasDataSource()

hasConnection

protected boolean hasConnection()

getDataSourceConnection

protected java.sql.Connection getDataSourceConnection()
                                               throws java.sql.SQLException
Attempt to establish a database connection using the wrapped datasource

Throws:
java.sql.SQLException

getDbConnection

protected java.sql.Connection getDbConnection()

setDbConnection

protected void setDbConnection(java.sql.Connection newValue)

getDataSource

protected javax.sql.DataSource getDataSource()

setDataSource

protected void setDataSource(javax.sql.DataSource newValue)