Top Description Fields Constructors Methods
org.apache.derby.impl.jdbc

public Class EmbedPooledConnection

extends Object
implements PooledConnection, BrokeredConnectionControl
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.jdbc.BrokeredConnectionControl, javax.sql.PooledConnection
Known Direct Subclasses
org.apache.derby.impl.jdbc.EmbedXAConnection
Imports
org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.reference.Property, org.apache.derby.shared.common.error.ExceptionSeverity, org.apache.derby.iapi.sql.conn.LanguageConnectionContext, org.apache.derby.impl.jdbc.Util, .EmbedConnection, .EmbedPreparedStatement, .EmbedCallableStatement, org.apache.derby.iapi.jdbc.BrokeredConnection, .BrokeredConnectionControl, .EngineConnection, .EmbeddedDataSourceInterface, java.sql.Connection, .ResultSet, .SQLException, .Statement, .PreparedStatement, .CallableStatement, java.util.ArrayList, java.util.concurrent.CopyOnWriteArrayList, javax.sql.ConnectionEventListener, .ConnectionEvent, .StatementEvent, .StatementEventListener

A PooledConnection object is a connection object that provides hooks for connection pool management.

This is Derby's implementation of a PooledConnection for use in the following environments:

Field Summary

Modifier and TypeField and Description
private String
connString

the connection string

pack-priv BrokeredConnection
pack-priv final EmbeddedDataSourceInterface
pack-priv int
private boolean
private int
eventIterators

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

private ArrayList<ConnectionEventListener>
eventListener

The list of ConnectionEventListeners.

protected boolean
private final String
pack-priv EmbedConnection
private final boolean
requestPassword

True if the password was passed in on the connection request, false if it came from the data source property.

private final CopyOnWriteArrayList<StatementEventListener>
statementEventListeners

List of statement event listeners.

private final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final 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.

Add an event listener.

public void
addStatementEventListener(StatementEventListener
an component which implements the StatementEventListener interface that is to be registered with this PooledConnection object
listener
)

Implements javax.sql.PooledConnection.addStatementEventListener.

Registers a StatementEventListener with this PooledConnection object.

pack-priv final void
public void
checkAutoCommit(boolean
New auto commit setting
autoCommit
)

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkAutoCommit.

Allow control over setting auto commit mode.

public void
checkClose()

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkClose.

Check if the brokered connection can be closed.

public void
checkCommit()

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkCommit.

Allow control over calling commit.

public int
checkHoldCursors(int
Current holdability
holdability
,
boolean
true to downgrade the holdability, false to throw an exception.
downgrade
)

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkHoldCursors.

Are held cursors allowed.

public void
public void
checkSavepoint()

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkSavepoint.

Allow control over creating a Savepoint (JDBC 3.0)

public synchronized void
close()

Implements javax.sql.PooledConnection.close.

Close the Pooled connection.

private void
closeCurrentConnectionHandle()

In this case the Listeners are *not* notified.

public synchronized boolean
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

Returns:

a Connection object
getConnection
()

Implements javax.sql.PooledConnection.getConnection.

Create an object handle for a database connection.

public synchronized LanguageConnectionContext

Returns:

The underlying language connection.
getLanguageConnection
()

private static LanguageConnectionContext
getLanguageConnectionContext(final EmbedConnection conn)

Gets the LanguageConnectionContext for this connection.

pack-priv final Connection
pack-priv String
public synchronized EngineConnection
getRealConnection()

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.getRealConnection.

Return the real JDBC connection for the brokered connection.

pack-priv String
public boolean

Returns:

boolean is isActive is true
isActive
()

getter function for isActive

public boolean
public boolean
isIsolationLevelSetUsingSQLorJDBC()

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.isIsolationLevelSetUsingSQLorJDBC.

Returns true if isolation level has been set using either JDBC api or SQL

public synchronized void
public void
notifyException(SQLException
A sql exception
sqle
)

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.notifyException.

