org.apache.derby.jdbc
Class EmbedPooledConnection

java.lang.Object
  extended by org.apache.derby.jdbc.EmbedPooledConnection
All Implemented Interfaces:
javax.sql.PooledConnection, BrokeredConnectionControl
Direct Known Subclasses:
EmbedPooledConnection40, EmbedXAConnection

 class EmbedPooledConnection
extends java.lang.Object
implements javax.sql.PooledConnection, BrokeredConnectionControl

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
private  int connectionId
          The id for this connection.
private  java.lang.String connString
          the connection string
(package private)  BrokeredConnection currentConnectionHandle
           
(package private)  ReferenceableDataSource dataSource
           
(package private)  int defaultIsolationLevel
           
private  boolean defaultReadOnly
           
private  int eventIterators
          The number of iterators going through the list of connection event listeners at the current time.
private  java.util.ArrayList eventListener
          The list of ConnectionEventListeners.
private static int idCounter
          Static counter for connection ids
protected  boolean isActive
           
private  java.lang.String password
           
(package private)  EmbedConnection realConnection
           
private  boolean requestPassword
          True if the password was passed in on the connection request, false if it came from the data source property.
private  java.lang.String username
           
 
Constructor Summary
EmbedPooledConnection(ReferenceableDataSource ds, java.lang.String u, java.lang.String p, boolean requestPassword)
           
 
Method Summary
 void addConnectionEventListener(javax.sql.ConnectionEventListener listener)
          Add an event listener.
(package private)  void checkActive()
           
 void checkAutoCommit(boolean autoCommit)
          Allow control over setting auto commit mode.
 void checkClose()
          Check if the brokered connection can be closed.
 void checkCommit()
          Allow control over calling commit.
 int checkHoldCursors(int holdability, boolean downgrade)
          Are held cursors allowed.
 void checkRollback()
          Allow control over calling rollback.
 void checkSavepoint()
          Allow control over creating a Savepoint (JDBC 3.0)
 void close()
          Close the Pooled connection.
private  void closeCurrentConnectionHandle()
          In this case the Listeners are *not* notified.
 boolean closingConnection()
          Close called on BrokeredConnection.
private  void fireConnectionEventListeners(java.sql.SQLException exception)
          Fire all the ConnectionEventListeners registered.
 java.sql.Connection getConnection()
          Create an object handle for a database connection.
 LanguageConnectionContext getLanguageConnection()
           
(package private)  java.sql.Connection getNewCurrentConnectionHandle()
           
(package private)  java.lang.String getPassword()
           
 EngineConnection getRealConnection()
          Return the real JDBC connection for the brokered connection.
(package private)  java.lang.String getUsername()
           
 boolean isInGlobalTransaction()
          Is this a global transaction
 boolean isIsolationLevelSetUsingSQLorJDBC()
          Returns true if isolation level has been set using either JDBC api or SQL
private  int nextId()
           
 void notifyError(java.sql.SQLException exception)
           
 void notifyException(java.sql.SQLException sqle)
          Notify the control class that a SQLException was thrown during a call on one of the brokered connection's methods.
 void onStatementClose(java.sql.PreparedStatement statement)
          Dummy implementation for the actual methods found in org.apache.derby.jdbc.EmbedPooledConnection40
 void onStatementErrorOccurred(java.sql.PreparedStatement statement, java.sql.SQLException sqle)
          Dummy implementation for the actual methods found in org.apache.derby.jdbc.EmbedPooledConnection40
(package private)  void openRealConnection()
           
 void removeConnectionEventListener(javax.sql.ConnectionEventListener listener)
          Remove an event listener.
 void resetIsolationLevelFlag()
          Reset the isolation level flag used to keep state in BrokeredConnection.
(package private)  void resetRealConnection()
           
 java.lang.String toString()
          Get the string representation of this pooled connection.
 java.sql.CallableStatement wrapStatement(java.sql.CallableStatement cs, java.lang.String sql)
          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
 java.sql.PreparedStatement wrapStatement(java.sql.PreparedStatement ps, java.lang.String sql, java.lang.Object generatedKeys)
          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
 java.sql.Statement wrapStatement(java.sql.Statement s)
          No need to wrap statements for PooledConnections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.sql.PooledConnection
