You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2018/06/12 00:42:16 UTC
commons-dbcp git commit: Javadoc and line length 120.
Repository: commons-dbcp
Updated Branches:
refs/heads/master 3df225721 -> 16626a9b8
Javadoc and line length 120.
Project: http://git-wip-us.apache.org/repos/asf/commons-dbcp/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-dbcp/commit/16626a9b
Tree: http://git-wip-us.apache.org/repos/asf/commons-dbcp/tree/16626a9b
Diff: http://git-wip-us.apache.org/repos/asf/commons-dbcp/diff/16626a9b
Branch: refs/heads/master
Commit: 16626a9b8fdecf3fa80876a244ff74dd171b06cd
Parents: 3df2257
Author: Gary Gregory <ga...@gmail.com>
Authored: Mon Jun 11 18:42:14 2018 -0600
Committer: Gary Gregory <ga...@gmail.com>
Committed: Mon Jun 11 18:42:14 2018 -0600
----------------------------------------------------------------------
.../java/org/apache/commons/dbcp2/PStmtKey.java | 290 ++++++++++++++++---
1 file changed, 246 insertions(+), 44 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/16626a9b/src/main/java/org/apache/commons/dbcp2/PStmtKey.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/PStmtKey.java b/src/main/java/org/apache/commons/dbcp2/PStmtKey.java
index 36b3c09..6fc5f65 100644
--- a/src/main/java/org/apache/commons/dbcp2/PStmtKey.java
+++ b/src/main/java/org/apache/commons/dbcp2/PStmtKey.java
@@ -26,6 +26,7 @@ import org.apache.commons.dbcp2.PoolingConnection.StatementType;
/**
* A key uniquely identifying {@link java.sql.PreparedStatement PreparedStatement}s.
+ *
* @since 2.0
*/
public class PStmtKey {
@@ -60,18 +61,42 @@ public class PStmtKey {
/** 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) {
+ /**
+ * 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 = stmtType;
+ this.statementType = statementType;
this.autoGeneratedKeys = null;
this.columnIndexes = null;
this.columnNames = null;
@@ -79,21 +104,46 @@ public class PStmtKey {
this.resultSetConcurrency = null;
this.resultSetHoldability = null;
// create builder
- if (stmtType == StatementType.PREPARED_STATEMENT) {
+ if (statementType == StatementType.PREPARED_STATEMENT) {
this.builder = new PreparedStatementSQL();
- } else if (stmtType == StatementType.CALLABLE_STATEMENT) {
+ } 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) {
+ /**
+ * 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 = stmtType;
+ this.statementType = statementType;
this.autoGeneratedKeys = autoGeneratedKeys;
this.columnIndexes = null;
this.columnNames = null;
@@ -101,13 +151,24 @@ public class PStmtKey {
this.resultSetConcurrency = null;
this.resultSetHoldability = null;
// create builder
- if (stmtType == StatementType.PREPARED_STATEMENT) {
+ if (statementType == StatementType.PREPARED_STATEMENT) {
this.builder = new PreparedStatementWithAutoGeneratedKeys();
- } else if (stmtType == StatementType.CALLABLE_STATEMENT) {
+ } 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) {
this.sql = sql;
this.catalog = catalog;
@@ -122,6 +183,16 @@ public class PStmtKey {
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) {
this.sql = sql;
this.catalog = catalog;
@@ -136,89 +207,216 @@ public class PStmtKey {
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) {
+ /**
+ * 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 = stmtType;
+ this.statementType = statementType;
this.autoGeneratedKeys = null;
this.columnIndexes = null;
this.columnNames = null;
// create builder
- if (stmtType == StatementType.PREPARED_STATEMENT) {
+ if (statementType == StatementType.PREPARED_STATEMENT) {
this.builder = new PreparedStatementWithResultSetConcurrency();
- } else if (stmtType == StatementType.CALLABLE_STATEMENT) {
+ } 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) {
+ 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 = stmtType;
+ this.statementType = statementType;
this.autoGeneratedKeys = null;
this.columnIndexes = null;
this.columnNames = null;
// create builder
- if (stmtType == StatementType.PREPARED_STATEMENT) {
+ if (statementType == StatementType.PREPARED_STATEMENT) {
this.builder = new PreparedStatementWithResultSetHoldability();
- } else if (stmtType == StatementType.CALLABLE_STATEMENT) {
+ } else if (statementType == StatementType.CALLABLE_STATEMENT) {
this.builder = new PreparedCallWithResultSetHoldability();
}
}
-
+ /**
+ * Gets the SQL statement.
+ *
+ * @return the SQL statement.
+ */
public String getSql() {
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;
}
+ /**
+ * 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;
}
+ /**
+ * 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;
}
+ /**
+ * 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;
}
+ /**
+ * 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;
}
+ /**
+ * 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;
}
+ /**
+ * The catalog.
+ *
+ * @return The catalog.
+ */
public String getCatalog() {
return catalog;
}
+ /**
+ * The SQL statement type.
+ *
+ * @return The SQL statement type.
+ */
public StatementType getStmtType() {
return statementType;
}
@@ -329,6 +527,15 @@ public class PStmtKey {
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,14 +544,14 @@ 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
@@ -355,68 +562,64 @@ public class PStmtKey {
}
/**
- * 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
@@ -427,26 +630,25 @@ public class PStmtKey {
}
/**
- * 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;
}
}