public class PooledConnection extends ConnectionDelegator
It is designed to be part of DataSourcePool. Closing the connection puts it back into the pool.
It defaults autoCommit and Transaction Isolation to the defaults of the DataSourcePool.
It has caching of Statements and PreparedStatements. Remembers the last statement that was executed. Keeps statistics on how long it is in use.
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE| Modifier | Constructor and Description |
|---|---|
|
PooledConnection(DataSourcePool pool,
int uniqueId,
Connection connection)
Construct the connection that can refer back to the pool it belongs to.
|
protected |
PooledConnection(String name)
For testing the pool without real connections.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addError(Throwable e)
When an error occurs during use add it the connection.
|
void |
clearWarnings() |
void |
close()
close the connection putting it back into the connection pool.
|
void |
closeConnectionFully(boolean logErrors)
Close the connection fully NOT putting in back into the pool.
|
void |
commit() |
Statement |
createStatement()
Creates a wrapper ExtendedStatement so that I can get the executed sql.
|
Statement |
createStatement(int resultSetType,
int resultSetConcurreny) |
Statement |
createStatement(int i,
int x,
int y) |
boolean |
exceedsMaxAge(long maxAgeMillis)
Return true if the connection is too old.
|
protected void |
finalize() |
boolean |
getAutoCommit() |
long |
getBusySeconds() |
String |
getCatalog() |
String |
getCreatedByMethod()
Returns the method that created the connection.
|
long |
getCreationTime()
Return the time the connection was created.
|
DataSourcePool |
getDataSourcePool()
Return the DataSourcePool that this connection belongs to.
|
String |
getDescription() |
String |
getFullDescription() |
int |
getHoldability() |
String |
getLastStatement()
Returns the last sql statement executed.
|
long |
getLastUsedTime()
Returns the time the connection was last used.
|
DatabaseMetaData |
getMetaData() |
String |
getName()
Return a string to identify the connection.
|
String |
getNameSlot() |
PstmtCache |
getPstmtCache()
A Least Recently used cache of PreparedStatements.
|
String |
getPstmtStatistics() |
int |
getSlotId()
Return the slot position in the busy buffer.
|
StackTraceElement[] |
getStackTrace()
Return the full stack trace that got the connection from the pool.
|
String |
getStackTraceAsString()
Return the stackTrace as a String for logging purposes.
|
long |
getStartUseTime()
Return the time the connection was passed to the client code.
|
PooledConnectionStatistics |
getStatistics() |
int |
getTransactionIsolation() |
Map<String,Class<?>> |
getTypeMap() |
SQLWarning |
getWarnings() |
boolean |
hadErrors()
Returns true if the connect threw any errors during use.
|
boolean |
isClosed() |
boolean |
isLongRunning()
Return true if the connection should be treated as long running (skip connection pool leak check).
|
boolean |
isReadOnly() |
String |
nativeSQL(String sql) |
CallableStatement |
prepareCall(String sql) |
CallableStatement |
prepareCall(String sql,
int resultSetType,
int resultSetConcurreny) |
CallableStatement |
prepareCall(String s,
int i,
int x,
int y) |
PreparedStatement |
prepareStatement(String sql)
This will try to use a cache of PreparedStatements.
|
PreparedStatement |
prepareStatement(String sql,
int returnKeysFlag)
This will try to use a cache of PreparedStatements.
|
PreparedStatement |
prepareStatement(String s,
int[] i) |
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurreny) |
PreparedStatement |
prepareStatement(String s,
int i,
int x,
int y) |
PreparedStatement |
prepareStatement(String s,
String[] s2) |
void |
releaseSavepoint(Savepoint sp) |
protected void |
resetForUse()
Reset the connection for returning to the client.
|
protected void |
returnPreparedStatement(ExtendedPreparedStatement pstmt)
Return a PreparedStatement back into the cache.
|
void |
rollback() |
void |
rollback(Savepoint sp) |
void |
setAutoCommit(boolean autoCommit) |
void |
setCatalog(String catalog) |
void |
setHoldability(int i) |
protected void |
setLastStatement(String lastStatement)
Called by ExtendedStatement to trace the sql being executed.
|
void |
setLongRunning(boolean longRunning)
Set this to true if the connection is a long running connection and should skip the
'suspected connection pool leak' checking.
|
void |
setReadOnly(boolean readOnly)
Also note the read only status needs to be reset when put back into the
pool.
|
Savepoint |
setSavepoint() |
Savepoint |
setSavepoint(String savepointName) |
void |
setSlotId(int slotId)
Set the slot position in the busy buffer.
|
protected void |
setStackTrace(StackTraceElement[] stackTrace)
Set the stack trace to help find connection pool leaks.
|
void |
setTransactionIsolation(int level)
Also note the Isolation level needs to be reset when put back into the
pool.
|
void |
setTypeMap(Map<String,Class<?>> map) |
boolean |
shouldTrim(long usedSince,
long createdSince)
Return true if the connection has been idle for too long or is too old.
|
boolean |
shouldTrimOnReturn(long lastResetTime,
long maxAgeMillis) |
String |
toString() |
abort, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStruct, getClientInfo, getClientInfo, getNetworkTimeout, getSchema, isValid, isWrapperFor, setClientInfo, setClientInfo, setNetworkTimeout, setSchema, unwrappublic PooledConnection(DataSourcePool pool, int uniqueId, Connection connection) throws SQLException
close() will return the connection back to the pool , while closeDestroy() will close() the underlining connection properly.
SQLExceptionprotected PooledConnection(String name)
public int getSlotId()
public void setSlotId(int slotId)
public DataSourcePool getDataSourcePool()
public long getCreationTime()
public String getName()
public String getNameSlot()
public long getBusySeconds()
public String getDescription()
public String getFullDescription()
public String getPstmtStatistics()
public PooledConnectionStatistics getStatistics()
public boolean isLongRunning()
public void setLongRunning(boolean longRunning)
public void closeConnectionFully(boolean logErrors)
The logErrors parameter exists so that expected errors are not logged such as when the database is known to be down.
logErrors - if false then don't log errors when closingpublic PstmtCache getPstmtCache()
public Statement createStatement() throws SQLException
createStatement in interface ConnectioncreateStatement in class ConnectionDelegatorSQLExceptionpublic Statement createStatement(int resultSetType, int resultSetConcurreny) throws SQLException
createStatement in interface ConnectioncreateStatement in class ConnectionDelegatorSQLExceptionprotected void returnPreparedStatement(ExtendedPreparedStatement pstmt)
public PreparedStatement prepareStatement(String sql, int returnKeysFlag) throws SQLException
prepareStatement in interface ConnectionprepareStatement in class ConnectionDelegatorSQLExceptionpublic PreparedStatement prepareStatement(String sql) throws SQLException
prepareStatement in interface ConnectionprepareStatement in class ConnectionDelegatorSQLExceptionpublic PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurreny) throws SQLException
prepareStatement in interface ConnectionprepareStatement in class ConnectionDelegatorSQLExceptionprotected void resetForUse()
public void addError(Throwable e)
Any PooledConnection that has an error is checked to make sure it works before it is placed back into the connection pool.
public boolean hadErrors()
Connections with errors are testing to make sure they are still good before putting them back into the pool.
public void close()
throws SQLException
Note that to ensure that the next transaction starts at the correct time a commit() or rollback() should be called. If neither has occured at this time then a rollback() is used (to end the transaction).
To close the connection fully use closeConnectionFully().
close in interface AutoCloseableclose in interface Connectionclose in class ConnectionDelegatorSQLExceptionprotected void finalize()
throws Throwable
public boolean exceedsMaxAge(long maxAgeMillis)
public boolean shouldTrimOnReturn(long lastResetTime,
long maxAgeMillis)
public boolean shouldTrim(long usedSince,
long createdSince)
public long getStartUseTime()
Used to detect busy connections that could be leaks.
public long getLastUsedTime()
Used to close connections that have been idle for some time. Typically 5 minutes.
public String getLastStatement()
protected void setLastStatement(String lastStatement)
Note with addBatch() this will not really work.
public void setReadOnly(boolean readOnly)
throws SQLException
setReadOnly in interface ConnectionsetReadOnly in class ConnectionDelegatorSQLExceptionpublic void setTransactionIsolation(int level)
throws SQLException
setTransactionIsolation in interface ConnectionsetTransactionIsolation in class ConnectionDelegatorSQLExceptionpublic void clearWarnings()
throws SQLException
clearWarnings in interface ConnectionclearWarnings in class ConnectionDelegatorSQLExceptionpublic void commit()
throws SQLException
commit in interface Connectioncommit in class ConnectionDelegatorSQLExceptionpublic boolean getAutoCommit()
throws SQLException
getAutoCommit in interface ConnectiongetAutoCommit in class ConnectionDelegatorSQLExceptionpublic String getCatalog() throws SQLException
getCatalog in interface ConnectiongetCatalog in class ConnectionDelegatorSQLExceptionpublic DatabaseMetaData getMetaData() throws SQLException
getMetaData in interface ConnectiongetMetaData in class ConnectionDelegatorSQLExceptionpublic int getTransactionIsolation()
throws SQLException
getTransactionIsolation in interface ConnectiongetTransactionIsolation in class ConnectionDelegatorSQLExceptionpublic Map<String,Class<?>> getTypeMap() throws SQLException
getTypeMap in interface ConnectiongetTypeMap in class ConnectionDelegatorSQLExceptionpublic SQLWarning getWarnings() throws SQLException
getWarnings in interface ConnectiongetWarnings in class ConnectionDelegatorSQLExceptionpublic boolean isClosed()
throws SQLException
isClosed in interface ConnectionisClosed in class ConnectionDelegatorSQLExceptionpublic boolean isReadOnly()
throws SQLException
isReadOnly in interface ConnectionisReadOnly in class ConnectionDelegatorSQLExceptionpublic String nativeSQL(String sql) throws SQLException
nativeSQL in interface ConnectionnativeSQL in class ConnectionDelegatorSQLExceptionpublic CallableStatement prepareCall(String sql) throws SQLException
prepareCall in interface ConnectionprepareCall in class ConnectionDelegatorSQLExceptionpublic CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurreny) throws SQLException
prepareCall in interface ConnectionprepareCall in class ConnectionDelegatorSQLExceptionpublic void rollback()
throws SQLException
rollback in interface Connectionrollback in class ConnectionDelegatorSQLExceptionpublic void setAutoCommit(boolean autoCommit)
throws SQLException
setAutoCommit in interface ConnectionsetAutoCommit in class ConnectionDelegatorSQLExceptionpublic void setCatalog(String catalog) throws SQLException
setCatalog in interface ConnectionsetCatalog in class ConnectionDelegatorSQLExceptionpublic void setTypeMap(Map<String,Class<?>> map) throws SQLException
setTypeMap in interface ConnectionsetTypeMap in class ConnectionDelegatorSQLExceptionpublic Savepoint setSavepoint() throws SQLException
setSavepoint in interface ConnectionsetSavepoint in class ConnectionDelegatorSQLExceptionpublic Savepoint setSavepoint(String savepointName) throws SQLException
setSavepoint in interface ConnectionsetSavepoint in class ConnectionDelegatorSQLExceptionpublic void rollback(Savepoint sp) throws SQLException
rollback in interface Connectionrollback in class ConnectionDelegatorSQLExceptionpublic void releaseSavepoint(Savepoint sp) throws SQLException
releaseSavepoint in interface ConnectionreleaseSavepoint in class ConnectionDelegatorSQLExceptionpublic void setHoldability(int i)
throws SQLException
setHoldability in interface ConnectionsetHoldability in class ConnectionDelegatorSQLExceptionpublic int getHoldability()
throws SQLException
getHoldability in interface ConnectiongetHoldability in class ConnectionDelegatorSQLExceptionpublic Statement createStatement(int i, int x, int y) throws SQLException
createStatement in interface ConnectioncreateStatement in class ConnectionDelegatorSQLExceptionpublic PreparedStatement prepareStatement(String s, int i, int x, int y) throws SQLException
prepareStatement in interface ConnectionprepareStatement in class ConnectionDelegatorSQLExceptionpublic PreparedStatement prepareStatement(String s, int[] i) throws SQLException
prepareStatement in interface ConnectionprepareStatement in class ConnectionDelegatorSQLExceptionpublic PreparedStatement prepareStatement(String s, String[] s2) throws SQLException
prepareStatement in interface ConnectionprepareStatement in class ConnectionDelegatorSQLExceptionpublic CallableStatement prepareCall(String s, int i, int x, int y) throws SQLException
prepareCall in interface ConnectionprepareCall in class ConnectionDelegatorSQLExceptionpublic String getCreatedByMethod()
Used to help finding connection pool leaks.
protected void setStackTrace(StackTraceElement[] stackTrace)
public String getStackTraceAsString()
public StackTraceElement[] getStackTrace()
Copyright © 2014. All Rights Reserved.