to.etc.dbpool
Class ConnectionProxy

java.lang.Object
  extended by to.etc.dbpool.ConnectionProxy
All Implemented Interfaces:
java.sql.Connection, java.sql.Wrapper

public final class ConnectionProxy
extends java.lang.Object
implements java.sql.Connection

This "implements" Connection, and is a proxy to the actual connection maintained in ConnectionPoolEntry. An instance is created every time a connection is allocated from the pool and returned to the user. This instance is never reused and becomes invalid after close() is called on it.

This also contains all of the data associated with a connection, for debugging, logging and statistics gathering. Most of the data herein is locked by this. FIXME Must implement java.sql.PooledConnection.

Author:
Frits Jalvingh Created on Nov 2, 2010

Field Summary
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Method Summary
 void addOwnerInfo(java.lang.Object oo)
          Adds owner info objects to the connection.
 void checkHangState(to.etc.dbpool.HangCheckState hs)
          Called without any locks to see if this connection is a "hanging" connection.
 void clearWarnings()
           
 void close()
          The "normal" close releases all resources associated with this connection by closing them, then it returns the connection to the pool.
protected  InfoCollector collector()
           
 void commit()
           
 java.sql.Array createArrayOf(java.lang.String arg0, java.lang.Object[] arg1)
           
 java.sql.Blob createBlob()
           
 java.sql.Clob createClob()
           
 java.sql.NClob createNClob()
           
 java.sql.SQLXML createSQLXML()
           
 java.sql.Statement createStatement()
           
 java.sql.Statement createStatement(int p1, int p2)
           
 java.sql.Statement createStatement(int p1, int p2, int p3)
           
 java.sql.Struct createStruct(java.lang.String arg0, java.lang.Object[] arg1)
           
 void forceClosed()
          Actually closes a proxy, if not already done.
 Tracepoint getAllocationPoint()
           
 long getAllocationTime()
          Return the immutable allocation time.
 boolean getAutoCommit()
           
 java.lang.String getCatalog()
           
 java.util.Properties getClientInfo()
           
 java.lang.String getClientInfo(java.lang.String arg0)
           
 int getHoldability()
           
 int getId()
           
 long getLastUsedTime()
          Return the time this was last used.
 java.sql.DatabaseMetaData getMetaData()
           
 java.lang.Thread getOwnerThread()
           
 ConnectionPool getPool()
           
 java.lang.String getPoolID()
           
 java.sql.Connection getRealConnection()
          Returns the REAL database connection (the one obtained from the JDBC driver) for this proxy.
 ConnState getState()
           
 java.util.List<Tracepoint> getTraceList()
          Return the list of tracepoints, from old to new.
 int getTransactionIsolation()
           
 java.util.Map getTypeMap()
           
 java.sql.SQLWarning getWarnings()
           
 boolean isClosed()
           
 boolean isCollectStatistics()
           
 boolean isReadOnly()
           
 boolean isUnpooled()
          THIS MAY ONLY LOCK THIS AND MUST BE IMMUTABLE.
 boolean isValid(int arg0)
           
 boolean isWrapperFor(java.lang.Class<?> iface)
           
 java.lang.String nativeSQL(java.lang.String p1)
           
 java.sql.CallableStatement prepareCall(java.lang.String p1)
           
 java.sql.CallableStatement prepareCall(java.lang.String p1, int p2, int p3)
           
 java.sql.CallableStatement prepareCall(java.lang.String name, int a, int b, int c)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String p1)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String p1, int p2)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String p1, int[] p2)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String p1, int p2, int p3)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String p1, int p2, int p3, int p4)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String a, java.lang.String[] ar)
           
 void releaseSavepoint(java.sql.Savepoint sp)
           
protected  void removeResource(java.lang.Object o)
          This removes the resource from the resource list because it was normally closed.
 void rollback()
           
 void rollback(java.sql.Savepoint sp)
           
 void setAutoCommit(boolean p1)
           
 void setCatalog(java.lang.String p1)
           
 void setClientInfo(java.util.Properties arg0)
           
 void setClientInfo(java.lang.String arg0, java.lang.String arg1)
           
 void setHoldability(int m)
           
 void setReadOnly(boolean p1)
           
 java.sql.Savepoint setSavepoint()
           
 java.sql.Savepoint setSavepoint(java.lang.String name)
           
 void setTransactionIsolation(int p1)
           
 void setTypeMap(java.util.Map p1)
           
 void setUncloseable(boolean unclosable)
          Forbid a connection from being closed using the normal close() method.
 java.lang.String toString()
           
<T> T
unwrap(java.lang.Class<T> iface)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getAllocationTime

public long getAllocationTime()
Return the immutable allocation time.

Returns:

getAllocationPoint

public Tracepoint getAllocationPoint()

getOwnerThread

public java.lang.Thread getOwnerThread()

getPoolID

public java.lang.String getPoolID()

