Top Description Fields Constructors Methods
org.apache.derby.client

public Class ClientPooledConnection

extends Object
implements PooledConnection
Class Inheritance
All Implemented Interfaces
javax.sql.PooledConnection
Known Direct Subclasses
org.apache.derby.client.ClientXAConnection
Imports
java.sql.Connection, .PreparedStatement, .SQLException, java.util.ArrayList, .Iterator, java.util.concurrent.CopyOnWriteArrayList, javax.sql.ConnectionEvent, .ConnectionEventListener, .PooledConnection, .StatementEvent, .StatementEventListener, org.apache.derby.client.am.ClientMessageId, .ClientConnection, .LogWriter, .LogicalConnection, .SqlException, org.apache.derby.client.am.stmtcache.JDBCStatementCache, org.apache.derby.client.net.NetXAConnection, org.apache.derby.shared.common.error.ExceptionSeverity, org.apache.derby.shared.common.reference.SQLState

A physical connection to a data source, to be used for creating logical connections to the same data source.

Field Summary

Modifier and TypeField and Description
private int
eventIterators

The number of iterators going through the list of connection event listeners at the current time.

private ArrayList<ConnectionEventListener>
listeners_

List of ConnectionEventListeners.

private LogicalConnection
logicalConnection_

The logical connection using the physical connection.

protected LogWriter
pack-priv NetXAConnection
private boolean
newPC_

Tells if this pooled connection is newly created.

pack-priv ClientConnection
protected int
rmId_

Resource manager identifier.

private final JDBCStatementCache
statementCache

The statement cache for the underlying physical connection.

private final CopyOnWriteArrayList<StatementEventListener>
statementEventListeners

List of statement event listeners.

Constructor Summary

AccessConstructor and Description
public
ClientPooledConnection(BasicClientDataSource
data source creating this pooled connection
ds
,
LogWriter
destination for log messages
logWriter
,
String
user name
user
,
String
user password
password
)

Constructor for non-XA pooled connections.

public
ClientPooledConnection(BasicClientDataSource
data source creating this pooled connection
ds
,
LogWriter
destination for log messages
logWriter
,
String
user name
user
,
String
user password
password
,
int
resource manager id
rmId
)

Constructor for XA pooled connections only.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addConnectionEventListener(ConnectionEventListener
a component, usually the connection pool manager, that has implemented the ConnectionEventListener interface and wants to be notified when the connection is closed or has an error
listener
)

Implements javax.sql.PooledConnection.addConnectionEventListener.

Registers the given event listener so that it will be notified when an event occurs on this PooledConnection object.
public void
addStatementEventListener(StatementEventListener
A component that implements the StatementEventListener interface and wants to be notified of Statement closed or or Statement error occurred events
listener
)

Implements javax.sql.PooledConnection.addStatementEventListener.

Registers a StatementEventListener with this PooledConnection object.
public synchronized void
close()

Implements javax.sql.PooledConnection.close.

Closes the physical connection to the data source and frees all associated resources.
private void
createLogicalConnection()

Creates a new logical connection by performing all the required steps to be able to reuse the physical connection.

protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
private void
fireConnectionEventListeners(SqlException
the exception that caused the event, or null if it is a close event
exception
)

Fire all the ConnectionEventListeners registered.

public synchronized Connection
getConnection()

Implements javax.sql.PooledConnection.getConnection.

Creates a logical connection.
public void
informListeners(SqlException
the exception that occurred on the connection
exception
)

Inform listeners that an error has occured on the connection, if the error severity is high enough.

public boolean

Returns:

true if enabled, false if disabled.
isStatementPoolingEnabled
()

Tells is statement pooling is enabled or not.

public synchronized void
nullLogicalConnection()

Used by LogicalConnection.close in some circumstances when it disassociates itself from the pooled connection.

public void
onStatementClose(PreparedStatement
The PreparedStatement that was closed
statement
)

Raise the statementClosed event for all the listeners when the corresponding events occurs.

public void
onStatementErrorOccurred(PreparedStatement
The PreparedStatement on which error occurred
statement
,
SQLException
The SQLException associated with the error that caused the invalidation of the PreparedStatements
sqle
)

Raise the statementErrorOccurred event for all the listeners when the corresponding events occurs.

public synchronized void
recycleConnection()

Inform listeners that the logical connection has been closed and that the physical connection is ready for reuse.

public synchronized void
removeConnectionEventListener(ConnectionEventListener
a component, usually the connection pool manager, that has implemented the ConnectionEventListener interface and been registered with this PooledConnection object as a listener
listener
)

Implements javax.sql.PooledConnection.removeConnectionEventListener.

Removes the given event listener from the list of components that will be notified when an event occurs on this PooledConnection object.
public void
removeStatementEventListener(StatementEventListener
The previously registered event listener that needs to be removed from the list of components
listener
)

Implements javax.sql.PooledConnection.removeStatementEventListener.

Removes the specified previously registered listener object from the list of components that would be informed of events with a PreparedStatement object.
Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

eventIteratorsback to summary
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.

listeners_back to summary
private ArrayList<ConnectionEventListener> listeners_

List of ConnectionEventListeners. Never null.

logicalConnection_back to summary
private LogicalConnection logicalConnection_

The logical connection using the physical connection.

logWriter_back to summary
protected LogWriter logWriter_
netXAPhysicalConnection_back to summary
pack-priv NetXAConnection netXAPhysicalConnection_
newPC_back to summary
private boolean newPC_

