org.opennms.core.resource.db
Class DataSourceDbConnectionFactory

java.lang.Object
  extended by org.opennms.core.resource.db.DataSourceDbConnectionFactory
All Implemented Interfaces:
DbConnectionFactory

public class DataSourceDbConnectionFactory
extends Object
implements DbConnectionFactory

DataSourceDbConnectionFactory class.

Version:
$Id: $
Author:
DJ Gregor

Constructor Summary
DataSourceDbConnectionFactory(DataSource dataSource)
          Constructor for DataSourceDbConnectionFactory.
 
Method Summary
 void destroy()
          destroy
 Connection getConnection()
          getConnection
 void init(String dbUrl, String dbDriver, String username, String password)
          Initialize a database factory with the given URL, driver classname, and database credentials.
 void releaseConnection(Connection connection)
          Replace a database connection back in the pool of available connections for its parent pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataSourceDbConnectionFactory

public DataSourceDbConnectionFactory(DataSource dataSource)

Constructor for DataSourceDbConnectionFactory.

Parameters:
dataSource - a DataSource object.
Method Detail

destroy

public void destroy()
             throws SQLException

destroy

Specified by:
destroy in interface DbConnectionFactory
Throws:
SQLException - if any.

getConnection

public Connection getConnection()
                         throws SQLException

getConnection

Specified by:
getConnection in interface DbConnectionFactory
Returns:
a Connection object.
Throws:
SQLException - if any.

init

public void init(String dbUrl,
                 String dbDriver,
                 String username,
                 String password)
          throws ClassNotFoundException,
                 SQLException
Initialize a database factory with the given URL, driver classname, and database credentials. Will guarantee that the JDBC driver is loaded and that connections will be available.

Only one init method should be called.

Specified by:
init in interface DbConnectionFactory
Parameters:
dbUrl - the JDBC URL used to retrieve connections
dbDriver - a fully qualified class name for the JDBC driver that will handle this JDBC URL
username - the name to use to authenticate us with the database
password - the credentials use to authenticate the username
Throws:
ClassNotFoundException - if any.
SQLException - if any.

releaseConnection

public void releaseConnection(Connection connection)
                       throws SQLException
Replace a database connection back in the pool of available connections for its parent pool.

Specified by:
releaseConnection in interface DbConnectionFactory
Parameters:
connection - the connection to release
Throws:
SQLException - if any.


Copyright © 2011. All Rights Reserved.