java.lang.AutoCloseable
, java.sql.Connection
, java.sql.Wrapper
, KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
, TrackedUse
public class PoolingConnection extends DelegatingConnection<java.sql.Connection> implements KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
DelegatingConnection
that pools PreparedStatement
s.
The prepareStatement(java.lang.String)
and prepareCall(java.lang.String)
methods, rather than creating a new PreparedStatement each
time, may actually pull the statement from a pool of unused statements. The Statement.close()
method of
the returned statement doesn't actually close the statement, but rather returns it to the pool. (See
PoolablePreparedStatement
, PoolableCallableStatement
.)
PoolablePreparedStatement
Modifier and Type | Class | Description |
---|---|---|
static class |
PoolingConnection.StatementType |
Statement types.
|
Constructor | Description |
---|---|
PoolingConnection(java.sql.Connection connection) |
Constructor.
|
Modifier and Type | Method | Description |
---|---|---|
void |
activateObject(PStmtKey key,
PooledObject<DelegatingPreparedStatement> pooledObject) |
KeyedPooledObjectFactory method for activating pooled statements. |
void |
close() |
Closes and frees all
PreparedStatement s or CallableStatement s from the pool, and close the
underlying connection. |
protected PStmtKey |
createKey(java.lang.String sql) |
Creates a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(java.lang.String sql,
int autoGeneratedKeys) |
|
protected PStmtKey |
createKey(java.lang.String sql,
int[] columnIndexes) |
Creates a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(java.lang.String sql,
int resultSetType,
int resultSetConcurrency) |
Creates a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) |
Creates a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability,
PoolingConnection.StatementType statementType) |
Creates a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
PoolingConnection.StatementType statementType) |
Creates a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(java.lang.String sql,
java.lang.String[] columnNames) |
Creates a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(java.lang.String sql,
PoolingConnection.StatementType statementType) |
Creates a PStmtKey for the given arguments.
|
void |
destroyObject(PStmtKey key,
PooledObject<DelegatingPreparedStatement> pooledObject) |
KeyedPooledObjectFactory method for destroying PoolablePreparedStatements and PoolableCallableStatements. |
PooledObject<DelegatingPreparedStatement> |
makeObject(PStmtKey key) |
KeyedPooledObjectFactory method for creating PoolablePreparedStatement s or
PoolableCallableStatement s. |
protected java.lang.String |
normalizeSQL(java.lang.String sql) |
Normalizes the given SQL statement, producing a canonical form that is semantically equivalent to the original.
|
void |
passivateObject(PStmtKey key,
PooledObject<DelegatingPreparedStatement> pooledObject) |
|
java.sql.CallableStatement |
prepareCall(java.lang.String sql) |
Creates or obtains a
CallableStatement from the pool. |
java.sql.CallableStatement |
prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency) |
Creates or obtains a
CallableStatement from the pool. |
java.sql.CallableStatement |
prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) |
Creates or obtains a
CallableStatement from the pool. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql) |
Creates or obtains a
PreparedStatement from the pool. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int autoGeneratedKeys) |
|
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int[] columnIndexes) |
Creates or obtains a
PreparedStatement from the pool. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency) |
Creates or obtains a
PreparedStatement from the pool. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) |
Creates or obtains a
PreparedStatement from the pool. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
java.lang.String[] columnNames) |
Creates or obtains a
PreparedStatement from the pool. |
void |
setStatementPool(KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> pool) |
Sets the prepared statement pool.
|
java.lang.String |
toString() |
Returns a string representation of the metadata associated with the innermost delegate connection.
|
boolean |
validateObject(PStmtKey key,
PooledObject<DelegatingPreparedStatement> pooledObject) |
KeyedPooledObjectFactory method for validating pooled statements. |
addTrace, clearTrace, getLastUsed, getTrace, removeTrace, setLastUsed, setLastUsed
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
abort, activate, checkOpen, clearCachedState, clearWarnings, closeInternal, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getAutoCommit, getCacheState, getCatalog, getClientInfo, getClientInfo, getDefaultQueryTimeout, getDelegate, getDelegateInternal, getHoldability, getInnermostDelegate, getInnermostDelegateInternal, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, handleException, innermostDelegateEquals, isClosed, isClosedInternal, isReadOnly, isValid, isWrapperFor, nativeSQL, passivate, releaseSavepoint, rollback, rollback, setAutoCommit, setCacheState, setCatalog, setClientInfo, setClientInfo, setClosedInternal, setDefaultQueryTimeout, setDelegate, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMap, unwrap
public PoolingConnection(java.sql.Connection connection)
connection
- the underlying Connection
.public void activateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) throws java.lang.Exception
KeyedPooledObjectFactory
method for activating pooled statements.activateObject
in interface KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- ignoredpooledObject
- wrapped pooled statement to be activatedjava.lang.Exception
- if there is a problem activating obj
,
this exception may be swallowed by the pool.KeyedPooledObjectFactory.destroyObject(K, org.apache.tomcat.dbcp.pool2.PooledObject<V>)
public void close() throws java.sql.SQLException
PreparedStatement
s or CallableStatement
s from the pool, and close the
underlying connection.close
in interface java.lang.AutoCloseable
close
in interface java.sql.Connection
close
in class DelegatingConnection<java.sql.Connection>
java.sql.SQLException
protected PStmtKey createKey(java.lang.String sql)
sql
- the SQL string used to define the statementprotected PStmtKey createKey(java.lang.String sql, int[] columnIndexes)
sql
- the SQL string used to define the statementcolumnIndexes
- column indexesprotected PStmtKey createKey(java.lang.String sql, int autoGeneratedKeys)
protected PStmtKey createKey(java.lang.String sql, int resultSetType, int resultSetConcurrency)
sql
- the SQL string used to define the statementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyprotected PStmtKey createKey(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
sql
- the SQL string used to define the statementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyresultSetHoldability
- result set holdabilityprotected PStmtKey createKey(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, PoolingConnection.StatementType statementType)
sql
- the SQL string used to define the statementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyresultSetHoldability
- result set holdabilitystatementType
- statement typeprotected PStmtKey createKey(java.lang.String sql, int resultSetType, int resultSetConcurrency, PoolingConnection.StatementType statementType)
sql
- the SQL string used to define the statementresultSetType
- result set typeresultSetConcurrency
- result set concurrencystatementType
- statement typeprotected PStmtKey createKey(java.lang.String sql, PoolingConnection.StatementType statementType)
sql
- the SQL string used to define the statementstatementType
- statement typeprotected PStmtKey createKey(java.lang.String sql, java.lang.String[] columnNames)
sql
- the SQL string used to define the statementcolumnNames
- column namespublic void destroyObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) throws java.lang.Exception
KeyedPooledObjectFactory
method for destroying PoolablePreparedStatements and PoolableCallableStatements.
Closes the underlying statement.destroyObject
in interface KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- ignoredpooledObject
- the wrapped pooled statement to be destroyed.java.lang.Exception
- should be avoided as it may be swallowed by
the pool implementation.KeyedPooledObjectFactory.validateObject(K, org.apache.tomcat.dbcp.pool2.PooledObject<V>)
,
KeyedObjectPool.invalidateObject(K, V)
public PooledObject<DelegatingPreparedStatement> makeObject(PStmtKey key) throws java.lang.Exception
KeyedPooledObjectFactory
method for creating PoolablePreparedStatement
s or
PoolableCallableStatement
s. The stmtType
field in the key determines whether a
PoolablePreparedStatement or PoolableCallableStatement is created.makeObject
in interface KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- the key for the PreparedStatement
to be createdPooledObject
wrapping an instance that can
be served by the pool.java.lang.Exception
- if there is a problem creating a new instance,
this will be propagated to the code requesting an object.createKey(String, int, int, StatementType)
protected java.lang.String normalizeSQL(java.lang.String sql)
sql
- The statement to be normalized.public void passivateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) throws java.lang.Exception
KeyedPooledObjectFactory
method for passivating PreparedStatement
s or CallableStatement
s.
Invokes PreparedStatement.clearParameters()
.passivateObject
in interface KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- ignoredpooledObject
- a wrapped PreparedStatement
java.lang.Exception
- if there is a problem passivating obj
,
this exception may be swallowed by the pool.KeyedPooledObjectFactory.destroyObject(K, org.apache.tomcat.dbcp.pool2.PooledObject<V>)
public java.sql.CallableStatement prepareCall(java.lang.String sql) throws java.sql.SQLException
CallableStatement
from the pool.prepareCall
in interface java.sql.Connection
prepareCall
in class DelegatingConnection<java.sql.Connection>
sql
- the SQL string used to define the CallableStatementPoolableCallableStatement
java.sql.SQLException
- Wraps an underlying exception.public java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
CallableStatement
from the pool.prepareCall
in interface java.sql.Connection
prepareCall
in class DelegatingConnection<java.sql.Connection>
sql
- the SQL string used to define the CallableStatementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyPoolableCallableStatement
java.sql.SQLException
- Wraps an underlying exception.public java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
CallableStatement
from the pool.prepareCall
in interface java.sql.Connection
prepareCall
in class DelegatingConnection<java.sql.Connection>
sql
- the SQL string used to define the CallableStatementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyresultSetHoldability
- result set holdabilityPoolableCallableStatement
java.sql.SQLException
- Wraps an underlying exception.public java.sql.PreparedStatement prepareStatement(java.lang.String sql) throws java.sql.SQLException
PreparedStatement
from the pool.prepareStatement
in interface java.sql.Connection
prepareStatement
in class DelegatingConnection<java.sql.Connection>
sql
- the SQL string used to define the PreparedStatementPoolablePreparedStatement
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
prepareStatement
in interface java.sql.Connection
prepareStatement
in class DelegatingConnection<java.sql.Connection>
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
PreparedStatement
from the pool.prepareStatement
in interface java.sql.Connection
prepareStatement
in class DelegatingConnection<java.sql.Connection>
sql
- the SQL string used to define the PreparedStatementcolumnIndexes
- column indexesPoolablePreparedStatement
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
PreparedStatement
from the pool.prepareStatement
in interface java.sql.Connection
prepareStatement
in class DelegatingConnection<java.sql.Connection>
sql
- the SQL string used to define the PreparedStatementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyPoolablePreparedStatement
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
PreparedStatement
from the pool.prepareStatement
in interface java.sql.Connection
prepareStatement
in class DelegatingConnection<java.sql.Connection>
sql
- the SQL string used to define the PreparedStatementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyresultSetHoldability
- result set holdabilityPoolablePreparedStatement
java.sql.SQLException
public java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
PreparedStatement
from the pool.prepareStatement
in interface java.sql.Connection
prepareStatement
in class DelegatingConnection<java.sql.Connection>
sql
- the SQL string used to define the PreparedStatementcolumnNames
- column namesPoolablePreparedStatement
java.sql.SQLException
public void setStatementPool(KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> pool)
pool
- the prepared statement pool.public java.lang.String toString()
DelegatingConnection
toString
in class DelegatingConnection<java.sql.Connection>
public boolean validateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject)
KeyedPooledObjectFactory
method for validating pooled statements. Currently always returns true.validateObject
in interface KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- ignoredpooledObject
- ignoredtrue
Copyright © 2000-2018 Apache Software Foundation. All Rights Reserved.