addStatementEventListener, removeStatementEventListener
 

Field Detail

idCounter

private static int idCounter
Static counter for connection ids


connectionId

private int connectionId
The id for this connection.


connString

private java.lang.String connString
the connection string


eventListener

private java.util.ArrayList eventListener
The list of ConnectionEventListeners. It is initially null and will be initialized lazily when the first listener is added.


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.


realConnection

EmbedConnection realConnection

defaultIsolationLevel

int defaultIsolationLevel

defaultReadOnly

private boolean defaultReadOnly

currentConnectionHandle

BrokeredConnection currentConnectionHandle

dataSource

final ReferenceableDataSource dataSource

username

private final java.lang.String username

password

private final java.lang.String password

requestPassword

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


isActive

protected boolean isActive
Constructor Detail

EmbedPooledConnection

EmbedPooledConnection(ReferenceableDataSource ds,
                      java.lang.String u,
                      java.lang.String p,
                      boolean requestPassword)
                throws java.sql.SQLException
Throws:
java.sql.SQLException
Method Detail

nextId

private int nextId()

getUsername

java.lang.String getUsername()

getPassword

java.lang.String getPassword()

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Create an object handle for a database connection.

Specified by:
getConnection in interface javax.sql.PooledConnection
Returns:
a Connection object
Throws:
java.sql.SQLException - - if a database-access error occurs.

openRealConnection

final void openRealConnection()
                       throws java.sql.SQLException
Throws:
java.sql.SQLException

getNewCurrentConnectionHandle

final java.sql.Connection getNewCurrentConnectionHandle()

closeCurrentConnectionHandle

private void closeCurrentConnectionHandle()
                                   throws java.sql.SQLException
In this case the Listeners are *not* notified. JDBC 3.0 spec section 11.4

Throws:
java.sql.SQLException

resetRealConnection

void resetRealConnection()
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

close

public void close()
           throws java.sql.SQLException
Close the Pooled connection.

Specified by:
close in interface javax.sql.PooledConnection
Throws:
java.sql.SQLException - - if a database-access error occurs.

addConnectionEventListener

public final void addConnectionEventListener(javax.sql.ConnectionEventListener listener)
Add an event listener.

Specified by:
addConnectionEventListener in interface javax.sql.PooledConnection

removeConnectionEventListener

public final void removeConnectionEventListener(javax.sql.ConnectionEventListener listener)
Remove an event listener.

Specified by:
removeConnectionEventListener in interface javax.sql.PooledConnection

getRealConnection

public EngineConnection getRealConnection()
                                   throws java.sql.SQLException
Description copied from interface: BrokeredConnectionControl
Return the real JDBC connection for the brokered connection.

Specified by:
getRealConnection in interface BrokeredConnectionControl
Throws:
java.sql.SQLException

getLanguageConnection

public LanguageConnectionContext getLanguageConnection()
                                                throws java.sql.SQLException
Returns:
The underlying language connection.
Throws:
java.sql.SQLException

notifyError

public void notifyError(java.sql.SQLException exception)

fireConnectionEventListeners

private void fireConnectionEventListeners(java.sql.SQLException exception)
Fire all the ConnectionEventListeners registered. Callers must synchronize on this to prevent others from modifying the list of listeners.

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

checkActive

final void checkActive()
                throws java.sql.SQLException
Throws:
java.sql.SQLException

isIsolationLevelSetUsingSQLorJDBC

public boolean isIsolationLevelSetUsingSQLorJDBC()
                                          throws java.sql.SQLException
Returns true if isolation level has been set using either JDBC api or SQL

Specified by:
isIsolationLevelSetUsingSQLorJDBC in interface BrokeredConnectionControl
Throws:
java.sql.SQLException

resetIsolationLevelFlag

public void resetIsolationLevelFlag()
                             throws java.sql.SQLException
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.

Specified by:
resetIsolationLevelFlag in interface BrokeredConnectionControl
Throws:
java.sql.SQLException

isInGlobalTransaction

public boolean isInGlobalTransaction()
Description copied from interface: BrokeredConnectionControl
Is this a global transaction

