org.datanucleus.store.rdbms.datasource
Class DriverManagerDataSource

java.lang.Object
  extended by org.datanucleus.store.rdbms.datasource.DriverManagerDataSource
All Implemented Interfaces:
java.sql.Wrapper, javax.sql.CommonDataSource, javax.sql.DataSource

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

Wrapper to the JDBC DataSource class. Provides checking for driver class existence, and utility methods for obtaining a connection.

It should be noted that setting the log writer and login timeout will apply to DriverManager and NOT to the Data Source on its own. If you have 2 or more DataSource's they will have THE SAME log writer and login timeout.


Constructor Summary
DriverManagerDataSource(java.lang.String driverName, java.lang.String url, java.lang.String userName, java.lang.String password, org.datanucleus.ClassLoaderResolver clr)
          Constructor.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Equality operator.
 java.sql.Connection getConnection()
          Accessor for a JDBC connection for this data source.
 java.sql.Connection getConnection(java.lang.String userName, java.lang.String password)
          Accessor for a JDBC connection for this data source, specifying username and password.
 int getLoginTimeout()
          Accessor for the Login timeout for the driver manager.
 java.io.PrintWriter getLogWriter()
          Accessor for the LogWriter of the driver manager.
 int hashCode()
          Hashcode operator.
 boolean isWrapperFor(java.lang.Class iface)
           
 void setLoginTimeout(int seconds)
          Mutator for the Login timeout for the driver manager.
 void setLogWriter(java.io.PrintWriter out)
          Mutator for the LogWriter of the driver manager.
 java.lang.Object unwrap(java.lang.Class iface)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DriverManagerDataSource

public DriverManagerDataSource(java.lang.String driverName,
                               java.lang.String url,
                               java.lang.String userName,
                               java.lang.String password,
                               org.datanucleus.ClassLoaderResolver clr)
Constructor.

Parameters:
driverName - Class name of the JDBC driver.
url - URL of the data source.
clr - ClassLoaderResolver to use for loading issues
Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Accessor for a JDBC connection for this data source.

Specified by:
getConnection in interface javax.sql.DataSource
Returns:
The connection
Throws:
java.sql.SQLException - Thrown when an error occurs obtaining the connection.

getConnection

public java.sql.Connection getConnection(java.lang.String userName,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Accessor for a JDBC connection for this data source, specifying username and password.

Specified by:
getConnection in interface javax.sql.DataSource
Parameters:
userName - User name for the data source (this user name is ignored)
password - Password for the data source (this password is ignored)
Returns:
The connection
Throws:
java.sql.SQLException - Thrown when an error occurs obtaining the connection.

getLogWriter

public java.io.PrintWriter getLogWriter()
Accessor for the LogWriter of the driver manager.

Specified by:
getLogWriter in interface javax.sql.CommonDataSource
Returns:
The Log Writer

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
Mutator for the LogWriter of the driver manager.

Specified by:
setLogWriter in interface javax.sql.CommonDataSource
Parameters:
out - The Log Writer

getLoginTimeout

public int getLoginTimeout()
Accessor for the Login timeout for the driver manager.

Specified by:
getLoginTimeout in interface javax.sql.CommonDataSource
Returns:
The login timeout (seconds)

setLoginTimeout

public void setLoginTimeout(int seconds)
Mutator for the Login timeout for the driver manager.

Specified by:
setLoginTimeout in interface javax.sql.CommonDataSource
Parameters:
seconds - The login timeout (seconds)

equals

public boolean equals(java.lang.Object obj)
Equality operator.

Overrides:
equals in class java.lang.Object
Parameters:
obj - The object to compare against.
Returns:
Whether the objects are equal.

hashCode

public int hashCode()
Hashcode operator.

Overrides:
hashCode in class java.lang.Object
Returns:
The Hashcode for this object.

unwrap

public java.lang.Object unwrap(java.lang.Class iface)
                        throws java.sql.SQLException
Specified by:
unwrap in interface java.sql.Wrapper
Throws:
java.sql.SQLException

isWrapperFor

public boolean isWrapperFor(java.lang.Class iface)
                     throws java.sql.SQLException
Specified by:
isWrapperFor in interface java.sql.Wrapper
Throws:
java.sql.SQLException


Copyright © 2009. All Rights Reserved.