com.jolbox.bonecp
Class ConnectionHandle

java.lang.Object
  extended by com.jolbox.bonecp.ConnectionHandle
All Implemented Interfaces:
java.sql.Connection, java.sql.Wrapper

public class ConnectionHandle
extends java.lang.Object
implements java.sql.Connection

Connection handle wrapper around a JDBC connection.

Author:
wwadge

Field Summary
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Constructor Summary
ConnectionHandle(java.sql.Connection connection, IStatementCache preparedStatementCache, IStatementCache callableStatementCache, BoneCP pool)
          Private constructor used solely for unit testing.
ConnectionHandle(java.lang.String url, java.lang.String username, java.lang.String password, BoneCP pool)
          Connection wrapper constructor
 
Method Summary
 void clearWarnings()
           
 void close()
          Release the connection if called.
 void commit()
           
 java.sql.Array createArrayOf(java.lang.String typeName, java.lang.Object[] elements)
           
 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 resultSetType, int resultSetConcurrency)
           
 java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
           
 java.sql.Struct createStruct(java.lang.String typeName, java.lang.Object[] attributes)
           
 boolean getAutoCommit()
           
 java.lang.String getCatalog()
           
 java.util.Properties getClientInfo()
           
 java.lang.String getClientInfo(java.lang.String name)
           
 long getConnectionCreationTime()
          Deprecated. please use getConnectionCreationTimeInMs() instead.
 long getConnectionCreationTimeInMs()
          Returns the connectionCreationTime field.
 ConnectionHook getConnectionHook()
          Returns the configured connection hook object.
 long getConnectionLastReset()
          Deprecated. Please use getConnectionLastResetInMs() instead
 long getConnectionLastResetInMs()
           
 long getConnectionLastUsed()
          Deprecated. Use getConnectionLastUsedInMs() instead.
 long getConnectionLastUsedInMs()
           
 java.lang.Object getDebugHandle()
          Returns a debug handle as previously set by an application
 int getHoldability()
           
 java.sql.Connection getInternalConnection()
          Returns the internal connection as obtained via the JDBC driver.
 java.sql.DatabaseMetaData getMetaData()
           
 ConnectionPartition getOriginatingPartition()
          Gets the partition this came from.
 BoneCP getPool()
          Returns a handle to the global pool from where this connection was obtained.
 java.lang.Object getProxyTarget()
          This method will be intercepted by the proxy if it is enabled to return the internal target.
 java.sql.Connection getRawConnection()
          Deprecated. 
 java.util.List<ReplayLog> getReplayLog()
          Returns transaction history log
 java.lang.Thread getThreadUsingConnection()
          Returns the thread that is currently utilizing this connection.
 int getTransactionIsolation()
           
 java.util.Map<java.lang.String,java.lang.Class<?>> getTypeMap()
           
 java.sql.SQLWarning getWarnings()
           
 boolean isClosed()
          Returns true if this connection has been (logically) closed.
 boolean isConnectionAlive()
          Sends a test query to the underlying connection and return true if connection is alive.
 boolean isExpired()
          Returns true if the given connection has exceeded the maxConnectionAge.
 boolean isLogStatementsEnabled()
          Returns true if logging of statements is enabled
 boolean isPossiblyBroken()
          Gets true if connection has triggered an exception at some point.
 boolean isReadOnly()
           
 boolean isValid(int timeout)
           
 boolean isWrapperFor(java.lang.Class<?> iface)
           
 java.lang.String nativeSQL(java.lang.String sql)
           
 java.sql.CallableStatement prepareCall(java.lang.String sql)
           
 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)
           
 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames)
           
 void releaseSavepoint(java.sql.Savepoint savepoint)
           
 void rollback()
           
 void rollback(java.sql.Savepoint savepoint)
           
 void sendInitSQL()
          Sends any configured SQL init statement.
 void setAutoCommit(boolean autoCommit)
           
 void setCatalog(java.lang.String catalog)
           
 void setClientInfo(java.util.Properties properties)
           
 void setClientInfo(java.lang.String name, java.lang.String value)
           
 void setDebugHandle(java.lang.Object debugHandle)
          Sets a debugHandle, an object that is not used by the connection pool at all but may be set by an application to track this particular connection handle for any purpose it deems fit.
 void setHoldability(int holdability)
           
 void setInternalConnection(java.sql.Connection rawConnection)
          Sets the internal connection to use.
 void setLogStatementsEnabled(boolean logStatementsEnabled)
          Enable or disable logging of this connection.
 void setReadOnly(boolean readOnly)
           
 java.sql.Savepoint setSavepoint()
           
 java.sql.Savepoint setSavepoint(java.lang.String name)
           
 void setTransactionIsolation(int level)
           
 void setTypeMap(java.util.Map<java.lang.String,java.lang.Class<?>> map)
           
