com.p6spy.engine.spy
Class P6PooledConnection

java.lang.Object
  extended bycom.p6spy.engine.spy.P6PooledConnection
All Implemented Interfaces:
PooledConnection

public class P6PooledConnection
extends Object
implements PooledConnection

This class is used to manage pooled connections. Instances are created by the P6ConnectionPoolDataSource factory class, and have a physical Connection. Instances of this class are usable for as long as the physical connections is open. Calls to getConnection on this class produce instances of the P6ProxyConnection class.

See Also:
PooledConnection, ConnectionPoolDataSource, P6ConnectionPoolDataSource, P6ProxyConnection

Field Summary
static int EVENT_TYPE_CLOSE
           
static int EVENT_TYPE_ERROR
           
protected  Connection proxyConnection
           
protected  Connection realConnection
           
 
Constructor Summary
P6PooledConnection(Connection connection)
          P6ConnectionPoolDataSource creates a realConnection (a P6 wrapper for the realDriver Connection) and then constructs this to contain it.
 
Method Summary
 void addConnectionEventListener(ConnectionEventListener eventTarget)
          Registers submitted ConnectionEventListener as a target for delivery of events of the ConnectionEvents type, either close or error events.
 void close()
          Connection Pool managers such as EJB containers call this when they want to close the real connections, as during shutdown or reconfiguration, or when this instance has delivered a connectionErrorOccured event.
protected  void deliverEvent(int type, SQLException sqlException)
          Creates and delivers a ConnectionEvent to all registered (as registered in addConnectionEventListener) event targets.
 Connection getConnection()
          Creates a new P6ProxyConnection, associates it with the real connection, and returns it.
 void removeConnectionEventListener(ConnectionEventListener eventTarget)
          Removes ConnectionEventListeners from the list of targets for event delivery.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

proxyConnection

protected Connection proxyConnection

realConnection

protected Connection realConnection

EVENT_TYPE_CLOSE

public static final int EVENT_TYPE_CLOSE
See Also:
Constant Field Values

EVENT_TYPE_ERROR

public static final int EVENT_TYPE_ERROR
See Also:
Constant Field Values
Constructor Detail

P6PooledConnection

public P6PooledConnection(Connection connection)
P6ConnectionPoolDataSource creates a realConnection (a P6 wrapper for the realDriver Connection) and then constructs this to contain it.

Parameters:
connection - the "real" or "physical" connection, i.e. the type of object that would result from a call to P6SpyDriver.connect()
Method Detail

getConnection

public Connection getConnection()
                         throws SQLException
Creates a new P6ProxyConnection, associates it with the real connection, and returns it. The specified behavior of this method is to return a new Connection (P6ProxyConnection) one each call. The specified behavior of the PooledConnection class is that at most one Connection is associated with the PooledConnection at any time, so any existing Connection is closed. If the real connection has been closed, then SQLException will be thrown. Other SQLExceptions may be thrown from the close call to the real connection.

Specified by:
getConnection in interface PooledConnection
Throws:
SQLException

close

public void close()
           throws SQLException
Connection Pool managers such as EJB containers call this when they want to close the real connections, as during shutdown or reconfiguration, or when this instance has delivered a connectionErrorOccured event. After this call, the instance can no longer be used.

Specified by:
close in interface PooledConnection
Throws:
SQLException - from underlying real connection close

addConnectionEventListener

public void addConnectionEventListener(ConnectionEventListener eventTarget)
Registers submitted ConnectionEventListener as a target for delivery of events of the ConnectionEvents type, either close or error events.

Specified by:
addConnectionEventListener in interface PooledConnection
Parameters:
eventTarget - listener to be notified with ConnectionEvents

removeConnectionEventListener

public void removeConnectionEventListener(ConnectionEventListener eventTarget)
Removes ConnectionEventListeners from the list of targets for event delivery.

Specified by:
removeConnectionEventListener in interface PooledConnection
Parameters:
eventTarget - listener to be removed

deliverEvent

protected void deliverEvent(int type,
                            SQLException sqlException)
Creates and delivers a ConnectionEvent to all registered (as registered in addConnectionEventListener) event targets. The newly created ConnectionEvent instance contains the provided sqlException.

Parameters:
type - indicating connectionClosed (P6PooledConnection.EVENT_TYPE_CLOSE) or connectionErrorOccurred (P6PooledConnection.EVENT_TYPE_ERROR)
Throws:
SQLException