isCollectStatistics

public boolean isCollectStatistics()

getId

public int getId()

collector

protected InfoCollector collector()

getPool

public ConnectionPool getPool()

isUnpooled

public final boolean isUnpooled()
THIS MAY ONLY LOCK THIS AND MUST BE IMMUTABLE.

Returns:

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

addOwnerInfo

public void addOwnerInfo(java.lang.Object oo)
Adds owner info objects to the connection. These will be rendered at debug time, when needed.

Parameters:
oo -

getState

public ConnState getState()

getRealConnection

public java.sql.Connection getRealConnection()
Returns the REAL database connection (the one obtained from the JDBC driver) for this proxy. LOCKS THIS.

Returns:
the connection

close

public void close()
           throws java.sql.SQLException
The "normal" close releases all resources associated with this connection by closing them, then it returns the connection to the pool. If the connection is already closed then nothing happens (multiple closes are allowed). LOCKS THIS. THIS CALL MAY ONLY BE CALLED BY USER CODE, NOT BY POOL CODE!!!

Specified by:
close in interface java.sql.Connection
Throws:
java.sql.SQLException

forceClosed

public void forceClosed()
                 throws java.sql.SQLException
Actually closes a proxy, if not already done. This also sets the close reason and location. This can be called from pool code. Can be called for connections that ignore the normal close operation to force the proxy closed. The connection is returned to the pool proper.

Throws:
java.sql.SQLException

getTraceList

public java.util.List<Tracepoint> getTraceList()
Return the list of tracepoints, from old to new. The first entry is always the allocation point. If stacktracing is disabled this returns the allocation point only (and the close point if known). This is valid even when the connection is closed/invalidated or whatnot. LOCKS THIS.

Returns:

getLastUsedTime

public long getLastUsedTime()
Return the time this was last used.

Returns:

checkHangState

public void checkHangState(to.etc.dbpool.HangCheckState hs)
Called without any locks to see if this connection is a "hanging" connection. This is racy by definition because no locks are maintained. It means that the connection's state can change during the process while locks are clear. This means that all parts of this process must accept a state transition from life to dead at any time. Because proxies are single-use only they cannot be resurrected, so when it is determined they are dead the process can quit immediately.

Determining hang state

Unpooled connections have their hang state checked using a staggered time interval. They are never cleared unless we are in "urgent" mode.

Parameters:
hs -

removeResource

protected void removeResource(java.lang.Object o)
This removes the resource from the resource list because it was normally closed.

Parameters:
o - the resource to remove.

setUncloseable

public void setUncloseable(boolean unclosable)
Forbid a connection from being closed using the normal close() method.


prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String p1)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String p1,
                                                   int[] p2)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String p1,
                                                   int p2)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String p1,
                                                   int p2,
                                                   int p3)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String p1,
                                                   int p2,
                                                   int p3,
                                                   int p4)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String name,
                                              int a,
                                              int b,
                                              int c)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String a,
                                                   java.lang.String[] ar)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement()
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement(int p1,
                                          int p2)
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement(int p1,
                                          int p2,
                                          int p3)
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String p1,
                                              int p2,
                                              int p3)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String p1)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException

setCatalog

public void setCatalog(java.lang.String p1)
                throws java.sql.SQLException
Specified by:
setCatalog in interface java.sql.Connection
Throws:
java.sql.SQLException

rollback

public void rollback()
              throws java.sql.SQLException
Specified by:
rollback in interface java.sql.Connection
Throws:
java.sql.SQLException

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
Specified by:
clearWarnings in interface java.sql.Connection
Throws:
java.sql.SQLException

getTypeMap

public java.util.Map getTypeMap()
                         throws java.sql.SQLException
Specified by:
getTypeMap in interface java.sql.Connection
Throws:
java.sql.SQLException

getTransactionIsolation

public int getTransactionIsolation()
                            throws java.sql.SQLException
Specified by:
getTransactionIsolation in interface java.sql.Connection
Throws:
java.sql.SQLException

setTransactionIsolation

public void setTransactionIsolation(int p1)
                             throws java.sql.SQLException
Specified by:
setTransactionIsolation in interface java.sql.Connection
Throws:
java.sql.SQLException

isClosed

public boolean isClosed()
                 throws java.sql.SQLException
Specified by:
isClosed in interface java.sql.Connection
Throws:
java.sql.SQLException

setAutoCommit

public void setAutoCommit(boolean p1)
                   throws java.sql.SQLException
Specified by:
setAutoCommit in interface java.sql.Connection
Throws:
java.sql.SQLException

commit

public void commit()
            throws java.sql.SQLException
Specified by:
commit in interface java.sql.Connection
Throws:
java.sql.SQLException

getCatalog

public java.lang.String getCatalog()
                            throws java.sql.SQLException
Specified by:
getCatalog in interface java.sql.Connection
Throws:
java.sql.SQLException

