org.pf.db.util
Class DataSourceProxy

java.lang.Object
  extended by org.pf.db.util.DataSourceProxy
All Implemented Interfaces:
DataSource

public class DataSourceProxy
extends Object
implements 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().

Version:
1.2
Author:
Manfred Duchrow

Constructor Summary
DataSourceProxy(Connection conn)
          Initialize the new instance with a ready-to-use connection.
DataSourceProxy(DataSource dataSource)
           
DataSourceProxy(DataSource dataSource, String username, String password)
           
DataSourceProxy(String url)
          Initialize the new instance with an URL for the database connection.
DataSourceProxy(String url, String username, String password)
          Initialize the new instance with all necessary connection information.
 
Method Summary
 Connection getConnection()
          Attempt to establish a database connection
 Connection getConnection(String username, String password)
          Attempt to establish a database connection
 String getDbPassword()
           
 String getDbUrl()
           
 String getDbUserid()
           
 int getLoginTimeout()
          Returns the maximum time in seconds that this data source can wait while attempting to connect to a database.
 PrintWriter getLogWriter()
          Returns the log writer for this data source
 void setDbPassword(String password)
           
 void setDbUrl(String url)
           
 void setDbUserid(String userId)
           
 void setDriverClassName(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(PrintWriter writer)
          Sets the log writer for this data source
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataSourceProxy

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


DataSourceProxy

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


DataSourceProxy

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


DataSourceProxy

public DataSourceProxy(DataSource dataSource,
                       String username,
                       String password)

DataSourceProxy

public DataSourceProxy(DataSource dataSource)
Method Detail

getConnection

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

Specified by:
getConnection in interface DataSource
Throws:
SQLException

getConnection

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

Specified by:
getConnection in interface DataSource
Throws:
SQLException

getDbUrl

public String getDbUrl()

setDbUrl

public void setDbUrl(String url)

getDbUserid

public String getDbUserid()

setDbUserid

public void setDbUserid(String userId)

getDbPassword

public String getDbPassword()

setDbPassword

public void setDbPassword(String password)

getLoginTimeout

public int getLoginTimeout()
                    throws 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 DataSource
Throws:
SQLException

getLogWriter

public PrintWriter getLogWriter()
                         throws SQLException
Returns the log writer for this data source

Specified by:
getLogWriter in interface DataSource
Throws:
SQLException

setLoginTimeout

public void setLoginTimeout(int timeout)
                     throws 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 DataSource
Throws:
SQLException

setLogWriter

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

Specified by:
setLogWriter in interface DataSource
Throws:
SQLException

setDriverClassName

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



Copyright © 2012 Manfred Duchrow Consulting & Software. All Rights Reserved.