You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2018/06/19 10:30:31 UTC
svn commit: r1833804 [9/16] - in /tomcat/tc8.5.x/trunk: ./
java/org/apache/tomcat/dbcp/dbcp2/
java/org/apache/tomcat/dbcp/dbcp2/cpdsadapter/
java/org/apache/tomcat/dbcp/dbcp2/datasources/ webapps/docs/
Modified: tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingStatement.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingStatement.java?rev=1833804&r1=1833803&r2=1833804&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingStatement.java (original)
+++ tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/DelegatingStatement.java Tue Jun 19 10:30:31 2018
@@ -26,74 +26,68 @@ import java.util.List;
/**
* A base delegating implementation of {@link Statement}.
* <p>
- * All of the methods from the {@link Statement} interface
- * simply check to see that the {@link Statement} is active,
- * and call the corresponding method on the "delegate"
- * provided in my constructor.
+ * All of the methods from the {@link Statement} interface simply check to see that the {@link Statement} is active, and
+ * call the corresponding method on the "delegate" provided in my constructor.
* <p>
- * Extends AbandonedTrace to implement Statement tracking and
- * logging of code which created the Statement. Tracking the
- * Statement ensures that the Connection which created it can
- * close any open Statement's on Connection close.
+ * Extends AbandonedTrace to implement Statement tracking and logging of code which created the Statement. Tracking the
+ * Statement ensures that the Connection which created it can close any open Statement's on Connection close.
*
- * @author Rodney Waldhoff
- * @author Glenn L. Nielsen
- * @author James House
- * @author Dirk Verbeeck
* @since 2.0
*/
public class DelegatingStatement extends AbandonedTrace implements Statement {
+
/** My delegate. */
- private Statement _stmt = null;
+ private Statement statement;
+
/** The connection that created me. **/
- private DelegatingConnection<?> _conn = null;
+ private DelegatingConnection<?> connection;
/**
- * Create a wrapper for the Statement which traces this
- * Statement to the Connection which created it and the
- * code which created it.
+ * Create a wrapper for the Statement which traces this Statement to the Connection which created it and the code
+ * which created it.
*
- * @param s the {@link Statement} to delegate all calls to.
- * @param c the {@link DelegatingConnection} that created this statement.
+ * @param statement
+ * the {@link Statement} to delegate all calls to.
+ * @param connection
+ * the {@link DelegatingConnection} that created this statement.
*/
- public DelegatingStatement(final DelegatingConnection<?> c, final Statement s) {
- super(c);
- _stmt = s;
- _conn = c;
+ public DelegatingStatement(final DelegatingConnection<?> connection, final Statement statement) {
+ super(connection);
+ this.statement = statement;
+ this.connection = connection;
}
/**
* Returns my underlying {@link Statement}.
+ *
* @return my underlying {@link Statement}.
* @see #getInnermostDelegate
*/
public Statement getDelegate() {
- return _stmt;
+ return statement;
}
-
/**
- * If my underlying {@link Statement} is not a
- * {@code DelegatingStatement}, returns it,
- * otherwise recursively invokes this method on
- * my delegate.
+ * If my underlying {@link Statement} is not a {@code DelegatingStatement}, returns it, otherwise recursively
+ * invokes this method on my delegate.
* <p>
- * Hence this method will return the first
- * delegate that is not a {@code DelegatingStatement}
- * or {@code null} when no non-{@code DelegatingStatement}
- * delegate can be found by traversing this chain.
+ * Hence this method will return the first delegate that is not a {@code DelegatingStatement} or {@code null} when
+ * no non-{@code DelegatingStatement} delegate can be found by traversing this chain.
+ * </p>
* <p>
- * This method is useful when you may have nested
- * {@code DelegatingStatement}s, and you want to make
- * sure to obtain a "genuine" {@link Statement}.
+ * This method is useful when you may have nested {@code DelegatingStatement}s, and you want to make sure to obtain
+ * a "genuine" {@link Statement}.
+ * </p>
+ *
+ * @return The innermost delegate.
+ *
* @see #getDelegate
- * @return the statement
*/
public Statement getInnermostDelegate() {
- Statement s = _stmt;
- while(s != null && s instanceof DelegatingStatement) {
- s = ((DelegatingStatement)s).getDelegate();
- if(this == s) {
+ Statement s = statement;
+ while (s != null && s instanceof DelegatingStatement) {
+ s = ((DelegatingStatement) s).getDelegate();
+ if (this == s) {
return null;
}
}
@@ -102,33 +96,32 @@ public class DelegatingStatement extends
/**
* Sets my delegate.
- * @param s The statement
+ *
+ * @param statement
+ * my delegate.
*/
- public void setDelegate(final Statement s) {
- _stmt = s;
+ public void setDelegate(final Statement statement) {
+ this.statement = statement;
}
- private boolean _closed = false;
+ private boolean closed = false;
protected boolean isClosedInternal() {
- return _closed;
+ return closed;
}
protected void setClosedInternal(final boolean closed) {
- this._closed = closed;
+ this.closed = closed;
}
protected void checkOpen() throws SQLException {
- if(isClosed()) {
- throw new SQLException
- (this.getClass().getName() + " with address: \"" +
- this.toString() + "\" is closed.");
+ if (isClosed()) {
+ throw new SQLException(this.getClass().getName() + " with address: \"" + this.toString() + "\" is closed.");
}
}
/**
- * Close this DelegatingStatement, and close
- * any ResultSets that were not explicitly closed.
+ * Close this DelegatingStatement, and close any ResultSets that were not explicitly closed.
*/
@Override
public void close() throws SQLException {
@@ -137,9 +130,9 @@ public class DelegatingStatement extends
}
try {
try {
- if (_conn != null) {
- _conn.removeTrace(this);
- _conn = null;
+ if (connection != null) {
+ connection.removeTrace(this);
+ connection = null;
}
// The JDBC spec requires that a statement close any open
@@ -147,7 +140,7 @@ public class DelegatingStatement extends
// FIXME The PreparedStatement we're wrapping should handle this for us.
// See bug 17301 for what could happen when ResultSets are closed twice.
final List<AbandonedTrace> resultSets = getTrace();
- if( resultSets != null) {
+ if (resultSets != null) {
final ResultSet[] set = resultSets.toArray(new ResultSet[resultSets.size()]);
for (final ResultSet element : set) {
element.close();
@@ -155,38 +148,47 @@ public class DelegatingStatement extends
clearTrace();
}
- if (_stmt != null) {
- _stmt.close();
+ if (statement != null) {
+ statement.close();
}
- }
- catch (final SQLException e) {
+ } catch (final SQLException e) {
handleException(e);
}
- }
- finally {
- _closed = true;
- _stmt = null;
+ } finally {
+ closed = true;
+ statement = null;
}
}
protected void handleException(final SQLException e) throws SQLException {
- if (_conn != null) {
- _conn.handleException(e);
- }
- else {
+ if (connection != null) {
+ connection.handleException(e);
+ } else {
throw e;
}
}
- protected void activate() throws SQLException {
- if(_stmt instanceof DelegatingStatement) {
- ((DelegatingStatement)_stmt).activate();
+ /**
+ *
+ * @throws SQLException
+ * thrown by the delegating statement.
+ * @since 2.4.0 made public, was protected in 2.3.0.
+ */
+ public void activate() throws SQLException {
+ if (statement instanceof DelegatingStatement) {
+ ((DelegatingStatement) statement).activate();
}
}
- protected void passivate() throws SQLException {
- if(_stmt instanceof DelegatingStatement) {
- ((DelegatingStatement)_stmt).passivate();
+ /**
+ *
+ * @throws SQLException
+ * thrown by the delegating statement.
+ * @since 2.4.0 made public, was protected in 2.3.0.
+ */
+ public void passivate() throws SQLException {
+ if (statement instanceof DelegatingStatement) {
+ ((DelegatingStatement) statement).passivate();
}
}
@@ -197,19 +199,18 @@ public class DelegatingStatement extends
}
protected DelegatingConnection<?> getConnectionInternal() {
- return _conn;
+ return connection;
}
@Override
public ResultSet executeQuery(final String sql) throws SQLException {
checkOpen();
- if (_conn != null) {
- _conn.setLastUsed();
+ if (connection != null) {
+ connection.setLastUsed();
}
try {
- return DelegatingResultSet.wrapResultSet(this,_stmt.executeQuery(sql));
- }
- catch (final SQLException e) {
+ return DelegatingResultSet.wrapResultSet(this, statement.executeQuery(sql));
+ } catch (final SQLException e) {
handleException(e);
throw new AssertionError();
}
@@ -219,9 +220,8 @@ public class DelegatingStatement extends
public ResultSet getResultSet() throws SQLException {
checkOpen();
try {
- return DelegatingResultSet.wrapResultSet(this,_stmt.getResultSet());
- }
- catch (final SQLException e) {
+ return DelegatingResultSet.wrapResultSet(this, statement.getResultSet());
+ } catch (final SQLException e) {
handleException(e);
throw new AssertionError();
}
@@ -230,68 +230,139 @@ public class DelegatingStatement extends
@Override
public int executeUpdate(final String sql) throws SQLException {
checkOpen();
- if (_conn != null) {
- _conn.setLastUsed();
+ if (connection != null) {
+ connection.setLastUsed();
}
try {
- return _stmt.executeUpdate(sql);
+ return statement.executeUpdate(sql);
} catch (final SQLException e) {
- handleException(e); return 0;
+ handleException(e);
+ return 0;
}
}
@Override
- public int getMaxFieldSize() throws SQLException
- { checkOpen(); try { return _stmt.getMaxFieldSize(); } catch (final SQLException e) { handleException(e); return 0; } }
+ public int getMaxFieldSize() throws SQLException {
+ checkOpen();
+ try {
+ return statement.getMaxFieldSize();
+ } catch (final SQLException e) {
+ handleException(e);
+ return 0;
+ }
+ }
@Override
- public void setMaxFieldSize(final int max) throws SQLException
- { checkOpen(); try { _stmt.setMaxFieldSize(max); } catch (final SQLException e) { handleException(e); } }
+ public void setMaxFieldSize(final int max) throws SQLException {
+ checkOpen();
+ try {
+ statement.setMaxFieldSize(max);
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
@Override
- public int getMaxRows() throws SQLException
- { checkOpen(); try { return _stmt.getMaxRows(); } catch (final SQLException e) { handleException(e); return 0; } }
+ public int getMaxRows() throws SQLException {
+ checkOpen();
+ try {
+ return statement.getMaxRows();
+ } catch (final SQLException e) {
+ handleException(e);
+ return 0;
+ }
+ }
@Override
- public void setMaxRows(final int max) throws SQLException
- { checkOpen(); try { _stmt.setMaxRows(max); } catch (final SQLException e) { handleException(e); } }
+ public void setMaxRows(final int max) throws SQLException {
+ checkOpen();
+ try {
+ statement.setMaxRows(max);
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
@Override
- public void setEscapeProcessing(final boolean enable) throws SQLException
- { checkOpen(); try { _stmt.setEscapeProcessing(enable); } catch (final SQLException e) { handleException(e); } }
+ public void setEscapeProcessing(final boolean enable) throws SQLException {
+ checkOpen();
+ try {
+ statement.setEscapeProcessing(enable);
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
@Override
- public int getQueryTimeout() throws SQLException
- { checkOpen(); try { return _stmt.getQueryTimeout(); } catch (final SQLException e) { handleException(e); return 0; } }
+ public int getQueryTimeout() throws SQLException {
+ checkOpen();
+ try {
+ return statement.getQueryTimeout();
+ } catch (final SQLException e) {
+ handleException(e);
+ return 0;
+ }
+ }
@Override
- public void setQueryTimeout(final int seconds) throws SQLException
- { checkOpen(); try { _stmt.setQueryTimeout(seconds); } catch (final SQLException e) { handleException(e); } }
+ public void setQueryTimeout(final int seconds) throws SQLException {
+ checkOpen();
+ try {
+ statement.setQueryTimeout(seconds);
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
@Override
- public void cancel() throws SQLException
- { checkOpen(); try { _stmt.cancel(); } catch (final SQLException e) { handleException(e); } }
+ public void cancel() throws SQLException {
+ checkOpen();
+ try {
+ statement.cancel();
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
@Override
- public SQLWarning getWarnings() throws SQLException
- { checkOpen(); try { return _stmt.getWarnings(); } catch (final SQLException e) { handleException(e); throw new AssertionError(); } }
+ public SQLWarning getWarnings() throws SQLException {
+ checkOpen();
+ try {
+ return statement.getWarnings();
+ } catch (final SQLException e) {
+ handleException(e);
+ throw new AssertionError();
+ }
+ }
@Override
- public void clearWarnings() throws SQLException
- { checkOpen(); try { _stmt.clearWarnings(); } catch (final SQLException e) { handleException(e); } }
+ public void clearWarnings() throws SQLException {
+ checkOpen();
+ try {
+ statement.clearWarnings();
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
@Override
- public void setCursorName(final String name) throws SQLException
- { checkOpen(); try { _stmt.setCursorName(name); } catch (final SQLException e) { handleException(e); } }
+ public void setCursorName(final String name) throws SQLException {
+ checkOpen();
+ try {
+ statement.setCursorName(name);
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
@Override
public boolean execute(final String sql) throws SQLException {
checkOpen();
- if (_conn != null) {
- _conn.setLastUsed();
+ if (connection != null) {
+ connection.setLastUsed();
}
try {
- return _stmt.execute(sql);
+ return statement.execute(sql);
} catch (final SQLException e) {
handleException(e);
return false;
@@ -299,53 +370,119 @@ public class DelegatingStatement extends
}
@Override
- public int getUpdateCount() throws SQLException
- { checkOpen(); try { return _stmt.getUpdateCount(); } catch (final SQLException e) { handleException(e); return 0; } }
+ public int getUpdateCount() throws SQLException {
+ checkOpen();
+ try {
+ return statement.getUpdateCount();
+ } catch (final SQLException e) {
+ handleException(e);
+ return 0;
+ }
+ }
@Override
- public boolean getMoreResults() throws SQLException
- { checkOpen(); try { return _stmt.getMoreResults(); } catch (final SQLException e) { handleException(e); return false; } }
+ public boolean getMoreResults() throws SQLException {
+ checkOpen();
+ try {
+ return statement.getMoreResults();
+ } catch (final SQLException e) {
+ handleException(e);
+ return false;
+ }
+ }
@Override
- public void setFetchDirection(final int direction) throws SQLException
- { checkOpen(); try { _stmt.setFetchDirection(direction); } catch (final SQLException e) { handleException(e); } }
+ public void setFetchDirection(final int direction) throws SQLException {
+ checkOpen();
+ try {
+ statement.setFetchDirection(direction);
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
@Override
- public int getFetchDirection() throws SQLException
- { checkOpen(); try { return _stmt.getFetchDirection(); } catch (final SQLException e) { handleException(e); return 0; } }
+ public int getFetchDirection() throws SQLException {
+ checkOpen();
+ try {
+ return statement.getFetchDirection();
+ } catch (final SQLException e) {
+ handleException(e);
+ return 0;
+ }
+ }
@Override
- public void setFetchSize(final int rows) throws SQLException
- { checkOpen(); try { _stmt.setFetchSize(rows); } catch (final SQLException e) { handleException(e); } }
+ public void setFetchSize(final int rows) throws SQLException {
+ checkOpen();
+ try {
+ statement.setFetchSize(rows);
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
@Override
- public int getFetchSize() throws SQLException
- { checkOpen(); try { return _stmt.getFetchSize(); } catch (final SQLException e) { handleException(e); return 0; } }
+ public int getFetchSize() throws SQLException {
+ checkOpen();
+ try {
+ return statement.getFetchSize();
+ } catch (final SQLException e) {
+ handleException(e);
+ return 0;
+ }
+ }
@Override
- public int getResultSetConcurrency() throws SQLException
- { checkOpen(); try { return _stmt.getResultSetConcurrency(); } catch (final SQLException e) { handleException(e); return 0; } }
+ public int getResultSetConcurrency() throws SQLException {
+ checkOpen();
+ try {
+ return statement.getResultSetConcurrency();
+ } catch (final SQLException e) {
+ handleException(e);
+ return 0;
+ }
+ }
@Override
- public int getResultSetType() throws SQLException
- { checkOpen(); try { return _stmt.getResultSetType(); } catch (final SQLException e) { handleException(e); return 0; } }
+ public int getResultSetType() throws SQLException {
+ checkOpen();
+ try {
+ return statement.getResultSetType();
+ } catch (final SQLException e) {
+ handleException(e);
+ return 0;
+ }
+ }
@Override
- public void addBatch(final String sql) throws SQLException
- { checkOpen(); try { _stmt.addBatch(sql); } catch (final SQLException e) { handleException(e); } }
+ public void addBatch(final String sql) throws SQLException {
+ checkOpen();
+ try {
+ statement.addBatch(sql);
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
@Override
- public void clearBatch() throws SQLException
- { checkOpen(); try { _stmt.clearBatch(); } catch (final SQLException e) { handleException(e); } }
+ public void clearBatch() throws SQLException {
+ checkOpen();
+ try {
+ statement.clearBatch();
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
@Override
public int[] executeBatch() throws SQLException {
checkOpen();
- if (_conn != null) {
- _conn.setLastUsed();
+ if (connection != null) {
+ connection.setLastUsed();
}
try {
- return _stmt.executeBatch();
+ return statement.executeBatch();
} catch (final SQLException e) {
handleException(e);
throw new AssertionError();
@@ -359,18 +496,25 @@ public class DelegatingStatement extends
*/
@Override
public String toString() {
- return _stmt == null ? "NULL" : _stmt.toString();
+ return statement == null ? "NULL" : statement.toString();
}
@Override
- public boolean getMoreResults(final int current) throws SQLException
- { checkOpen(); try { return _stmt.getMoreResults(current); } catch (final SQLException e) { handleException(e); return false; } }
+ public boolean getMoreResults(final int current) throws SQLException {
+ checkOpen();
+ try {
+ return statement.getMoreResults(current);
+ } catch (final SQLException e) {
+ handleException(e);
+ return false;
+ }
+ }
@Override
public ResultSet getGeneratedKeys() throws SQLException {
checkOpen();
try {
- return DelegatingResultSet.wrapResultSet(this, _stmt.getGeneratedKeys());
+ return DelegatingResultSet.wrapResultSet(this, statement.getGeneratedKeys());
} catch (final SQLException e) {
handleException(e);
throw new AssertionError();
@@ -380,11 +524,11 @@ public class DelegatingStatement extends
@Override
public int executeUpdate(final String sql, final int autoGeneratedKeys) throws SQLException {
checkOpen();
- if (_conn != null) {
- _conn.setLastUsed();
+ if (connection != null) {
+ connection.setLastUsed();
}
try {
- return _stmt.executeUpdate(sql, autoGeneratedKeys);
+ return statement.executeUpdate(sql, autoGeneratedKeys);
} catch (final SQLException e) {
handleException(e);
return 0;
@@ -394,11 +538,11 @@ public class DelegatingStatement extends
@Override
public int executeUpdate(final String sql, final int columnIndexes[]) throws SQLException {
checkOpen();
- if (_conn != null) {
- _conn.setLastUsed();
+ if (connection != null) {
+ connection.setLastUsed();
}
try {
- return _stmt.executeUpdate(sql, columnIndexes);
+ return statement.executeUpdate(sql, columnIndexes);
} catch (final SQLException e) {
handleException(e);
return 0;
@@ -408,11 +552,11 @@ public class DelegatingStatement extends
@Override
public int executeUpdate(final String sql, final String columnNames[]) throws SQLException {
checkOpen();
- if (_conn != null) {
- _conn.setLastUsed();
+ if (connection != null) {
+ connection.setLastUsed();
}
try {
- return _stmt.executeUpdate(sql, columnNames);
+ return statement.executeUpdate(sql, columnNames);
} catch (final SQLException e) {
handleException(e);
return 0;
@@ -422,11 +566,11 @@ public class DelegatingStatement extends
@Override
public boolean execute(final String sql, final int autoGeneratedKeys) throws SQLException {
checkOpen();
- if (_conn != null) {
- _conn.setLastUsed();
+ if (connection != null) {
+ connection.setLastUsed();
}
try {
- return _stmt.execute(sql, autoGeneratedKeys);
+ return statement.execute(sql, autoGeneratedKeys);
} catch (final SQLException e) {
handleException(e);
return false;
@@ -436,11 +580,11 @@ public class DelegatingStatement extends
@Override
public boolean execute(final String sql, final int columnIndexes[]) throws SQLException {
checkOpen();
- if (_conn != null) {
- _conn.setLastUsed();
+ if (connection != null) {
+ connection.setLastUsed();
}
try {
- return _stmt.execute(sql, columnIndexes);
+ return statement.execute(sql, columnIndexes);
} catch (final SQLException e) {
handleException(e);
return false;
@@ -450,11 +594,11 @@ public class DelegatingStatement extends
@Override
public boolean execute(final String sql, final String columnNames[]) throws SQLException {
checkOpen();
- if (_conn != null) {
- _conn.setLastUsed();
+ if (connection != null) {
+ connection.setLastUsed();
}
try {
- return _stmt.execute(sql, columnNames);
+ return statement.execute(sql, columnNames);
} catch (final SQLException e) {
handleException(e);
return false;
@@ -462,26 +606,32 @@ public class DelegatingStatement extends
}
@Override
- public int getResultSetHoldability() throws SQLException
- { checkOpen(); try { return _stmt.getResultSetHoldability(); } catch (final SQLException e) { handleException(e); return 0; } }
+ public int getResultSetHoldability() throws SQLException {
+ checkOpen();
+ try {
+ return statement.getResultSetHoldability();
+ } catch (final SQLException e) {
+ handleException(e);
+ return 0;
+ }
+ }
/*
* Note was protected prior to JDBC 4
*/
@Override
public boolean isClosed() throws SQLException {
- return _closed;
+ return closed;
}
-
@Override
public boolean isWrapperFor(final Class<?> iface) throws SQLException {
if (iface.isAssignableFrom(getClass())) {
return true;
- } else if (iface.isAssignableFrom(_stmt.getClass())) {
+ } else if (iface.isAssignableFrom(statement.getClass())) {
return true;
} else {
- return _stmt.isWrapperFor(iface);
+ return statement.isWrapperFor(iface);
}
}
@@ -489,10 +639,10 @@ public class DelegatingStatement extends
public <T> T unwrap(final Class<T> iface) throws SQLException {
if (iface.isAssignableFrom(getClass())) {
return iface.cast(this);
- } else if (iface.isAssignableFrom(_stmt.getClass())) {
- return iface.cast(_stmt);
+ } else if (iface.isAssignableFrom(statement.getClass())) {
+ return iface.cast(statement);
} else {
- return _stmt.unwrap(iface);
+ return statement.unwrap(iface);
}
}
@@ -500,9 +650,8 @@ public class DelegatingStatement extends
public void setPoolable(final boolean poolable) throws SQLException {
checkOpen();
try {
- _stmt.setPoolable(poolable);
- }
- catch (final SQLException e) {
+ statement.setPoolable(poolable);
+ } catch (final SQLException e) {
handleException(e);
}
}
@@ -511,9 +660,8 @@ public class DelegatingStatement extends
public boolean isPoolable() throws SQLException {
checkOpen();
try {
- return _stmt.isPoolable();
- }
- catch (final SQLException e) {
+ return statement.isPoolable();
+ } catch (final SQLException e) {
handleException(e);
return false;
}
@@ -523,7 +671,7 @@ public class DelegatingStatement extends
public void closeOnCompletion() throws SQLException {
checkOpen();
try {
- _stmt.closeOnCompletion();
+ statement.closeOnCompletion();
} catch (final SQLException e) {
handleException(e);
}
@@ -533,7 +681,7 @@ public class DelegatingStatement extends
public boolean isCloseOnCompletion() throws SQLException {
checkOpen();
try {
- return _stmt.isCloseOnCompletion();
+ return statement.isCloseOnCompletion();
} catch (final SQLException e) {
handleException(e);
return false;
Modified: tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/DriverConnectionFactory.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/DriverConnectionFactory.java?rev=1833804&r1=1833803&r2=1833804&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/DriverConnectionFactory.java (original)
+++ tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/DriverConnectionFactory.java Tue Jun 19 10:30:31 2018
@@ -23,28 +23,38 @@ import java.util.Properties;
/**
* A {@link Driver}-based implementation of {@link ConnectionFactory}.
*
- * @author Rodney Waldhoff
* @since 2.0
*/
public class DriverConnectionFactory implements ConnectionFactory {
- public DriverConnectionFactory(final Driver driver, final String connectUri, final Properties props) {
- _driver = driver;
- _connectUri = connectUri;
- _props = props;
+
+ private final String connectionString;
+ private final Driver driver;
+ private final Properties properties;
+
+ /**
+ * Constructs a connection factory for a given Driver.
+ *
+ * @param driver
+ * The Driver.
+ * @param connectString
+ * The connection string.
+ * @param properties
+ * The connection properties.
+ */
+ public DriverConnectionFactory(final Driver driver, final String connectString, final Properties properties) {
+ this.driver = driver;
+ this.connectionString = connectString;
+ this.properties = properties;
}
@Override
public Connection createConnection() throws SQLException {
- return _driver.connect(_connectUri,_props);
+ return driver.connect(connectionString, properties);
}
- private final Driver _driver;
- private final String _connectUri;
- private final Properties _props;
-
@Override
public String toString() {
- return this.getClass().getName() + " [" + String.valueOf(_driver) + ";" +
- String.valueOf(_connectUri) + ";" + String.valueOf(_props) + "]";
+ return this.getClass().getName() + " [" + String.valueOf(driver) + ";" + String.valueOf(connectionString) + ";"
+ + String.valueOf(properties) + "]";
}
}
Modified: tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/DriverManagerConnectionFactory.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/DriverManagerConnectionFactory.java?rev=1833804&r1=1833803&r2=1833804&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/DriverManagerConnectionFactory.java (original)
+++ tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/DriverManagerConnectionFactory.java Tue Jun 19 10:30:31 2018
@@ -24,9 +24,6 @@ import java.util.Properties;
/**
* A {@link DriverManager}-based implementation of {@link ConnectionFactory}.
*
- * @author Rodney Waldhoff
- * @author Ignacio J. Ortega
- * @author Dirk Verbeeck
* @since 2.0
*/
public class DriverManagerConnectionFactory implements ConnectionFactory {
@@ -40,57 +37,62 @@ public class DriverManagerConnectionFact
DriverManager.getDrivers();
}
-
/**
* Constructor for DriverManagerConnectionFactory.
- * @param connectUri a database url of the form
- * <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
+ *
+ * @param connectionUri
+ * a database url of the form <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
* @since 2.2
*/
- public DriverManagerConnectionFactory(final String connectUri) {
- _connectUri = connectUri;
- _props = new Properties();
+ public DriverManagerConnectionFactory(final String connectionUri) {
+ this.connectionUri = connectionUri;
+ this.propeties = new Properties();
}
/**
* Constructor for DriverManagerConnectionFactory.
- * @param connectUri a database url of the form
- * <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
- * @param props a list of arbitrary string tag/value pairs as
- * connection arguments; normally at least a "user" and "password"
- * property should be included.
+ *
+ * @param connectionUri
+ * a database url of the form <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
+ * @param properties
+ * a list of arbitrary string tag/value pairs as connection arguments; normally at least a "user" and
+ * "password" property should be included.
*/
- public DriverManagerConnectionFactory(final String connectUri, final Properties props) {
- _connectUri = connectUri;
- _props = props;
+ public DriverManagerConnectionFactory(final String connectionUri, final Properties properties) {
+ this.connectionUri = connectionUri;
+ this.propeties = properties;
}
/**
* Constructor for DriverManagerConnectionFactory.
- * @param connectUri a database url of the form
- * <code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
- * @param uname the database user
- * @param passwd the user's password
+ *
+ * @param connectionUri
+ * a database url of the form <code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
+ * @param userName
+ * the database user
+ * @param userPassword
+ * the user's password
*/
- public DriverManagerConnectionFactory(final String connectUri, final String uname, final String passwd) {
- _connectUri = connectUri;
- _uname = uname;
- _passwd = passwd;
+ public DriverManagerConnectionFactory(final String connectionUri, final String userName,
+ final String userPassword) {
+ this.connectionUri = connectionUri;
+ this.userName = userName;
+ this.userPassword = userPassword;
}
@Override
public Connection createConnection() throws SQLException {
- if(null == _props) {
- if(_uname == null && _passwd == null) {
- return DriverManager.getConnection(_connectUri);
+ if (null == propeties) {
+ if (userName == null && userPassword == null) {
+ return DriverManager.getConnection(connectionUri);
}
- return DriverManager.getConnection(_connectUri,_uname,_passwd);
+ return DriverManager.getConnection(connectionUri, userName, userPassword);
}
- return DriverManager.getConnection(_connectUri,_props);
+ return DriverManager.getConnection(connectionUri, propeties);
}
- private String _connectUri = null;
- private String _uname = null;
- private String _passwd = null;
- private Properties _props = null;
+ private final String connectionUri;
+ private String userName;
+ private String userPassword;
+ private Properties propeties;
}
Modified: tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/LifetimeExceededException.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/LifetimeExceededException.java?rev=1833804&r1=1833803&r2=1833804&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/LifetimeExceededException.java (original)
+++ tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/LifetimeExceededException.java Tue Jun 19 10:30:31 2018
@@ -21,7 +21,7 @@ package org.apache.tomcat.dbcp.dbcp2;
*
* @since 2.1
*/
- class LifetimeExceededException extends Exception {
+class LifetimeExceededException extends Exception {
private static final long serialVersionUID = -3783783104516492659L;
@@ -35,7 +35,8 @@ package org.apache.tomcat.dbcp.dbcp2;
/**
* Create a LifetimeExceededException with the given message.
*
- * @param message The message with which to create the exception
+ * @param message
+ * The message with which to create the exception
*/
public LifetimeExceededException(final String message) {
super(message);
Modified: tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/PStmtKey.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/PStmtKey.java?rev=1833804&r1=1833803&r2=1833804&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/PStmtKey.java (original)
+++ tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/PStmtKey.java Tue Jun 19 10:30:31 2018
@@ -26,201 +26,419 @@ import org.apache.tomcat.dbcp.dbcp2.Pool
/**
* A key uniquely identifying {@link java.sql.PreparedStatement PreparedStatement}s.
+ *
* @since 2.0
*/
public class PStmtKey {
- /** SQL defining Prepared or Callable Statement */
- private final String _sql;
+ /**
+ * SQL defining Prepared or Callable Statement
+ */
+ private final String sql;
- /** Result set type */
- private final Integer _resultSetType;
+ /**
+ * Result set type; one of <code>ResultSet.TYPE_FORWARD_ONLY</code>, <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>,
+ * or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>.
+ */
+ private final Integer resultSetType;
- /** Result set concurrency */
- private final Integer _resultSetConcurrency;
+ /**
+ * Result set concurrency. A concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code> or
+ * <code>ResultSet.CONCUR_UPDATABLE</code>.
+ */
+ private final Integer resultSetConcurrency;
- /** Result set holdability */
- private final Integer _resultSetHoldability;
+ /**
+ * Result set holdability. One of the following <code>ResultSet</code> constants:
+ * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>.
+ */
+ private final Integer resultSetHoldability;
/** Database catalog */
- private final String _catalog;
+ private final String catalog;
- /** Auto generated keys */
- private final Integer _autoGeneratedKeys;
+ /**
+ * A flag indicating whether auto-generated keys should be returned; one of
+ * <code>Statement.RETURN_GENERATED_KEYS</code> or <code>Statement.NO_GENERATED_KEYS</code>.
+ */
+ private final Integer autoGeneratedKeys;
- /** column indexes */
- private final int[] _columnIndexes;
+ /**
+ * An array of column indexes indicating the columns that should be returned from the inserted row or rows.
+ */
+ private final int[] columnIndexes;
- /** column names */
- private final String[] _columnNames;
+ /**
+ * An array of column names indicating the columns that should be returned from the inserted row or rows.
+ */
+ private final String[] columnNames;
- /** Statement type */
- private final StatementType _stmtType;
+ /**
+ * Statement type, prepared or callable.
+ */
+ private final StatementType statementType;
/** Statement builder */
private StatementBuilder builder;
+ /**
+ * Constructs a key to uniquely identify a prepared statement.
+ *
+ * @param sql
+ * The SQL statement.
+ */
public PStmtKey(final String sql) {
this(sql, null, StatementType.PREPARED_STATEMENT);
}
+ /**
+ * Constructs a key to uniquely identify a prepared statement.
+ *
+ * @param sql
+ * The SQL statement.
+ * @param catalog
+ * The catalog.
+ */
public PStmtKey(final String sql, final String catalog) {
this(sql, catalog, StatementType.PREPARED_STATEMENT);
}
- public PStmtKey(final String sql, final String catalog, final StatementType stmtType) {
- _sql = sql;
- _catalog = catalog;
- _stmtType = stmtType;
- _autoGeneratedKeys = null;
- _columnIndexes = null;
- _columnNames = null;
- _resultSetType = null;
- _resultSetConcurrency = null;
- _resultSetHoldability = null;
+ /**
+ * Constructs a key to uniquely identify a prepared statement.
+ *
+ * @param sql
+ * The SQL statement.
+ * @param catalog
+ * The catalog.
+ * @param statementType
+ * The SQL statement type, prepared or callable.
+ */
+ public PStmtKey(final String sql, final String catalog, final StatementType statementType) {
+ this.sql = sql;
+ this.catalog = catalog;
+ this.statementType = statementType;
+ this.autoGeneratedKeys = null;
+ this.columnIndexes = null;
+ this.columnNames = null;
+ this.resultSetType = null;
+ this.resultSetConcurrency = null;
+ this.resultSetHoldability = null;
// create builder
- if (stmtType == StatementType.PREPARED_STATEMENT) {
- builder = new PreparedStatementSQL();
- } else if (stmtType == StatementType.CALLABLE_STATEMENT) {
- builder = new PreparedCallSQL();
+ if (statementType == StatementType.PREPARED_STATEMENT) {
+ this.builder = new PreparedStatementSQL();
+ } else if (statementType == StatementType.CALLABLE_STATEMENT) {
+ this.builder = new PreparedCallSQL();
}
}
+ /**
+ * Constructs a key to uniquely identify a prepared statement.
+ *
+ * @param sql
+ * The SQL statement.
+ * @param catalog
+ * The catalog.
+ * @param autoGeneratedKeys
+ * A flag indicating whether auto-generated keys should be returned; one of
+ * <code>Statement.RETURN_GENERATED_KEYS</code> or <code>Statement.NO_GENERATED_KEYS</code>.
+ */
public PStmtKey(final String sql, final String catalog, final int autoGeneratedKeys) {
this(sql, catalog, StatementType.PREPARED_STATEMENT, Integer.valueOf(autoGeneratedKeys));
}
- public PStmtKey(final String sql, final String catalog, final StatementType stmtType, final Integer autoGeneratedKeys) {
- _sql = sql;
- _catalog = catalog;
- _stmtType = stmtType;
- _autoGeneratedKeys = autoGeneratedKeys;
- _columnIndexes = null;
- _columnNames = null;
- _resultSetType = null;
- _resultSetConcurrency = null;
- _resultSetHoldability = null;
+ /**
+ * Constructs a key to uniquely identify a prepared statement.
+ *
+ * @param sql
+ * The SQL statement.
+ * @param catalog
+ * The catalog.
+ * @param statementType
+ * The SQL statement type, prepared or callable.
+ * @param autoGeneratedKeys
+ * A flag indicating whether auto-generated keys should be returned; one of
+ * <code>Statement.RETURN_GENERATED_KEYS</code> or <code>Statement.NO_GENERATED_KEYS</code>.
+ */
+ public PStmtKey(final String sql, final String catalog, final StatementType statementType,
+ final Integer autoGeneratedKeys) {
+ this.sql = sql;
+ this.catalog = catalog;
+ this.statementType = statementType;
+ this.autoGeneratedKeys = autoGeneratedKeys;
+ this.columnIndexes = null;
+ this.columnNames = null;
+ this.resultSetType = null;
+ this.resultSetConcurrency = null;
+ this.resultSetHoldability = null;
// create builder
- if (stmtType == StatementType.PREPARED_STATEMENT) {
- builder = new PreparedStatementWithAutoGeneratedKeys();
- } else if (stmtType == StatementType.CALLABLE_STATEMENT) {
- builder = new PreparedCallSQL();
+ if (statementType == StatementType.PREPARED_STATEMENT) {
+ this.builder = new PreparedStatementWithAutoGeneratedKeys();
+ } else if (statementType == StatementType.CALLABLE_STATEMENT) {
+ this.builder = new PreparedCallSQL();
}
}
+ /**
+ * Constructs a key to uniquely identify a prepared statement.
+ *
+ * @param sql
+ * The SQL statement.
+ * @param catalog
+ * The catalog.
+ * @param columnIndexes
+ * An array of column indexes indicating the columns that should be returned from the inserted row or
+ * rows.
+ */
public PStmtKey(final String sql, final String catalog, final int[] columnIndexes) {
- _sql = sql;
- _catalog = catalog;
- _stmtType = StatementType.PREPARED_STATEMENT;
- _autoGeneratedKeys = null;
- _columnIndexes = columnIndexes;
- _columnNames = null;
- _resultSetType = null;
- _resultSetConcurrency = null;
- _resultSetHoldability = null;
+ this.sql = sql;
+ this.catalog = catalog;
+ this.statementType = StatementType.PREPARED_STATEMENT;
+ this.autoGeneratedKeys = null;
+ this.columnIndexes = columnIndexes == null ? null : Arrays.copyOf(columnIndexes, columnIndexes.length);
+ this.columnNames = null;
+ this.resultSetType = null;
+ this.resultSetConcurrency = null;
+ this.resultSetHoldability = null;
// create builder
- builder = new PreparedStatementWithColumnIndexes();
+ this.builder = new PreparedStatementWithColumnIndexes();
}
+ /**
+ * Constructs a key to uniquely identify a prepared statement.
+ *
+ * @param sql
+ * The SQL statement.
+ * @param catalog
+ * The catalog.
+ * @param columnNames
+ * An array of column names indicating the columns that should be returned from the inserted row or rows.
+ */
public PStmtKey(final String sql, final String catalog, final String[] columnNames) {
- _sql = sql;
- _catalog = catalog;
- _stmtType = StatementType.PREPARED_STATEMENT;
- _autoGeneratedKeys = null;
- _columnIndexes = null;
- _columnNames = columnNames;
- _resultSetType = null;
- _resultSetConcurrency = null;
- _resultSetHoldability = null;
+ this.sql = sql;
+ this.catalog = catalog;
+ this.statementType = StatementType.PREPARED_STATEMENT;
+ this.autoGeneratedKeys = null;
+ this.columnIndexes = null;
+ this.columnNames = columnNames == null ? null : Arrays.copyOf(columnNames, columnNames.length);
+ this.resultSetType = null;
+ this.resultSetConcurrency = null;
+ this.resultSetHoldability = null;
// create builder
builder = new PreparedStatementWithColumnNames();
}
- public PStmtKey(final String sql, final int resultSetType, final int resultSetConcurrency) {
+ /**
+ * Constructs a key to uniquely identify a prepared statement.
+ *
+ * @param sql
+ * The SQL statement.
+ * @param resultSetType
+ * A result set type; one of <code>ResultSet.TYPE_FORWARD_ONLY</code>,
+ * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>.
+ * @param resultSetConcurrency
+ * A concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code> or
+ * <code>ResultSet.CONCUR_UPDATABLE</code>.
+ */
+ public PStmtKey(final String sql, final int resultSetType, final int resultSetConcurrency) {
this(sql, null, resultSetType, resultSetConcurrency, StatementType.PREPARED_STATEMENT);
}
+ /**
+ * Constructs a key to uniquely identify a prepared statement.
+ *
+ * @param sql
+ * The SQL statement.
+ * @param catalog
+ * The catalog.
+ * @param resultSetType
+ * A result set type; one of <code>ResultSet.TYPE_FORWARD_ONLY</code>,
+ * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>.
+ * @param resultSetConcurrency
+ * A concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code> or
+ * <code>ResultSet.CONCUR_UPDATABLE</code>.
+ */
public PStmtKey(final String sql, final String catalog, final int resultSetType, final int resultSetConcurrency) {
this(sql, catalog, resultSetType, resultSetConcurrency, StatementType.PREPARED_STATEMENT);
}
- public PStmtKey(final String sql, final String catalog, final int resultSetType, final int resultSetConcurrency, final StatementType stmtType) {
- _sql = sql;
- _catalog = catalog;
- _resultSetType = Integer.valueOf(resultSetType);
- _resultSetConcurrency = Integer.valueOf(resultSetConcurrency);
- _resultSetHoldability = null;
- _stmtType = stmtType;
- _autoGeneratedKeys = null;
- _columnIndexes = null;
- _columnNames = null;
+ /**
+ * Constructs a key to uniquely identify a prepared statement.
+ *
+ * @param sql
+ * The SQL statement.
+ * @param catalog
+ * The catalog.
+ * @param resultSetType
+ * A result set type; one of <code>ResultSet.TYPE_FORWARD_ONLY</code>,
+ * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>.
+ * @param resultSetConcurrency
+ * A concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code> or
+ * <code>ResultSet.CONCUR_UPDATABLE</code>.
+ * @param statementType
+ * The SQL statement type, prepared or callable.
+ */
+ public PStmtKey(final String sql, final String catalog, final int resultSetType, final int resultSetConcurrency,
+ final StatementType statementType) {
+ this.sql = sql;
+ this.catalog = catalog;
+ this.resultSetType = Integer.valueOf(resultSetType);
+ this.resultSetConcurrency = Integer.valueOf(resultSetConcurrency);
+ this.resultSetHoldability = null;
+ this.statementType = statementType;
+ this.autoGeneratedKeys = null;
+ this.columnIndexes = null;
+ this.columnNames = null;
// create builder
- if (stmtType == StatementType.PREPARED_STATEMENT) {
- builder = new PreparedStatementWithResultSetConcurrency();
- } else if (stmtType == StatementType.CALLABLE_STATEMENT) {
- builder = new PreparedCallWithResultSetConcurrency();
+ if (statementType == StatementType.PREPARED_STATEMENT) {
+ this.builder = new PreparedStatementWithResultSetConcurrency();
+ } else if (statementType == StatementType.CALLABLE_STATEMENT) {
+ this.builder = new PreparedCallWithResultSetConcurrency();
}
}
+ /**
+ * Constructs a key to uniquely identify a prepared statement.
+ *
+ * @param sql
+ * The SQL statement.
+ * @param catalog
+ * The catalog.
+ * @param resultSetType
+ * a result set type; one of <code>ResultSet.TYPE_FORWARD_ONLY</code>,
+ * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>.
+ * @param resultSetConcurrency
+ * A concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code> or
+ * <code>ResultSet.CONCUR_UPDATABLE</code>
+ * @param resultSetHoldability
+ * One of the following <code>ResultSet</code> constants: <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code>
+ * or <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>.
+ */
public PStmtKey(final String sql, final String catalog, final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability) {
this(sql, catalog, resultSetType, resultSetConcurrency, resultSetHoldability, StatementType.PREPARED_STATEMENT);
}
+ /**
+ * Constructs a key to uniquely identify a prepared statement.
+ *
+ * @param sql
+ * The SQL statement.
+ * @param catalog
+ * The catalog.
+ * @param resultSetType
+ * a result set type; one of <code>ResultSet.TYPE_FORWARD_ONLY</code>,
+ * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
+ * @param resultSetConcurrency
+ * A concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code> or
+ * <code>ResultSet.CONCUR_UPDATABLE</code>.
+ * @param resultSetHoldability
+ * One of the following <code>ResultSet</code> constants: <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code>
+ * or <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>.
+ * @param statementType
+ * The SQL statement type, prepared or callable.
+ */
public PStmtKey(final String sql, final String catalog, final int resultSetType, final int resultSetConcurrency,
- final int resultSetHoldability, final StatementType stmtType) {
- _sql = sql;
- _catalog = catalog;
- _resultSetType = Integer.valueOf(resultSetType);
- _resultSetConcurrency = Integer.valueOf(resultSetConcurrency);
- _resultSetHoldability = Integer.valueOf(resultSetHoldability);
- _stmtType = stmtType;
- _autoGeneratedKeys = null;
- _columnIndexes = null;
- _columnNames = null;
+ final int resultSetHoldability, final StatementType statementType) {
+ this.sql = sql;
+ this.catalog = catalog;
+ this.resultSetType = Integer.valueOf(resultSetType);
+ this.resultSetConcurrency = Integer.valueOf(resultSetConcurrency);
+ this.resultSetHoldability = Integer.valueOf(resultSetHoldability);
+ this.statementType = statementType;
+ this.autoGeneratedKeys = null;
+ this.columnIndexes = null;
+ this.columnNames = null;
// create builder
- if (stmtType == StatementType.PREPARED_STATEMENT) {
- builder = new PreparedStatementWithResultSetHoldability();
- } else if (stmtType == StatementType.CALLABLE_STATEMENT) {
- builder = new PreparedCallWithResultSetHoldability();
+ if (statementType == StatementType.PREPARED_STATEMENT) {
+ this.builder = new PreparedStatementWithResultSetHoldability();
+ } else if (statementType == StatementType.CALLABLE_STATEMENT) {
+ this.builder = new PreparedCallWithResultSetHoldability();
}
}
-
+ /**
+ * Gets the SQL statement.
+ *
+ * @return the SQL statement.
+ */
public String getSql() {
- return _sql;
+ return sql;
}
+ /**
+ * Gets the result set type, one of <code>ResultSet.TYPE_FORWARD_ONLY</code>,
+ * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>.
+ *
+ * @return the result set type.
+ */
public Integer getResultSetType() {
- return _resultSetType;
+ return resultSetType;
}
+ /**
+ * Gets the result set concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code> or
+ * <code>ResultSet.CONCUR_UPDATABLE</code>.
+ *
+ * @return The result set concurrency type.
+ */
public Integer getResultSetConcurrency() {
- return _resultSetConcurrency;
+ return resultSetConcurrency;
}
+ /**
+ * Gets the result set holdability, one of the following <code>ResultSet</code> constants:
+ * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>.
+ *
+ * @return The result set holdability.
+ */
public Integer getResultSetHoldability() {
- return _resultSetHoldability;
+ return resultSetHoldability;
}
+ /**
+ * Gets a flag indicating whether auto-generated keys should be returned; one of
+ * <code>Statement.RETURN_GENERATED_KEYS</code> or <code>Statement.NO_GENERATED_KEYS</code>.
+ *
+ * @return a flag indicating whether auto-generated keys should be returned.
+ */
public Integer getAutoGeneratedKeys() {
- return _autoGeneratedKeys;
+ return autoGeneratedKeys;
}
+ /**
+ * Gets an array of column indexes indicating the columns that should be returned from the inserted row or rows.
+ *
+ * @return An array of column indexes.
+ */
public int[] getColumnIndexes() {
- return _columnIndexes;
+ return columnIndexes;
}
+ /**
+ * Gets an array of column names indicating the columns that should be returned from the inserted row or rows.
+ *
+ * @return An array of column names.
+ */
public String[] getColumnNames() {
- return _columnNames;
+ return columnNames;
}
+ /**
+ * The catalog.
+ *
+ * @return The catalog.
+ */
public String getCatalog() {
- return _catalog;
+ return catalog;
}
+ /**
+ * The SQL statement type.
+ *
+ * @return The SQL statement type.
+ */
public StatementType getStmtType() {
- return _stmtType;
+ return statementType;
}
@Override
@@ -235,55 +453,55 @@ public class PStmtKey {
return false;
}
final PStmtKey other = (PStmtKey) obj;
- if (_catalog == null) {
- if (other._catalog != null) {
+ if (catalog == null) {
+ if (other.catalog != null) {
return false;
}
- } else if (!_catalog.equals(other._catalog)) {
+ } else if (!catalog.equals(other.catalog)) {
return false;
}
- if (_resultSetConcurrency == null) {
- if (other._resultSetConcurrency != null) {
+ if (resultSetConcurrency == null) {
+ if (other.resultSetConcurrency != null) {
return false;
}
- } else if (!_resultSetConcurrency.equals(other._resultSetConcurrency)) {
+ } else if (!resultSetConcurrency.equals(other.resultSetConcurrency)) {
return false;
}
- if (_resultSetType == null) {
- if (other._resultSetType != null) {
+ if (resultSetType == null) {
+ if (other.resultSetType != null) {
return false;
}
- } else if (!_resultSetType.equals(other._resultSetType)) {
+ } else if (!resultSetType.equals(other.resultSetType)) {
return false;
}
- if (_resultSetHoldability == null) {
- if (other._resultSetHoldability != null) {
+ if (resultSetHoldability == null) {
+ if (other.resultSetHoldability != null) {
return false;
}
- } else if (!_resultSetHoldability.equals(other._resultSetHoldability)) {
+ } else if (!resultSetHoldability.equals(other.resultSetHoldability)) {
return false;
}
- if (_autoGeneratedKeys == null) {
- if (other._autoGeneratedKeys != null) {
+ if (autoGeneratedKeys == null) {
+ if (other.autoGeneratedKeys != null) {
return false;
}
- } else if (!_autoGeneratedKeys.equals(other._autoGeneratedKeys)) {
+ } else if (!autoGeneratedKeys.equals(other.autoGeneratedKeys)) {
return false;
}
- if (!Arrays.equals(_columnIndexes, other._columnIndexes)) {
+ if (!Arrays.equals(columnIndexes, other.columnIndexes)) {
return false;
}
- if (!Arrays.equals(_columnNames, other._columnNames)) {
+ if (!Arrays.equals(columnNames, other.columnNames)) {
return false;
}
- if (_sql == null) {
- if (other._sql != null) {
+ if (sql == null) {
+ if (other.sql != null) {
return false;
}
- } else if (!_sql.equals(other._sql)) {
+ } else if (!sql.equals(other.sql)) {
return false;
}
- if (_stmtType != other._stmtType) {
+ if (statementType != other.statementType) {
return false;
}
return true;
@@ -293,15 +511,15 @@ public class PStmtKey {
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + (_catalog == null ? 0 : _catalog.hashCode());
- result = prime * result + (_resultSetConcurrency == null ? 0 : _resultSetConcurrency.hashCode());
- result = prime * result + (_resultSetType == null ? 0 : _resultSetType.hashCode());
- result = prime * result + (_resultSetHoldability == null ? 0 : _resultSetHoldability.hashCode());
- result = prime * result + (_sql == null ? 0 : _sql.hashCode());
- result = prime * result + (_autoGeneratedKeys == null ? 0 : _autoGeneratedKeys.hashCode());
- result = prime * result + Arrays.hashCode(_columnIndexes);
- result = prime * result + Arrays.hashCode(_columnNames);
- result = prime * result + _stmtType.hashCode();
+ result = prime * result + (catalog == null ? 0 : catalog.hashCode());
+ result = prime * result + (resultSetConcurrency == null ? 0 : resultSetConcurrency.hashCode());
+ result = prime * result + (resultSetType == null ? 0 : resultSetType.hashCode());
+ result = prime * result + (resultSetHoldability == null ? 0 : resultSetHoldability.hashCode());
+ result = prime * result + (sql == null ? 0 : sql.hashCode());
+ result = prime * result + (autoGeneratedKeys == null ? 0 : autoGeneratedKeys.hashCode());
+ result = prime * result + Arrays.hashCode(columnIndexes);
+ result = prime * result + Arrays.hashCode(columnNames);
+ result = prime * result + statementType.hashCode();
return result;
}
@@ -309,26 +527,35 @@ public class PStmtKey {
public String toString() {
final StringBuffer buf = new StringBuffer();
buf.append("PStmtKey: sql=");
- buf.append(_sql);
+ buf.append(sql);
buf.append(", catalog=");
- buf.append(_catalog);
+ buf.append(catalog);
buf.append(", resultSetType=");
- buf.append(_resultSetType);
+ buf.append(resultSetType);
buf.append(", resultSetConcurrency=");
- buf.append(_resultSetConcurrency);
+ buf.append(resultSetConcurrency);
buf.append(", resultSetHoldability=");
- buf.append(_resultSetHoldability);
+ buf.append(resultSetHoldability);
buf.append(", autoGeneratedKeys=");
- buf.append(_autoGeneratedKeys);
+ buf.append(autoGeneratedKeys);
buf.append(", columnIndexes=");
- buf.append(Arrays.toString(_columnIndexes));
+ buf.append(Arrays.toString(columnIndexes));
buf.append(", columnNames=");
- buf.append(Arrays.toString(_columnNames));
+ buf.append(Arrays.toString(columnNames));
buf.append(", statementType=");
- buf.append(_stmtType);
+ buf.append(statementType);
return buf.toString();
}
+ /**
+ * Creates a new Statement from the given Connection.
+ *
+ * @param connection
+ * The Connection to use to create the statement.
+ * @return The statement.
+ * @throws SQLException
+ * Thrown when there is a problem creating the statement.
+ */
public Statement createStatement(final Connection connection) throws SQLException {
if (builder == null) {
throw new IllegalStateException("Prepared statement key is invalid.");
@@ -337,116 +564,111 @@ public class PStmtKey {
}
/**
- * Interface for Prepared or Callable Statement
+ * Interface for Prepared or Callable Statement.
*/
private interface StatementBuilder {
public Statement createStatement(Connection connection) throws SQLException;
}
/**
- * Builder for prepareStatement(String sql)
+ * Builder for prepareStatement(String sql).
*/
private class PreparedStatementSQL implements StatementBuilder {
@Override
public Statement createStatement(final Connection connection) throws SQLException {
- final PreparedStatement statement = connection.prepareStatement(_sql);
+ final PreparedStatement statement = connection.prepareStatement(sql);
return statement;
}
}
/**
- * Builder for prepareStatement(String sql, int autoGeneratedKeys)
+ * Builder for prepareStatement(String sql, int autoGeneratedKeys).
*/
private class PreparedStatementWithAutoGeneratedKeys implements StatementBuilder {
@Override
public Statement createStatement(final Connection connection) throws SQLException {
- final PreparedStatement statement = connection.prepareStatement(
- _sql, _autoGeneratedKeys.intValue());
+ final PreparedStatement statement = connection.prepareStatement(sql, autoGeneratedKeys.intValue());
return statement;
}
}
/**
- * Builder for prepareStatement(String sql, int[] columnIndexes)
+ * Builder for prepareStatement(String sql, int[] columnIndexes).
*/
private class PreparedStatementWithColumnIndexes implements StatementBuilder {
@Override
public Statement createStatement(final Connection connection) throws SQLException {
- final PreparedStatement statement = connection.prepareStatement(
- _sql, _columnIndexes);
+ final PreparedStatement statement = connection.prepareStatement(sql, columnIndexes);
return statement;
}
}
/**
- * Builder for prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
+ * Builder for prepareStatement(String sql, int resultSetType, int resultSetConcurrency).
*/
private class PreparedStatementWithResultSetConcurrency implements StatementBuilder {
@Override
public Statement createStatement(final Connection connection) throws SQLException {
- final PreparedStatement statement = connection.prepareStatement(
- _sql, _resultSetType.intValue(), _resultSetConcurrency.intValue());
+ final PreparedStatement statement = connection.prepareStatement(sql, resultSetType.intValue(),
+ resultSetConcurrency.intValue());
return statement;
}
}
/**
- * Builder for prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
+ * Builder for prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability).
*/
private class PreparedStatementWithResultSetHoldability implements StatementBuilder {
@Override
public Statement createStatement(final Connection connection) throws SQLException {
- final PreparedStatement statement = connection.prepareStatement(
- _sql, _resultSetType.intValue(), _resultSetConcurrency.intValue(),
- _resultSetHoldability.intValue());
+ final PreparedStatement statement = connection.prepareStatement(sql, resultSetType.intValue(),
+ resultSetConcurrency.intValue(), resultSetHoldability.intValue());
return statement;
}
}
/**
- * Builder for prepareStatement(String sql, String[] columnNames)
+ * Builder for prepareStatement(String sql, String[] columnNames).
*/
private class PreparedStatementWithColumnNames implements StatementBuilder {
@Override
public Statement createStatement(final Connection connection) throws SQLException {
- final PreparedStatement statement = connection.prepareStatement(
- _sql, _columnNames);
+ final PreparedStatement statement = connection.prepareStatement(sql, columnNames);
return statement;
}
}
/**
- * Builder for prepareCall(String sql)
+ * Builder for prepareCall(String sql).
*/
private class PreparedCallSQL implements StatementBuilder {
@Override
public Statement createStatement(final Connection connection) throws SQLException {
- final PreparedStatement statement = connection.prepareCall(_sql);
+ final PreparedStatement statement = connection.prepareCall(sql);
return statement;
}
}
/**
- * Builder for prepareCall(String sql, int resultSetType, int resultSetConcurrency)
+ * Builder for prepareCall(String sql, int resultSetType, int resultSetConcurrency).
*/
private class PreparedCallWithResultSetConcurrency implements StatementBuilder {
@Override
public Statement createStatement(final Connection connection) throws SQLException {
- final PreparedStatement statement = connection.prepareCall(
- _sql, _resultSetType.intValue(), _resultSetConcurrency.intValue());
+ final PreparedStatement statement = connection.prepareCall(sql, resultSetType.intValue(),
+ resultSetConcurrency.intValue());
return statement;
}
}
/**
- * Builder for prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
+ * Builder for prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability).
*/
private class PreparedCallWithResultSetHoldability implements StatementBuilder {
@Override
public Statement createStatement(final Connection connection) throws SQLException {
- final PreparedStatement statement = connection.prepareCall(
- _sql, _resultSetType.intValue(), _resultSetConcurrency.intValue(),
- _resultSetHoldability.intValue());
+ final PreparedStatement statement = connection.prepareCall(sql, resultSetType.intValue(),
+ resultSetConcurrency.intValue(), resultSetHoldability.intValue());
return statement;
}
}
Modified: tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/PoolableCallableStatement.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/PoolableCallableStatement.java?rev=1833804&r1=1833803&r2=1833804&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/PoolableCallableStatement.java (original)
+++ tomcat/tc8.5.x/trunk/java/org/apache/tomcat/dbcp/dbcp2/PoolableCallableStatement.java Tue Jun 19 10:30:31 2018
@@ -26,8 +26,8 @@ import java.util.List;
import org.apache.tomcat.dbcp.pool2.KeyedObjectPool;
/**
- * A {@link DelegatingCallableStatement} that cooperates with
- * {@link PoolingConnection} to implement a pool of {@link CallableStatement}s.
+ * A {@link DelegatingCallableStatement} that cooperates with {@link PoolingConnection} to implement a pool of
+ * {@link CallableStatement}s.
* <p>
* The {@link #close} method returns this statement to its containing pool. (See {@link PoolingConnection}.)
*
@@ -39,75 +39,83 @@ public class PoolableCallableStatement e
/**
* The {@link KeyedObjectPool} from which this CallableStatement was obtained.
*/
- private final KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> _pool;
+ private final KeyedObjectPool<PStmtKey, DelegatingPreparedStatement> pool;
/**
* Key for this statement in the containing {@link KeyedObjectPool}.
*/
- private final PStmtKey _key;
+ private final PStmtKey key;
/**
* Constructor.
*
- * @param stmt the underlying {@link CallableStatement}
- * @param key the key for this statement in the {@link KeyedObjectPool}
- * @param pool the {@link KeyedObjectPool} from which this CallableStatement was obtained
- * @param conn the {@link DelegatingConnection} that created this CallableStatement
- */
- public PoolableCallableStatement(final CallableStatement stmt, final PStmtKey key,
- final KeyedObjectPool<PStmtKey,DelegatingPreparedStatement> pool,
- final DelegatingConnection<Connection> conn) {
- super(conn, stmt);
- _pool = pool;
- _key = key;
+ * @param callableStatement
+ * the underlying {@link CallableStatement}
+ * @param key
+ * the key for this statement in the {@link KeyedObjectPool}
+ * @param pool
+ * the {@link KeyedObjectPool} from which this CallableStatement was obtained
+ * @param connection
+ * the {@link DelegatingConnection} that created this CallableStatement
+ */
+ public PoolableCallableStatement(final CallableStatement callableStatement, final PStmtKey key,
+ final KeyedObjectPool<PStmtKey, DelegatingPreparedStatement> pool,
+ final DelegatingConnection<Connection> connection) {
+ super(connection, callableStatement);
+ this.pool = pool;
+ this.key = key;
// Remove from trace now because this statement will be
// added by the activate method.
- if(getConnectionInternal() != null) {
+ if (getConnectionInternal() != null) {
getConnectionInternal().removeTrace(this);
}
}
/**
- * Returns the CallableStatement to the pool. If {{@link #isClosed()}, this is a No-op.
+ * Returns the CallableStatement to the pool. If {{@link #isClosed()}, this is a No-op.
*/
@Override
public void close() throws SQLException {
// calling close twice should have no effect
if (!isClosed()) {
try {
- _pool.returnObject(_key,this);
- } catch(final SQLException e) {
+ pool.returnObject(key, this);
+ } catch (final SQLException e) {
throw e;
- } catch(final RuntimeException e) {
+ } catch (final RuntimeException e) {
throw e;
- } catch(final Exception e) {
+ } catch (final Exception e) {
throw new SQLException("Cannot close CallableStatement (return to pool failed)", e);
}
}
}
/**
- * Activates after retrieval from the pool. Adds a trace for this CallableStatement to the Connection
- * that created it.
+ * Activates after retrieval from the pool. Adds a trace for this CallableStatement to the Connection that created
+ * it.
+ *
+ * @since 2.4.0 made public, was protected in 2.3.0.
*/
@Override
- protected void activate() throws SQLException {
+ public void activate() throws SQLException {
setClosedInternal(false);
- if( getConnectionInternal() != null ) {
- getConnectionInternal().addTrace( this );
+ if (getConnectionInternal() != null) {
+ getConnectionInternal().addTrace(this);
}
super.activate();
}
/**
- * Passivates to prepare for return to the pool. Removes the trace associated with this CallableStatement
- * from the Connection that created it. Also closes any associated ResultSets.
+ * Passivates to prepare for return to the pool. Removes the trace associated with this CallableStatement from the
+ * Connection that created it. Also closes any associated ResultSets.
+ *
+ * @since 2.4.0 made public, was protected in 2.3.0.
*/
@Override
- protected void passivate() throws SQLException {
+ public void passivate() throws SQLException {
setClosedInternal(true);
- if( getConnectionInternal() != null ) {
+ if (getConnectionInternal() != null) {
getConnectionInternal().removeTrace(this);
}
@@ -116,7 +124,7 @@ public class PoolableCallableStatement e
// FIXME The PreparedStatement we're wrapping should handle this for us.
// See DBCP-10 for what could happen when ResultSets are closed twice.
final List<AbandonedTrace> resultSets = getTrace();
- if(resultSets != null) {
+ if (resultSets != null) {
final ResultSet[] set = resultSets.toArray(new ResultSet[resultSets.size()]);
for (final ResultSet element : set) {
element.close();
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org