isReadOnly

public boolean isReadOnly()
                   throws java.sql.SQLException
Specified by:
isReadOnly in interface java.sql.Connection
Throws:
java.sql.SQLException

getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.sql.SQLException
Specified by:
getMetaData in interface java.sql.Connection
Throws:
java.sql.SQLException

setReadOnly

public void setReadOnly(boolean p1)
                 throws java.sql.SQLException
Specified by:
setReadOnly in interface java.sql.Connection
Throws:
java.sql.SQLException

getAutoCommit

public boolean getAutoCommit()
                      throws java.sql.SQLException
Specified by:
getAutoCommit in interface java.sql.Connection
Throws:
java.sql.SQLException

nativeSQL

public java.lang.String nativeSQL(java.lang.String p1)
                           throws java.sql.SQLException
Specified by:
nativeSQL in interface java.sql.Connection
Throws:
java.sql.SQLException

setTypeMap

public void setTypeMap(java.util.Map p1)
                throws java.sql.SQLException
Specified by:
setTypeMap in interface java.sql.Connection
Throws:
java.sql.SQLException

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
Specified by:
getWarnings in interface java.sql.Connection
Throws:
java.sql.SQLException

releaseSavepoint

public void releaseSavepoint(java.sql.Savepoint sp)
                      throws java.sql.SQLException
Specified by:
releaseSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException

rollback

public void rollback(java.sql.Savepoint sp)
              throws java.sql.SQLException
Specified by:
rollback in interface java.sql.Connection
Throws:
java.sql.SQLException

setSavepoint

public java.sql.Savepoint setSavepoint(java.lang.String name)
                                throws java.sql.SQLException
Specified by:
setSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException

setSavepoint

public java.sql.Savepoint setSavepoint()
                                throws java.sql.SQLException
Specified by:
setSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException

getHoldability

public int getHoldability()
                   throws java.sql.SQLException
Specified by:
getHoldability in interface java.sql.Connection
Throws:
java.sql.SQLException

setHoldability

public void setHoldability(int m)
                    throws java.sql.SQLException
Specified by:
setHoldability in interface java.sql.Connection
Throws:
java.sql.SQLException

createArrayOf

public java.sql.Array createArrayOf(java.lang.String arg0,
                                    java.lang.Object[] arg1)
                             throws java.sql.SQLException
Specified by:
createArrayOf in interface java.sql.Connection
Throws:
java.sql.SQLException

createBlob

public java.sql.Blob createBlob()
                         throws java.sql.SQLException
Specified by:
createBlob in interface java.sql.Connection
Throws:
java.sql.SQLException

createClob

public java.sql.Clob createClob()
                         throws java.sql.SQLException
Specified by:
createClob in interface java.sql.Connection
Throws:
java.sql.SQLException

createNClob

public java.sql.NClob createNClob()
                           throws java.sql.SQLException
Specified by:
createNClob in interface java.sql.Connection
Throws:
java.sql.SQLException

createSQLXML

public java.sql.SQLXML createSQLXML()
                             throws java.sql.SQLException
Specified by:
createSQLXML in interface java.sql.Connection
Throws:
java.sql.SQLException

createStruct

public java.sql.Struct createStruct(java.lang.String arg0,
                                    java.lang.Object[] arg1)
                             throws java.sql.SQLException
Specified by:
createStruct in interface java.sql.Connection
Throws:
java.sql.SQLException

getClientInfo

public java.util.Properties getClientInfo()
                                   throws java.sql.SQLException
Specified by:
getClientInfo in interface java.sql.Connection
Throws:
java.sql.SQLException

getClientInfo

public java.lang.String getClientInfo(java.lang.String arg0)
                               throws java.sql.SQLException
Specified by:
getClientInfo in interface java.sql.Connection
Throws:
java.sql.SQLException

isValid

public boolean isValid(int arg0)
                throws java.sql.SQLException
Specified by:
isValid in interface java.sql.Connection
Throws:
java.sql.SQLException

isWrapperFor

public boolean isWrapperFor(java.lang.Class<?> iface)
                     throws java.sql.SQLException
Specified by:
isWrapperFor in interface java.sql.Wrapper
Throws:
java.sql.SQLException

setClientInfo

public void setClientInfo(java.util.Properties arg0)
                   throws java.sql.SQLClientInfoException
Specified by:
setClientInfo in interface java.sql.Connection
Throws:
java.sql.SQLClientInfoException

setClientInfo

public void setClientInfo(java.lang.String arg0,
                          java.lang.String arg1)
                   throws java.sql.SQLClientInfoException
Specified by:
setClientInfo in interface java.sql.Connection
Throws:
java.sql.SQLClientInfoException

unwrap

public <T> T unwrap(java.lang.Class<T> iface)
         throws java.sql.SQLException
Specified by:
unwrap in interface java.sql.Wrapper
Throws:
java.sql.SQLException