public class ConnectionHandle extends Object implements Connection, Serializable
| Modifier and Type | Field and Description |
|---|---|
protected String |
autoCommitStackTrace
Stack track dump.
|
protected boolean |
closeOpenStatements
Config setting.
|
protected Connection |
connection
Connection handle.
|
protected long |
connectionCreationTimeInMs
Time when this connection was created.
|
protected boolean |
connectionTrackingDisabled
If true, connection tracking is disabled in the config.
|
protected boolean |
detectUnclosedStatements
Config setting.
|
protected boolean |
detectUnresolvedTransactions
Config setting.
|
protected boolean |
doubleCloseCheck
If true, give warnings if application tried to issue a close twice (for debugging only).
|
protected String |
doubleCloseException
exception trace if doubleCloseCheck is enabled.
|
protected Map<Connection,Reference<ConnectionHandle>> |
finalizableRefs
Handle to pool.finalizationRefs.
|
protected static org.slf4j.Logger |
logger
Logger handle.
|
protected AtomicBoolean |
logicallyClosed
If true, we've called close() on this connection.
|
protected long |
maxConnectionAgeInMs
Configured max connection age.
|
protected boolean |
possiblyBroken
If true, this connection might have failed communicating with the
database.
|
protected TransactionRecoveryResult |
recoveryResult
Map of translations + result from last recovery.
|
protected boolean |
resetConnectionOnClose
Config setting.
|
protected boolean |
statementCachingEnabled
Set to true if we have statement caching enabled.
|
protected static boolean |
testSupport
This is only to aid code coverage since otherwise we are unable to cover the case of normal code but stmt set to null.
|
protected Thread |
threadUsingConnection
Keep track of the thread.
|
protected ConcurrentMap<Statement,String> |
trackedStatement
Keep track of open statements.
|
protected boolean |
txResolved
If true, transaction has been marked as COMMITed or ROLLBACKed.
|
protected String |
url
Connection url.
|
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE| Modifier | Constructor and Description |
|---|---|
protected |
ConnectionHandle(Connection connection,
ConnectionPartition partition,
BoneCP pool,
boolean recreating)
Internal constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
abort(Executor executor) |
protected void |
clearStatementCaches(boolean internalClose)
Clears out the statement handles.
|
void |
clearWarnings() |
void |
close()
Release the connection back to the pool.
|
void |
commit() |
Array |
createArrayOf(String typeName,
Object[] elements) |
Blob |
createBlob() |
Clob |
createClob() |
NClob |
createNClob() |
SQLXML |
createSQLXML() |
Statement |
createStatement() |
Statement |
createStatement(int resultSetType,
int resultSetConcurrency) |
Statement |
createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) |
Struct |
createStruct(String typeName,
Object[] attributes) |
protected static ConnectionHandle |
createTestConnectionHandle(Connection connection,
IStatementCache preparedStatementCache,
IStatementCache callableStatementCache,
BoneCP pool)
Private -- used solely for unit testing.
|
boolean |
getAutoCommit() |
protected String |
getAutoCommitStackTrace()
Returns the autoCommitStackTrace field.
|
String |
getCatalog() |
Properties |
getClientInfo() |
String |
getClientInfo(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() |
Object |
getDebugHandle()
Returns a debug handle as previously set by an application
|
int |
getHoldability() |
Connection |
getInternalConnection()
Returns the internal connection as obtained via the JDBC driver.
|
DatabaseMetaData |
getMetaData() |
int |
getNetworkTimeout() |
ConnectionPartition |
getOriginatingPartition()
Gets the partition this came from.
|
BoneCP |
getPool()
Returns a handle to the global pool from where this connection was obtained.
|
Object |
getProxyTarget()
This method will be intercepted by the proxy if it is enabled to return the internal target.
|
Connection |
getRawConnection()
Deprecated.
|
List<ReplayLog> |
getReplayLog()
Returns transaction history log
|
String |
getSchema() |
Thread |
getThreadUsingConnection()
Returns the thread that is currently utilizing this connection.
|
Thread |
getThreadWatch()
Returns the thread watching over this connection.
|
int |
getTransactionIsolation() |
Map<String,Class<?>> |
getTypeMap() |
String |
getUrl()
Returns the url field.
|
SQLWarning |
getWarnings() |
protected void |
internalClose()
Close off the connection.
|
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.
|
protected boolean |
isExpired(long currentTime)
Returns true if the given connection has exceeded the maxConnectionAge.
|
protected boolean |
isInReplayMode() |
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() |
protected boolean |
isTxResolved()
If true, autocommit is set to true or else commit/rollback has been called.
|
boolean |
isValid(int timeout) |
boolean |
isWrapperFor(Class<?> iface) |
protected SQLException |
markPossiblyBroken(SQLException e)
Given an exception, flag the connection (or database) as being potentially broken.
|
protected String |
maybeCaptureStackTrace()
Depending on options, return a stack trace or an empty string
|
String |
nativeSQL(String sql) |
CallableStatement |
prepareCall(String sql) |
CallableStatement |
prepareCall(String sql,
int resultSetType,
int resultSetConcurrency) |
CallableStatement |
prepareCall(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) |
PreparedStatement |
prepareStatement(String sql) |
PreparedStatement |
prepareStatement(String sql,
int autoGeneratedKeys) |
PreparedStatement |
prepareStatement(String sql,
int[] columnIndexes) |
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency) |
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) |
PreparedStatement |
prepareStatement(String sql,
String[] columnNames) |
ConnectionHandle |
recreateConnectionHandle()
Creates the connection handle again.
|
void |
refreshConnection()
Destroys the internal connection handle and creates a new one.
|
void |
releaseSavepoint(Savepoint savepoint) |
protected void |
renewConnection()
Renews this connection, i.e.
|
void |
rollback() |
void |
rollback(Savepoint savepoint) |
void |
sendInitSQL()
Sends any configured SQL init statement.
|
protected static void |
sendInitSQL(Connection connection,
String initSQL)
Sends out the SQL as defined in the config upon first init of the connection.
|
void |
setAutoCommit(boolean autoCommit) |
protected void |
setAutoCommitStackTrace(String autoCommitStackTrace)
Sets the autoCommitStackTrace.
|
void |
setCatalog(String catalog) |
void |
setClientInfo(Properties properties) |
void |
setClientInfo(String name,
String value) |
protected void |
setConnectionLastResetInMs(long connectionLastReset) |
protected void |
setConnectionLastUsedInMs(long connectionLastUsed) |
void |
setDebugHandle(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) |
protected void |
setInReplayMode(boolean inReplayMode) |
void |
setInternalConnection(Connection rawConnection)
Sets the internal connection to use.
|
void |
setLogStatementsEnabled(boolean logStatementsEnabled)
Enable or disable logging of this connection.
|
void |
setNetworkTimeout(Executor executor,
int milliseconds) |
protected void |
setOriginatingPartition(ConnectionPartition originatingPartition)
Sets Originating partition
|
void |
setReadOnly(boolean readOnly) |
protected void |
setReplayLog(List<ReplayLog> replayLog)
Sets the transaction history log
|
Savepoint |
setSavepoint() |
Savepoint |
setSavepoint(String name) |
void |
setSchema(String schema) |
protected void |
setThreadWatch(Thread threadWatch)
Sets the thread watching over this connection.
|
void |
setTransactionIsolation(int level) |
void |
setTypeMap(Map<String,Class<?>> map) |
String |
toString() |
protected void |
untrackStatement(StatementHandle statement)
Stop tracking the given statement.
|
<T> T |
unwrap(Class<T> iface) |
protected static boolean testSupport
protected Connection connection
protected long connectionCreationTimeInMs
protected boolean resetConnectionOnClose
protected boolean possiblyBroken
protected AtomicBoolean logicallyClosed
protected static org.slf4j.Logger logger
protected boolean doubleCloseCheck
protected volatile String doubleCloseException
protected boolean statementCachingEnabled
protected TransactionRecoveryResult recoveryResult
protected String url
protected Thread threadUsingConnection
protected long maxConnectionAgeInMs
protected Map<Connection,Reference<ConnectionHandle>> finalizableRefs
protected boolean connectionTrackingDisabled
protected boolean txResolved
protected boolean detectUnresolvedTransactions
protected String autoCommitStackTrace
protected boolean detectUnclosedStatements
protected boolean closeOpenStatements
protected ConcurrentMap<Statement,String> trackedStatement
protected ConnectionHandle(Connection connection, ConnectionPartition partition, BoneCP pool, boolean recreating) throws SQLException
connection - partition - pool - recreating - SQLExceptionpublic ConnectionHandle recreateConnectionHandle() throws SQLException
SQLExceptionprotected static ConnectionHandle createTestConnectionHandle(Connection connection, IStatementCache preparedStatementCache, IStatementCache callableStatementCache, BoneCP pool)
connection - preparedStatementCache - callableStatementCache - pool - public void sendInitSQL()
throws SQLException
SQLException - on errorprotected static void sendInitSQL(Connection connection, String initSQL) throws SQLException
connection - initSQL - SQLExceptionprotected SQLException markPossiblyBroken(SQLException e)
e - SQLException epublic void clearWarnings()
throws SQLException
clearWarnings in interface ConnectionSQLExceptionpublic void close()
throws SQLException
close in interface AutoCloseableclose in interface ConnectionSQLException - Never really thrownprotected void internalClose()
throws SQLException
SQLExceptionpublic void commit()
throws SQLException
commit in interface ConnectionSQLExceptionpublic Properties getClientInfo() throws SQLException
getClientInfo in interface ConnectionSQLExceptionpublic String getClientInfo(String name) throws SQLException
getClientInfo in interface ConnectionSQLExceptionpublic boolean isValid(int timeout)
throws SQLException
isValid in interface ConnectionSQLExceptionpublic boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor in interface WrapperSQLExceptionpublic <T> T unwrap(Class<T> iface) throws SQLException
unwrap in interface WrapperSQLExceptionpublic void setClientInfo(Properties properties) throws SQLClientInfoException
setClientInfo in interface ConnectionSQLClientInfoExceptionpublic void setClientInfo(String name, String value) throws SQLClientInfoException
setClientInfo in interface ConnectionSQLClientInfoExceptionpublic Struct createStruct(String typeName, Object[] attributes) throws SQLException
createStruct in interface ConnectionSQLExceptionpublic Array createArrayOf(String typeName, Object[] elements) throws SQLException
createArrayOf in interface ConnectionSQLExceptionpublic Blob createBlob() throws SQLException
createBlob in interface ConnectionSQLExceptionpublic Clob createClob() throws SQLException
createClob in interface ConnectionSQLExceptionpublic NClob createNClob() throws SQLException
createNClob in interface ConnectionSQLExceptionpublic SQLXML createSQLXML() throws SQLException
createSQLXML in interface ConnectionSQLExceptionpublic void setSchema(String schema) throws SQLException
setSchema in interface ConnectionSQLExceptionpublic String getSchema() throws SQLException
getSchema in interface ConnectionSQLExceptionpublic void abort(Executor executor) throws SQLException
abort in interface ConnectionSQLExceptionpublic void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException
setNetworkTimeout in interface ConnectionSQLExceptionpublic int getNetworkTimeout()
throws SQLException
getNetworkTimeout in interface ConnectionSQLExceptionpublic Statement createStatement() throws SQLException
createStatement in interface ConnectionSQLExceptionpublic Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
createStatement in interface ConnectionSQLExceptionpublic Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
createStatement in interface ConnectionSQLExceptionprotected String maybeCaptureStackTrace()
public boolean getAutoCommit()
throws SQLException
getAutoCommit in interface ConnectionSQLExceptionpublic String getCatalog() throws SQLException
getCatalog in interface ConnectionSQLExceptionpublic int getHoldability()
throws SQLException
getHoldability in interface ConnectionSQLExceptionpublic DatabaseMetaData getMetaData() throws SQLException
getMetaData in interface ConnectionSQLExceptionpublic int getTransactionIsolation()
throws SQLException
getTransactionIsolation in interface ConnectionSQLExceptionpublic Map<String,Class<?>> getTypeMap() throws SQLException
getTypeMap in interface ConnectionSQLExceptionpublic SQLWarning getWarnings() throws SQLException
getWarnings in interface ConnectionSQLExceptionpublic boolean isClosed()
isClosed in interface Connectionpublic boolean isReadOnly()
throws SQLException
isReadOnly in interface ConnectionSQLExceptionpublic String nativeSQL(String sql) throws SQLException
nativeSQL in interface ConnectionSQLExceptionpublic CallableStatement prepareCall(String sql) throws SQLException
prepareCall in interface ConnectionSQLExceptionpublic CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
prepareCall in interface ConnectionSQLExceptionpublic CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
prepareCall in interface ConnectionSQLExceptionpublic PreparedStatement prepareStatement(String sql) throws SQLException
prepareStatement in interface ConnectionSQLExceptionpublic PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
prepareStatement in interface ConnectionSQLExceptionpublic PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
prepareStatement in interface ConnectionSQLExceptionpublic PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
prepareStatement in interface ConnectionSQLExceptionpublic PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
prepareStatement in interface ConnectionSQLExceptionpublic PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
prepareStatement in interface ConnectionSQLExceptionpublic void releaseSavepoint(Savepoint savepoint) throws SQLException
releaseSavepoint in interface ConnectionSQLExceptionpublic void rollback()
throws SQLException
rollback in interface ConnectionSQLExceptionpublic void rollback(Savepoint savepoint) throws SQLException
rollback in interface ConnectionSQLExceptionpublic void setAutoCommit(boolean autoCommit)
throws SQLException
setAutoCommit in interface ConnectionSQLExceptionpublic void setCatalog(String catalog) throws SQLException
setCatalog in interface ConnectionSQLExceptionpublic void setHoldability(int holdability)
throws SQLException
setHoldability in interface ConnectionSQLExceptionpublic void setReadOnly(boolean readOnly)
throws SQLException
setReadOnly in interface ConnectionSQLExceptionpublic Savepoint setSavepoint() throws SQLException
setSavepoint in interface ConnectionSQLExceptionpublic Savepoint setSavepoint(String name) throws SQLException
setSavepoint in interface ConnectionSQLExceptionpublic void setTransactionIsolation(int level)
throws SQLException
setTransactionIsolation in interface ConnectionSQLExceptionpublic void setTypeMap(Map<String,Class<?>> map) throws SQLException
setTypeMap in interface ConnectionSQLExceptionpublic long getConnectionLastUsedInMs()
@Deprecated public long getConnectionLastUsed()
getConnectionLastUsedInMs() instead.getConnectionLastUsedInMs() instead.protected void setConnectionLastUsedInMs(long connectionLastUsed)
connectionLastUsed - the connectionLastUsed to setpublic long getConnectionLastResetInMs()
@Deprecated public long getConnectionLastReset()
getConnectionLastResetInMs() insteadgetConnectionLastResetInMs() instead.protected void setConnectionLastResetInMs(long connectionLastReset)
connectionLastReset - the connectionLastReset to setpublic boolean isPossiblyBroken()
public ConnectionPartition getOriginatingPartition()
protected void setOriginatingPartition(ConnectionPartition originatingPartition)
originatingPartition - to setprotected void renewConnection()
protected void clearStatementCaches(boolean internalClose)
internalClose - if true, close the inner statement handle too.public Object getDebugHandle()
public void setDebugHandle(Object debugHandle)
debugHandle - any object.@Deprecated public Connection getRawConnection()
public Connection getInternalConnection()
public ConnectionHook getConnectionHook()
public boolean isLogStatementsEnabled()
public void setLogStatementsEnabled(boolean logStatementsEnabled)
logStatementsEnabled - true to enable logging, false to disable.protected boolean isInReplayMode()
protected void setInReplayMode(boolean inReplayMode)
inReplayMode - the inReplayMode to setpublic boolean isConnectionAlive()
public void setInternalConnection(Connection rawConnection)
rawConnection - to setpublic BoneCP getPool()
public List<ReplayLog> getReplayLog()
protected void setReplayLog(List<ReplayLog> replayLog)
replayLog - to set.public Object getProxyTarget()
public Thread getThreadUsingConnection()
@Deprecated public long getConnectionCreationTime()
getConnectionCreationTimeInMs() instead.getConnectionCreationTimeInMs() instead.public long getConnectionCreationTimeInMs()
public boolean isExpired()
protected boolean isExpired(long currentTime)
currentTime - current time to use.protected void setThreadWatch(Thread threadWatch)
threadWatch - the threadWatch to setpublic Thread getThreadWatch()
protected boolean isTxResolved()
protected String getAutoCommitStackTrace()
protected void setAutoCommitStackTrace(String autoCommitStackTrace)
autoCommitStackTrace - the autoCommitStackTrace to setpublic void refreshConnection()
throws SQLException
SQLExceptionprotected void untrackStatement(StatementHandle statement)
statement - public String getUrl()
Copyright © 2009-2013 JolBox. All Rights Reserved.