com.ibm.as400.access
Class AS400JDBCPooledConnection

java.lang.Object
  |
  +--com.ibm.as400.access.AS400JDBCPooledConnection
All Implemented Interfaces:
javax.sql.PooledConnection
Direct Known Subclasses:
AS400JDBCXAConnection

public class AS400JDBCPooledConnection
extends java.lang.Object
implements javax.sql.PooledConnection

The AS400JDBCPooledConnection class represents a connection object that provides hooks for connection pool management. The following example creates an AS400JDBCPooledConnection object that can be used to cache JDBC connections.

// Create a data source for making the connection. AS400JDBCConnectionPoolDataSource dataSource = new AS400JDBCConnectionPoolDataSource("myAS400"); datasource.setUser("Mickey Mouse"); datasource.setPassword("IAMNORAT"); // Get a PooledConnection and get the connection handle to the database. AS400JDBCPooledConnection pooledConnection = datasource.getPooledConnection(); Connection connection = pooledConnection.getConnection(); ... work with the connection handle. // Close the connection handle to make available for reuse (physical connection not closed). connection.close(); // Reuse the connection somewhere else. Connection reusedConnection = pooledConnection.getConnection(); ... work with the connection handle. reusedConnection.close(); // Close the physical connection. pooledConnection.close();

AS400JDBCPooledConnection objects generate the following events:


Method Summary
 void addConnectionEventListener(javax.sql.ConnectionEventListener listener)
          Adds a ConnectionEventListener.
 void close()
          Closes the physical connection.
 void closeAll()
          Closes all the Statement objects that have been opened by this PooledConnection object.
 java.sql.Connection getConnection()
          Returns the connection handle to the database.
 long getInactivityTime()
          Returns the elapsed time the connection has been idle waiting in the pool.
 long getInUseTime()
          Returns the elapsed time the connection has been in use.
 long getLifeSpan()
          Returns the elapsed time the pooled connection has been alive.
 int getUseCount()
          Returns the number of times the pooled connection has been used.
 boolean isInUse()
          Indicates if the pooled connection is in use.
 void removeConnectionEventListener(javax.sql.ConnectionEventListener listener)
          Removes a ConnectionEventListener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addConnectionEventListener

public void addConnectionEventListener(javax.sql.ConnectionEventListener listener)
Adds a ConnectionEventListener.
Specified by:
addConnectionEventListener in interface javax.sql.PooledConnection
Parameters:
listener - The listener.

close

public void close()
           throws java.sql.SQLException
Closes the physical connection.
Specified by:
close in interface javax.sql.PooledConnection
Throws:
java.sql.SQLException - If an error occurs closing the connection.

closeAll

public void closeAll()
              throws java.sql.SQLException
Closes all the Statement objects that have been opened by this PooledConnection object. This method is not supported.
Throws:
java.sql.SQLException - Always thrown because this method is not supported.

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Returns the connection handle to the database.
Specified by:
getConnection in interface javax.sql.PooledConnection
Returns:
The connection handle.
Throws:
java.sql.SQLException - If a database error occurs.

getInactivityTime

public long getInactivityTime()
Returns the elapsed time the connection has been idle waiting in the pool.
Returns:
The idle time.

getInUseTime

public long getInUseTime()
Returns the elapsed time the connection has been in use.
Returns:
The elapsed time.

getLifeSpan

public long getLifeSpan()
Returns the elapsed time the pooled connection has been alive.
Returns:
The elapsed time.

getUseCount

public int getUseCount()
Returns the number of times the pooled connection has been used.
Returns:
The number of times used.

isInUse

public boolean isInUse()
Indicates if the pooled connection is in use.
Returns:
true if the pooled connection is in use; false otherwise.

removeConnectionEventListener

public void removeConnectionEventListener(javax.sql.ConnectionEventListener listener)
Removes a ConnectionEventListener.
Specified by:
removeConnectionEventListener in interface javax.sql.PooledConnection
Parameters:
listener - The listener to be removed.