OpenNMS API 1.2.3

org.opennms.netmgt.config
Class DatabaseConnectionFactory.CachedConnection

java.lang.Object
  extended byorg.opennms.netmgt.config.DatabaseConnectionFactory.CachedConnection
All Implemented Interfaces:
java.sql.Connection
Enclosing class:
DatabaseConnectionFactory

static final class DatabaseConnectionFactory.CachedConnection
extends java.lang.Object
implements java.sql.Connection

This class is used to represent a cached database connection within this factory. The cached connection may or may not have been collected by the main java garbage collector thread. If the connection still exists and is not in use and does not have any errors then it may be reissued to another thread requestor.

Author:
Brian Weaver , OpenNMS

Field Summary
private  java.sql.Connection m_delegate
          The cached connection
private  boolean m_hadError
          This flag is set to true if the connection experienced an error.
private  boolean m_inUse
          This flag is set to true if the connection is currently in use.
private  long m_lastUse
          This value is used to mark the last time the connection was returned to the pool.
private  DatabaseConnectionFactory m_owner
          The owner of the cached connection
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Constructor Summary
(package private) DatabaseConnectionFactory.CachedConnection(java.sql.Connection dbc, DatabaseConnectionFactory owner)
          The class constructor used to create a new cached connection for a particular factory.
 
Method Summary
(package private)  long age()
          Returns the current age of the connection since it was last used in milliseconds.
private  void checkAccess()
          This method checks the access of the connection.
 void clearWarnings()
          Forwards the request to the encapsulated connection after access to the connection is granted.
 void close()
          Closes the SQL connection for the owner of the conneciton.
 void commit()
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.sql.Statement createStatement()
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 boolean getAutoCommit()
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.lang.String getCatalog()
          Forwards the request to the encapsulated connection after access to the connection is granted.
 int getHoldability()
           
 java.sql.DatabaseMetaData getMetaData()
          Forwards the request to the encapsulated connection after access to the connection is granted.
 int getTransactionIsolation()
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.util.Map getTypeMap()
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.sql.SQLWarning getWarnings()
          Forwards the request to the encapsulated connection after access to the connection is granted.
(package private)  boolean isAvailable()
          Returns true if the cached connection is available for use.
(package private)  boolean isBad()
          Returns true if the connection has experienced any errors.
 boolean isClosed()
          Forwards the request to the encapuslated connection, or returns true if the connection is not in use.
 boolean isReadOnly()
          Forwards the request to the encapsulated connection after access to the connection is granted.
(package private)  void markUsed()
          Marks the connection as in use
 java.lang.String nativeSQL(java.lang.String sql)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.sql.CallableStatement prepareCall(java.lang.String sql)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 void releaseSavepoint(java.sql.Savepoint savepoint)
           
 void rollback()
          Forwards the request to the encapsulated connection after access to the connection is granted.
 void rollback(java.sql.Savepoint savepoint)
           
 void setAutoCommit(boolean autoCommit)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 void setCatalog(java.lang.String catalog)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 void setHoldability(int holdability)
           
 void setReadOnly(boolean readOnly)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.sql.Savepoint setSavepoint()
           
 java.sql.Savepoint setSavepoint(java.lang.String name)
           
 void setTransactionIsolation(int level)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 void setTypeMap(java.util.Map map)
          Forwards the request to the encapsulated connection after access to the connection is granted.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_delegate

private final java.sql.Connection m_delegate
The cached connection


m_owner

private final DatabaseConnectionFactory m_owner
The owner of the cached connection


m_inUse

private boolean m_inUse
This flag is set to true if the connection is currently in use.


m_hadError

private boolean m_hadError
This flag is set to true if the connection experienced an error.


m_lastUse

private long m_lastUse
This value is used to mark the last time the connection was returned to the pool. If the last use reaches a certian time and the connection is on the bottom of the stack, then it is released. This time is set via the system time.

See Also:
System.currentTimeMillis()
Constructor Detail

DatabaseConnectionFactory.CachedConnection

DatabaseConnectionFactory.CachedConnection(java.sql.Connection dbc,
                                           DatabaseConnectionFactory owner)
The class constructor used to create a new cached connection for a particular factory.

Parameters:
dbc - The database connection to cache.
owner - The owner of the cached connection.
Method Detail

checkAccess

private void checkAccess()
                  throws java.sql.SQLException
