java.lang.AutoCloseable
, java.sql.Connection
, java.sql.Wrapper
, org.apache.commons.pool2.KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
, org.apache.commons.pool2.TrackedUse
public class PoolingConnection extends DelegatingConnection<java.sql.Connection> implements org.apache.commons.pool2.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
Constructor | Description |
---|---|
PoolingConnection(java.sql.Connection c) |
Constructor.
|
Modifier and Type | Method | Description |
---|---|---|
void |
activateObject(PStmtKey key,
org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p) |
KeyedPooledObjectFactory method for activating
pooled statements. |
void |
close() |
Close and free all
PreparedStatement s or
CallableStatement s from the pool, and close the underlying
connection. |
void |
destroyObject(PStmtKey key,
org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p) |
KeyedPooledObjectFactory method for destroying
PoolablePreparedStatements and PoolableCallableStatements. |
org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> |
makeObject(PStmtKey key) |
KeyedPooledObjectFactory method for creating
PoolablePreparedStatement s or PoolableCallableStatement s. |
void |
passivateObject(PStmtKey key,
org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p) |
KeyedPooledObjectFactory method for passivating
PreparedStatement s or CallableStatement s. |
java.sql.CallableStatement |
prepareCall(java.lang.String sql) |
Create or obtain a
CallableStatement from the pool. |
java.sql.CallableStatement |
prepareCall(java.lang.String sql,
int resultSetType,
int resultSetConcurrency) |
Create or obtain a
CallableStatement from the pool. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql) |
Create or obtain a
PreparedStatement from the pool. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int autoGeneratedKeys) |
|
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql,
int resultSetType,
int resultSetConcurrency) |
Create or obtain a
PreparedStatement from the pool. |
void |
setStatementPool(org.apache.commons.pool2.KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> pool) |
|
java.lang.String |
toString() |
Returns a string representation of the metadata associated with
the innermost delegate connection.
|
boolean |
validateObject(PStmtKey key,
org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p) |
KeyedPooledObjectFactory method for validating
pooled statements. |
getLastUsed
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
abort, clearCachedState, clearWarnings, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getAutoCommit, getCacheState, getCatalog, getClientInfo, getClientInfo, getDefaultQueryTimeout, getDelegate, getHoldability, getInnermostDelegate, getInnermostDelegateInternal, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, innermostDelegateEquals, isClosed, isReadOnly, isValid, isWrapperFor, nativeSQL, prepareCall, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCacheState, setCatalog, setClientInfo, setClientInfo, setDefaultQueryTimeout, setDelegate, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMap, unwrap
public PoolingConnection(java.sql.Connection c)
c
- the underlying Connection
.public void activateObject(PStmtKey key, org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p) throws java.lang.Exception
KeyedPooledObjectFactory
method for activating
pooled statements.activateObject
in interface org.apache.commons.pool2.KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- ignoredp
- wrapped pooled statement to be activatedjava.lang.Exception
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
public void destroyObject(PStmtKey key, org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p) throws java.lang.Exception
KeyedPooledObjectFactory
method for destroying
PoolablePreparedStatements and PoolableCallableStatements.
Closes the underlying statement.destroyObject
in interface org.apache.commons.pool2.KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- ignoredp
- the wrapped pooled statement to be destroyed.java.lang.Exception
public org.apache.commons.pool2.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 org.apache.commons.pool2.KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- the key for the PreparedStatement
to be createdjava.lang.Exception
createKey(String, int, int, StatementType)
public void passivateObject(PStmtKey key, org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p) throws java.lang.Exception
KeyedPooledObjectFactory
method for passivating
PreparedStatement
s or CallableStatement
s.
Invokes PreparedStatement.clearParameters()
.passivateObject
in interface org.apache.commons.pool2.KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- ignoredp
- a wrapped PreparedStatement
java.lang.Exception
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
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
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 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 void setStatementPool(org.apache.commons.pool2.KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> pool)
public java.lang.String toString()
DelegatingConnection
toString
in class DelegatingConnection<java.sql.Connection>
public boolean validateObject(PStmtKey key, org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p)
KeyedPooledObjectFactory
method for validating
pooled statements. Currently always returns true.validateObject
in interface org.apache.commons.pool2.KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
key
- ignoredp
- ignoredtrue
Copyright © 2001-2015 Apache Software Foundation. Documenation generated October 31 2016.