org.datanucleus.store.rdbms.datasource
Class DriverManagerDataSource

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

public class DriverManagerDataSource
extends Object
implements 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(String driverName, String url, String userName, String password, org.datanucleus.ClassLoaderResolver clr, Properties props)
          Constructor.
 
Method Summary
 boolean equals(Object obj)
          Equality operator.
 Connection getConnection()
          Accessor for a JDBC connection for this data source.
 Connection getConnection(String userName, 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.
 PrintWriter getLogWriter()
          Accessor for the LogWriter of the driver manager.
 Logger getParentLogger()
           
 int hashCode()
          Hashcode operator.
 boolean isWrapperFor(Class iface)
           
 void setLoginTimeout(int seconds)
          Mutator for the Login timeout for the driver manager.
 void setLogWriter(PrintWriter out)
          Mutator for the LogWriter of the driver manager.
 Object unwrap(Class iface)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DriverManagerDataSource

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

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

getConnection

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

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

getConnection

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

Specified by:
getConnection in interface 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:
SQLException - Thrown when an error occurs obtaining the connection.

getLogWriter

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

Specified by:
getLogWriter in interface CommonDataSource
Returns:
The Log Writer

setLogWriter

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

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

getLoginTimeout

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

Specified by:
getLoginTimeout in interface 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 CommonDataSource
Parameters:
seconds - The login timeout (seconds)

equals

public boolean equals(Object obj)
Equality operator.

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

hashCode

public int hashCode()
Hashcode operator.

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

unwrap

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

isWrapperFor

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

getParentLogger

public Logger getParentLogger()
                       throws SQLFeatureNotSupportedException
Throws:
SQLFeatureNotSupportedException


Copyright © 2012. All Rights Reserved.