Specified by:
isInGlobalTransaction in interface BrokeredConnectionControl
Returns:
true if this is a global XA transaction
See Also:
BrokeredConnectionControl.isInGlobalTransaction()

notifyException

public void notifyException(java.sql.SQLException sqle)
Notify the control class that a SQLException was thrown during a call on one of the brokered connection's methods.

Specified by:
notifyException in interface BrokeredConnectionControl

checkAutoCommit

public void checkAutoCommit(boolean autoCommit)
                     throws java.sql.SQLException
Allow control over setting auto commit mode.

Specified by:
checkAutoCommit in interface BrokeredConnectionControl
Throws:
java.sql.SQLException

checkHoldCursors

public int checkHoldCursors(int holdability,
                            boolean downgrade)
                     throws java.sql.SQLException
Are held cursors allowed.

Specified by:
checkHoldCursors in interface BrokeredConnectionControl
downgrade - true to downgrade the holdability, false to throw an exception.
Throws:
java.sql.SQLException

checkSavepoint

public void checkSavepoint()
                    throws java.sql.SQLException
Allow control over creating a Savepoint (JDBC 3.0)

Specified by:
checkSavepoint in interface BrokeredConnectionControl
Throws:
java.sql.SQLException

checkRollback

public void checkRollback()
                   throws java.sql.SQLException
Allow control over calling rollback.

Specified by:
checkRollback in interface BrokeredConnectionControl
Throws:
java.sql.SQLException

checkCommit

public void checkCommit()
                 throws java.sql.SQLException
Allow control over calling commit.

Specified by:
checkCommit in interface BrokeredConnectionControl
Throws:
java.sql.SQLException

checkClose

public void checkClose()
                throws java.sql.SQLException
Description copied from interface: BrokeredConnectionControl
Check if the brokered connection can be closed.

Specified by:
checkClose in interface BrokeredConnectionControl
Throws:
java.sql.SQLException - if it is not allowed to call close on the brokered connection
See Also:
BrokeredConnectionControl.checkClose()

closingConnection

public boolean closingConnection()
                          throws java.sql.SQLException
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.

Specified by:
closingConnection in interface BrokeredConnectionControl
Throws:
java.sql.SQLException

wrapStatement

public java.sql.Statement wrapStatement(java.sql.Statement s)
                                 throws java.sql.SQLException
No need to wrap statements for PooledConnections.

Specified by:
wrapStatement in interface BrokeredConnectionControl
Throws:
java.sql.SQLException

wrapStatement

public java.sql.PreparedStatement wrapStatement(java.sql.PreparedStatement ps,
                                                java.lang.String sql,
                                                java.lang.Object generatedKeys)
                                         throws java.sql.SQLException
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

Specified by:
wrapStatement in interface BrokeredConnectionControl
Parameters:
ps - PreparedStatment to be wrapped
sql - String
generatedKeys - Object
Returns:
returns the wrapped PreparedStatement
Throws:
java.sql.SQLException

wrapStatement

public java.sql.CallableStatement wrapStatement(java.sql.CallableStatement cs,
                                                java.lang.String sql)
                                         throws java.sql.SQLException
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

Specified by:
wrapStatement in interface BrokeredConnectionControl
Parameters:
cs - CallableStatment to be wrapped
sql - String
Returns:
returns the wrapped CallableStatement
Throws:
java.sql.SQLException

toString

public java.lang.String 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.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the uniquie id for this pooled connection.

onStatementClose

public void onStatementClose(java.sql.PreparedStatement statement)
Dummy implementation for the actual methods found in org.apache.derby.jdbc.EmbedPooledConnection40

Specified by:
onStatementClose in interface BrokeredConnectionControl
Parameters:
statement - PreparedStatement

onStatementErrorOccurred

public void onStatementErrorOccurred(java.sql.PreparedStatement statement,
                                     java.sql.SQLException sqle)
Dummy implementation for the actual methods found in org.apache.derby.jdbc.EmbedPooledConnection40

Specified by:
onStatementErrorOccurred in interface BrokeredConnectionControl
Parameters:
statement - PreparedStatement
sqle - SQLException

Built on Thu 2010-12-23 20:49:13+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.