public class PoolingConnection extends DelegatingConnection<java.sql.Connection> implements org.apache.commons.pool2.KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>
DelegatingConnection that pools PreparedStatements.
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 and Description |
|---|
PoolingConnection(java.sql.Connection c)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
activateObject(PStmtKey key,
org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p)
KeyedPooledObjectFactory method for activating
pooled statements. |
void |
close()
Close and free all
PreparedStatements or
CallableStatements 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
PoolablePreparedStatements or PoolableCallableStatements. |
void |
passivateObject(PStmtKey key,
org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p)
KeyedPooledObjectFactory method for passivating
PreparedStatements or CallableStatements. |
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. |
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, unwrapgetLastUsedpublic 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.Exceptionpublic void close()
throws java.sql.SQLException
PreparedStatements or
CallableStatements from the pool, and close the underlying
connection.close in interface java.lang.AutoCloseableclose in interface java.sql.Connectionclose in class DelegatingConnection<java.sql.Connection>java.sql.SQLExceptionpublic 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.Exceptionpublic org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> makeObject(PStmtKey key) throws java.lang.Exception
KeyedPooledObjectFactory method for creating
PoolablePreparedStatements or PoolableCallableStatements.
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.ExceptioncreateKey(String, int, int, StatementType)public void passivateObject(PStmtKey key, org.apache.commons.pool2.PooledObject<DelegatingPreparedStatement> p) throws java.lang.Exception
KeyedPooledObjectFactory method for passivating
PreparedStatements or CallableStatements.
Invokes PreparedStatement.clearParameters().passivateObject in interface org.apache.commons.pool2.KeyedPooledObjectFactory<PStmtKey,DelegatingPreparedStatement>key - ignoredp - a wrapped PreparedStatementjava.lang.Exceptionpublic java.sql.CallableStatement prepareCall(java.lang.String sql)
throws java.sql.SQLException
CallableStatement from the pool.prepareCall in interface java.sql.ConnectionprepareCall in class DelegatingConnection<java.sql.Connection>sql - the sql string used to define the CallableStatementPoolableCallableStatementjava.sql.SQLExceptionpublic 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.ConnectionprepareCall in class DelegatingConnection<java.sql.Connection>sql - the sql string used to define the CallableStatementresultSetType - result set typeresultSetConcurrency - result set concurrencyPoolableCallableStatementjava.sql.SQLExceptionpublic java.sql.PreparedStatement prepareStatement(java.lang.String sql)
throws java.sql.SQLException
PreparedStatement from the pool.prepareStatement in interface java.sql.ConnectionprepareStatement in class DelegatingConnection<java.sql.Connection>sql - the sql string used to define the PreparedStatementPoolablePreparedStatementjava.sql.SQLExceptionpublic java.sql.PreparedStatement prepareStatement(java.lang.String sql,
int autoGeneratedKeys)
throws java.sql.SQLException
prepareStatement in interface java.sql.ConnectionprepareStatement in class DelegatingConnection<java.sql.Connection>java.sql.SQLExceptionpublic 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.ConnectionprepareStatement in class DelegatingConnection<java.sql.Connection>sql - the sql string used to define the PreparedStatementresultSetType - result set typeresultSetConcurrency - result set concurrencyPoolablePreparedStatementjava.sql.SQLExceptionpublic void setStatementPool(org.apache.commons.pool2.KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> pool)
public java.lang.String toString()
DelegatingConnectiontoString 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 - ignoredtrueCopyright © 2001-2015 Apache Software Foundation. Documenation generated October 5 2016.