<T> T
unwrap(java.lang.Class<T> iface)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionHandle

public ConnectionHandle(java.lang.String url,
                        java.lang.String username,
                        java.lang.String password,
                        BoneCP pool)
                 throws java.sql.SQLException
Connection wrapper constructor

Parameters:
url - JDBC connection string
username - user to use
password - password for db
pool - pool handle.
Throws:
java.sql.SQLException - on error

ConnectionHandle

public ConnectionHandle(java.sql.Connection connection,
                        IStatementCache preparedStatementCache,
                        IStatementCache callableStatementCache,
                        BoneCP pool)
Private constructor used solely for unit testing.

Parameters:
connection -
preparedStatementCache -
callableStatementCache -
pool -
Method Detail

sendInitSQL

public void sendInitSQL()
                 throws java.sql.SQLException
Sends any configured SQL init statement.

Throws:
java.sql.SQLException - on error

clearWarnings

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

close

public void close()
           throws java.sql.SQLException
Release the connection if called.

Specified by:
close in interface java.sql.Connection
Throws:
java.sql.SQLException - Never really thrown

commit

public void commit()
            throws java.sql.SQLException
Specified by:
commit 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 name)
                               throws java.sql.SQLException
Specified by:
getClientInfo in interface java.sql.Connection
Throws:
java.sql.SQLException

isValid

public boolean isValid(int timeout)
                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

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

setClientInfo

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

setClientInfo

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

createStruct

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

createArrayOf

public java.sql.Array createArrayOf(java.lang.String typeName,
                                    java.lang.Object[] elements)
                             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

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 resultSetType,
                                          int resultSetConcurrency)
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement(int resultSetType,
                                          int resultSetConcurrency,
                                          int resultSetHoldability)
                                   throws java.sql.SQLException
Specified by:
createStatement 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

getCatalog

public java.lang.String getCatalog()
                            throws java.sql.SQLException
Specified by:
getCatalog 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

getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.sql.SQLException
Specified by:
getMetaData 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

getTypeMap

public java.util.Map<java.lang.String,java.lang.Class<?>> getTypeMap()
                                                              throws java.sql.SQLException
Specified by:
getTypeMap 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

isClosed

public boolean isClosed()
Returns true if this connection has been (logically) closed.

Specified by:
isClosed in interface java.sql.Connection
Returns:
the logicallyClosed setting.

isReadOnly

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

nativeSQL

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

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql)
                                       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 sql,
                                              int resultSetType,
                                              int resultSetConcurrency)
                                       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 sql,
                                              int resultSetType,
                                              int resultSetConcurrency,
                                              int resultSetHoldability)
                                       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 sql)
                                            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 sql,
                                                   int autoGeneratedKeys)
                                            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 sql,
                                                   int[] columnIndexes)
                                            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 sql,
                                                   java.lang.String[] columnNames)
                                            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 sql,
                                                   int resultSetType,
                                                   int resultSetConcurrency)
                                            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 sql,
                                                   int resultSetType,
                                                   int resultSetConcurrency,
                                                   int resultSetHoldability)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

releaseSavepoint

public void releaseSavepoint(java.sql.Savepoint savepoint)
                      throws java.sql.SQLException
Specified by:
releaseSavepoint 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

rollback

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

setAutoCommit

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

setCatalog

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

setHoldability

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

setReadOnly

public void setReadOnly(boolean readOnly)
                 throws java.sql.SQLException
