public final class CacheConnection extends Object implements Connection, Reusable
Connection wrapper that implements statement caching.CachedStatement,
CachedPreparedStatement,
CachedCallableStatement| Modifier and Type | Field and Description |
|---|---|
protected org.slf4j.Logger |
logger
SLF4J logger instance for writing log entries.
|
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE| Constructor and Description |
|---|
CacheConnection(ConnectionPool pool,
Connection con)
Creates a new
CacheConnection object, using the supplied Connection. |
| Modifier and Type | Method and Description |
|---|---|
void |
abort(Executor executor) |
void |
clearWarnings() |
void |
close()
Overrides method to provide caching support.
|
void |
commit() |
Array |
createArrayOf(String typeName,
Object[] elements) |
Blob |
createBlob() |
Clob |
createClob() |
NClob |
createNClob() |
SQLXML |
createSQLXML() |
Statement |
createStatement()
Overrides method to provide caching support.
|
Statement |
createStatement(int resultSetType,
int resultSetConcurrency)
Overrides method to provide caching support.
|
Statement |
createStatement(int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Overrides method to provide caching support.
|
Struct |
createStruct(String typeName,
Object[] attributes) |
protected void |
flushOpenCallableStatements()
Flushes the open
CallableStatement cache for this connection. |
protected void |
flushOpenNonCacheableStatements()
Flushes the non-cacheable
Statement instances for this connection. |
protected void |
flushOpenPreparedStatements()
Flushes the open
PreparedStatement cache for this connection. |
protected void |
flushOpenStatements()
Flushes the open
Statement cache for this connection. |
protected void |
flushSpareCallableStatements()
Flushes the spare
CallableStatement cache for this connection. |
protected void |
flushSparePreparedStatements()
Flushes the spare
PreparedStatement cache for this connection. |
protected void |
flushSpareStatements()
Flushes the spare
Statement caches for this connection. |
boolean |
getAutoCommit() |
String |
getCatalog() |
Properties |
getClientInfo() |
String |
getClientInfo(String name) |
Connection |
getConnection() |
Connection |
getDelegateConnection()
Returns the delegate
Connection instance for which this provides
a wrapper. |
int |
getHoldability() |
DatabaseMetaData |
getMetaData() |
int |
getNetworkTimeout() |
int |
getOpenCallableStatementCount()
Returns the current number of
CallableStatement instances that are in use. |
int |
getOpenNonCacheableStatementCount()
Returns the current number of non-cacheable statements that are in use.
|
int |
getOpenPreparedStatementCount()
Returns the current number of
PreparedStatement instances that
are in use (not including CallableStatement instances). |
int |
getOpenStatementCount()
Returns the current number of
Statement instances that are in use
(not including PreparedStatement or CallableStatement instances). |
protected ConnectionPool |
getPool()
Returns the
ConnectionPool to which this CacheConnection belongs. |
String |
getSchema() |
int |
getSpareCallableStatementCount()
Returns the current number of spare
CallableStatement instances that are cached. |
int |
getSparePreparedStatementCount()
Returns the current number of spare
PreparedStatement instances that are cached. |
int |
getSpareStatementCount()
Returns the current number of spare Statements that are cached.
|
int |
getTransactionIsolation() |
Map<String,Class<?>> |
getTypeMap() |
SQLWarning |
getWarnings() |
boolean |
isCachingAllStatements()
Returns whether caching of all
Statement instances is enabled. |
boolean |
isCachingCallableStatements()
Returns whether caching of
CallableStatement instances is enabled. |
boolean |
isCachingPreparedStatements()
Returns whether caching of
PreparedStatement instances is enabled. |
boolean |
isCachingStatements()
Returns whether caching of standard
Statement instances is enabled. |
boolean |
isClosed() |
boolean |
isDirty()
Determines if this object is "dirty" (i.e.
|
boolean |
isReadOnly() |
boolean |
isValid(int timeout) |
boolean |
isWrapperFor(Class<?> iface) |
protected void |
log_debug(String s)
Logging relay method (to prefix pool name).
|
protected void |
log_debug(String s,
Throwable throwable)
Logging relay method (to prefix pool name).
|
protected void |
log_warn(String s)
Logging relay method (to prefix pool name).
|
protected void |
log_warn(String s,
Throwable throwable)
Logging relay method (to prefix pool name).
|
String |
nativeSQL(String sql) |
CallableStatement |
prepareCall(String sql)
Overrides method to provide caching support.
|
CallableStatement |
prepareCall(String sql,
int resultSetType,
int resultSetConcurrency)
Overrides method to provide caching support.
|
CallableStatement |
prepareCall(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Overrides method to provide caching support.
|
PreparedStatement |
prepareStatement(String sql)
Overrides method to provide caching support.
|
PreparedStatement |
prepareStatement(String sql,
int autoGeneratedKeys) |
PreparedStatement |
prepareStatement(String sql,
int[] columnIndexes) |
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency)
Overrides method to provide caching support.
|
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Overrides method to provide caching support.
|
PreparedStatement |
prepareStatement(String sql,
String[] columnNames) |
void |
recycle()
Puts the connection back in a state where it can be reused.
|
void |
release()
Destroys the wrapped
Connection instance. |
void |
releaseSavepoint(Savepoint savepoint) |
void |
rollback() |
void |
rollback(Savepoint savepoint) |
void |
setAutoCommit(boolean autoCommit) |
void |
setCacheAll(boolean cache)
Sets whether to use caching for all types of Statement.
|
void |
setCacheCallableStatements(boolean cache)
Sets whether to use caching for
CallableStatement instances. |
void |
setCachePreparedStatements(boolean cache)
Sets whether to use caching for
PreparedStatement instances. |
void |
setCacheStatements(boolean cache)
Sets whether to use caching for
Statement instances. |
void |
setCatalog(String catalog) |
void |
setClientInfo(Properties properties) |
void |
setClientInfo(String name,
String value) |
void |
setHoldability(int holdability) |
void |
setNetworkTimeout(Executor executor,
int milliseconds) |
void |
setReadOnly(boolean readOnly) |
Savepoint |
setSavepoint() |
Savepoint |
setSavepoint(String name) |
void |
setSchema(String schema) |
void |
setTransactionIsolation(int level) |
void |
setTypeMap(Map<String,Class<?>> map) |
void |
statementClosed(CachedStatement s)
Callback invoked when a
CachedStatement is closed. |
<T> T |
unwrap(Class<T> iface) |
protected org.slf4j.Logger logger
public CacheConnection(ConnectionPool pool, Connection con)
CacheConnection object, using the supplied Connection.pool - ConnectionPool to which this CacheConnection belongscon - Connection instance to which database calls should be delegatedpublic void setCacheStatements(boolean cache)
Statement instances.cache - whether to cache Statement instancespublic void setCachePreparedStatements(boolean cache)
PreparedStatement instances.cache - whether to cache PreparedStatement instancespublic void setCacheCallableStatements(boolean cache)
CallableStatement instances.cache - whether to cache CallableStatement instancespublic void setCacheAll(boolean cache)
cache - whether to cache all types of statementpublic boolean isCachingAllStatements()
Statement instances is enabled.public boolean isCachingStatements()
Statement instances is enabled.Statement instances are flagged for caching, false otherwise.public boolean isCachingPreparedStatements()
PreparedStatement instances is enabled.PreparedStatement instances are flagged for caching, false otherwise.public boolean isCachingCallableStatements()
CallableStatement instances is enabled.CallableStatement instances are flagged for caching, false otherwise.public Connection getDelegateConnection()
Connection instance for which this provides
a wrapper. This is provided as a convenience method for using database-specific
features for which the Connection object needs to be upcast.
(e.g. to use Oracle-specific features needs to be cast to
oracle.jdbc.OracleConnection).
To maintain the stability of the pooling system it is important that the
raw connection is not destabilized when used in this way.Connection instance being used for database access.protected final ConnectionPool getPool()
ConnectionPool to which this CacheConnection belongs.
This is provided as a convenience for internal library code (testing etc.)ConnectionPool to which this CacheConnection belongsprotected void log_warn(String s)
s - string to logprotected void log_warn(String s, Throwable throwable)
s - string to logthrowable - Throwable instance to logprotected void log_debug(String s)
s - string to logprotected void log_debug(String s, Throwable throwable)
s - string to logthrowable - Throwable instance to logpublic 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 ConnectionSQLExceptionpublic PreparedStatement prepareStatement(String sql) 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 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 void statementClosed(CachedStatement s) throws SQLException
CachedStatement is closed.
This method should only be called by CachedStatement instances.s - CachedStatement on which close() method was calledSQLException - if thrown while attempting to close statementpublic String nativeSQL(String sql) throws SQLException
nativeSQL in interface ConnectionSQLExceptionpublic void setAutoCommit(boolean autoCommit)
throws SQLException
setAutoCommit in interface ConnectionSQLExceptionpublic boolean getAutoCommit()
throws SQLException
getAutoCommit in interface ConnectionSQLExceptionpublic void commit()
throws SQLException
commit in interface ConnectionSQLExceptionpublic void rollback()
throws SQLException
rollback in interface ConnectionSQLExceptionpublic void recycle()
throws SQLException
ConnectionPool instances.recycle in interface ReusableSQLException - if thrown while attempting to recyclepublic boolean isDirty()
isDirty in interface ReusableConnectionPool.isRecycleAfterDelegateUse() is true and delegate has been used, false otherwisepublic void close()
throws SQLException
close in interface AutoCloseableclose in interface ConnectionSQLExceptionpublic int getSpareStatementCount()
public int getOpenStatementCount()
Statement instances that are in use
(not including PreparedStatement or CallableStatement instances).public int getSparePreparedStatementCount()
PreparedStatement instances that are cached.public int getOpenPreparedStatementCount()
PreparedStatement instances that
are in use (not including CallableStatement instances).public int getSpareCallableStatementCount()
CallableStatement instances that are cached.public int getOpenCallableStatementCount()
CallableStatement instances that are in use.public int getOpenNonCacheableStatementCount()
PreparedStatement instances are non-cacheable
by virtue of a request made at creation for support for auto-generated keys.)prepareStatement(String, int),
prepareStatement(String, int[]),
prepareStatement(String, String[])protected void flushSpareStatements()
throws SQLException
Statement caches for this connection.SQLException - if thrown while attempting to flush statementsprotected void flushOpenStatements()
throws SQLException
Statement cache for this connection.SQLException - if thrown while attempting to flush statementsprotected void flushSparePreparedStatements()
throws SQLException
PreparedStatement cache for this connection.SQLException - if thrown while attempting to flush statementsprotected void flushOpenPreparedStatements()
throws SQLException
PreparedStatement cache for this connection.SQLException - if thrown while attempting to flush statementsprotected void flushSpareCallableStatements()
throws SQLException
CallableStatement cache for this connection.SQLException - if thrown while attempting to flush statementsprotected void flushOpenCallableStatements()
throws SQLException
CallableStatement cache for this connection.SQLException - if thrown while attempting to flush statementsprotected void flushOpenNonCacheableStatements()
throws SQLException
Statement instances for this connection.SQLException - if thrown while attempting to flush statementspublic void release()
throws SQLException
Connection instance.
This method should only be called by ConnectionPool instances.SQLException - if thrown while attempting to release statementpublic boolean isClosed()
throws SQLException
isClosed in interface ConnectionSQLExceptionpublic DatabaseMetaData getMetaData() throws SQLException
getMetaData in interface ConnectionSQLExceptionpublic void setReadOnly(boolean readOnly)
throws SQLException
setReadOnly in interface ConnectionSQLExceptionpublic boolean isReadOnly()
throws SQLException
isReadOnly in interface ConnectionSQLExceptionpublic void setCatalog(String catalog) throws SQLException
setCatalog in interface ConnectionSQLExceptionpublic String getCatalog() throws SQLException
getCatalog in interface ConnectionSQLExceptionpublic void setTransactionIsolation(int level)
throws SQLException
setTransactionIsolation in interface ConnectionSQLExceptionpublic int getTransactionIsolation()
throws SQLException
getTransactionIsolation in interface ConnectionSQLExceptionpublic SQLWarning getWarnings() throws SQLException
getWarnings in interface ConnectionSQLExceptionpublic void clearWarnings()
throws SQLException
clearWarnings in interface ConnectionSQLExceptionpublic Map<String,Class<?>> getTypeMap() throws SQLException
getTypeMap in interface ConnectionSQLExceptionpublic void setTypeMap(Map<String,Class<?>> map) throws SQLException
setTypeMap in interface ConnectionSQLExceptionpublic void setHoldability(int holdability)
throws SQLException
setHoldability in interface ConnectionSQLExceptionpublic int getHoldability()
throws SQLException
getHoldability in interface ConnectionSQLExceptionpublic Savepoint setSavepoint() throws SQLException
setSavepoint in interface ConnectionSQLExceptionpublic Savepoint setSavepoint(String name) throws SQLException
setSavepoint in interface ConnectionSQLExceptionpublic void rollback(Savepoint savepoint) throws SQLException
rollback in interface ConnectionSQLExceptionpublic void releaseSavepoint(Savepoint savepoint) throws SQLException
releaseSavepoint 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 Connection getConnection() throws SQLException
SQLExceptionpublic boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor in interface WrapperSQLExceptionpublic <T> T unwrap(Class<T> iface) throws SQLException
unwrap in interface WrapperSQLExceptionpublic Clob createClob() throws SQLException
createClob in interface ConnectionSQLExceptionpublic Blob createBlob() throws SQLException
createBlob in interface ConnectionSQLExceptionpublic NClob createNClob() throws SQLException
createNClob in interface ConnectionSQLExceptionpublic SQLXML createSQLXML() throws SQLException
createSQLXML in interface ConnectionSQLExceptionpublic boolean isValid(int timeout)
throws SQLException
isValid in interface ConnectionSQLExceptionpublic void setClientInfo(String name, String value) throws SQLClientInfoException
setClientInfo in interface ConnectionSQLClientInfoExceptionpublic void setClientInfo(Properties properties) throws SQLClientInfoException
setClientInfo in interface ConnectionSQLClientInfoExceptionpublic String getClientInfo(String name) throws SQLException
getClientInfo in interface ConnectionSQLExceptionpublic Properties getClientInfo() throws SQLException
getClientInfo in interface ConnectionSQLExceptionpublic Array createArrayOf(String typeName, Object[] elements) throws SQLException
createArrayOf in interface ConnectionSQLExceptionpublic Struct createStruct(String typeName, Object[] attributes) throws SQLException
createStruct 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 ConnectionSQLExceptionCopyright © 2015. All rights reserved.