Notify the control class that a SQLException was thrown during a call on one of the brokered connection's methods.

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

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.onStatementClose.

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

public void
onStatementErrorOccurred(PreparedStatement
the PreparedStatement in which the error occurred
statement
,
SQLException
the SQLException that was thrown
sqle
)

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.onStatementErrorOccurred.

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

pack-priv final void
public final 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.

Remove an event listener.

public void
removeStatementEventListener(StatementEventListener
the component which implements the StatementEventListener interface that was previously registered with this PooledConnection object
listener
)

Implements javax.sql.PooledConnection.removeStatementEventListener.

Removes the specified StatementEventListener from the list of components that will be notified when the driver detects that a PreparedStatement has been closed or is invalid.

public void
resetIsolationLevelFlag()

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.resetIsolationLevelFlag.

Reset the isolation level flag used to keep state in BrokeredConnection.

pack-priv void
public String

Returns:

a string representation of the uniquie id for this pooled connection.
toString
()

Overrides java.lang.Object.toString.

Get the string representation of this pooled connection.

public Statement
wrapStatement(Statement
The original statement
s
)

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.wrapStatement.

No need to wrap statements for PooledConnections.

public PreparedStatement

Returns:

returns the wrapped PreparedStatement
wrapStatement
(PreparedStatement
PreparedStatment to be wrapped
ps
,
String
String
sql
,
Object
Object
generatedKeys
)

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.wrapStatement.

Call the setBrokeredConnectionControl method inside the EmbedPreparedStatement class to set the BrokeredConnectionControl variable to this instance of EmbedPooledConnection This will then be used to call the onStatementErrorOccurred and onStatementClose events when the corresponding events occur on the PreparedStatement

public CallableStatement

Returns:

returns the wrapped CallableStatement
wrapStatement
(CallableStatement
CallableStatment to be wrapped
cs
,
String
String
sql
)

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.wrapStatement.

Call the setBrokeredConnectionControl method inside the EmbedCallableStatement class to set the BrokeredConnectionControl variable to this instance of EmbedPooledConnection This will then be used to call the onStatementErrorOccurred and onStatementClose events when the corresponding events occur on the CallableStatement

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

connStringback to summary
private String connString

the connection string

currentConnectionHandleback to summary
pack-priv BrokeredConnection currentConnectionHandle
dataSourceback to summary
pack-priv final EmbeddedDataSourceInterface dataSource
defaultIsolationLevelback to summary
pack-priv int defaultIsolationLevel
defaultReadOnlyback to summary
private boolean defaultReadOnly
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.

eventListenerback to summary
private ArrayList<ConnectionEventListener> eventListener

The list of ConnectionEventListeners. It is initially null and will be initialized lazily when the first listener is added.

isActiveback to summary
protected boolean isActive
passwordback to summary
private final String password
realConnectionback to summary
pack-priv EmbedConnection realConnection
requestPasswordback to summary
private final boolean requestPassword

True if the password was passed in on the connection request, false if it came from the data source property.

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.

usernameback to summary
private final String username

Constructor Detail

EmbedPooledConnectionback to summary
public EmbedPooledConnection(EmbeddedDataSourceInterface ds, String u, String p, boolean requestPassword) throws SQLException

Method Detail

addConnectionEventListenerback to summary
public final synchronized void addConnectionEventListener(ConnectionEventListener listener)

Implements javax.sql.PooledConnection.addConnectionEventListener.

Add an event listener.

Parameters
listener:ConnectionEventListener

Doc from javax.sql.PooledConnection.addConnectionEventListener.

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 notified when PreparedStatements created by the connection are closed or are detected to be invalid may use this method to register a StatementEventListener with this PooledConnection object.

Parameters
listener:StatementEventListener

an component which implements the StatementEventListener interface that is to be registered with this PooledConnection object

checkActiveback to summary
pack-priv final void checkActive() throws SQLException
checkAutoCommitback to summary
public void checkAutoCommit(boolean autoCommit) throws SQLException

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkAutoCommit.

Allow control over setting auto commit mode.

