public class PoolingConnection extends DelegatingConnection<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 and Description |
---|---|
static class |
PoolingConnection.StatementType
Statement types.
|
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
Constructor and Description |
---|
PoolingConnection(Connection connection)
Constructor.
|
Modifier and Type | Method and 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(String sql)
Creates a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(String sql,
int autoGeneratedKeys) |
protected PStmtKey |
createKey(String sql,
int[] columnIndexes)
Creates a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(String sql,
int resultSetType,
int resultSetConcurrency)
Creates a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Creates a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability,
PoolingConnection.StatementType statementType)
Creates a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(String sql,
int resultSetType,
int resultSetConcurrency,
PoolingConnection.StatementType statementType)
Creates a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(String sql,
PoolingConnection.StatementType statementType)
Creates a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(String sql,
String[] columnNames)
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 String |
normalizeSQL(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)
|
CallableStatement |
prepareCall(String sql)
Creates or obtains a
CallableStatement from the pool. |
CallableStatement |
prepareCall(String sql,
int resultSetType,
int resultSetConcurrency)
Creates or obtains a
CallableStatement from the pool. |
CallableStatement |
prepareCall(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Creates or obtains a
CallableStatement from the pool. |
PreparedStatement |
prepareStatement(String sql)
Creates or obtains a
PreparedStatement from the pool. |
PreparedStatement |
prepareStatement(String sql,
int autoGeneratedKeys) |
PreparedStatement |
prepareStatement(String sql,
int[] columnIndexes)
Creates or obtains a
PreparedStatement from the pool. |
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency)
Creates or obtains a
PreparedStatement from the pool. |
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Creates or obtains a
PreparedStatement from the pool. |
PreparedStatement |
prepareStatement(String sql,
String[] columnNames)
Creates or obtains a
PreparedStatement from the pool. |
void |
setStatementPool(KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> pool)
Sets the prepared statement pool.
|
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. |
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, handleExceptionNoThrow, 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
addTrace, clearTrace, getLastUsed, getTrace, removeThisTrace, removeTrace, setLastUsed, setLastUsed
public PoolingConnection(Connection connection)
connection
- the underlying Connection
.public void activateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) throws Exception
KeyedPooledObjectFactory
method for activating pooled statements.activateObject
in interface KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- ignoredpooledObject
- wrapped pooled statement to be activatedException
public void close() throws SQLException
PreparedStatement
s or CallableStatement
s from the pool, and close the
underlying connection.close
in interface AutoCloseable
close
in interface Connection
close
in class DelegatingConnection<Connection>
SQLException
protected PStmtKey createKey(String sql)
sql
- the SQL string used to define the statementprotected PStmtKey createKey(String sql, int[] columnIndexes)
sql
- the SQL string used to define the statementcolumnIndexes
- column indexesprotected PStmtKey createKey(String sql, int resultSetType, int resultSetConcurrency)
sql
- the SQL string used to define the statementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyprotected PStmtKey createKey(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(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(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(String sql, PoolingConnection.StatementType statementType)
sql
- the SQL string used to define the statementstatementType
- statement typeprotected PStmtKey createKey(String sql, String[] columnNames)
sql
- the SQL string used to define the statementcolumnNames
- column namespublic void destroyObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) throws 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.Exception
public PooledObject<DelegatingPreparedStatement> makeObject(PStmtKey key) throws 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 createdException
createKey(String, int, int, StatementType)
protected String normalizeSQL(String sql)
sql
- The statement to be normalized.public void passivateObject(PStmtKey key, PooledObject<DelegatingPreparedStatement> pooledObject) throws Exception
KeyedPooledObjectFactory
method for passivating PreparedStatement
s or CallableStatement
s.
Invokes PreparedStatement.clearParameters()
.passivateObject
in interface KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- ignoredpooledObject
- a wrapped PreparedStatement
Exception
public CallableStatement prepareCall(String sql) throws SQLException
CallableStatement
from the pool.prepareCall
in interface Connection
prepareCall
in class DelegatingConnection<Connection>
sql
- the SQL string used to define the CallableStatementPoolableCallableStatement
SQLException
- Wraps an underlying exception.public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
CallableStatement
from the pool.prepareCall
in interface Connection
prepareCall
in class DelegatingConnection<Connection>
sql
- the SQL string used to define the CallableStatementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyPoolableCallableStatement
SQLException
- Wraps an underlying exception.public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
CallableStatement
from the pool.prepareCall
in interface Connection
prepareCall
in class DelegatingConnection<Connection>
sql
- the SQL string used to define the CallableStatementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyresultSetHoldability
- result set holdabilityPoolableCallableStatement
SQLException
- Wraps an underlying exception.public PreparedStatement prepareStatement(String sql) throws SQLException
PreparedStatement
from the pool.prepareStatement
in interface Connection
prepareStatement
in class DelegatingConnection<Connection>
sql
- the SQL string used to define the PreparedStatementPoolablePreparedStatement
SQLException
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
prepareStatement
in interface Connection
prepareStatement
in class DelegatingConnection<Connection>
SQLException
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
PreparedStatement
from the pool.prepareStatement
in interface Connection
prepareStatement
in class DelegatingConnection<Connection>
sql
- the SQL string used to define the PreparedStatementcolumnIndexes
- column indexesPoolablePreparedStatement
SQLException
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
PreparedStatement
from the pool.prepareStatement
in interface Connection
prepareStatement
in class DelegatingConnection<Connection>
sql
- the SQL string used to define the PreparedStatementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyPoolablePreparedStatement
SQLException
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
PreparedStatement
from the pool.prepareStatement
in interface Connection
prepareStatement
in class DelegatingConnection<Connection>
sql
- the SQL string used to define the PreparedStatementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyresultSetHoldability
- result set holdabilityPoolablePreparedStatement
SQLException
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
PreparedStatement
from the pool.prepareStatement
in interface Connection
prepareStatement
in class DelegatingConnection<Connection>
sql
- the SQL string used to define the PreparedStatementcolumnNames
- column namesPoolablePreparedStatement
SQLException
public void setStatementPool(KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> pool)
pool
- the prepared statement pool.public String toString()
DelegatingConnection
toString
in class DelegatingConnection<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 © 2001–2019 The Apache Software Foundation. All rights reserved.