OpenNMS API 1.2.9

## org.opennms.core.resource.db
Class SimpleDbConnectionFactory

    java.lang.Object
      org.opennms.core.resource.db.SimpleDbConnectionFactory

All Implemented Interfaces:
  DbConnectionFactory

public class SimpleDbConnectionFactory
extends java.lang.Object
implements DbConnectionFactory

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).

Author:
  Lawrence Karnowski , OpenNMS

Field Summary
`protected java.lang.String` `password`
`protected java.util.Properties` `properties`
`protected java.lang.String` `url`
`protected java.lang.String` `username`

Constructor Summary
`SimpleDbConnectionFactory()`

Method Summary
`void` `destroy()` Clear all database URL and credential information so no more connections can be requested.
`java.sql.Connection` `getConnection()` Create a new connection for the given database URL.
`void` `init(java.lang.String dbUrl, java.lang.String dbDriver)` Initialize a new database pool.
`void` `init(java.lang.String dbUrl, java.lang.String dbDriver, java.util.Properties properties)` Initialize a new database pool with the given database properties.
`void` `init(java.lang.String dbUrl, java.lang.String dbDriver, java.lang.String username, java.lang.String password)` Initialize a new database pool with the given database username and password.
`void` `releaseConnection(java.sql.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

### url

    protected java.lang.String url

### username

    protected java.lang.String username

### password

    protected java.lang.String password

### properties

    protected java.util.Properties properties

Constructor Detail

### SimpleDbConnectionFactory

    public SimpleDbConnectionFactory()

Method Detail

### init

    public void init(java.lang.String dbUrl,
                     java.lang.String dbDriver)
              throws java.lang.ClassNotFoundException,
                     java.sql.SQLException

  Initialize a new database pool. This method will only load the JDBC driver.

  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 handles this JDBC URL
  Throws:
    `java.lang.ClassNotFoundException`
    `java.sql.SQLException`

### init

    public void init(java.lang.String dbUrl,
                     java.lang.String dbDriver,
                     java.lang.String username,
                     java.lang.String password)
              throws java.lang.ClassNotFoundException,
                     java.sql.SQLException

  Initialize a new database pool with the given database username and password. This method will load the JDBC driver and store the given database credentials. When a connection is requested, a new connection will be made using the credentials.

  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:
    `java.lang.ClassNotFoundException`
    `java.sql.SQLException`

### init

    public void init(java.lang.String dbUrl,
                     java.lang.String dbDriver,
                     java.util.Properties properties)
              throws java.lang.ClassNotFoundException,
                     java.sql.SQLException

  Initialize a new database pool with the given database properties. This method will load the JDBC driver and store the given database properties. When a connection is requested, a new connection will be made using the properties.

  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
    `properties` - a collection of database properties, these may be specific to your particular database
  Throws:
    `java.lang.ClassNotFoundException`
    `java.sql.SQLException`

### destroy

    public void destroy()

  Clear all database URL and credential information so no more connections can be requested.

  Specified by:
    `destroy` in interface `DbConnectionFactory`

### getConnection

    public java.sql.Connection getConnection()
                                      throws java.sql.SQLException

  Create a new connection for the given database URL. This method will check to ensure that the URL has already been registered as a valid database pool. If any database credentials or properties were registered, those will be used when creating the new connection.

  Specified by:
    `getConnection` in interface `DbConnectionFactory`
  Throws:
    `java.sql.SQLException`

### releaseConnection

    public void releaseConnection(java.sql.Connection connection)
                           throws java.sql.SQLException

  Close the given connection.

  Specified by:
    `releaseConnection` in interface `DbConnectionFactory`
  Parameters:
    `connection` - the connection to release
  Throws:
    `java.sql.SQLException`

OpenNMS API 1.2.9

Generated by ranger on May 19 2007 2335.