public class PoolingConnection extends DelegatingConnection implements KeyedPoolableObjectFactory<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 |
Modifier and Type | Field and Description |
---|---|
protected KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> |
_pstmtPool
Pool of
PreparedStatement s. and CallableStatement s |
_closed, _conn
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
Constructor and Description |
---|
PoolingConnection(Connection c)
Constructor.
|
PoolingConnection(Connection c,
KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> pool)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
activateObject(PStmtKey key,
DelegatingPreparedStatement obj)
KeyedPoolableObjectFactory method for activating
pooled statements. |
void |
close()
Close and free all
PreparedStatement s or CallableStatement from the pool, and
close the underlying connection. |
protected PStmtKey |
createKey(String sql)
Create a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(String sql,
int autoGeneratedKeys) |
protected PStmtKey |
createKey(String sql,
int[] columnIndexes) |
protected PStmtKey |
createKey(String sql,
int resultSetType,
int resultSetConcurrency)
Create a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) |
protected PStmtKey |
createKey(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability,
PoolingConnection.StatementType statementType) |
protected PStmtKey |
createKey(String sql,
int resultSetType,
int resultSetConcurrency,
PoolingConnection.StatementType stmtType)
Create a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(String sql,
PoolingConnection.StatementType stmtType)
Create a PStmtKey for the given arguments.
|
protected PStmtKey |
createKey(String sql,
String[] columnNames)
Create a PStmtKey for the given arguments.
|
void |
destroyObject(PStmtKey key,
DelegatingPreparedStatement obj)
KeyedPoolableObjectFactory method for destroying
PoolablePreparedStatements and PoolableCallableStatements. |
DelegatingPreparedStatement |
makeObject(PStmtKey key)
KeyedPoolableObjectFactory method for creating
PoolablePreparedStatement s or PoolableCallableStatement s. |
protected String |
normalizeSQL(String sql)
Normalize the given SQL statement, producing a
cannonical form that is semantically equivalent to the original.
|
void |
passivateObject(PStmtKey key,
DelegatingPreparedStatement obj)
|
CallableStatement |
prepareCall(String sql)
Create or obtain a
CallableStatement from the pool. |
CallableStatement |
prepareCall(String sql,
int resultSetType,
int resultSetConcurrency)
Create or obtain a
CallableStatement from the pool. |
CallableStatement |
prepareCall(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Create or obtain a
CallableStatement from the pool. |
PreparedStatement |
prepareStatement(String sql)
Create or obtain a
PreparedStatement from the pool. |
PreparedStatement |
prepareStatement(String sql,
int autoGeneratedKeys) |
PreparedStatement |
prepareStatement(String sql,
int[] columnIndexes)
Create or obtain a
PreparedStatement from the pool. |
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency)
Create or obtain a
PreparedStatement from the pool. |
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability)
Create or obtain a
PreparedStatement from the pool. |
PreparedStatement |
prepareStatement(String sql,
String[] columnNames)
Create or obtain a
PreparedStatement from the pool. |
String |
toString()
Returns a string representation of the metadata associated with
the innnermost delegate connection.
|
boolean |
validateObject(PStmtKey key,
DelegatingPreparedStatement obj)
KeyedPoolableObjectFactory method for validating
pooled statements. |
abort, activate, checkOpen, clearWarnings, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, equals, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getDelegate, getDelegateInternal, getHoldability, getInnermostDelegate, getInnermostDelegateInternal, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, handleException, hashCode, innermostDelegateEquals, isClosed, isReadOnly, isValid, isWrapperFor, nativeSQL, passivate, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setDelegate, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMap, unwrap
addTrace, clearTrace, getConfig, getLastUsed, getTrace, printStackTrace, removeTrace, setLastUsed, setLastUsed, setStackTrace
protected KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> _pstmtPool
PreparedStatement
s. and CallableStatement
spublic PoolingConnection(Connection c)
c
- the underlying Connection
.public PoolingConnection(Connection c, KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> pool)
c
- the underlying Connection
.pool
- KeyedObjectPool
of PreparedStatement
s and CallableStatement
s.public void close() throws SQLException
PreparedStatement
s or CallableStatement
from the pool, and
close the underlying connection.close
in interface AutoCloseable
close
in interface Connection
close
in class DelegatingConnection
SQLException
public PreparedStatement prepareStatement(String sql) throws SQLException
PreparedStatement
from the pool.prepareStatement
in interface Connection
prepareStatement
in class DelegatingConnection
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
SQLException
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
PreparedStatement
from the pool.prepareStatement
in interface Connection
prepareStatement
in class DelegatingConnection
sql
- the sql string used to define the PreparedStatementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyPoolablePreparedStatement
SQLException
public CallableStatement prepareCall(String sql) throws SQLException
CallableStatement
from the pool.prepareCall
in interface Connection
prepareCall
in class DelegatingConnection
sql
- the sql string used to define the CallableStatementPoolableCallableStatement
SQLException
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
CallableStatement
from the pool.prepareCall
in interface Connection
prepareCall
in class DelegatingConnection
sql
- the sql string used to define the CallableStatementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyPoolableCallableStatement
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
sql
- the sql string used to define the PreparedStatementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyresultSetHoldability
- result set holdabilityPoolablePreparedStatement
SQLException
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
PreparedStatement
from the pool.prepareStatement
in interface Connection
prepareStatement
in class DelegatingConnection
sql
- the sql string used to define the PreparedStatementcolumnIndexes
- column indexesPoolablePreparedStatement
SQLException
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
PreparedStatement
from the pool.prepareStatement
in interface Connection
prepareStatement
in class DelegatingConnection
sql
- the sql string used to define the PreparedStatementcolumnNames
- column namesPoolablePreparedStatement
SQLException
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
sql
- the sql string used to define the CallableStatementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyresultSetHoldability
- result set holdabilityPoolableCallableStatement
SQLException
protected PStmtKey createKey(String sql)
sql
- the sql string used to define the statementprotected 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)
protected PStmtKey createKey(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability, PoolingConnection.StatementType statementType)
protected PStmtKey createKey(String sql, int resultSetType, int resultSetConcurrency, PoolingConnection.StatementType stmtType)
sql
- the sql string used to define the statementresultSetType
- result set typeresultSetConcurrency
- result set concurrencystmtType
- statement typeprotected PStmtKey createKey(String sql, PoolingConnection.StatementType stmtType)
sql
- the sql string used to define the statementstmtType
- statement typeprotected PStmtKey createKey(String sql, String[] columnNames)
sql
- the sql string used to define the statementcolumnNames
- column namesprotected String normalizeSQL(String sql)
public DelegatingPreparedStatement makeObject(PStmtKey key) throws Exception
KeyedPoolableObjectFactory
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 KeyedPoolableObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- the key for the PreparedStatement
to be createdException
- if there is a problem creating a new instance,
this will be propagated to the code requesting an object.createKey(String, int, int, StatementType)
public void destroyObject(PStmtKey key, DelegatingPreparedStatement obj) throws Exception
KeyedPoolableObjectFactory
method for destroying
PoolablePreparedStatements and PoolableCallableStatements.
Closes the underlying statement.destroyObject
in interface KeyedPoolableObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- ignoredobj
- the pooled statement to be destroyed.Exception
- should be avoided as it may be swallowed by
the pool implementation.KeyedPoolableObjectFactory.validateObject(K, V)
,
KeyedObjectPool.invalidateObject(K, V)
public boolean validateObject(PStmtKey key, DelegatingPreparedStatement obj)
KeyedPoolableObjectFactory
method for validating
pooled statements. Currently always returns true.validateObject
in interface KeyedPoolableObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- ignoredobj
- ignoredtrue
public void activateObject(PStmtKey key, DelegatingPreparedStatement obj) throws Exception
KeyedPoolableObjectFactory
method for activating
pooled statements.activateObject
in interface KeyedPoolableObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- ignoredobj
- pooled statement to be activatedException
- if there is a problem activating obj
,
this exception may be swallowed by the pool.KeyedPoolableObjectFactory.destroyObject(K, V)
public void passivateObject(PStmtKey key, DelegatingPreparedStatement obj) throws Exception
KeyedPoolableObjectFactory
method for passivating
PreparedStatement
s or CallableStatement
s.
Invokes PreparedStatement.clearParameters()
.passivateObject
in interface KeyedPoolableObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- ignoredobj
- a PreparedStatement
Exception
- if there is a problem passivating obj
,
this exception may be swallowed by the pool.KeyedPoolableObjectFactory.destroyObject(K, V)
public String toString()
DelegatingConnection
toString
in class DelegatingConnection
Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.