Parameters
autoCommit:boolean

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkAutoCommit.

New auto commit setting

Exceptions
SQLException:

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkAutoCommit.

on error

checkCloseback to summary
public void checkClose() throws SQLException

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkClose.

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkClose.

Check if the brokered connection can be closed.

Exceptions
SQLException:
if it is not allowed to call close on the brokered connection
See Also
BrokeredConnectionControl#checkClose()
checkCommitback to summary
public void checkCommit() throws SQLException

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkCommit.

Allow control over calling commit.

Exceptions
SQLException:

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkCommit.

on error

checkHoldCursorsback to summary
public int checkHoldCursors(int holdability, boolean downgrade) throws SQLException

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkHoldCursors.

Are held cursors allowed.

Parameters
holdability:int

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkHoldCursors.

Current holdability

downgrade:boolean

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkHoldCursors.

true to downgrade the holdability, false to throw an exception.

Returns:int

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkHoldCursors.

whether cursors can be held across commits

Exceptions
SQLException:

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkHoldCursors.

on error

checkRollbackback to summary
public void checkRollback() throws SQLException

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkRollback.

Allow control over calling rollback.

Exceptions
SQLException:

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkRollback.

on error

checkSavepointback to summary
public void checkSavepoint() throws SQLException

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkSavepoint.

Allow control over creating a Savepoint (JDBC 3.0)

Exceptions
SQLException:

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.checkSavepoint.

on error

closeback to summary
public synchronized void close() throws SQLException

Implements javax.sql.PooledConnection.close.

Close the Pooled connection.

Exceptions
SQLException:
- if a database-access error occurs.
closeCurrentConnectionHandleback to summary
private void closeCurrentConnectionHandle() throws SQLException

In this case the Listeners are *not* notified. JDBC 3.0 spec section 11.4

closingConnectionback to summary
public synchronized boolean closingConnection() throws SQLException

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.closingConnection.

Close called on BrokeredConnection. If this call returns true then getRealConnection().close() will be called. Notify listners that connection is closed. Don't close the underlying real connection as it is pooled.

Returns:boolean

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.closingConnection.

true if getRealConnection().close() will be called

Exceptions
SQLException:

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.closingConnection.

on error

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.

Create an object handle for a database connection.

Returns:Connection

a Connection object

Exceptions
SQLException:
- if a database-access error occurs.
getLanguageConnectionback to summary
public synchronized LanguageConnectionContext getLanguageConnection() throws SQLException
Returns:LanguageConnectionContext

The underlying language connection.

getLanguageConnectionContextback to summary
private static LanguageConnectionContext getLanguageConnectionContext(final EmbedConnection conn)

Gets the LanguageConnectionContext for this connection.

getNewCurrentConnectionHandleback to summary
pack-priv final Connection getNewCurrentConnectionHandle() throws SQLException
getPasswordback to summary
pack-priv String getPassword()
getRealConnectionback to summary
public synchronized EngineConnection getRealConnection() throws SQLException

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.getRealConnection.

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.getRealConnection.

Return the real JDBC connection for the brokered connection.

Returns:EngineConnection

the real JDBC connection

Exceptions
SQLException:
on error
getUsernameback to summary
pack-priv String getUsername()
isActiveback to summary
public boolean isActive()

getter function for isActive

Returns:boolean

boolean is isActive is true

isInGlobalTransactionback to summary
public boolean isInGlobalTransaction()

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.isInGlobalTransaction.

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.isInGlobalTransaction.

Is this a global transaction

Returns:boolean

true if this is a global XA transaction

See Also
BrokeredConnectionControl#isInGlobalTransaction()
isIsolationLevelSetUsingSQLorJDBCback to summary
public boolean isIsolationLevelSetUsingSQLorJDBC() throws SQLException

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.isIsolationLevelSetUsingSQLorJDBC.

Returns true if isolation level has been set using either JDBC api or SQL

Returns:boolean

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.isIsolationLevelSetUsingSQLorJDBC.