Tells if this pooled connection is newly created.

physicalConnection_back to summary
pack-priv ClientConnection physicalConnection_
rmId_back to summary
protected int rmId_

Resource manager identifier.

statementCacheback to summary
private final JDBCStatementCache statementCache

The statement cache for the underlying physical connection.

This will be null if statement caching is disabled (default).

statementEventListenersback to summary
private final CopyOnWriteArrayList<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

ClientPooledConnectionback to summary
public ClientPooledConnection(BasicClientDataSource ds, LogWriter logWriter, String user, String password) throws 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:BasicClientDataSource

data source creating this pooled connection

logWriter:LogWriter

destination for log messages

user:String

user name

password:String

user password

Exceptions
SQLException:
if creating the pooled connection fails due problems in the database, or problems communicating with the database
ClientPooledConnectionback to summary
public ClientPooledConnection(BasicClientDataSource ds, LogWriter logWriter, String user, String password, int rmId) throws 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:BasicClientDataSource

data source creating this pooled connection

logWriter:LogWriter

destination for log messages

user:String

user name

password:String

user password

rmId:int

resource manager id

Exceptions
SQLException:
if creating the pooled connection fails due problems in the database, or problems communicating with the database

Method Detail

addConnectionEventListenerback to summary
public synchronized void addConnectionEventListener(ConnectionEventListener listener)

Implements javax.sql.PooledConnection.addConnectionEventListener.

Doc from javax.sql.PooledConnection.addConnectionEventListener.

Registers the given event listener so that it will be notified when an event occurs on this PooledConnection object.

Parameters
listener:ConnectionEventListener

a component, usually the connection pool manager, that has implemented the ConnectionEventListener interface and wants to be notified when the connection is closed or has an error

addStatementEventListenerback to summary
public void addStatementEventListener(StatementEventListener listener)

Implements javax.sql.PooledConnection.addStatementEventListener.

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.

Parameters
listener:StatementEventListener

A component that implements the StatementEventListener interface and wants to be notified of Statement closed or or Statement error occurred events

closeback to summary
public synchronized void close() throws SQLException

Implements javax.sql.PooledConnection.close.

Closes the physical connection to the data source and frees all associated resources.

Exceptions
SQLException:
if closing the connection causes an error. Note that this connection can still be considered closed even if an error occurs.
createLogicalConnectionback to summary
private void createLogicalConnection() throws SqlException

Creates a new logical connection by performing all the required steps to be able to reuse the physical connection.

Exceptions
SqlException:
if there is no physical connection, or if any error occurs when recycling the physical connection or closing/craeting the logical connection
finalizeback to summary
protected void finalize() throws Throwable

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Annotations
@SuppressWarnings:deprecation, removal
Exceptions
Throwable:
the Exception raised by this method
fireConnectionEventListenersback to summary
private void fireConnectionEventListeners(SqlException exception)

Fire all the ConnectionEventListeners registered. Callers must synchronize on this to prevent others from modifying the list of listeners.

Parameters
exception:SqlException

the exception that caused the event, or null if it is a close event

getConnectionback to summary
public synchronized Connection getConnection() throws SQLException

Implements javax.sql.PooledConnection.getConnection.

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

Returns:Connection

Doc from javax.sql.PooledConnection.getConnection.

a Connection object that is a handle to this PooledConnection object

Exceptions
SQLException:
if creating a new logical connection fails
informListenersback to summary
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:SqlException

the exception that occurred on the connection

isStatementPoolingEnabledback to summary
public boolean isStatementPoolingEnabled()

Tells is statement pooling is enabled or not.

Returns:boolean

true if enabled, false if disabled.

nullLogicalConnectionback to summary
public synchronized void nullLogicalConnection()

Used by LogicalConnection.close in some circumstances when it disassociates itself from the pooled connection.

onStatementCloseback to summary
public void onStatementClose(PreparedStatement statement)

Raise the statementClosed event for all the listeners when the corresponding events occurs.

Parameters
statement:PreparedStatement

The PreparedStatement that was closed

onStatementErrorOccurredback to summary
public void onStatementErrorOccurred(PreparedStatement statement, SQLException sqle)

Raise the statementErrorOccurred event for all the listeners when the corresponding events occurs.

Parameters
statement:PreparedStatement

The PreparedStatement on which error occurred

sqle:SQLException

The SQLException associated with the error that caused the invalidation of the PreparedStatements

recycleConnectionback to summary
public synchronized 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

removeConnectionEventListenerback to summary
public synchronized void removeConnectionEventListener(ConnectionEventListener listener)

Implements javax.sql.PooledConnection.removeConnectionEventListener.

Doc from javax.sql.PooledConnection.removeConnectionEventListener.

Removes the given event listener from the list of components that will be notified when an event occurs on this PooledConnection object.

Parameters
listener:ConnectionEventListener

a component, usually the connection pool manager, that has implemented the ConnectionEventListener interface and been registered with this PooledConnection object as a listener

removeStatementEventListenerback to summary
public void removeStatementEventListener(StatementEventListener listener)

Implements javax.sql.PooledConnection.removeStatementEventListener.

Removes the specified previously registered listener object from the list of components that would be informed of events with a PreparedStatement object.

Parameters
listener:StatementEventListener

The previously registered event listener that needs to be removed from the list of components