Package org.apache.derby.client
Class ClientPooledConnection
- java.lang.Object
-
- org.apache.derby.client.ClientPooledConnection
-
- All Implemented Interfaces:
javax.sql.PooledConnection
- Direct Known Subclasses:
ClientXAConnection
public class ClientPooledConnection extends java.lang.Object implements javax.sql.PooledConnectionA physical connection to a data source, to be used for creating logical connections to the same data source.
-
-
Field Summary
Fields Modifier and Type Field Description private inteventIteratorsThe number of iterators going through the list of connection event listeners at the current time.private java.util.ArrayList<javax.sql.ConnectionEventListener>listeners_List ofConnectionEventListeners.private LogicalConnectionlogicalConnection_The logical connection using the physical connection.protected LogWriterlogWriter_(package private) NetXAConnectionnetXAPhysicalConnection_private booleannewPC_Tells if this pooled connection is newly created.(package private) ClientConnectionphysicalConnection_protected intrmId_Resource manager identifier.private JDBCStatementCachestatementCacheThe statement cache for the underlying physical connection.private java.util.concurrent.CopyOnWriteArrayList<javax.sql.StatementEventListener>statementEventListenersList of statement event listeners.
-
Constructor Summary
Constructors Constructor Description ClientPooledConnection(BasicClientDataSource40 ds, LogWriter logWriter, java.lang.String user, java.lang.String password)Constructor for non-XA pooled connections.ClientPooledConnection(BasicClientDataSource40 ds, LogWriter logWriter, java.lang.String user, java.lang.String password, int rmId)Constructor for XA pooled connections only.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConnectionEventListener(javax.sql.ConnectionEventListener listener)voidaddStatementEventListener(javax.sql.StatementEventListener listener)Registers a StatementEventListener with this PooledConnection object.voidclose()Closes the physical connection to the data source and frees all associated resources.private voidcreateLogicalConnection()Creates a new logical connection by performing all the required steps to be able to reuse the physical connection.protected voidfinalize()private voidfireConnectionEventListeners(SqlException exception)Fire all theConnectionEventListeners registered.java.sql.ConnectiongetConnection()Creates a logical connection.voidinformListeners(SqlException exception)Inform listeners that an error has occured on the connection, if the error severity is high enough.booleanisStatementPoolingEnabled()Tells is statement pooling is enabled or not.voidnullLogicalConnection()Used byLogicalConnection.closein some circumstances when it disassociates itself from the pooled connection.voidonStatementClose(java.sql.PreparedStatement statement)Raise the statementClosed event for all the listeners when the corresponding events occurs.voidonStatementErrorOccurred(java.sql.PreparedStatement statement, java.sql.SQLException sqle)Raise the statementErrorOccurred event for all the listeners when the corresponding events occurs.voidrecycleConnection()Inform listeners that the logical connection has been closed and that the physical connection is ready for reuse.voidremoveConnectionEventListener(javax.sql.ConnectionEventListener listener)voidremoveStatementEventListener(javax.sql.StatementEventListener listener)Removes the specified previously registered listener object from the list of components that would be informed of events with a PreparedStatement object.
-
-
-
Field Detail
-
newPC_
private boolean newPC_
Tells if this pooled connection is newly created.
-
listeners_
private java.util.ArrayList<javax.sql.ConnectionEventListener> listeners_
List ofConnectionEventListeners. Nevernull.
-
eventIterators
private int eventIterators
The number of iterators going through the list of connection event listeners at the current time. Only one thread may be iterating over the list at any time (because of synchronization), but a single thread may have multiple iterators if for instance an event listener performs database calls that trigger a new event.
-
physicalConnection_
ClientConnection physicalConnection_
-
netXAPhysicalConnection_
NetXAConnection netXAPhysicalConnection_
-
statementCache
private final JDBCStatementCache statementCache
The statement cache for the underlying physical connection.This will be
nullif statement caching is disabled (default).
-
logicalConnection_
private LogicalConnection logicalConnection_
The logical connection using the physical connection.
-
logWriter_
protected LogWriter logWriter_
-
rmId_
protected int rmId_
Resource manager identifier.
-
statementEventListeners
private final java.util.concurrent.CopyOnWriteArrayList<javax.sql.StatementEventListener> statementEventListeners
List of statement event listeners. The list is copied on each write, ensuring that it can be safely iterated over even if other threads or the listeners fired in the same thread add or remove listeners.
-
-
Constructor Detail
-
ClientPooledConnection
public ClientPooledConnection(BasicClientDataSource40 ds, LogWriter logWriter, java.lang.String user, java.lang.String password) throws java.sql.SQLException
Constructor for non-XA pooled connections.Using standard Java APIs, a CPDS is passed in. Arguments for user/password overrides anything on the data source.
- Parameters:
ds- data source creating this pooled connectionlogWriter- destination for log messagesuser- user namepassword- user password- Throws:
java.sql.SQLException- if creating the pooled connection fails due problems in the database, or problems communicating with the database
-
ClientPooledConnection
public ClientPooledConnection(BasicClientDataSource40 ds, LogWriter logWriter, java.lang.String user, java.lang.String password, int rmId) throws java.sql.SQLException
Constructor for XA pooled connections only.Using standard Java APIs, a CPDS is passed in. Arguments for user/password overrides anything on the data source.
- Parameters:
ds- data source creating this pooled connectionlogWriter- destination for log messagesuser- user namepassword- user passwordrmId- resource manager id- Throws:
java.sql.SQLException- if creating the pooled connection fails due problems in the database, or problems communicating with the database
-
-
Method Detail
-
isStatementPoolingEnabled
public boolean isStatementPoolingEnabled()
Tells is statement pooling is enabled or not.- Returns:
trueif enabled,falseif disabled.
-
finalize
protected void finalize() throws java.lang.Throwable- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
close
public void close() throws java.sql.SQLExceptionCloses the physical connection to the data source and frees all associated resources.- Specified by:
closein interfacejavax.sql.PooledConnection- Throws:
java.sql.SQLException- if closing the connection causes an error. Note that this connection can still be considered closed even if an error occurs.
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLExceptionCreates a logical connection.This is the standard API for getting a logical connection handle for a pooled connection. No "resettable" properties are passed, so user, password, and all other properties may not change.
- Specified by:
getConnectionin interfacejavax.sql.PooledConnection- Throws:
java.sql.SQLException- if creating a new logical connection fails
-
createLogicalConnection
private void createLogicalConnection() throws SqlExceptionCreates a new logical connection by performing all the required steps to be able to reuse the physical connection.- Throws:
SqlException- if there is no physical connection, or if any error occurs when recycling the physical connection or closing/craeting the logical connection
-
addConnectionEventListener
public void addConnectionEventListener(javax.sql.ConnectionEventListener listener)
- Specified by:
addConnectionEventListenerin interfacejavax.sql.PooledConnection
-
removeConnectionEventListener
public void removeConnectionEventListener(javax.sql.ConnectionEventListener listener)
- Specified by:
removeConnectionEventListenerin interfacejavax.sql.PooledConnection
-
recycleConnection
public void recycleConnection()
Inform listeners that the logical connection has been closed and that the physical connection is ready for reuse.Not public, but needs to be visible to am.LogicalConnection
-
informListeners
public void informListeners(SqlException exception)
Inform listeners that an error has occured on the connection, if the error severity is high enough.Not public, but needs to be visible to am.LogicalConnection
- Parameters:
exception- the exception that occurred on the connection
-
fireConnectionEventListeners
private void fireConnectionEventListeners(SqlException exception)
Fire all theConnectionEventListeners registered. Callers must synchronize onthisto prevent others from modifying the list of listeners.- Parameters:
exception- the exception that caused the event, ornullif it is a close event
-
nullLogicalConnection
public void nullLogicalConnection()
Used byLogicalConnection.closein some circumstances when it disassociates itself from the pooled connection.
-
addStatementEventListener
public void addStatementEventListener(javax.sql.StatementEventListener listener)
Registers a StatementEventListener with this PooledConnection object. Components that wish to be informed of events associated with the PreparedStatement object created by this PooledConnection like the close or error occurred event can register a StatementEventListener with this PooledConnection object.- Specified by:
addStatementEventListenerin interfacejavax.sql.PooledConnection- Parameters:
listener- A component that implements the StatementEventListener interface and wants to be notified of Statement closed or or Statement error occurred events
-
removeStatementEventListener
public void removeStatementEventListener(javax.sql.StatementEventListener listener)
Removes the specified previously registered listener object from the list of components that would be informed of events with a PreparedStatement object.- Specified by:
removeStatementEventListenerin interfacejavax.sql.PooledConnection- Parameters:
listener- The previously registered event listener that needs to be removed from the list of components
-
onStatementClose
public void onStatementClose(java.sql.PreparedStatement statement)
Raise the statementClosed event for all the listeners when the corresponding events occurs.- Parameters:
statement- The PreparedStatement that was closed
-
onStatementErrorOccurred
public void onStatementErrorOccurred(java.sql.PreparedStatement statement, java.sql.SQLException sqle)Raise the statementErrorOccurred event for all the listeners when the corresponding events occurs.- Parameters:
statement- The PreparedStatement on which error occurredsqle- The SQLException associated with the error that caused the invalidation of the PreparedStatements
-
-