true if isolation level has been set by user

Exceptions
SQLException:

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.isIsolationLevelSetUsingSQLorJDBC.

on error

notifyErrorback to summary
public synchronized void notifyError(SQLException exception)
notifyExceptionback to summary
public void notifyException(SQLException sqle)

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.notifyException.

Notify the control class that a SQLException was thrown during a call on one of the brokered connection's methods.

Parameters
sqle:SQLException

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.notifyException.

A sql exception

onStatementCloseback to summary
public void onStatementClose(PreparedStatement statement)

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.onStatementClose.

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)

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.onStatementErrorOccurred.

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

Parameters
statement:PreparedStatement

the PreparedStatement in which the error occurred

sqle:SQLException

the SQLException that was thrown

openRealConnectionback to summary
pack-priv final void openRealConnection() throws SQLException
removeConnectionEventListenerback to summary
public final synchronized void removeConnectionEventListener(ConnectionEventListener listener)

Implements javax.sql.PooledConnection.removeConnectionEventListener.

Remove an event listener.

Parameters
listener:ConnectionEventListener

Doc from javax.sql.PooledConnection.removeConnectionEventListener.

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 StatementEventListener from the list of components that will be notified when the driver detects that a PreparedStatement has been closed or is invalid.

Parameters
listener:StatementEventListener

the component which implements the StatementEventListener interface that was previously registered with this PooledConnection object

resetIsolationLevelFlagback to summary
public void resetIsolationLevelFlag() throws SQLException

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.resetIsolationLevelFlag.

Reset the isolation level flag used to keep state in BrokeredConnection. It will get set to true when isolation level is set using JDBC/SQL. It will get reset to false at the start and the end of a global transaction.

Exceptions
SQLException:

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.resetIsolationLevelFlag.

on error

resetRealConnectionback to summary
pack-priv void resetRealConnection() throws SQLException
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Get the string representation of this pooled connection. A pooled connection is assigned a separate id from a physical connection. When a container calls PooledConnection.toString(), it gets the string representation of this id. This is useful for developers implementing connection pools when they are trying to debug pooled connections.

Returns:String

a string representation of the uniquie id for this pooled connection.

wrapStatementback to summary
public Statement wrapStatement(Statement s) throws SQLException

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.wrapStatement.

No need to wrap statements for PooledConnections.

Parameters
s:Statement

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.wrapStatement.

The original statement

Returns:Statement

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.wrapStatement.

a wrapper statement

Exceptions
SQLException:

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.wrapStatement.

on error

wrapStatementback to summary
public PreparedStatement wrapStatement(PreparedStatement ps, String sql, Object generatedKeys) throws SQLException

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.wrapStatement.

Call the setBrokeredConnectionControl method inside the EmbedPreparedStatement class to set the BrokeredConnectionControl variable to this instance of EmbedPooledConnection This will then be used to call the onStatementErrorOccurred and onStatementClose events when the corresponding events occur on the PreparedStatement

Parameters
ps:PreparedStatement

PreparedStatment to be wrapped

sql:String

String

generatedKeys:Object

Object

Returns:PreparedStatement

returns the wrapped PreparedStatement

Exceptions
SQLException:

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.wrapStatement.

on error

wrapStatementback to summary
public CallableStatement wrapStatement(CallableStatement cs, String sql) throws SQLException

Implements org.apache.derby.iapi.jdbc.BrokeredConnectionControl.wrapStatement.

Call the setBrokeredConnectionControl method inside the EmbedCallableStatement class to set the BrokeredConnectionControl variable to this instance of EmbedPooledConnection This will then be used to call the onStatementErrorOccurred and onStatementClose events when the corresponding events occur on the CallableStatement

Parameters
cs:CallableStatement

CallableStatment to be wrapped

sql:String

String

Returns:CallableStatement

returns the wrapped CallableStatement

Exceptions
SQLException:

Doc from org.apache.derby.iapi.jdbc.BrokeredConnectionControl.wrapStatement.

on error