public class PoolingConnection extends DelegatingConnection implements Connection, KeyedPoolableObjectFactory
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 | Field and Description |
---|---|
protected KeyedObjectPool |
_pstmtPool
Pool of
PreparedStatement 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 pool)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
activateObject(Object key,
Object obj) |
void |
close()
Close and free all
PreparedStatement s or CallableStatement from the pool, and
close the underlying connection. |
protected Object |
createKey(String sql) |
protected Object |
createKey(String sql,
byte stmtType) |
protected Object |
createKey(String sql,
int resultSetType,
int resultSetConcurrency) |
protected Object |
createKey(String sql,
int resultSetType,
int resultSetConcurrency,
byte stmtType) |
void |
destroyObject(Object key,
Object obj) |
Object |
makeObject(Object obj) |
protected String |
normalizeSQL(String sql) |
void |
passivateObject(Object key,
Object obj) |
CallableStatement |
prepareCall(String sql) |
CallableStatement |
prepareCall(String sql,
int resultSetType,
int resultSetConcurrency) |
PreparedStatement |
prepareStatement(String sql)
Create or obtain a
PreparedStatement from the pool. |
PreparedStatement |
prepareStatement(String sql,
int resultSetType,
int resultSetConcurrency)
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(Object key,
Object obj) |
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, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, 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
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
abort, clearWarnings, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getHoldability, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, isClosed, isReadOnly, isValid, nativeSQL, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMap
isWrapperFor, unwrap
protected KeyedObjectPool _pstmtPool
PreparedStatement
s. and CallableStatement
spublic PoolingConnection(Connection c)
c
- the underlying Connection
.public PoolingConnection(Connection c, KeyedObjectPool 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 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
prepareCall
in interface Connection
prepareCall
in class DelegatingConnection
SQLException
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
prepareCall
in interface Connection
prepareCall
in class DelegatingConnection
SQLException
protected Object createKey(String sql, int resultSetType, int resultSetConcurrency, byte stmtType)
public Object makeObject(Object obj) throws Exception
makeObject
in interface KeyedPoolableObjectFactory
Exception
public void destroyObject(Object key, Object obj) throws Exception
destroyObject
in interface KeyedPoolableObjectFactory
Exception
public boolean validateObject(Object key, Object obj)
validateObject
in interface KeyedPoolableObjectFactory
public void activateObject(Object key, Object obj) throws Exception
activateObject
in interface KeyedPoolableObjectFactory
Exception
public void passivateObject(Object key, Object obj) throws Exception
passivateObject
in interface KeyedPoolableObjectFactory
Exception
public String toString()
DelegatingConnection
toString
in class DelegatingConnection
Copyright © 2017. All rights reserved.