Specified by:
setReadOnly 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

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

setTransactionIsolation

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

setTypeMap

public void setTypeMap(java.util.Map<java.lang.String,java.lang.Class<?>> map)
                throws java.sql.SQLException
Specified by:
setTypeMap in interface java.sql.Connection
Throws:
java.sql.SQLException

getConnectionLastUsedInMs

public long getConnectionLastUsedInMs()
Returns:
the connectionLastUsed

getConnectionLastUsed

@Deprecated
public long getConnectionLastUsed()
Deprecated. Use getConnectionLastUsedInMs() instead.

Deprecated. Use getConnectionLastUsedInMs() instead.

Returns:
the connectionLastUsed

getConnectionLastResetInMs

public long getConnectionLastResetInMs()
Returns:
the connectionLastReset

getConnectionLastReset

@Deprecated
public long getConnectionLastReset()
Deprecated. Please use getConnectionLastResetInMs() instead

Deprecated. Use getConnectionLastResetInMs() instead.

Returns:
the connectionLastReset

isPossiblyBroken

public boolean isPossiblyBroken()
Gets true if connection has triggered an exception at some point.

Returns:
true if the connection has triggered an error

getOriginatingPartition

public ConnectionPartition getOriginatingPartition()
Gets the partition this came from.

Returns:
the partition this came from

getDebugHandle

public java.lang.Object getDebugHandle()
Returns a debug handle as previously set by an application

Returns:
DebugHandle

setDebugHandle

public void setDebugHandle(java.lang.Object debugHandle)
Sets a debugHandle, an object that is not used by the connection pool at all but may be set by an application to track this particular connection handle for any purpose it deems fit.

Parameters:
debugHandle - any object.

getRawConnection

@Deprecated
public java.sql.Connection getRawConnection()
Deprecated. 

Deprecated. Please use getInternalConnection() instead.

Returns:
the raw connection

getInternalConnection

public java.sql.Connection getInternalConnection()
Returns the internal connection as obtained via the JDBC driver.

Returns:
the raw connection

getConnectionHook

public ConnectionHook getConnectionHook()
Returns the configured connection hook object.

Returns:
the connectionHook that was set in the config

isLogStatementsEnabled

public boolean isLogStatementsEnabled()
Returns true if logging of statements is enabled

Returns:
logStatementsEnabled status

setLogStatementsEnabled

public void setLogStatementsEnabled(boolean logStatementsEnabled)
Enable or disable logging of this connection.

Parameters:
logStatementsEnabled - true to enable logging, false to disable.

isConnectionAlive

public boolean isConnectionAlive()
Sends a test query to the underlying connection and return true if connection is alive.

Returns:
True if connection is valid, false otherwise.

setInternalConnection

public void setInternalConnection(java.sql.Connection rawConnection)
Sets the internal connection to use. Be careful how to use this method, normally you should never need it! This is here for odd use cases only!

Parameters:
rawConnection - to set

getPool

public BoneCP getPool()
Returns a handle to the global pool from where this connection was obtained.

Returns:
BoneCP handle

getReplayLog

public java.util.List<ReplayLog> getReplayLog()
Returns transaction history log

Returns:
replay list

getProxyTarget

public java.lang.Object getProxyTarget()
This method will be intercepted by the proxy if it is enabled to return the internal target.

Returns:
the target.

getThreadUsingConnection

public java.lang.Thread getThreadUsingConnection()
Returns the thread that is currently utilizing this connection.

Returns:
the threadUsingConnection

getConnectionCreationTime

@Deprecated
public long getConnectionCreationTime()
Deprecated. please use getConnectionCreationTimeInMs() instead.

Deprecated. Use getConnectionCreationTimeInMs() instead.

Returns:
connectionCreationTime

getConnectionCreationTimeInMs

public long getConnectionCreationTimeInMs()
Returns the connectionCreationTime field.

Returns:
connectionCreationTime

isExpired

public boolean isExpired()
Returns true if the given connection has exceeded the maxConnectionAge.

Returns:
true if the connection has expired.


Copyright © 2009-2011 JolBox. All Rights Reserved.