This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git
commit 50d33ac186e8b32aaf49c7651ba30d70bb5bde64 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Mon Aug 10 16:18:14 2020 -0400 Sort methods. --- .../apache/commons/dbcp2/PoolingConnection.java | 132 ++++++++++----------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java b/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java index f713428..2661644 100644 --- a/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java +++ b/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java @@ -119,6 +119,23 @@ public class PoolingConnection extends DelegatingConnection<Connection> } /** + * Notification from {@link PoolableConnection} that we returned to the pool. + * + * @throws SQLException when <code>clearStatementPoolOnReturn</code> is true and the statement pool could not be + * cleared + * @since 2.8.0 + */ + public void connectionReturnedToPool() throws SQLException { + if (pstmtPool != null && clearStatementPoolOnReturn) { + try { + pstmtPool.clear(); + } catch (Exception e) { + throw new SQLException("Error clearing statement pool", e); + } + } + } + + /** * Creates a PStmtKey for the given arguments. * * @param sql @@ -301,6 +318,16 @@ public class PoolingConnection extends DelegatingConnection<Connection> } /** + * Returns the prepared statement pool we're using. + * + * @return statement pool + * @since 2.8.0 + */ + public KeyedObjectPool<PStmtKey, DelegatingPreparedStatement> getStatementPool() { + return pstmtPool; + } + + /** * {@link KeyedPooledObjectFactory} method for creating {@link PoolablePreparedStatement}s or * {@link PoolableCallableStatement}s. The <code>stmtType</code> field in the key determines whether a * PoolablePreparedStatement or PoolableCallableStatement is created. @@ -358,6 +385,27 @@ public class PoolingConnection extends DelegatingConnection<Connection> /** * Creates or obtains a {@link CallableStatement} from the pool. * + * @param key + * a {@link PStmtKey} for the given arguments + * @return a {@link PoolableCallableStatement} + * @throws SQLException + * Wraps an underlying exception. + */ + private CallableStatement prepareCall(final PStmtKey key) throws SQLException { + try { + return (CallableStatement) pstmtPool.borrowObject(key); + } catch (final NoSuchElementException e) { + throw new SQLException("MaxOpenCallableStatements limit reached", e); + } catch (final RuntimeException e) { + throw e; + } catch (final Exception e) { + throw new SQLException("Borrow callableStatement from pool failed", e); + } + } + + /** + * Creates or obtains a {@link CallableStatement} from the pool. + * * @param sql * the SQL string used to define the CallableStatement * @return a {@link PoolableCallableStatement} @@ -411,23 +459,26 @@ public class PoolingConnection extends DelegatingConnection<Connection> } /** - * Creates or obtains a {@link CallableStatement} from the pool. + * Creates or obtains a {@link PreparedStatement} from the pool. * * @param key * a {@link PStmtKey} for the given arguments - * @return a {@link PoolableCallableStatement} + * @return a {@link PoolablePreparedStatement} * @throws SQLException * Wraps an underlying exception. */ - private CallableStatement prepareCall(final PStmtKey key) throws SQLException { + private PreparedStatement prepareStatement(final PStmtKey key) throws SQLException { + if (null == pstmtPool) { + throw new SQLException("Statement pool is null - closed or invalid PoolingConnection."); + } try { - return (CallableStatement) pstmtPool.borrowObject(key); + return pstmtPool.borrowObject(key); } catch (final NoSuchElementException e) { - throw new SQLException("MaxOpenCallableStatements limit reached", e); + throw new SQLException("MaxOpenPreparedStatements limit reached", e); } catch (final RuntimeException e) { throw e; } catch (final Exception e) { - throw new SQLException("Borrow callableStatement from pool failed", e); + throw new SQLException("Borrow prepareStatement from pool failed", e); } } @@ -535,31 +586,18 @@ public class PoolingConnection extends DelegatingConnection<Connection> public PreparedStatement prepareStatement(final String sql, final String columnNames[]) throws SQLException { return prepareStatement(createKey(sql, columnNames)); } - + /** - * Creates or obtains a {@link PreparedStatement} from the pool. - * - * @param key - * a {@link PStmtKey} for the given arguments - * @return a {@link PoolablePreparedStatement} - * @throws SQLException - * Wraps an underlying exception. + * Sets whether the pool of statements should be cleared when the connection is returned to its pool. + * Default is false. + * + * @param clearStatementPoolOnReturn clear or not + * @since 2.8.0 */ - private PreparedStatement prepareStatement(final PStmtKey key) throws SQLException { - if (null == pstmtPool) { - throw new SQLException("Statement pool is null - closed or invalid PoolingConnection."); - } - try { - return pstmtPool.borrowObject(key); - } catch (final NoSuchElementException e) { - throw new SQLException("MaxOpenPreparedStatements limit reached", e); - } catch (final RuntimeException e) { - throw e; - } catch (final Exception e) { - throw new SQLException("Borrow prepareStatement from pool failed", e); - } + public void setClearStatementPoolOnReturn(final boolean clearStatementPoolOnReturn) { + this.clearStatementPoolOnReturn = clearStatementPoolOnReturn; } - + /** * Sets the prepared statement pool. * @@ -570,27 +608,6 @@ public class PoolingConnection extends DelegatingConnection<Connection> pstmtPool = pool; } - /** - * Returns the prepared statement pool we're using. - * - * @return statement pool - * @since 2.8.0 - */ - public KeyedObjectPool<PStmtKey, DelegatingPreparedStatement> getStatementPool() { - return pstmtPool; - } - - /** - * Sets whether the pool of statements should be cleared when the connection is returned to its pool. - * Default is false. - * - * @param clearStatementPoolOnReturn clear or not - * @since 2.8.0 - */ - public void setClearStatementPoolOnReturn(final boolean clearStatementPoolOnReturn) { - this.clearStatementPoolOnReturn = clearStatementPoolOnReturn; - } - @Override public synchronized String toString() { if (pstmtPool != null) { @@ -612,21 +629,4 @@ public class PoolingConnection extends DelegatingConnection<Connection> public boolean validateObject(final PStmtKey key, final PooledObject<DelegatingPreparedStatement> pooledObject) { return true; } - - /** - * Notification from {@link PoolableConnection} that we returned to the pool. - * - * @throws SQLException when <code>clearStatementPoolOnReturn</code> is true and the statement pool could not be - * cleared - * @since 2.8.0 - */ - public void connectionReturnedToPool() throws SQLException { - if (pstmtPool != null && clearStatementPoolOnReturn) { - try { - pstmtPool.clear(); - } catch (Exception e) { - throw new SQLException("Error clearing statement pool", e); - } - } - } }