This method checks the access of the connection. If the connection is not marked in use then access is denied via an exception.

Throws:
java.sql.SQLException - Thrown if access is denied.

isAvailable

boolean isAvailable()
Returns true if the cached connection is available for use.


markUsed

void markUsed()
Marks the connection as in use


isBad

boolean isBad()
Returns true if the connection has experienced any errors.


age

long age()
Returns the current age of the connection since it was last used in milliseconds. The time is based upon the last time the connection was returned to the database pool. If the connection is kept in use then the value returned by this method is of no value.

Returns:
The time since the connection was last closed.

close

public void close()
           throws java.sql.SQLException
Closes the SQL connection for the owner of the conneciton. The close request may be forwarded to the encapsulate connection if an error has occured or the connection is read-only. Otherwise the connection is returned to the connection pool for reuse.

Specified by:
close in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

isClosed

public boolean isClosed()
                 throws java.sql.SQLException
Forwards the request to the encapuslated connection, or returns true if the connection is not in use.

Specified by:
isClosed in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

createStatement

public java.sql.Statement createStatement()
                                   throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                            throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int autoGeneratedKeys)
                                            throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int[] columnIndexes)
                                            throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   java.lang.String[] columnNames)
                                            throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql)
                                       throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

nativeSQL

public java.lang.String nativeSQL(java.lang.String sql)
                           throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
nativeSQL in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
setAutoCommit in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

getAutoCommit

public boolean getAutoCommit()
                      throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
getAutoCommit in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

commit

public void commit()
            throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
commit in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

rollback

public void rollback()
              throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
rollback in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

rollback

public void rollback(java.sql.Savepoint savepoint)
              throws java.sql.SQLException
Specified by:
rollback in interface java.sql.Connection
Throws:
java.sql.SQLException

getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
getMetaData in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

setReadOnly

public void setReadOnly(boolean readOnly)
                 throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
setReadOnly in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

isReadOnly

public boolean isReadOnly()
                   throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
isReadOnly in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

setCatalog

public void setCatalog(java.lang.String catalog)
                throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
setCatalog in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

getCatalog

public java.lang.String getCatalog()
                            throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
getCatalog in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

setTransactionIsolation

public void setTransactionIsolation(int level)
                             throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
setTransactionIsolation in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

getTransactionIsolation

public int getTransactionIsolation()
                            throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
getTransactionIsolation in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
getWarnings in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
clearWarnings in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

createStatement

public java.sql.Statement createStatement(int resultSetType,
                                          int resultSetConcurrency)
                                   throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

createStatement

public java.sql.Statement createStatement(int resultSetType,
                                          int resultSetConcurrency,
                                          int resultSetHoldability)
                                   throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int resultSetType,
                                                   int resultSetConcurrency)
                                            throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int resultSetType,
                                                   int resultSetConcurrency,
                                                   int resultSetHoldability)
                                            throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                              int resultSetType,
                                              int resultSetConcurrency)
                                       throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                              int resultSetType,
                                              int resultSetConcurrency,
                                              int resultSetHoldability)
                                       throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

getTypeMap

public java.util.Map getTypeMap()
                         throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
getTypeMap in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

setTypeMap

public void setTypeMap(java.util.Map map)
                throws java.sql.SQLException
Forwards the request to the encapsulated connection after access to the connection is granted.

Specified by:
setTypeMap in interface java.sql.Connection
Throws:
java.sql.SQLException - May be thrown by the encapsulated connection

toString

public java.lang.String toString()

getHoldability

public int getHoldability()
                   throws java.sql.SQLException
Specified by:
getHoldability in interface java.sql.Connection
Throws:
java.sql.SQLException

setHoldability

public void setHoldability(int holdability)
                    throws java.sql.SQLException
Specified by:
setHoldability in interface java.sql.Connection
Throws:
java.sql.SQLException

setSavepoint

public java.sql.Savepoint setSavepoint()
                                throws java.sql.SQLException
Specified by:
setSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException

setSavepoint

public java.sql.Savepoint setSavepoint(java.lang.String name)
                                throws java.sql.SQLException
Specified by:
setSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException

releaseSavepoint

public void releaseSavepoint(java.sql.Savepoint savepoint)
                      throws java.sql.SQLException
Specified by:
releaseSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException

OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.