|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.opennms.core.resource.db.SimpleDbConnectionFactory
public class SimpleDbConnectionFactory
A trivial implementation of DbConnectionFactory that creates a
new connection for every request and does no caching or connection sharing.
Note that no real connection pooling is occurring within this class. This factory will be an inefficient connection management scheme for most real-world applications. It was designed only for development/debugging purposes and for applications that are very infrequently used. In those cases, caching idle database connections for long periods of time can be wasteful, and this pooling scheme would be appropriate.
This manager simply initializes the JDBC driver and then stores the database credential information (if any). Then when a connection is requested, a new connection is made with the stored credentials (if any).
| Field Summary | |
|---|---|
protected String |
password
|
protected Properties |
properties
|
protected String |
url
|
protected String |
username
|
| Constructor Summary | |
|---|---|
SimpleDbConnectionFactory()
|
|
| Method Summary | |
|---|---|
void |
destroy()
Clear all database URL and credential information so no more connections can be requested. |
Connection |
getConnection()
Create a new connection for the given database URL. |
void |
init(String dbUrl,
String dbDriver,
String username,
String password)
Initialize a new database pool with the given database username and password. |
void |
releaseConnection(Connection connection)
Close the given connection. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected String url
protected String username
protected String password
protected Properties properties
| Constructor Detail |
|---|
public SimpleDbConnectionFactory()
| Method Detail |
|---|
public void init(String dbUrl,
String dbDriver,
String username,
String password)
throws ClassNotFoundException,
SQLException
init in interface DbConnectionFactorydbUrl - the JDBC URL used to retrieve connectionsdbDriver - a fully qualified class name for the JDBC driver that will
handle this JDBC URLusername - the name to use to authenticate us with the databasepassword - the credentials use to authenticate the username
ClassNotFoundException
SQLExceptionpublic void destroy()
destroy in interface DbConnectionFactory
public Connection getConnection()
throws SQLException
getConnection in interface DbConnectionFactorySQLException
public void releaseConnection(Connection connection)
throws SQLException
releaseConnection in interface DbConnectionFactoryconnection - the connection to release
SQLException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||