public class PoolingConnection extends DelegatingConnection implements java.sql.Connection, org.apache.commons.pool.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 | Class and Description |
---|---|
(package private) static class |
PoolingConnection.PStmtKey
A key uniquely identifiying
PreparedStatement s. |
AbandonedTrace.AbandonedObjectException
Modifier and Type | Field and Description |
---|---|
protected org.apache.commons.pool.KeyedObjectPool |
_pstmtPool
Pool of
PreparedStatement s. |
private static byte |
STATEMENT_CALLABLESTMT
Callable Statement type
|
private static byte |
STATEMENT_PREPAREDSTMT
Prepared Statement type
|
_closed, _conn
Constructor and Description |
---|
PoolingConnection(java.sql.Connection c)
Constructor.
|
PoolingConnection(java.sql.Connection c,
org.apache.commons.pool.KeyedObjectPool pool)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
abort(java.util.concurrent.Executor executor) |
void |
activateObject(java.lang.Object key,
java.lang.Object 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 java.lang.Object |
createKey(java.lang.String sql)
Create a PStmtKey for the given arguments.
|
protected java.lang.Object |
createKey(java.lang.String sql,
byte stmtType)
Create a PStmtKey for the given arguments.
|
protected java.lang.Object |
createKey(java.lang.String sql,
int resultSetType,
int resultSetConcurrency)
Create a PStmtKey for the given arguments.
|
protected java.lang.Object |
createKey(java.lang.String sql,
int resultSetType,
int resultSetConcurrency,
byte stmtType)
Create a PStmtKey for the given arguments.
|
void |
destroyObject(java.lang.Object key,
java.lang.Object obj)
KeyedPoolableObjectFactory method for destroying
PoolablePreparedStatements and PoolableCallableStatements. |
int |
getNetworkTimeout() |
java.lang.String |
getSchema() |
java.lang.Object |
makeObject(java.lang.Object obj)
KeyedPoolableObjectFactory method for creating
PoolablePreparedStatement s or PoolableCallableStatement s. |
protected java.lang.String |
normalizeSQL(java.lang.String sql)
Normalize the given SQL statement, producing a
cannonical form that is semantically equivalent to the original.
|
void |
passivateObject(java.lang.Object key,
java.lang.Object obj)
KeyedPoolableObjectFactory 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 resultSetType,
int resultSetConcurrency)
Create or obtain a
PreparedStatement from the pool. |
void |
setNetworkTimeout(java.util.concurrent.Executor executor,
int milliseconds) |
void |
setSchema(java.lang.String schema) |
java.lang.String |
toString()
Returns a string representation of the metadata associated with
the innnermost delegate connection.
|
boolean |
validateObject(java.lang.Object key,
java.lang.Object obj)
KeyedPoolableObjectFactory method for validating
pooled statements. |
activate, checkOpen, clearWarnings, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, equals, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getDelegate, getDelegateInternal, getHoldability, getInnermostDelegate, getInnermostDelegateInternal, getMetaData, 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, setReadOnly, setSavepoint, setSavepoint, setTransactionIsolation, setTypeMap, unwrap
addTrace, clearTrace, getConfig, getLastUsed, getTrace, printStackTrace, removeTrace, setLastUsed, setLastUsed, setStackTrace
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
clearWarnings, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getHoldability, getMetaData, getTransactionIsolation, getTypeMap, getWarnings, isClosed, isReadOnly, isValid, nativeSQL, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setHoldability, setReadOnly, setSavepoint, setSavepoint, setTransactionIsolation, setTypeMap
protected org.apache.commons.pool.KeyedObjectPool _pstmtPool
PreparedStatement
s. and CallableStatement
sprivate static final byte STATEMENT_PREPAREDSTMT
private static final byte STATEMENT_CALLABLESTMT
public PoolingConnection(java.sql.Connection c)
c
- the underlying Connection
.public PoolingConnection(java.sql.Connection c, org.apache.commons.pool.KeyedObjectPool pool)
c
- the underlying Connection
.pool
- KeyedObjectPool
of PreparedStatement
s and CallableStatement
s.public void close() throws java.sql.SQLException
PreparedStatement
s or CallableStatement
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.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
sql
- the sql string used to define the PreparedStatementPoolablePreparedStatement
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
sql
- the sql string used to define the PreparedStatementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyPoolablePreparedStatement
java.sql.SQLException
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
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
sql
- the sql string used to define the CallableStatementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyPoolableCallableStatement
java.sql.SQLException
protected java.lang.Object createKey(java.lang.String sql, int resultSetType, int resultSetConcurrency)
sql
- the sql string used to define the statementresultSetType
- result set typeresultSetConcurrency
- result set concurrencyprotected java.lang.Object createKey(java.lang.String sql, int resultSetType, int resultSetConcurrency, byte stmtType)
sql
- the sql string used to define the statementresultSetType
- result set typeresultSetConcurrency
- result set concurrencystmtType
- statement type - either STATEMENT_CALLABLESTMT
or STATEMENT_PREPAREDSTMT
protected java.lang.Object createKey(java.lang.String sql)
sql
- the sql string used to define the statementprotected java.lang.Object createKey(java.lang.String sql, byte stmtType)
sql
- the sql string used to define the statementstmtType
- statement type - either STATEMENT_CALLABLESTMT
or STATEMENT_PREPAREDSTMT
protected java.lang.String normalizeSQL(java.lang.String sql)
public java.lang.Object makeObject(java.lang.Object obj) throws java.lang.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 org.apache.commons.pool.KeyedPoolableObjectFactory
obj
- the key for the PreparedStatement
to be createdjava.lang.Exception
createKey(String, int, int, byte)
public void destroyObject(java.lang.Object key, java.lang.Object obj) throws java.lang.Exception
KeyedPoolableObjectFactory
method for destroying
PoolablePreparedStatements and PoolableCallableStatements.
Closes the underlying statement.destroyObject
in interface org.apache.commons.pool.KeyedPoolableObjectFactory
key
- ignoredobj
- the pooled statement to be destroyed.java.lang.Exception
public boolean validateObject(java.lang.Object key, java.lang.Object obj)
KeyedPoolableObjectFactory
method for validating
pooled statements. Currently always returns true.validateObject
in interface org.apache.commons.pool.KeyedPoolableObjectFactory
key
- ignoredobj
- ignoredpublic void activateObject(java.lang.Object key, java.lang.Object obj) throws java.lang.Exception
KeyedPoolableObjectFactory
method for activating
pooled statements.activateObject
in interface org.apache.commons.pool.KeyedPoolableObjectFactory
key
- ignoredobj
- pooled statement to be activatedjava.lang.Exception
public void passivateObject(java.lang.Object key, java.lang.Object obj) throws java.lang.Exception
KeyedPoolableObjectFactory
method for passivating
PreparedStatement
s or CallableStatement
s.
Invokes PreparedStatement.clearParameters()
.passivateObject
in interface org.apache.commons.pool.KeyedPoolableObjectFactory
key
- ignoredobj
- a PreparedStatement
java.lang.Exception
public java.lang.String toString()
DelegatingConnection
toString
in class DelegatingConnection
public int getNetworkTimeout() throws java.sql.SQLException
getNetworkTimeout
in interface java.sql.Connection
getNetworkTimeout
in class DelegatingConnection
java.sql.SQLException
public void setNetworkTimeout(java.util.concurrent.Executor executor, int milliseconds) throws java.sql.SQLException
setNetworkTimeout
in interface java.sql.Connection
setNetworkTimeout
in class DelegatingConnection
java.sql.SQLException
public void abort(java.util.concurrent.Executor executor) throws java.sql.SQLException
abort
in interface java.sql.Connection
abort
in class DelegatingConnection
java.sql.SQLException
public java.lang.String getSchema() throws java.sql.SQLException
getSchema
in interface java.sql.Connection
getSchema
in class DelegatingConnection
java.sql.SQLException
public void setSchema(java.lang.String schema) throws java.sql.SQLException
setSchema
in interface java.sql.Connection
setSchema
in class DelegatingConnection
java.sql.SQLException