iface) throws SQLException {
+ if (iface.isAssignableFrom(getClass())) {
+ return iface.cast(this);
+ } else if (iface.isAssignableFrom(connection.getClass())) {
+ return iface.cast(connection);
+ } else {
+ return connection.unwrap(iface);
}
}
}
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java b/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java
index 9aea2d30c7..a0edcfb393 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java
@@ -22,6 +22,14 @@
import java.sql.RowIdLifetime;
import java.sql.SQLException;
+import org.apache.commons.dbcp2.function.SQLFunction0;
+import org.apache.commons.dbcp2.function.SQLFunction1;
+import org.apache.commons.dbcp2.function.SQLFunction2;
+import org.apache.commons.dbcp2.function.SQLFunction3;
+import org.apache.commons.dbcp2.function.SQLFunction4;
+import org.apache.commons.dbcp2.function.SQLFunction5;
+import org.apache.commons.dbcp2.function.SQLFunction6;
+
/**
*
* A base delegating implementation of {@link DatabaseMetaData}.
@@ -33,7 +41,7 @@
*
* @since 2.0
*/
-public class DelegatingDatabaseMetaData implements DatabaseMetaData {
+public class DelegatingDatabaseMetaData extends ResourceFunctions implements DatabaseMetaData {
/** My delegate {@link DatabaseMetaData} */
private final DatabaseMetaData databaseMetaData;
@@ -44,10 +52,8 @@ public class DelegatingDatabaseMetaData implements DatabaseMetaData {
/**
* Constructs a new instance for the given delegating connection and database meta data.
*
- * @param connection
- * the delegating connection
- * @param databaseMetaData
- * the database meta data
+ * @param connection the delegating connection
+ * @param databaseMetaData the database meta data
*/
public DelegatingDatabaseMetaData(final DelegatingConnection> connection,
final DatabaseMetaData databaseMetaData) {
@@ -58,177 +64,87 @@ public DelegatingDatabaseMetaData(final DelegatingConnection> connection,
@Override
public boolean allProceduresAreCallable() throws SQLException {
- try {
- return databaseMetaData.allProceduresAreCallable();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::allProceduresAreCallable);
}
@Override
public boolean allTablesAreSelectable() throws SQLException {
- try {
- return databaseMetaData.allTablesAreSelectable();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::allTablesAreSelectable);
}
@Override
public boolean autoCommitFailureClosesAllResultSets() throws SQLException {
- try {
- return databaseMetaData.autoCommitFailureClosesAllResultSets();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::autoCommitFailureClosesAllResultSets);
}
@Override
public boolean dataDefinitionCausesTransactionCommit() throws SQLException {
- try {
- return databaseMetaData.dataDefinitionCausesTransactionCommit();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::dataDefinitionCausesTransactionCommit);
}
@Override
public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
- try {
- return databaseMetaData.dataDefinitionIgnoredInTransactions();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::dataDefinitionIgnoredInTransactions);
}
@Override
public boolean deletesAreDetected(final int type) throws SQLException {
- try {
- return databaseMetaData.deletesAreDetected(type);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyIntTo(databaseMetaData::deletesAreDetected, type, false);
}
@Override
public boolean doesMaxRowSizeIncludeBlobs() throws SQLException {
- try {
- return databaseMetaData.doesMaxRowSizeIncludeBlobs();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::doesMaxRowSizeIncludeBlobs);
}
@Override
public boolean generatedKeyAlwaysReturned() throws SQLException {
- connection.checkOpen();
- try {
- return Jdbc41Bridge.generatedKeyAlwaysReturned(databaseMetaData);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::generatedKeyAlwaysReturned);
}
@Override
public ResultSet getAttributes(final String catalog, final String schemaPattern, final String typeNamePattern,
final String attributeNamePattern) throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getAttributes(catalog, schemaPattern, typeNamePattern, attributeNamePattern));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getAttributes, catalog, schemaPattern, typeNamePattern,
+ attributeNamePattern);
}
@Override
public ResultSet getBestRowIdentifier(final String catalog, final String schema, final String table,
final int scope, final boolean nullable) throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getBestRowIdentifier(catalog, schema, table, scope, nullable));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getBestRowIdentifier, catalog, schema, table, scope, nullable);
}
@Override
public ResultSet getCatalogs() throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getCatalogs());
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getCatalogs);
}
@Override
public String getCatalogSeparator() throws SQLException {
- try {
- return databaseMetaData.getCatalogSeparator();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getCatalogSeparator);
}
@Override
public String getCatalogTerm() throws SQLException {
- try {
- return databaseMetaData.getCatalogTerm();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getCatalogTerm);
}
@Override
public ResultSet getClientInfoProperties() throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getClientInfoProperties());
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getClientInfoProperties);
}
@Override
public ResultSet getColumnPrivileges(final String catalog, final String schema, final String table,
final String columnNamePattern) throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getColumnPrivileges(catalog, schema, table, columnNamePattern));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getColumnPrivileges, catalog, schema, table, columnNamePattern);
}
@Override
public ResultSet getColumns(final String catalog, final String schemaPattern, final String tableNamePattern,
final String columnNamePattern) throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getColumns, catalog, schemaPattern, tableNamePattern, columnNamePattern);
}
@Override
@@ -239,64 +155,33 @@ public Connection getConnection() throws SQLException {
@Override
public ResultSet getCrossReference(final String parentCatalog, final String parentSchema, final String parentTable,
final String foreignCatalog, final String foreignSchema, final String foreignTable) throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getCrossReference(parentCatalog,
- parentSchema, parentTable, foreignCatalog, foreignSchema, foreignTable));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getCrossReference, parentCatalog, parentSchema, parentTable,
+ foreignCatalog, foreignSchema, foreignTable);
}
@Override
public int getDatabaseMajorVersion() throws SQLException {
- try {
- return databaseMetaData.getDatabaseMajorVersion();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getDatabaseMajorVersion);
}
@Override
public int getDatabaseMinorVersion() throws SQLException {
- try {
- return databaseMetaData.getDatabaseMinorVersion();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getDatabaseMinorVersion);
}
@Override
public String getDatabaseProductName() throws SQLException {
- try {
- return databaseMetaData.getDatabaseProductName();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getDatabaseProductName);
}
@Override
public String getDatabaseProductVersion() throws SQLException {
- try {
- return databaseMetaData.getDatabaseProductVersion();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getDatabaseProductVersion);
}
@Override
public int getDefaultTransactionIsolation() throws SQLException {
- try {
- return databaseMetaData.getDefaultTransactionIsolation();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getDefaultTransactionIsolation);
}
/**
@@ -320,107 +205,53 @@ public int getDriverMinorVersion() {
@Override
public String getDriverName() throws SQLException {
- try {
- return databaseMetaData.getDriverName();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getDriverName);
}
@Override
public String getDriverVersion() throws SQLException {
- try {
- return databaseMetaData.getDriverVersion();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getDriverVersion);
}
@Override
public ResultSet getExportedKeys(final String catalog, final String schema, final String table)
throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getExportedKeys(catalog, schema, table));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getExportedKeys, catalog, schema, table);
}
@Override
public String getExtraNameCharacters() throws SQLException {
- try {
- return databaseMetaData.getExtraNameCharacters();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getExtraNameCharacters);
}
@Override
public ResultSet getFunctionColumns(final String catalog, final String schemaPattern,
final String functionNamePattern, final String columnNamePattern) throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getFunctionColumns(catalog,
- schemaPattern, functionNamePattern, columnNamePattern));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getFunctionColumns, catalog, schemaPattern, functionNamePattern,
+ columnNamePattern);
}
@Override
public ResultSet getFunctions(final String catalog, final String schemaPattern, final String functionNamePattern)
throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getFunctions(catalog, schemaPattern, functionNamePattern));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getFunctions, catalog, schemaPattern, functionNamePattern);
}
@Override
public String getIdentifierQuoteString() throws SQLException {
- try {
- return databaseMetaData.getIdentifierQuoteString();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getIdentifierQuoteString);
}
@Override
public ResultSet getImportedKeys(final String catalog, final String schema, final String table)
throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getImportedKeys(catalog, schema, table));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getImportedKeys, catalog, schema, table);
}
@Override
public ResultSet getIndexInfo(final String catalog, final String schema, final String table, final boolean unique,
final boolean approximate) throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getIndexInfo(catalog, schema, table, unique, approximate));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getIndexInfo, catalog, schema, table, unique, approximate);
}
/**
@@ -450,142 +281,72 @@ public DatabaseMetaData getInnermostDelegate() {
@Override
public int getJDBCMajorVersion() throws SQLException {
- try {
- return databaseMetaData.getJDBCMajorVersion();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getJDBCMajorVersion);
}
@Override
public int getJDBCMinorVersion() throws SQLException {
- try {
- return databaseMetaData.getJDBCMinorVersion();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getJDBCMinorVersion);
}
@Override
public int getMaxBinaryLiteralLength() throws SQLException {
- try {
- return databaseMetaData.getMaxBinaryLiteralLength();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxBinaryLiteralLength);
}
@Override
public int getMaxCatalogNameLength() throws SQLException {
- try {
- return databaseMetaData.getMaxCatalogNameLength();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxCatalogNameLength);
}
@Override
public int getMaxCharLiteralLength() throws SQLException {
- try {
- return databaseMetaData.getMaxCharLiteralLength();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxCharLiteralLength);
}
@Override
public int getMaxColumnNameLength() throws SQLException {
- try {
- return databaseMetaData.getMaxColumnNameLength();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxColumnNameLength);
}
@Override
public int getMaxColumnsInGroupBy() throws SQLException {
- try {
- return databaseMetaData.getMaxColumnsInGroupBy();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxColumnsInGroupBy);
}
@Override
public int getMaxColumnsInIndex() throws SQLException {
- try {
- return databaseMetaData.getMaxColumnsInIndex();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxColumnsInIndex);
}
@Override
public int getMaxColumnsInOrderBy() throws SQLException {
- try {
- return databaseMetaData.getMaxColumnsInOrderBy();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxColumnsInOrderBy);
}
@Override
public int getMaxColumnsInSelect() throws SQLException {
- try {
- return databaseMetaData.getMaxColumnsInSelect();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxColumnsInSelect);
}
@Override
public int getMaxColumnsInTable() throws SQLException {
- try {
- return databaseMetaData.getMaxColumnsInTable();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxColumnsInTable);
}
@Override
public int getMaxConnections() throws SQLException {
- try {
- return databaseMetaData.getMaxConnections();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxConnections);
}
@Override
public int getMaxCursorNameLength() throws SQLException {
- try {
- return databaseMetaData.getMaxCursorNameLength();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxCursorNameLength);
}
@Override
public int getMaxIndexLength() throws SQLException {
- try {
- return databaseMetaData.getMaxIndexLength();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxIndexLength);
}
/**
@@ -593,397 +354,196 @@ public int getMaxIndexLength() throws SQLException {
*/
@Override
public long getMaxLogicalLobSize() throws SQLException {
- try {
- return databaseMetaData.getMaxLogicalLobSize();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0L(databaseMetaData::getMaxLogicalLobSize);
}
@Override
public int getMaxProcedureNameLength() throws SQLException {
- try {
- return databaseMetaData.getMaxProcedureNameLength();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxProcedureNameLength);
}
@Override
public int getMaxRowSize() throws SQLException {
- try {
- return databaseMetaData.getMaxRowSize();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxRowSize);
}
@Override
public int getMaxSchemaNameLength() throws SQLException {
- try {
- return databaseMetaData.getMaxSchemaNameLength();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxSchemaNameLength);
}
@Override
public int getMaxStatementLength() throws SQLException {
- try {
- return databaseMetaData.getMaxStatementLength();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxStatementLength);
}
@Override
public int getMaxStatements() throws SQLException {
- try {
- return databaseMetaData.getMaxStatements();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxStatements);
}
@Override
public int getMaxTableNameLength() throws SQLException {
- try {
- return databaseMetaData.getMaxTableNameLength();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxTableNameLength);
}
@Override
public int getMaxTablesInSelect() throws SQLException {
- try {
- return databaseMetaData.getMaxTablesInSelect();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxTablesInSelect);
}
@Override
public int getMaxUserNameLength() throws SQLException {
- try {
- return databaseMetaData.getMaxUserNameLength();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getMaxUserNameLength);
}
@Override
public String getNumericFunctions() throws SQLException {
- try {
- return databaseMetaData.getNumericFunctions();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getNumericFunctions);
}
@Override
public ResultSet getPrimaryKeys(final String catalog, final String schema, final String table) throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getPrimaryKeys(catalog, schema, table));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getPrimaryKeys, catalog, schema, table);
}
@Override
public ResultSet getProcedureColumns(final String catalog, final String schemaPattern,
final String procedureNamePattern, final String columnNamePattern) throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getProcedureColumns(catalog,
- schemaPattern, procedureNamePattern, columnNamePattern));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getProcedureColumns, catalog, schemaPattern, procedureNamePattern,
+ columnNamePattern);
}
@Override
public ResultSet getProcedures(final String catalog, final String schemaPattern, final String procedureNamePattern)
throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getProcedures(catalog, schemaPattern, procedureNamePattern));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getProcedures, catalog, schemaPattern, procedureNamePattern);
}
@Override
public String getProcedureTerm() throws SQLException {
- try {
- return databaseMetaData.getProcedureTerm();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getProcedureTerm);
}
@Override
public ResultSet getPseudoColumns(final String catalog, final String schemaPattern, final String tableNamePattern,
final String columnNamePattern) throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection, Jdbc41Bridge.getPseudoColumns(databaseMetaData,
- catalog, schemaPattern, tableNamePattern, columnNamePattern));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getPseudoColumns, catalog, schemaPattern, tableNamePattern,
+ columnNamePattern);
}
@Override
public int getResultSetHoldability() throws SQLException {
- try {
- return databaseMetaData.getResultSetHoldability();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(databaseMetaData::getResultSetHoldability);
}
@Override
public RowIdLifetime getRowIdLifetime() throws SQLException {
- try {
- return databaseMetaData.getRowIdLifetime();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getRowIdLifetime);
}
@Override
public ResultSet getSchemas() throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getSchemas());
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getSchemas);
}
@Override
public ResultSet getSchemas(final String catalog, final String schemaPattern) throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getSchemas(catalog, schemaPattern));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getSchemas, catalog, schemaPattern);
}
@Override
public String getSchemaTerm() throws SQLException {
- try {
- return databaseMetaData.getSchemaTerm();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getSchemaTerm);
}
@Override
public String getSearchStringEscape() throws SQLException {
- try {
- return databaseMetaData.getSearchStringEscape();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getSearchStringEscape);
}
@Override
public String getSQLKeywords() throws SQLException {
- try {
- return databaseMetaData.getSQLKeywords();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getSQLKeywords);
}
@Override
public int getSQLStateType() throws SQLException {
- try {
- return databaseMetaData.getSQLStateType();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return apply(databaseMetaData::getSQLStateType);
}
@Override
public String getStringFunctions() throws SQLException {
- try {
- return databaseMetaData.getStringFunctions();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getStringFunctions);
}
@Override
public ResultSet getSuperTables(final String catalog, final String schemaPattern, final String tableNamePattern)
throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getSuperTables(catalog, schemaPattern, tableNamePattern));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getSuperTables,catalog, schemaPattern, tableNamePattern);
}
@Override
public ResultSet getSuperTypes(final String catalog, final String schemaPattern, final String typeNamePattern)
throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getSuperTypes(catalog, schemaPattern, typeNamePattern));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getSuperTypes,catalog, schemaPattern, typeNamePattern);
}
@Override
public String getSystemFunctions() throws SQLException {
- try {
- return databaseMetaData.getSystemFunctions();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getSystemFunctions);
}
@Override
public ResultSet getTablePrivileges(final String catalog, final String schemaPattern, final String tableNamePattern)
throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getTablePrivileges(catalog, schemaPattern, tableNamePattern));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getTablePrivileges,catalog, schemaPattern, tableNamePattern);
}
@Override
public ResultSet getTables(final String catalog, final String schemaPattern, final String tableNamePattern,
final String[] types) throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getTables(catalog, schemaPattern, tableNamePattern, types));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getTables,catalog, schemaPattern, tableNamePattern, types);
}
@Override
public ResultSet getTableTypes() throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getTableTypes());
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getTableTypes);
}
@Override
public String getTimeDateFunctions() throws SQLException {
- try {
- return databaseMetaData.getTimeDateFunctions();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getTimeDateFunctions);
}
@Override
public ResultSet getTypeInfo() throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection, databaseMetaData.getTypeInfo());
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getTypeInfo);
}
@Override
public ResultSet getUDTs(final String catalog, final String schemaPattern, final String typeNamePattern,
final int[] types) throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getUDTs(catalog, schemaPattern, typeNamePattern, types));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getUDTs,catalog, schemaPattern, typeNamePattern, types);
}
@Override
public String getURL() throws SQLException {
- try {
- return databaseMetaData.getURL();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getURL);
}
@Override
public String getUserName() throws SQLException {
- try {
- return databaseMetaData.getUserName();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(databaseMetaData::getUserName);
}
@Override
public ResultSet getVersionColumns(final String catalog, final String schema, final String table)
throws SQLException {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getVersionColumns(catalog, schema, table));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return toResultSet(databaseMetaData::getVersionColumns,catalog, schema, table);
}
+ @Override
protected void handleException(final SQLException e) throws SQLException {
if (connection != null) {
connection.handleException(e);
@@ -994,32 +554,17 @@ protected void handleException(final SQLException e) throws SQLException {
@Override
public boolean insertsAreDetected(final int type) throws SQLException {
- try {
- return databaseMetaData.insertsAreDetected(type);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyIntTo(databaseMetaData::insertsAreDetected, type, false);
}
@Override
public boolean isCatalogAtStart() throws SQLException {
- try {
- return databaseMetaData.isCatalogAtStart();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::isCatalogAtStart);
}
@Override
public boolean isReadOnly() throws SQLException {
- try {
- return databaseMetaData.isReadOnly();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::isReadOnly);
}
@Override
@@ -1035,632 +580,317 @@ public boolean isWrapperFor(final Class> iface) throws SQLException {
@Override
public boolean locatorsUpdateCopy() throws SQLException {
- try {
- return databaseMetaData.locatorsUpdateCopy();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::locatorsUpdateCopy);
}
@Override
public boolean nullPlusNonNullIsNull() throws SQLException {
- try {
- return databaseMetaData.nullPlusNonNullIsNull();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::nullPlusNonNullIsNull);
}
@Override
public boolean nullsAreSortedAtEnd() throws SQLException {
- try {
- return databaseMetaData.nullsAreSortedAtEnd();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::nullsAreSortedAtEnd);
}
@Override
public boolean nullsAreSortedAtStart() throws SQLException {
- try {
- return databaseMetaData.nullsAreSortedAtStart();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::nullsAreSortedAtStart);
}
@Override
public boolean nullsAreSortedHigh() throws SQLException {
- try {
- return databaseMetaData.nullsAreSortedHigh();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::nullsAreSortedHigh);
}
@Override
public boolean nullsAreSortedLow() throws SQLException {
- try {
- return databaseMetaData.nullsAreSortedLow();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::nullsAreSortedLow);
}
@Override
public boolean othersDeletesAreVisible(final int type) throws SQLException {
- try {
- return databaseMetaData.othersDeletesAreVisible(type);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyIntTo(databaseMetaData::othersDeletesAreVisible, type, false);
}
@Override
public boolean othersInsertsAreVisible(final int type) throws SQLException {
- try {
- return databaseMetaData.othersInsertsAreVisible(type);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyIntTo(databaseMetaData::othersInsertsAreVisible, type, false);
}
@Override
public boolean othersUpdatesAreVisible(final int type) throws SQLException {
- try {
- return databaseMetaData.othersUpdatesAreVisible(type);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyIntTo(databaseMetaData::othersUpdatesAreVisible, type, false);
}
@Override
public boolean ownDeletesAreVisible(final int type) throws SQLException {
- try {
- return databaseMetaData.ownDeletesAreVisible(type);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyIntTo(databaseMetaData::ownDeletesAreVisible, type, false);
}
@Override
public boolean ownInsertsAreVisible(final int type) throws SQLException {
- try {
- return databaseMetaData.ownInsertsAreVisible(type);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyIntTo(databaseMetaData::ownInsertsAreVisible, type, false);
}
@Override
public boolean ownUpdatesAreVisible(final int type) throws SQLException {
- try {
- return databaseMetaData.ownUpdatesAreVisible(type);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyIntTo(databaseMetaData::ownUpdatesAreVisible, type, false);
}
@Override
public boolean storesLowerCaseIdentifiers() throws SQLException {
- try {
- return databaseMetaData.storesLowerCaseIdentifiers();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::storesLowerCaseIdentifiers);
}
@Override
public boolean storesLowerCaseQuotedIdentifiers() throws SQLException {
- try {
- return databaseMetaData.storesLowerCaseQuotedIdentifiers();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::storesLowerCaseQuotedIdentifiers);
}
@Override
public boolean storesMixedCaseIdentifiers() throws SQLException {
- try {
- return databaseMetaData.storesMixedCaseIdentifiers();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::storesMixedCaseIdentifiers);
}
@Override
public boolean storesMixedCaseQuotedIdentifiers() throws SQLException {
- try {
- return databaseMetaData.storesMixedCaseQuotedIdentifiers();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::storesMixedCaseQuotedIdentifiers);
}
@Override
public boolean storesUpperCaseIdentifiers() throws SQLException {
- try {
- return databaseMetaData.storesUpperCaseIdentifiers();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::storesUpperCaseIdentifiers);
}
@Override
public boolean storesUpperCaseQuotedIdentifiers() throws SQLException {
- try {
- return databaseMetaData.storesUpperCaseQuotedIdentifiers();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::storesUpperCaseQuotedIdentifiers);
}
@Override
public boolean supportsAlterTableWithAddColumn() throws SQLException {
- try {
- return databaseMetaData.supportsAlterTableWithAddColumn();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsAlterTableWithAddColumn);
}
@Override
public boolean supportsAlterTableWithDropColumn() throws SQLException {
- try {
- return databaseMetaData.supportsAlterTableWithDropColumn();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsAlterTableWithDropColumn);
}
@Override
public boolean supportsANSI92EntryLevelSQL() throws SQLException {
- try {
- return databaseMetaData.supportsANSI92EntryLevelSQL();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsANSI92EntryLevelSQL);
}
@Override
public boolean supportsANSI92FullSQL() throws SQLException {
- try {
- return databaseMetaData.supportsANSI92FullSQL();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsANSI92FullSQL);
}
@Override
public boolean supportsANSI92IntermediateSQL() throws SQLException {
- try {
- return databaseMetaData.supportsANSI92IntermediateSQL();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsANSI92IntermediateSQL);
}
@Override
public boolean supportsBatchUpdates() throws SQLException {
- try {
- return databaseMetaData.supportsBatchUpdates();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsBatchUpdates);
}
@Override
public boolean supportsCatalogsInDataManipulation() throws SQLException {
- try {
- return databaseMetaData.supportsCatalogsInDataManipulation();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsCatalogsInDataManipulation);
}
@Override
public boolean supportsCatalogsInIndexDefinitions() throws SQLException {
- try {
- return databaseMetaData.supportsCatalogsInIndexDefinitions();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsCatalogsInIndexDefinitions);
}
@Override
public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException {
- try {
- return databaseMetaData.supportsCatalogsInPrivilegeDefinitions();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsCatalogsInPrivilegeDefinitions);
}
@Override
public boolean supportsCatalogsInProcedureCalls() throws SQLException {
- try {
- return databaseMetaData.supportsCatalogsInProcedureCalls();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsCatalogsInProcedureCalls);
}
@Override
public boolean supportsCatalogsInTableDefinitions() throws SQLException {
- try {
- return databaseMetaData.supportsCatalogsInTableDefinitions();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsCatalogsInTableDefinitions);
}
@Override
public boolean supportsColumnAliasing() throws SQLException {
- try {
- return databaseMetaData.supportsColumnAliasing();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsColumnAliasing);
}
@Override
public boolean supportsConvert() throws SQLException {
- try {
- return databaseMetaData.supportsConvert();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsConvert);
}
@Override
public boolean supportsConvert(final int fromType, final int toType) throws SQLException {
- try {
- return databaseMetaData.supportsConvert(fromType, toType);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyTo(databaseMetaData::supportsConvert, fromType, toType, false);
}
@Override
public boolean supportsCoreSQLGrammar() throws SQLException {
- try {
- return databaseMetaData.supportsCoreSQLGrammar();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsCoreSQLGrammar);
}
@Override
public boolean supportsCorrelatedSubqueries() throws SQLException {
- try {
- return databaseMetaData.supportsCorrelatedSubqueries();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsCorrelatedSubqueries);
}
@Override
public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException {
- try {
- return databaseMetaData.supportsDataDefinitionAndDataManipulationTransactions();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsDataDefinitionAndDataManipulationTransactions);
}
@Override
public boolean supportsDataManipulationTransactionsOnly() throws SQLException {
- try {
- return databaseMetaData.supportsDataManipulationTransactionsOnly();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsDataManipulationTransactionsOnly);
}
@Override
public boolean supportsDifferentTableCorrelationNames() throws SQLException {
- try {
- return databaseMetaData.supportsDifferentTableCorrelationNames();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsDifferentTableCorrelationNames);
}
@Override
public boolean supportsExpressionsInOrderBy() throws SQLException {
- try {
- return databaseMetaData.supportsExpressionsInOrderBy();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsExpressionsInOrderBy);
}
@Override
public boolean supportsExtendedSQLGrammar() throws SQLException {
- try {
- return databaseMetaData.supportsExtendedSQLGrammar();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsExtendedSQLGrammar);
}
@Override
public boolean supportsFullOuterJoins() throws SQLException {
- try {
- return databaseMetaData.supportsFullOuterJoins();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsFullOuterJoins);
}
@Override
public boolean supportsGetGeneratedKeys() throws SQLException {
- try {
- return databaseMetaData.supportsGetGeneratedKeys();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsGetGeneratedKeys);
}
@Override
public boolean supportsGroupBy() throws SQLException {
- try {
- return databaseMetaData.supportsGroupBy();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsGroupBy);
}
@Override
public boolean supportsGroupByBeyondSelect() throws SQLException {
- try {
- return databaseMetaData.supportsGroupByBeyondSelect();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsGroupByBeyondSelect);
}
@Override
public boolean supportsGroupByUnrelated() throws SQLException {
- try {
- return databaseMetaData.supportsGroupByUnrelated();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsGroupByUnrelated);
}
@Override
public boolean supportsIntegrityEnhancementFacility() throws SQLException {
- try {
- return databaseMetaData.supportsIntegrityEnhancementFacility();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsIntegrityEnhancementFacility);
}
@Override
public boolean supportsLikeEscapeClause() throws SQLException {
- try {
- return databaseMetaData.supportsLikeEscapeClause();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsLikeEscapeClause);
}
@Override
public boolean supportsLimitedOuterJoins() throws SQLException {
- try {
- return databaseMetaData.supportsLimitedOuterJoins();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsLimitedOuterJoins);
}
@Override
public boolean supportsMinimumSQLGrammar() throws SQLException {
- try {
- return databaseMetaData.supportsMinimumSQLGrammar();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsMinimumSQLGrammar);
}
@Override
public boolean supportsMixedCaseIdentifiers() throws SQLException {
- try {
- return databaseMetaData.supportsMixedCaseIdentifiers();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsMixedCaseIdentifiers);
}
@Override
public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException {
- try {
- return databaseMetaData.supportsMixedCaseQuotedIdentifiers();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsMixedCaseQuotedIdentifiers);
}
@Override
public boolean supportsMultipleOpenResults() throws SQLException {
- try {
- return databaseMetaData.supportsMultipleOpenResults();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsMultipleOpenResults);
}
@Override
public boolean supportsMultipleResultSets() throws SQLException {
- try {
- return databaseMetaData.supportsMultipleResultSets();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsMultipleResultSets);
}
@Override
public boolean supportsMultipleTransactions() throws SQLException {
- try {
- return databaseMetaData.supportsMultipleTransactions();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsMultipleTransactions);
}
@Override
public boolean supportsNamedParameters() throws SQLException {
- try {
- return databaseMetaData.supportsNamedParameters();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsNamedParameters);
}
@Override
public boolean supportsNonNullableColumns() throws SQLException {
- try {
- return databaseMetaData.supportsNonNullableColumns();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsNonNullableColumns);
}
@Override
public boolean supportsOpenCursorsAcrossCommit() throws SQLException {
- try {
- return databaseMetaData.supportsOpenCursorsAcrossCommit();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsOpenCursorsAcrossCommit);
}
@Override
public boolean supportsOpenCursorsAcrossRollback() throws SQLException {
- try {
- return databaseMetaData.supportsOpenCursorsAcrossRollback();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsOpenCursorsAcrossRollback);
}
@Override
public boolean supportsOpenStatementsAcrossCommit() throws SQLException {
- try {
- return databaseMetaData.supportsOpenStatementsAcrossCommit();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsOpenStatementsAcrossCommit);
}
@Override
public boolean supportsOpenStatementsAcrossRollback() throws SQLException {
- try {
- return databaseMetaData.supportsOpenStatementsAcrossRollback();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsOpenStatementsAcrossRollback);
}
@Override
public boolean supportsOrderByUnrelated() throws SQLException {
- try {
- return databaseMetaData.supportsOrderByUnrelated();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsOrderByUnrelated);
}
@Override
public boolean supportsOuterJoins() throws SQLException {
- try {
- return databaseMetaData.supportsOuterJoins();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsOuterJoins);
}
@Override
public boolean supportsPositionedDelete() throws SQLException {
- try {
- return databaseMetaData.supportsPositionedDelete();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsPositionedDelete);
}
@Override
public boolean supportsPositionedUpdate() throws SQLException {
- try {
- return databaseMetaData.supportsPositionedUpdate();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsPositionedUpdate);
}
/**
@@ -1668,234 +898,161 @@ public boolean supportsPositionedUpdate() throws SQLException {
*/
@Override
public boolean supportsRefCursors() throws SQLException {
- try {
- return databaseMetaData.supportsRefCursors();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsRefCursors);
}
@Override
public boolean supportsResultSetConcurrency(final int type, final int concurrency) throws SQLException {
- try {
- return databaseMetaData.supportsResultSetConcurrency(type, concurrency);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyTo(databaseMetaData::supportsResultSetConcurrency, type, concurrency, false);
}
@Override
public boolean supportsResultSetHoldability(final int holdability) throws SQLException {
- try {
- return databaseMetaData.supportsResultSetHoldability(holdability);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyTo(databaseMetaData::supportsResultSetHoldability, holdability, false);
}
@Override
public boolean supportsResultSetType(final int type) throws SQLException {
- try {
- return databaseMetaData.supportsResultSetType(type);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyTo(databaseMetaData::supportsResultSetType, type, false);
}
@Override
public boolean supportsSavepoints() throws SQLException {
- try {
- return databaseMetaData.supportsSavepoints();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsSavepoints);
}
@Override
public boolean supportsSchemasInDataManipulation() throws SQLException {
- try {
- return databaseMetaData.supportsSchemasInDataManipulation();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsSchemasInDataManipulation);
}
@Override
public boolean supportsSchemasInIndexDefinitions() throws SQLException {
- try {
- return databaseMetaData.supportsSchemasInIndexDefinitions();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsSchemasInIndexDefinitions);
}
@Override
public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException {
- try {
- return databaseMetaData.supportsSchemasInPrivilegeDefinitions();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsSchemasInPrivilegeDefinitions);
}
@Override
public boolean supportsSchemasInProcedureCalls() throws SQLException {
- try {
- return databaseMetaData.supportsSchemasInProcedureCalls();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsSchemasInProcedureCalls);
}
@Override
public boolean supportsSchemasInTableDefinitions() throws SQLException {
- try {
- return databaseMetaData.supportsSchemasInTableDefinitions();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsSchemasInTableDefinitions);
}
@Override
public boolean supportsSelectForUpdate() throws SQLException {
- try {
- return databaseMetaData.supportsSelectForUpdate();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsSelectForUpdate);
}
@Override
public boolean supportsStatementPooling() throws SQLException {
- try {
- return databaseMetaData.supportsStatementPooling();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsStatementPooling);
}
@Override
public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
- try {
- return databaseMetaData.supportsStoredFunctionsUsingCallSyntax();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsStoredFunctionsUsingCallSyntax);
}
@Override
public boolean supportsStoredProcedures() throws SQLException {
- try {
- return databaseMetaData.supportsStoredProcedures();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsStoredProcedures);
}
- /* JDBC_4_ANT_KEY_BEGIN */
-
@Override
public boolean supportsSubqueriesInComparisons() throws SQLException {
- try {
- return databaseMetaData.supportsSubqueriesInComparisons();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsSubqueriesInComparisons);
}
@Override
public boolean supportsSubqueriesInExists() throws SQLException {
- try {
- return databaseMetaData.supportsSubqueriesInExists();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsSubqueriesInExists);
}
@Override
public boolean supportsSubqueriesInIns() throws SQLException {
- try {
- return databaseMetaData.supportsSubqueriesInIns();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsSubqueriesInIns);
}
@Override
public boolean supportsSubqueriesInQuantifieds() throws SQLException {
- try {
- return databaseMetaData.supportsSubqueriesInQuantifieds();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsSubqueriesInQuantifieds);
}
@Override
public boolean supportsTableCorrelationNames() throws SQLException {
- try {
- return databaseMetaData.supportsTableCorrelationNames();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsTableCorrelationNames);
}
@Override
public boolean supportsTransactionIsolationLevel(final int level) throws SQLException {
- try {
- return databaseMetaData.supportsTransactionIsolationLevel(level);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyTo(databaseMetaData::supportsTransactionIsolationLevel, level, false);
}
@Override
public boolean supportsTransactions() throws SQLException {
- try {
- return databaseMetaData.supportsTransactions();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsTransactions);
}
+ /* JDBC_4_ANT_KEY_BEGIN */
+
@Override
public boolean supportsUnion() throws SQLException {
- try {
- return databaseMetaData.supportsUnion();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsUnion);
}
@Override
public boolean supportsUnionAll() throws SQLException {
- try {
- return databaseMetaData.supportsUnionAll();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::supportsUnionAll);
+ }
+
+ private ResultSet toResultSet(final SQLFunction0 callableResultSet) throws SQLException {
+ connection.checkOpen();
+ return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply()));
+ }
+
+ private ResultSet toResultSet(final SQLFunction1 callableResultSet, final T t)
+ throws SQLException {
+ connection.checkOpen();
+ return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t)));
+ }
+
+ private ResultSet toResultSet(final SQLFunction2 callableResultSet, final T t, final U u)
+ throws SQLException {
+ connection.checkOpen();
+ return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t, u)));
+ }
+
+ private ResultSet toResultSet(final SQLFunction3 callableResultSet, final T t,
+ final U u, final V v) throws SQLException {
+ connection.checkOpen();
+ return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t, u, v)));
+ }
+
+ private ResultSet toResultSet(final SQLFunction4 callableResultSet, final T t,
+ final U u, final V v, final X x) throws SQLException {
+ connection.checkOpen();
+ return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t, u, v, x)));
+ }
+
+ private ResultSet toResultSet(final SQLFunction5 callableResultSet,
+ final T t, final U u, final V v, final X x, final Y y) throws SQLException {
+ connection.checkOpen();
+ return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t, u, v, x, y)));
+ }
+
+ private ResultSet toResultSet(
+ final SQLFunction6 callableResultSet, final T t, final U u, final V v,
+ final X x, final Y y, final Z z) throws SQLException {
+ connection.checkOpen();
+ return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t, u, v, x, y, z)));
}
/* JDBC_4_ANT_KEY_END */
@@ -1913,31 +1070,16 @@ public T unwrap(final Class iface) throws SQLException {
@Override
public boolean updatesAreDetected(final int type) throws SQLException {
- try {
- return databaseMetaData.updatesAreDetected(type);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyTo(databaseMetaData::updatesAreDetected, type, false);
}
@Override
public boolean usesLocalFilePerTable() throws SQLException {
- try {
- return databaseMetaData.usesLocalFilePerTable();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::usesLocalFilePerTable);
}
@Override
public boolean usesLocalFiles() throws SQLException {
- try {
- return databaseMetaData.usesLocalFiles();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(databaseMetaData::usesLocalFiles);
}
}
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java b/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java
index 048687c055..f1bc2848c2 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java
@@ -43,9 +43,11 @@
*
* All of the methods from the {@link PreparedStatement} interface simply check to see that the
* {@link PreparedStatement} is active, and call the corresponding method on the "delegate" provided in my constructor.
+ *
*
* 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.
+ *
*
* @since 2.0
*/
@@ -55,10 +57,8 @@ public class DelegatingPreparedStatement extends DelegatingStatement implements
* Create a wrapper for the Statement which traces this Statement to the Connection which created it and the code
* which created it.
*
- * @param statement
- * the {@link PreparedStatement} to delegate all calls to.
- * @param connection
- * the {@link DelegatingConnection} that created this statement.
+ * @param statement the {@link PreparedStatement} to delegate all calls to.
+ * @param connection the {@link DelegatingConnection} that created this statement.
*/
public DelegatingPreparedStatement(final DelegatingConnection> connection, final PreparedStatement statement) {
super(connection, statement);
@@ -66,36 +66,17 @@ public DelegatingPreparedStatement(final DelegatingConnection> connection, fin
@Override
public void addBatch() throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().addBatch();
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(PreparedStatement::addBatch, getDelegatePreparedStatement());
}
@Override
public void clearParameters() throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().clearParameters();
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(PreparedStatement::clearParameters, getDelegatePreparedStatement());
}
@Override
public boolean execute() throws SQLException {
- checkOpen();
- if (getConnectionInternal() != null) {
- getConnectionInternal().setLastUsed();
- }
- try {
- return getDelegatePreparedStatement().execute();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyTo(PreparedStatement::execute, getDelegatePreparedStatement(), false);
}
/**
@@ -103,41 +84,17 @@ public boolean execute() throws SQLException {
*/
@Override
public long executeLargeUpdate() throws SQLException {
- checkOpen();
- try {
- return getDelegatePreparedStatement().executeLargeUpdate();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(PreparedStatement::executeLargeUpdate, getDelegatePreparedStatement(), 0L);
}
@Override
public ResultSet executeQuery() throws SQLException {
- checkOpen();
- if (getConnectionInternal() != null) {
- getConnectionInternal().setLastUsed();
- }
- try {
- return DelegatingResultSet.wrapResultSet(this, getDelegatePreparedStatement().executeQuery());
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(() -> DelegatingResultSet.wrapResultSet(this, getDelegatePreparedStatement().executeQuery()));
}
@Override
public int executeUpdate() throws SQLException {
- checkOpen();
- if (getConnectionInternal() != null) {
- getConnectionInternal().setLastUsed();
- }
- try {
- return getDelegatePreparedStatement().executeUpdate();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(PreparedStatement::executeUpdate, getDelegatePreparedStatement(), 0);
}
private PreparedStatement getDelegatePreparedStatement() {
@@ -146,539 +103,289 @@ private PreparedStatement getDelegatePreparedStatement() {
@Override
public ResultSetMetaData getMetaData() throws SQLException {
- checkOpen();
- try {
- return getDelegatePreparedStatement().getMetaData();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(PreparedStatement::getMetaData, getDelegatePreparedStatement());
}
@Override
public java.sql.ParameterMetaData getParameterMetaData() throws SQLException {
- checkOpen();
- try {
- return getDelegatePreparedStatement().getParameterMetaData();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(PreparedStatement::getParameterMetaData, getDelegatePreparedStatement());
}
@Override
- public void setArray(final int i, final Array x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setArray(i, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setArray(final int inputStream, final Array value) throws SQLException {
+ accept(PreparedStatement::setArray, getDelegatePreparedStatement(), inputStream, value);
}
@Override
- public void setAsciiStream(final int parameterIndex, final InputStream inputStream) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setAsciiStream(parameterIndex, inputStream);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setAsciiStream(final int parameterIndex, final InputStream value) throws SQLException {
+ accept(PreparedStatement::setAsciiStream, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setAsciiStream(final int parameterIndex, final InputStream x, final int length) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setAsciiStream(parameterIndex, x, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setAsciiStream(final int parameterIndex, final InputStream value, final int length) throws SQLException {
+ accept(PreparedStatement::setAsciiStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
- public void setAsciiStream(final int parameterIndex, final InputStream inputStream, final long length)
+ public void setAsciiStream(final int parameterIndex, final InputStream value, final long length)
throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setAsciiStream(parameterIndex, inputStream, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(PreparedStatement::setAsciiStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
- public void setBigDecimal(final int parameterIndex, final BigDecimal x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setBigDecimal(parameterIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setBigDecimal(final int parameterIndex, final BigDecimal value) throws SQLException {
+ accept(PreparedStatement::setBigDecimal, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setBinaryStream(final int parameterIndex, final InputStream inputStream) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setBinaryStream(parameterIndex, inputStream);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setBinaryStream(final int parameterIndex, final InputStream value) throws SQLException {
+ accept(PreparedStatement::setBinaryStream, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setBinaryStream(final int parameterIndex, final InputStream x, final int length) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setBinaryStream(parameterIndex, x, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setBinaryStream(final int parameterIndex, final InputStream value, final int length)
+ throws SQLException {
+ accept(PreparedStatement::setBinaryStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
- public void setBinaryStream(final int parameterIndex, final InputStream inputStream, final long length)
+ public void setBinaryStream(final int parameterIndex, final InputStream value, final long length)
throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setBinaryStream(parameterIndex, inputStream, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(PreparedStatement::setBinaryStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
- public void setBlob(final int i, final Blob x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setBlob(i, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setBlob(final int parameterIndex, final Blob value) throws SQLException {
+ accept(PreparedStatement::setBlob, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setBlob(final int parameterIndex, final InputStream inputStream) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setBlob(parameterIndex, inputStream);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setBlob(final int parameterIndex, final InputStream value) throws SQLException {
+ accept(PreparedStatement::setBlob, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setBlob(final int parameterIndex, final InputStream inputStream, final long length)
+ public void setBlob(final int parameterIndex, final InputStream value, final long length)
throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setBlob(parameterIndex, inputStream, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(PreparedStatement::setBlob, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
- public void setBoolean(final int parameterIndex, final boolean x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setBoolean(parameterIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setBoolean(final int parameterIndex, final boolean value) throws SQLException {
+ accept(PreparedStatement::setBoolean, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setByte(final int parameterIndex, final byte x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setByte(parameterIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setByte(final int parameterIndex, final byte value) throws SQLException {
+ accept(PreparedStatement::setByte, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setBytes(final int parameterIndex, final byte[] x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setBytes(parameterIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setBytes(final int parameterIndex, final byte[] value) throws SQLException {
+ accept(PreparedStatement::setBytes, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setCharacterStream(final int parameterIndex, final Reader reader) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setCharacterStream(parameterIndex, reader);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setCharacterStream(final int parameterIndex, final Reader value) throws SQLException {
+ accept(PreparedStatement::setCharacterStream, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setCharacterStream(final int parameterIndex, final Reader reader, final int length)
+ public void setCharacterStream(final int parameterIndex, final Reader value, final int length)
throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setCharacterStream(parameterIndex, reader, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(PreparedStatement::setCharacterStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
- public void setCharacterStream(final int parameterIndex, final Reader reader, final long length)
+ public void setCharacterStream(final int parameterIndex, final Reader value, final long length)
throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setCharacterStream(parameterIndex, reader, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(PreparedStatement::setCharacterStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
- public void setClob(final int i, final Clob x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setClob(i, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setClob(final int parameterIndex, final Clob value) throws SQLException {
+ accept(PreparedStatement::setClob, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setClob(final int parameterIndex, final Reader reader) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setClob(parameterIndex, reader);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setClob(final int parameterIndex, final Reader value) throws SQLException {
+ accept(PreparedStatement::setClob, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setClob(final int parameterIndex, final Reader reader, final long length) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setClob(parameterIndex, reader, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setClob(final int parameterIndex, final Reader value, final long length) throws SQLException {
+ accept(PreparedStatement::setClob, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
- public void setDate(final int parameterIndex, final Date x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setDate(parameterIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setDate(final int parameterIndex, final Date value) throws SQLException {
+ accept(PreparedStatement::setDate, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setDate(final int parameterIndex, final Date x, final Calendar cal) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setDate(parameterIndex, x, cal);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setDate(final int parameterIndex, final Date value, final Calendar calendar) throws SQLException {
+ accept(PreparedStatement::setDate, getDelegatePreparedStatement(), parameterIndex, value, calendar);
}
@Override
- public void setDouble(final int parameterIndex, final double x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setDouble(parameterIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setDouble(final int parameterIndex, final double value) throws SQLException {
+ accept(PreparedStatement::setDouble, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setFloat(final int parameterIndex, final float x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setFloat(parameterIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setFloat(final int parameterIndex, final float value) throws SQLException {
+ accept(PreparedStatement::setFloat, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setInt(final int parameterIndex, final int x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setInt(parameterIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setInt(final int parameterIndex, final int value) throws SQLException {
+ accept(PreparedStatement::setInt, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setLong(final int parameterIndex, final long x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setLong(parameterIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setLong(final int parameterIndex, final long value) throws SQLException {
+ accept(PreparedStatement::setLong, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setNCharacterStream(final int parameterIndex, final Reader reader) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setNCharacterStream(parameterIndex, reader);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setNCharacterStream(final int parameterIndex, final Reader value) throws SQLException {
+ accept(PreparedStatement::setNCharacterStream, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setNCharacterStream(final int parameterIndex, final Reader value, final long length)
throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setNCharacterStream(parameterIndex, value, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(PreparedStatement::setNCharacterStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
public void setNClob(final int parameterIndex, final NClob value) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setNClob(parameterIndex, value);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(PreparedStatement::setNClob, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setNClob(final int parameterIndex, final Reader reader) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setNClob(parameterIndex, reader);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setNClob(final int parameterIndex, final Reader value) throws SQLException {
+ accept(PreparedStatement::setNClob, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setNClob(final int parameterIndex, final Reader reader, final long length) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setNClob(parameterIndex, reader, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setNClob(final int parameterIndex, final Reader value, final long length) throws SQLException {
+ accept(PreparedStatement::setNClob, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
public void setNString(final int parameterIndex, final String value) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setNString(parameterIndex, value);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(PreparedStatement::setNString, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setNull(final int parameterIndex, final int sqlType) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setNull(parameterIndex, sqlType);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(PreparedStatement::setNull, getDelegatePreparedStatement(), parameterIndex, sqlType);
}
@Override
- public void setNull(final int paramIndex, final int sqlType, final String typeName) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setNull(paramIndex, sqlType, typeName);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setNull(final int parameterIndex, final int sqlType, final String typeName) throws SQLException {
+ accept(PreparedStatement::setNull, getDelegatePreparedStatement(), parameterIndex, sqlType, typeName);
}
@Override
- public void setObject(final int parameterIndex, final Object x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setObject(parameterIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setObject(final int parameterIndex, final Object value) throws SQLException {
+ accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setObject(final int parameterIndex, final Object x, final int targetSqlType) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setObject(parameterIndex, x, targetSqlType);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setObject(final int parameterIndex, final Object value, final int targetSqlType) throws SQLException {
+ accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value, targetSqlType);
}
@Override
- public void setObject(final int parameterIndex, final Object x, final int targetSqlType, final int scale)
+ public void setObject(final int parameterIndex, final Object value, final int targetSqlType, final int scale)
throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setObject(parameterIndex, x, targetSqlType, scale);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value, targetSqlType,
+ scale);
}
/**
* @since 2.5.0
*/
@Override
- public void setObject(final int parameterIndex, final Object x, final SQLType targetSqlType) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setObject(parameterIndex, x, targetSqlType);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setObject(final int parameterIndex, final Object value, final SQLType targetSqlType)
+ throws SQLException {
+ accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value, targetSqlType);
}
/**
* @since 2.5.0
*/
@Override
- public void setObject(final int parameterIndex, final Object x, final SQLType targetSqlType, final int scaleOrLength) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setObject(parameterIndex, x, targetSqlType, scaleOrLength);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setObject(final int parameterIndex, final Object value, final SQLType targetSqlType,
+ final int scaleOrLength) throws SQLException {
+ accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value, targetSqlType,
+ scaleOrLength);
}
@Override
- public void setRef(final int i, final Ref x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setRef(i, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setRef(final int parameterIndex, final Ref value) throws SQLException {
+ accept(PreparedStatement::setRef, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setRowId(final int parameterIndex, final RowId value) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setRowId(parameterIndex, value);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(PreparedStatement::setRowId, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setShort(final int parameterIndex, final short x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setShort(parameterIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setShort(final int parameterIndex, final short value) throws SQLException {
+ accept(PreparedStatement::setShort, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setSQLXML(final int parameterIndex, final SQLXML value) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setSQLXML(parameterIndex, value);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(PreparedStatement::setSQLXML, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setString(final int parameterIndex, final String x) throws SQLException {
+ public void setString(final int parameterIndex, final String value) throws SQLException {
checkOpen();
try {
- getDelegatePreparedStatement().setString(parameterIndex, x);
+ getDelegatePreparedStatement().setString(parameterIndex, value);
} catch (final SQLException e) {
handleException(e);
}
}
@Override
- public void setTime(final int parameterIndex, final Time x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setTime(parameterIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setTime(final int parameterIndex, final Time value) throws SQLException {
+ accept(PreparedStatement::setTime, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setTime(final int parameterIndex, final Time x, final Calendar cal) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setTime(parameterIndex, x, cal);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setTime(final int parameterIndex, final Time value, final Calendar calendar) throws SQLException {
+ accept(PreparedStatement::setTime, getDelegatePreparedStatement(), parameterIndex, value, calendar);
}
@Override
- public void setTimestamp(final int parameterIndex, final Timestamp x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setTimestamp(parameterIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setTimestamp(final int parameterIndex, final Timestamp value) throws SQLException {
+ accept(PreparedStatement::setTimestamp, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
- public void setTimestamp(final int parameterIndex, final Timestamp x, final Calendar cal) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setTimestamp(parameterIndex, x, cal);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setTimestamp(final int parameterIndex, final Timestamp value, final Calendar calendar)
+ throws SQLException {
+ accept(PreparedStatement::setTimestamp, getDelegatePreparedStatement(), parameterIndex, value, calendar);
}
/** @deprecated Use setAsciiStream(), setCharacterStream() or setNCharacterStream() */
@Deprecated
@Override
- public void setUnicodeStream(final int parameterIndex, final InputStream x, final int length) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setUnicodeStream(parameterIndex, x, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setUnicodeStream(final int parameterIndex, final InputStream value, final int length)
+ throws SQLException {
+ accept(PreparedStatement::setUnicodeStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
- public void setURL(final int parameterIndex, final java.net.URL x) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setURL(parameterIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setURL(final int parameterIndex, final java.net.URL value) throws SQLException {
+ accept(PreparedStatement::setURL, getDelegatePreparedStatement(), parameterIndex, value);
}
/**
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java b/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java
index 86e4d43ee3..875db1fc07 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java
@@ -60,8 +60,7 @@ public final class DelegatingResultSet extends AbandonedTrace implements ResultS
*
* @param connection
* The Connection which created the ResultSet.
- * @param resultSet
- * The ResultSet to wrap.
+ * @param resultSet The ResultSet to wrap.
* @return a new delegate.
*/
public static ResultSet wrapResultSet(final Connection connection, final ResultSet resultSet) {
@@ -74,10 +73,8 @@ public static ResultSet wrapResultSet(final Connection connection, final ResultS
/**
* Wraps the given result set in a delegate.
*
- * @param statement
- * The Statement which created the ResultSet.
- * @param resultSet
- * The ResultSet to wrap.
+ * @param statement The Statement which created the ResultSet.
+ * @param resultSet The ResultSet to wrap.
* @return a new delegate.
*/
public static ResultSet wrapResultSet(final Statement statement, final ResultSet resultSet) {
@@ -103,10 +100,8 @@ public static ResultSet wrapResultSet(final Statement statement, final ResultSet
* Private to ensure all construction is {@link #wrapResultSet(Connection, ResultSet)}
*
*
- * @param conn
- * Connection which created this ResultSet
- * @param res
- * ResultSet to wrap
+ * @param conn Connection which created this ResultSet
+ * @param res ResultSet to wrap
*/
private DelegatingResultSet(final Connection conn, final ResultSet res) {
super((AbandonedTrace) conn);
@@ -121,10 +116,8 @@ private DelegatingResultSet(final Connection conn, final ResultSet res) {
* Private to ensure all construction is {@link #wrapResultSet(Statement, ResultSet)}
*
*
- * @param statement
- * The Statement which created the ResultSet.
- * @param resultSet
- * The ResultSet to wrap.
+ * @param statement The Statement which created the ResultSet.
+ * @param resultSet The ResultSet to wrap.
*/
private DelegatingResultSet(final Statement statement, final ResultSet resultSet) {
super((AbandonedTrace) statement);
@@ -134,48 +127,27 @@ private DelegatingResultSet(final Statement statement, final ResultSet resultSet
@Override
public boolean absolute(final int row) throws SQLException {
- try {
- return resultSet.absolute(row);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return apply(resultSet::absolute, row);
}
@Override
public void afterLast() throws SQLException {
- try {
- resultSet.afterLast();
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::afterLast);
}
@Override
public void beforeFirst() throws SQLException {
- try {
- resultSet.beforeFirst();
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::beforeFirst);
}
@Override
public void cancelRowUpdates() throws SQLException {
- try {
- resultSet.cancelRowUpdates();
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::cancelRowUpdates);
}
@Override
public void clearWarnings() throws SQLException {
- try {
- resultSet.clearWarnings();
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::clearWarnings);
}
/**
@@ -201,315 +173,161 @@ public void close() throws SQLException {
@Override
public void deleteRow() throws SQLException {
- try {
- resultSet.deleteRow();
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::deleteRow);
}
@Override
- public int findColumn(final String columnName) throws SQLException {
- try {
- return resultSet.findColumn(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ public int findColumn(final String columnLabel) throws SQLException {
+ return apply(resultSet::findColumn, columnLabel);
}
@Override
public boolean first() throws SQLException {
- try {
- return resultSet.first();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return getAsBoolean(resultSet::first);
}
@Override
- public Array getArray(final int i) throws SQLException {
- try {
- return resultSet.getArray(i);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public Array getArray(final int columnIndex) throws SQLException {
+ return apply(resultSet::getArray, columnIndex);
}
@Override
- public Array getArray(final String colName) throws SQLException {
- try {
- return resultSet.getArray(colName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public Array getArray(final String columnLabel) throws SQLException {
+ return apply(resultSet::getArray, columnLabel);
}
@Override
public InputStream getAsciiStream(final int columnIndex) throws SQLException {
- try {
- return resultSet.getAsciiStream(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getAsciiStream, columnIndex);
}
@Override
- public InputStream getAsciiStream(final String columnName) throws SQLException {
- try {
- return resultSet.getAsciiStream(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public InputStream getAsciiStream(final String columnLabel) throws SQLException {
+ return apply(resultSet::getAsciiStream, columnLabel);
}
@Override
public BigDecimal getBigDecimal(final int columnIndex) throws SQLException {
- try {
- return resultSet.getBigDecimal(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getBigDecimal, columnIndex);
}
/** @deprecated Use {@link #getBigDecimal(int)} */
@Deprecated
@Override
public BigDecimal getBigDecimal(final int columnIndex, final int scale) throws SQLException {
- try {
- return resultSet.getBigDecimal(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getBigDecimal, columnIndex, scale);
}
@Override
- public BigDecimal getBigDecimal(final String columnName) throws SQLException {
- try {
- return resultSet.getBigDecimal(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public BigDecimal getBigDecimal(final String columnLabel) throws SQLException {
+ return apply(resultSet::getBigDecimal, columnLabel);
}
/** @deprecated Use {@link #getBigDecimal(String)} */
@Deprecated
@Override
- public BigDecimal getBigDecimal(final String columnName, final int scale) throws SQLException {
- try {
- return resultSet.getBigDecimal(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public BigDecimal getBigDecimal(final String columnLabel, final int scale) throws SQLException {
+ return apply(resultSet::getBigDecimal, columnLabel, scale);
}
@Override
public InputStream getBinaryStream(final int columnIndex) throws SQLException {
- try {
- return resultSet.getBinaryStream(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getBinaryStream, columnIndex);
}
@Override
- public InputStream getBinaryStream(final String columnName) throws SQLException {
- try {
- return resultSet.getBinaryStream(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public InputStream getBinaryStream(final String columnLabel) throws SQLException {
+ return apply(resultSet::getBinaryStream, columnLabel);
}
@Override
- public Blob getBlob(final int i) throws SQLException {
- try {
- return resultSet.getBlob(i);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public Blob getBlob(final int columnIndex) throws SQLException {
+ return apply(resultSet::getBlob, columnIndex);
}
@Override
- public Blob getBlob(final String colName) throws SQLException {
- try {
- return resultSet.getBlob(colName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public Blob getBlob(final String columnLabel) throws SQLException {
+ return apply(resultSet::getBlob, columnLabel);
}
@Override
public boolean getBoolean(final int columnIndex) throws SQLException {
- try {
- return resultSet.getBoolean(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyTo(resultSet::getBoolean, columnIndex, false);
}
@Override
- public boolean getBoolean(final String columnName) throws SQLException {
- try {
- return resultSet.getBoolean(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ public boolean getBoolean(final String columnLabel) throws SQLException {
+ return applyTo(resultSet::getBoolean, columnLabel, false);
}
@Override
public byte getByte(final int columnIndex) throws SQLException {
- try {
- return resultSet.getByte(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(resultSet::getByte, columnIndex, (byte) 0);
}
@Override
- public byte getByte(final String columnName) throws SQLException {
- try {
- return resultSet.getByte(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ public byte getByte(final String columnLabel) throws SQLException {
+ return applyTo(resultSet::getByte, columnLabel, (byte) 0);
}
@Override
public byte[] getBytes(final int columnIndex) throws SQLException {
- try {
- return resultSet.getBytes(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getBytes, columnIndex);
}
@Override
- public byte[] getBytes(final String columnName) throws SQLException {
- try {
- return resultSet.getBytes(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public byte[] getBytes(final String columnLabel) throws SQLException {
+ return apply(resultSet::getBytes, columnLabel);
}
@Override
public Reader getCharacterStream(final int columnIndex) throws SQLException {
- try {
- return resultSet.getCharacterStream(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getCharacterStream, columnIndex);
}
@Override
- public Reader getCharacterStream(final String columnName) throws SQLException {
- try {
- return resultSet.getCharacterStream(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public Reader getCharacterStream(final String columnLabel) throws SQLException {
+ return apply(resultSet::getCharacterStream, columnLabel);
}
@Override
- public Clob getClob(final int i) throws SQLException {
- try {
- return resultSet.getClob(i);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public Clob getClob(final int columnIndex) throws SQLException {
+ return apply(resultSet::getClob, columnIndex);
}
@Override
- public Clob getClob(final String colName) throws SQLException {
- try {
- return resultSet.getClob(colName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public Clob getClob(final String columnLabel) throws SQLException {
+ return apply(resultSet::getClob, columnLabel);
}
@Override
public int getConcurrency() throws SQLException {
- try {
- return resultSet.getConcurrency();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo0(resultSet::getConcurrency);
}
@Override
public String getCursorName() throws SQLException {
- try {
- return resultSet.getCursorName();
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getCursorName);
}
@Override
public Date getDate(final int columnIndex) throws SQLException {
- try {
- return resultSet.getDate(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getDate, columnIndex);
}
@Override
public Date getDate(final int columnIndex, final Calendar cal) throws SQLException {
- try {
- return resultSet.getDate(columnIndex, cal);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getDate, columnIndex, cal);
}
@Override
- public Date getDate(final String columnName) throws SQLException {
- try {
- return resultSet.getDate(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public Date getDate(final String columnLabel) throws SQLException {
+ return apply(resultSet::getDate, columnLabel);
}
@Override
- public Date getDate(final String columnName, final Calendar cal) throws SQLException {
- try {
- return resultSet.getDate(columnName, cal);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public Date getDate(final String columnLabel, final Calendar cal) throws SQLException {
+ return apply(resultSet::getDate, columnLabel, cal);
}
/**
@@ -523,72 +341,38 @@ public ResultSet getDelegate() {
@Override
public double getDouble(final int columnIndex) throws SQLException {
- try {
- return resultSet.getDouble(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(resultSet::getDouble, columnIndex, 0d);
}
@Override
- public double getDouble(final String columnName) throws SQLException {
- try {
- return resultSet.getDouble(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ public double getDouble(final String columnLabel) throws SQLException {
+ return applyTo(resultSet::getDouble, columnLabel, 0d);
}
@Override
public int getFetchDirection() throws SQLException {
- try {
- return resultSet.getFetchDirection();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return getAsInt(resultSet::getFetchDirection);
+
}
@Override
public int getFetchSize() throws SQLException {
- try {
- return resultSet.getFetchSize();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return getAsInt(resultSet::getFetchSize);
}
@Override
public float getFloat(final int columnIndex) throws SQLException {
- try {
- return resultSet.getFloat(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(resultSet::getFloat, columnIndex, 0f);
}
@Override
- public float getFloat(final String columnName) throws SQLException {
- try {
- return resultSet.getFloat(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ public float getFloat(final String columnLabel) throws SQLException {
+ return applyTo(resultSet::getFloat, columnLabel, 0f);
}
@Override
public int getHoldability() throws SQLException {
- try {
- return resultSet.getHoldability();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return getAsInt(resultSet::getHoldability);
}
/**
@@ -619,262 +403,132 @@ public ResultSet getInnermostDelegate() {
@Override
public int getInt(final int columnIndex) throws SQLException {
- try {
- return resultSet.getInt(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyIntTo(resultSet::getInt, columnIndex, 0);
}
@Override
- public int getInt(final String columnName) throws SQLException {
- try {
- return resultSet.getInt(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ public int getInt(final String columnLabel) throws SQLException {
+ return applyTo(resultSet::getInt, columnLabel, 0);
}
@Override
public long getLong(final int columnIndex) throws SQLException {
- try {
- return resultSet.getLong(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyIntTo(resultSet::getLong, columnIndex, 0L);
}
@Override
- public long getLong(final String columnName) throws SQLException {
- try {
- return resultSet.getLong(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ public long getLong(final String columnLabel) throws SQLException {
+ return applyTo(resultSet::getLong, columnLabel, 0L);
}
@Override
public ResultSetMetaData getMetaData() throws SQLException {
- try {
- return resultSet.getMetaData();
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getMetaData);
}
@Override
public Reader getNCharacterStream(final int columnIndex) throws SQLException {
- try {
- return resultSet.getNCharacterStream(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getNCharacterStream, columnIndex);
}
@Override
public Reader getNCharacterStream(final String columnLabel) throws SQLException {
- try {
- return resultSet.getNCharacterStream(columnLabel);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getNCharacterStream, columnLabel);
}
@Override
public NClob getNClob(final int columnIndex) throws SQLException {
- try {
- return resultSet.getNClob(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getNClob, columnIndex);
}
@Override
public NClob getNClob(final String columnLabel) throws SQLException {
- try {
- return resultSet.getNClob(columnLabel);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getNClob, columnLabel);
}
@Override
public String getNString(final int columnIndex) throws SQLException {
- try {
- return resultSet.getNString(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getNString, columnIndex);
}
@Override
public String getNString(final String columnLabel) throws SQLException {
- try {
- return resultSet.getNString(columnLabel);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getNString, columnLabel);
}
@Override
public Object getObject(final int columnIndex) throws SQLException {
- try {
- return resultSet.getObject(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getObject, columnIndex);
}
@Override
public T getObject(final int columnIndex, final Class type) throws SQLException {
- try {
- return Jdbc41Bridge.getObject(resultSet, columnIndex, type);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(Jdbc41Bridge::getObject, resultSet, columnIndex, type);
}
@Override
public Object getObject(final int i, final Map> map) throws SQLException {
- try {
- return resultSet.getObject(i, map);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getObject, i, map);
}
@Override
- public Object getObject(final String columnName) throws SQLException {
- try {
- return resultSet.getObject(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public Object getObject(final String columnLabel) throws SQLException {
+ return apply(resultSet::getObject, columnLabel);
}
@Override
public T getObject(final String columnLabel, final Class type) throws SQLException {
- try {
- return Jdbc41Bridge.getObject(resultSet, columnLabel, type);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(Jdbc41Bridge::getObject, resultSet, columnLabel, type);
}
@Override
- public Object getObject(final String colName, final Map> map) throws SQLException {
- try {
- return resultSet.getObject(colName, map);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public Object getObject(final String columnLabel, final Map> map) throws SQLException {
+ return apply(resultSet::getObject, columnLabel, map);
}
@Override
public Ref getRef(final int i) throws SQLException {
- try {
- return resultSet.getRef(i);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getRef, i);
}
@Override
- public Ref getRef(final String colName) throws SQLException {
- try {
- return resultSet.getRef(colName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public Ref getRef(final String columnLabel) throws SQLException {
+ return apply(resultSet::getRef, columnLabel);
}
@Override
public int getRow() throws SQLException {
- try {
- return resultSet.getRow();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return getAsInt(resultSet::getRow);
}
@Override
public RowId getRowId(final int columnIndex) throws SQLException {
- try {
- return resultSet.getRowId(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getRowId, columnIndex);
}
@Override
public RowId getRowId(final String columnLabel) throws SQLException {
- try {
- return resultSet.getRowId(columnLabel);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getRowId, columnLabel);
}
@Override
public short getShort(final int columnIndex) throws SQLException {
- try {
- return resultSet.getShort(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(resultSet::getShort, columnIndex, (short) 0);
}
@Override
- public short getShort(final String columnName) throws SQLException {
- try {
- return resultSet.getShort(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ public short getShort(final String columnLabel) throws SQLException {
+ return applyTo(resultSet::getShort, columnLabel, (short) 0);
}
@Override
public SQLXML getSQLXML(final int columnIndex) throws SQLException {
- try {
- return resultSet.getSQLXML(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getSQLXML, columnIndex);
}
- @Override
- public SQLXML getSQLXML(final String columnLabel) throws SQLException {
- try {
- return resultSet.getSQLXML(columnLabel);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ @Override
+ public SQLXML getSQLXML(final String columnLabel) throws SQLException {
+ return apply(resultSet::getSQLXML, columnLabel);
}
@Override
@@ -884,168 +538,89 @@ public Statement getStatement() throws SQLException {
@Override
public String getString(final int columnIndex) throws SQLException {
- try {
- return resultSet.getString(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getString, columnIndex);
}
@Override
- public String getString(final String columnName) throws SQLException {
- try {
- return resultSet.getString(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public String getString(final String columnLabel) throws SQLException {
+ return apply(resultSet::getString, columnLabel);
}
@Override
public Time getTime(final int columnIndex) throws SQLException {
- try {
- return resultSet.getTime(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getTime, columnIndex);
}
@Override
public Time getTime(final int columnIndex, final Calendar cal) throws SQLException {
- try {
- return resultSet.getTime(columnIndex, cal);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getTime, columnIndex, cal);
}
@Override
- public Time getTime(final String columnName) throws SQLException {
- try {
- return resultSet.getTime(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public Time getTime(final String columnLabel) throws SQLException {
+ return apply(resultSet::getTime, columnLabel);
}
@Override
- public Time getTime(final String columnName, final Calendar cal) throws SQLException {
- try {
- return resultSet.getTime(columnName, cal);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public Time getTime(final String columnLabel, final Calendar cal) throws SQLException {
+ return apply(resultSet::getTime, columnLabel, cal);
}
@Override
public Timestamp getTimestamp(final int columnIndex) throws SQLException {
- try {
- return resultSet.getTimestamp(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getTimestamp, columnIndex);
}
@Override
public Timestamp getTimestamp(final int columnIndex, final Calendar cal) throws SQLException {
- try {
- return resultSet.getTimestamp(columnIndex, cal);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getTimestamp, columnIndex, cal);
}
@Override
- public Timestamp getTimestamp(final String columnName) throws SQLException {
- try {
- return resultSet.getTimestamp(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public Timestamp getTimestamp(final String columnLabel) throws SQLException {
+ return apply(resultSet::getTimestamp, columnLabel);
}
@Override
- public Timestamp getTimestamp(final String columnName, final Calendar cal) throws SQLException {
- try {
- return resultSet.getTimestamp(columnName, cal);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public Timestamp getTimestamp(final String columnLabel, final Calendar cal) throws SQLException {
+ return apply(resultSet::getTimestamp, columnLabel, cal);
}
@Override
public int getType() throws SQLException {
- try {
- return resultSet.getType();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return getAsInt(resultSet::getType);
}
/** @deprecated Use {@link #getCharacterStream(int)} */
@Deprecated
@Override
public InputStream getUnicodeStream(final int columnIndex) throws SQLException {
- try {
- return resultSet.getUnicodeStream(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getUnicodeStream, columnIndex);
}
/** @deprecated Use {@link #getCharacterStream(String)} */
@Deprecated
@Override
- public InputStream getUnicodeStream(final String columnName) throws SQLException {
- try {
- return resultSet.getUnicodeStream(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public InputStream getUnicodeStream(final String columnLabel) throws SQLException {
+ return apply(resultSet::getUnicodeStream, columnLabel);
}
@Override
public java.net.URL getURL(final int columnIndex) throws SQLException {
- try {
- return resultSet.getURL(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getURL, columnIndex);
}
@Override
- public java.net.URL getURL(final String columnName) throws SQLException {
- try {
- return resultSet.getURL(columnName);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ public java.net.URL getURL(final String columnLabel) throws SQLException {
+ return apply(resultSet::getURL, columnLabel);
}
@Override
public SQLWarning getWarnings() throws SQLException {
- try {
- return resultSet.getWarnings();
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(resultSet::getWarnings);
}
+ @Override
protected void handleException(final SQLException e) throws SQLException {
if (statement != null && statement instanceof DelegatingStatement) {
((DelegatingStatement) statement).handleException(e);
@@ -1058,61 +633,32 @@ protected void handleException(final SQLException e) throws SQLException {
@Override
public void insertRow() throws SQLException {
- try {
- resultSet.insertRow();
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::insertRow);
}
@Override
public boolean isAfterLast() throws SQLException {
- try {
- return resultSet.isAfterLast();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return getAsBoolean(resultSet::isAfterLast);
}
@Override
public boolean isBeforeFirst() throws SQLException {
- try {
- return resultSet.isBeforeFirst();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return getAsBoolean(resultSet::isBeforeFirst);
}
@Override
public boolean isClosed() throws SQLException {
- try {
- return resultSet.isClosed();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return getAsBoolean(resultSet::isClosed);
}
@Override
public boolean isFirst() throws SQLException {
- try {
- return resultSet.isFirst();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return getAsBoolean(resultSet::isFirst);
}
@Override
public boolean isLast() throws SQLException {
- try {
- return resultSet.isLast();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return getAsBoolean(resultSet::isLast);
}
@Override
@@ -1128,122 +674,68 @@ public boolean isWrapperFor(final Class> iface) throws SQLException {
@Override
public boolean last() throws SQLException {
- try {
- return resultSet.last();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return getAsBoolean(resultSet::last);
}
@Override
public void moveToCurrentRow() throws SQLException {
- try {
- resultSet.moveToCurrentRow();
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::moveToCurrentRow);
}
@Override
public void moveToInsertRow() throws SQLException {
- try {
- resultSet.moveToInsertRow();
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::moveToInsertRow);
}
@Override
public boolean next() throws SQLException {
- try {
- return resultSet.next();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return getAsBoolean(resultSet::next);
}
@Override
public boolean previous() throws SQLException {
- try {
- return resultSet.previous();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return getAsBoolean(resultSet::previous);
}
@Override
public void refreshRow() throws SQLException {
- try {
- resultSet.refreshRow();
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::refreshRow);
}
@Override
public boolean relative(final int rows) throws SQLException {
- try {
- return resultSet.relative(rows);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyIntTo(resultSet::relative, rows, false);
}
@Override
public boolean rowDeleted() throws SQLException {
- try {
- return resultSet.rowDeleted();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return getAsBoolean(resultSet::rowDeleted);
}
@Override
public boolean rowInserted() throws SQLException {
- try {
- return resultSet.rowInserted();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return getAsBoolean(resultSet::rowInserted);
}
@Override
public boolean rowUpdated() throws SQLException {
- try {
- return resultSet.rowUpdated();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return getAsBoolean(resultSet::rowUpdated);
}
@Override
public void setFetchDirection(final int direction) throws SQLException {
- try {
- resultSet.setFetchDirection(direction);
- } catch (final SQLException e) {
- handleException(e);
- }
+ acceptInt(resultSet::setFetchDirection, direction);
}
@Override
public void setFetchSize(final int rows) throws SQLException {
- try {
- resultSet.setFetchSize(rows);
- } catch (final SQLException e) {
- handleException(e);
- }
+ acceptInt(resultSet::setFetchSize, rows);
}
@Override
public synchronized String toString() {
- return super.toString() + "[resultSet=" + resultSet + ", statement=" + statement + ", connection=" + connection + "]";
+ return super.toString() + "[resultSet=" + resultSet + ", statement=" + statement + ", connection=" + connection
+ + "]";
}
@Override
@@ -1259,607 +751,343 @@ public T unwrap(final Class iface) throws SQLException {
@Override
public void updateArray(final int columnIndex, final Array x) throws SQLException {
- try {
- resultSet.updateArray(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateArray, columnIndex, x);
}
@Override
public void updateArray(final String columnName, final Array x) throws SQLException {
- try {
- resultSet.updateArray(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateArray, columnName, x);
}
@Override
public void updateAsciiStream(final int columnIndex, final InputStream inputStream) throws SQLException {
- try {
- resultSet.updateAsciiStream(columnIndex, inputStream);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateAsciiStream, columnIndex, inputStream);
}
@Override
public void updateAsciiStream(final int columnIndex, final InputStream x, final int length) throws SQLException {
- try {
- resultSet.updateAsciiStream(columnIndex, x, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateAsciiStream, columnIndex, x, length);
}
@Override
public void updateAsciiStream(final int columnIndex, final InputStream inputStream, final long length)
throws SQLException {
- try {
- resultSet.updateAsciiStream(columnIndex, inputStream, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateAsciiStream, columnIndex, inputStream, length);
}
@Override
public void updateAsciiStream(final String columnLabel, final InputStream inputStream) throws SQLException {
- try {
- resultSet.updateAsciiStream(columnLabel, inputStream);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateAsciiStream, columnLabel, inputStream);
}
@Override
public void updateAsciiStream(final String columnName, final InputStream x, final int length) throws SQLException {
- try {
- resultSet.updateAsciiStream(columnName, x, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateAsciiStream, columnName, x, length);
}
@Override
public void updateAsciiStream(final String columnLabel, final InputStream inputStream, final long length)
throws SQLException {
- try {
- resultSet.updateAsciiStream(columnLabel, inputStream, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateAsciiStream, columnLabel, inputStream, length);
}
@Override
public void updateBigDecimal(final int columnIndex, final BigDecimal x) throws SQLException {
- try {
- resultSet.updateBigDecimal(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBigDecimal, columnIndex, x);
}
@Override
public void updateBigDecimal(final String columnName, final BigDecimal x) throws SQLException {
- try {
- resultSet.updateBigDecimal(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBigDecimal, columnName, x);
}
@Override
public void updateBinaryStream(final int columnIndex, final InputStream inputStream) throws SQLException {
- try {
- resultSet.updateBinaryStream(columnIndex, inputStream);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBinaryStream, columnIndex, inputStream);
}
@Override
public void updateBinaryStream(final int columnIndex, final InputStream x, final int length) throws SQLException {
- try {
- resultSet.updateBinaryStream(columnIndex, x, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBinaryStream, columnIndex, x, length);
}
@Override
public void updateBinaryStream(final int columnIndex, final InputStream inputStream, final long length)
throws SQLException {
- try {
- resultSet.updateBinaryStream(columnIndex, inputStream, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBinaryStream, columnIndex, inputStream, length);
}
@Override
public void updateBinaryStream(final String columnLabel, final InputStream inputStream) throws SQLException {
- try {
- resultSet.updateBinaryStream(columnLabel, inputStream);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBinaryStream, columnLabel, inputStream);
}
@Override
public void updateBinaryStream(final String columnName, final InputStream x, final int length) throws SQLException {
- try {
- resultSet.updateBinaryStream(columnName, x, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBinaryStream, columnName, x, length);
}
@Override
public void updateBinaryStream(final String columnLabel, final InputStream inputStream, final long length)
throws SQLException {
- try {
- resultSet.updateBinaryStream(columnLabel, inputStream, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBinaryStream, columnLabel, inputStream, length);
}
@Override
public void updateBlob(final int columnIndex, final Blob x) throws SQLException {
- try {
- resultSet.updateBlob(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBlob, columnIndex, x);
}
@Override
public void updateBlob(final int columnIndex, final InputStream inputStream) throws SQLException {
- try {
- resultSet.updateBlob(columnIndex, inputStream);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBlob, columnIndex, inputStream);
}
@Override
public void updateBlob(final int columnIndex, final InputStream inputStream, final long length)
throws SQLException {
- try {
- resultSet.updateBlob(columnIndex, inputStream, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBlob, columnIndex, inputStream, length);
}
@Override
public void updateBlob(final String columnName, final Blob x) throws SQLException {
- try {
- resultSet.updateBlob(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBlob, columnName, x);
}
@Override
public void updateBlob(final String columnLabel, final InputStream inputStream) throws SQLException {
- try {
- resultSet.updateBlob(columnLabel, inputStream);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBlob, columnLabel, inputStream);
}
@Override
public void updateBlob(final String columnLabel, final InputStream inputStream, final long length)
throws SQLException {
- try {
- resultSet.updateBlob(columnLabel, inputStream, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBlob, columnLabel, inputStream, length);
}
@Override
public void updateBoolean(final int columnIndex, final boolean x) throws SQLException {
- try {
- resultSet.updateBoolean(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBoolean, columnIndex, x);
}
@Override
public void updateBoolean(final String columnName, final boolean x) throws SQLException {
- try {
- resultSet.updateBoolean(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBoolean, columnName, x);
}
- @Override
- public void updateByte(final int columnIndex, final byte x) throws SQLException {
- try {
- resultSet.updateByte(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ @Override
+ public void updateByte(final int columnIndex, final byte x) throws SQLException {
+ accept(resultSet::updateByte, columnIndex, x);
}
@Override
public void updateByte(final String columnName, final byte x) throws SQLException {
- try {
- resultSet.updateByte(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateByte, columnName, x);
}
@Override
public void updateBytes(final int columnIndex, final byte[] x) throws SQLException {
- try {
- resultSet.updateBytes(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBytes, columnIndex, x);
}
@Override
public void updateBytes(final String columnName, final byte[] x) throws SQLException {
- try {
- resultSet.updateBytes(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateBytes, columnName, x);
}
@Override
public void updateCharacterStream(final int columnIndex, final Reader reader) throws SQLException {
- try {
- resultSet.updateCharacterStream(columnIndex, reader);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateCharacterStream, columnIndex, reader);
}
@Override
public void updateCharacterStream(final int columnIndex, final Reader x, final int length) throws SQLException {
- try {
- resultSet.updateCharacterStream(columnIndex, x, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateCharacterStream, columnIndex, x, length);
}
@Override
public void updateCharacterStream(final int columnIndex, final Reader reader, final long length)
throws SQLException {
- try {
- resultSet.updateCharacterStream(columnIndex, reader, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateCharacterStream, columnIndex, reader, length);
}
@Override
public void updateCharacterStream(final String columnLabel, final Reader reader) throws SQLException {
- try {
- resultSet.updateCharacterStream(columnLabel, reader);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateCharacterStream, columnLabel, reader);
}
@Override
public void updateCharacterStream(final String columnName, final Reader reader, final int length)
throws SQLException {
- try {
- resultSet.updateCharacterStream(columnName, reader, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateCharacterStream, columnName, reader, length);
}
@Override
public void updateCharacterStream(final String columnLabel, final Reader reader, final long length)
throws SQLException {
- try {
- resultSet.updateCharacterStream(columnLabel, reader, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateCharacterStream, columnLabel, reader, length);
}
@Override
public void updateClob(final int columnIndex, final Clob x) throws SQLException {
- try {
- resultSet.updateClob(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateClob, columnIndex, x);
}
@Override
public void updateClob(final int columnIndex, final Reader reader) throws SQLException {
- try {
- resultSet.updateClob(columnIndex, reader);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateClob, columnIndex, reader);
}
@Override
public void updateClob(final int columnIndex, final Reader reader, final long length) throws SQLException {
- try {
- resultSet.updateClob(columnIndex, reader, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateClob, columnIndex, reader, length);
}
@Override
public void updateClob(final String columnName, final Clob x) throws SQLException {
- try {
- resultSet.updateClob(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateClob, columnName, x);
}
@Override
public void updateClob(final String columnLabel, final Reader reader) throws SQLException {
- try {
- resultSet.updateClob(columnLabel, reader);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateClob, columnLabel, reader);
}
@Override
public void updateClob(final String columnLabel, final Reader reader, final long length) throws SQLException {
- try {
- resultSet.updateClob(columnLabel, reader, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateClob, columnLabel, reader, length);
}
@Override
public void updateDate(final int columnIndex, final Date x) throws SQLException {
- try {
- resultSet.updateDate(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateDate, columnIndex, x);
}
@Override
public void updateDate(final String columnName, final Date x) throws SQLException {
- try {
- resultSet.updateDate(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateDate, columnName, x);
}
@Override
public void updateDouble(final int columnIndex, final double x) throws SQLException {
- try {
- resultSet.updateDouble(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateDouble, columnIndex, x);
}
@Override
public void updateDouble(final String columnName, final double x) throws SQLException {
- try {
- resultSet.updateDouble(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateDouble, columnName, x);
}
@Override
public void updateFloat(final int columnIndex, final float x) throws SQLException {
- try {
- resultSet.updateFloat(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateFloat, columnIndex, x);
}
@Override
public void updateFloat(final String columnName, final float x) throws SQLException {
- try {
- resultSet.updateFloat(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateFloat, columnName, x);
}
@Override
public void updateInt(final int columnIndex, final int x) throws SQLException {
- try {
- resultSet.updateInt(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateInt, columnIndex, x);
}
@Override
public void updateInt(final String columnName, final int x) throws SQLException {
- try {
- resultSet.updateInt(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateInt, columnName, x);
}
@Override
public void updateLong(final int columnIndex, final long x) throws SQLException {
- try {
- resultSet.updateLong(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateLong, columnIndex, x);
}
@Override
public void updateLong(final String columnName, final long x) throws SQLException {
- try {
- resultSet.updateLong(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateLong, columnName, x);
}
@Override
public void updateNCharacterStream(final int columnIndex, final Reader reader) throws SQLException {
- try {
- resultSet.updateNCharacterStream(columnIndex, reader);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateNCharacterStream, columnIndex, reader);
}
@Override
public void updateNCharacterStream(final int columnIndex, final Reader reader, final long length)
throws SQLException {
- try {
- resultSet.updateNCharacterStream(columnIndex, reader, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateNCharacterStream, columnIndex, reader, length);
}
@Override
public void updateNCharacterStream(final String columnLabel, final Reader reader) throws SQLException {
- try {
- resultSet.updateNCharacterStream(columnLabel, reader);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateNCharacterStream, columnLabel, reader);
}
@Override
public void updateNCharacterStream(final String columnLabel, final Reader reader, final long length)
throws SQLException {
- try {
- resultSet.updateNCharacterStream(columnLabel, reader, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateNCharacterStream, columnLabel, reader, length);
}
@Override
public void updateNClob(final int columnIndex, final NClob value) throws SQLException {
- try {
- resultSet.updateNClob(columnIndex, value);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateNClob, columnIndex, value);
}
@Override
public void updateNClob(final int columnIndex, final Reader reader) throws SQLException {
- try {
- resultSet.updateNClob(columnIndex, reader);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateNClob, columnIndex, reader);
}
@Override
public void updateNClob(final int columnIndex, final Reader reader, final long length) throws SQLException {
- try {
- resultSet.updateNClob(columnIndex, reader, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateNClob, columnIndex, reader, length);
}
@Override
public void updateNClob(final String columnLabel, final NClob value) throws SQLException {
- try {
- resultSet.updateNClob(columnLabel, value);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateNClob, columnLabel, value);
}
@Override
public void updateNClob(final String columnLabel, final Reader reader) throws SQLException {
- try {
- resultSet.updateNClob(columnLabel, reader);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateNClob, columnLabel, reader);
}
@Override
public void updateNClob(final String columnLabel, final Reader reader, final long length) throws SQLException {
- try {
- resultSet.updateNClob(columnLabel, reader, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateNClob, columnLabel, reader, length);
}
@Override
public void updateNString(final int columnIndex, final String value) throws SQLException {
- try {
- resultSet.updateNString(columnIndex, value);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateNString, columnIndex, value);
}
@Override
public void updateNString(final String columnLabel, final String value) throws SQLException {
- try {
- resultSet.updateNString(columnLabel, value);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateNString, columnLabel, value);
}
@Override
public void updateNull(final int columnIndex) throws SQLException {
- try {
- resultSet.updateNull(columnIndex);
- } catch (final SQLException e) {
- handleException(e);
- }
+ acceptInt(resultSet::updateNull, columnIndex);
}
@Override
public void updateNull(final String columnName) throws SQLException {
- try {
- resultSet.updateNull(columnName);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateNull, columnName);
}
@Override
public void updateObject(final int columnIndex, final Object x) throws SQLException {
- try {
- resultSet.updateObject(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateObject, columnIndex, x);
}
@Override
public void updateObject(final int columnIndex, final Object x, final int scale) throws SQLException {
- try {
- resultSet.updateObject(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateObject, columnIndex, x);
}
/**
@@ -1867,210 +1095,123 @@ public void updateObject(final int columnIndex, final Object x, final int scale)
*/
@Override
public void updateObject(final int columnIndex, final Object x, final SQLType targetSqlType) throws SQLException {
- try {
- resultSet.updateObject(columnIndex, x, targetSqlType);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateObject, columnIndex, x, targetSqlType);
}
/**
* @since 2.5.0
*/
@Override
- public void updateObject(final int columnIndex, final Object x, final SQLType targetSqlType, final int scaleOrLength) throws SQLException {
- try {
- resultSet.updateObject(columnIndex, x, targetSqlType, scaleOrLength);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void updateObject(final int columnIndex, final Object x, final SQLType targetSqlType,
+ final int scaleOrLength) throws SQLException {
+ accept(resultSet::updateObject, columnIndex, x, targetSqlType, scaleOrLength);
}
@Override
public void updateObject(final String columnName, final Object x) throws SQLException {
- try {
- resultSet.updateObject(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateObject, columnName, x);
}
@Override
public void updateObject(final String columnName, final Object x, final int scale) throws SQLException {
- try {
- resultSet.updateObject(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateObject, columnName, x);
}
/**
* @since 2.5.0
*/
@Override
- public void updateObject(final String columnLabel, final Object x, final SQLType targetSqlType) throws SQLException {
- try {
- resultSet.updateObject(columnLabel, x, targetSqlType);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void updateObject(final String columnLabel, final Object x, final SQLType targetSqlType)
+ throws SQLException {
+ accept(resultSet::updateObject, columnLabel, x, targetSqlType);
}
/**
* @since 2.5.0
*/
@Override
- public void updateObject(final String columnLabel, final Object x, final SQLType targetSqlType, final int scaleOrLength)
- throws SQLException {
- try {
- resultSet.updateObject(columnLabel, x, targetSqlType, scaleOrLength);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void updateObject(final String columnLabel, final Object x, final SQLType targetSqlType,
+ final int scaleOrLength) throws SQLException {
+ accept(resultSet::updateObject, columnLabel, x, targetSqlType, scaleOrLength);
}
@Override
public void updateRef(final int columnIndex, final Ref x) throws SQLException {
- try {
- resultSet.updateRef(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateRef, columnIndex, x);
}
@Override
public void updateRef(final String columnName, final Ref x) throws SQLException {
- try {
- resultSet.updateRef(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateRef, columnName, x);
}
@Override
public void updateRow() throws SQLException {
- try {
- resultSet.updateRow();
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateRow);
}
@Override
public void updateRowId(final int columnIndex, final RowId value) throws SQLException {
- try {
- resultSet.updateRowId(columnIndex, value);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateRowId, columnIndex, value);
}
@Override
public void updateRowId(final String columnLabel, final RowId value) throws SQLException {
- try {
- resultSet.updateRowId(columnLabel, value);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateRowId, columnLabel, value);
}
@Override
public void updateShort(final int columnIndex, final short x) throws SQLException {
- try {
- resultSet.updateShort(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateShort, columnIndex, x);
}
@Override
public void updateShort(final String columnName, final short x) throws SQLException {
- try {
- resultSet.updateShort(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateShort, columnName, x);
}
@Override
public void updateSQLXML(final int columnIndex, final SQLXML value) throws SQLException {
- try {
- resultSet.updateSQLXML(columnIndex, value);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateSQLXML, columnIndex, value);
}
@Override
public void updateSQLXML(final String columnLabel, final SQLXML value) throws SQLException {
- try {
- resultSet.updateSQLXML(columnLabel, value);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateSQLXML, columnLabel, value);
}
@Override
public void updateString(final int columnIndex, final String x) throws SQLException {
- try {
- resultSet.updateString(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateString, columnIndex, x);
}
@Override
public void updateString(final String columnName, final String x) throws SQLException {
- try {
- resultSet.updateString(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateString, columnName, x);
}
@Override
public void updateTime(final int columnIndex, final Time x) throws SQLException {
- try {
- resultSet.updateTime(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateTime, columnIndex, x);
}
@Override
public void updateTime(final String columnName, final Time x) throws SQLException {
- try {
- resultSet.updateTime(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateTime, columnName, x);
}
@Override
public void updateTimestamp(final int columnIndex, final Timestamp x) throws SQLException {
- try {
- resultSet.updateTimestamp(columnIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateTimestamp, columnIndex, x);
}
@Override
public void updateTimestamp(final String columnName, final Timestamp x) throws SQLException {
- try {
- resultSet.updateTimestamp(columnName, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(resultSet::updateTimestamp, columnName, x);
}
@Override
public boolean wasNull() throws SQLException {
- try {
- return resultSet.wasNull();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyToFalse(resultSet::wasNull);
}
}
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java b/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java
index 95253e5009..8059b97197 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java
@@ -49,10 +49,8 @@ public class DelegatingStatement extends AbandonedTrace implements Statement {
* Create a wrapper for the Statement which traces this Statement to the Connection which created it and the code
* which created it.
*
- * @param statement
- * the {@link Statement} to delegate all calls to.
- * @param connection
- * 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> connection, final Statement statement) {
super(connection);
@@ -62,8 +60,7 @@ public DelegatingStatement(final DelegatingConnection> connection, final State
/**
*
- * @throws SQLException
- * thrown by the delegating statement.
+ * @throws SQLException thrown by the delegating statement.
* @since 2.4.0 made public, was protected in 2.3.0.
*/
public void activate() throws SQLException {
@@ -74,24 +71,15 @@ public void activate() throws SQLException {
@Override
public void addBatch(final String sql) throws SQLException {
- checkOpen();
- try {
- statement.addBatch(sql);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(Statement::addBatch, statement, sql);
}
@Override
public void cancel() throws SQLException {
- checkOpen();
- try {
- statement.cancel();
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(Statement::cancel, statement);
}
+ @Override
protected void checkOpen() throws SQLException {
if (isClosed()) {
throw new SQLException(this.getClass().getName() + " with address: \"" + this.toString() + "\" is closed.");
@@ -100,22 +88,12 @@ protected void checkOpen() throws SQLException {
@Override
public void clearBatch() throws SQLException {
- checkOpen();
- try {
- statement.clearBatch();
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(Statement::clearBatch, statement);
}
@Override
public void clearWarnings() throws SQLException {
- checkOpen();
- try {
- statement.clearWarnings();
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(Statement::clearWarnings, statement);
}
/**
@@ -145,7 +123,7 @@ public void close() throws SQLException {
if (resultSet != null) {
try {
resultSet.close();
- } catch (Exception e) {
+ } catch (final Exception e) {
if (connection != null) {
// Does not rethrow e.
connection.handleExceptionNoThrow(e);
@@ -159,7 +137,7 @@ public void close() throws SQLException {
if (statement != null) {
try {
statement.close();
- } catch (Exception e) {
+ } catch (final Exception e) {
if (connection != null) {
// Does not rethrow e.
connection.handleExceptionNoThrow(e);
@@ -178,72 +156,32 @@ public void close() throws SQLException {
@Override
public void closeOnCompletion() throws SQLException {
- checkOpen();
- try {
- Jdbc41Bridge.closeOnCompletion(statement);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(Jdbc41Bridge::closeOnCompletion, statement);
}
@Override
public boolean execute(final String sql) throws SQLException {
- checkOpen();
- setLastUsedInParent();
- try {
- return statement.execute(sql);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyTo(Statement::execute, statement, sql, false);
}
@Override
public boolean execute(final String sql, final int autoGeneratedKeys) throws SQLException {
- checkOpen();
- setLastUsedInParent();
- try {
- return statement.execute(sql, autoGeneratedKeys);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyTo(Statement::execute, statement, sql, autoGeneratedKeys, false);
}
@Override
public boolean execute(final String sql, final int columnIndexes[]) throws SQLException {
- checkOpen();
- setLastUsedInParent();
- try {
- return statement.execute(sql, columnIndexes);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyTo(Statement::execute, statement, sql, columnIndexes, false);
}
@Override
public boolean execute(final String sql, final String columnNames[]) throws SQLException {
- checkOpen();
- setLastUsedInParent();
- try {
- return statement.execute(sql, columnNames);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyTo(Statement::execute, statement, sql, columnNames, false);
}
@Override
public int[] executeBatch() throws SQLException {
- checkOpen();
- setLastUsedInParent();
- try {
- return statement.executeBatch();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(Statement::executeBatch, statement);
}
/**
@@ -251,14 +189,7 @@ public int[] executeBatch() throws SQLException {
*/
@Override
public long[] executeLargeBatch() throws SQLException {
- checkOpen();
- setLastUsedInParent();
- try {
- return statement.executeLargeBatch();
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(Statement::executeLargeBatch, statement);
}
/**
@@ -266,14 +197,7 @@ public long[] executeLargeBatch() throws SQLException {
*/
@Override
public long executeLargeUpdate(final String sql) throws SQLException {
- checkOpen();
- setLastUsedInParent();
- try {
- return statement.executeLargeUpdate(sql);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::executeLargeUpdate, statement, sql, 0L);
}
/**
@@ -281,14 +205,7 @@ public long executeLargeUpdate(final String sql) throws SQLException {
*/
@Override
public long executeLargeUpdate(final String sql, final int autoGeneratedKeys) throws SQLException {
- checkOpen();
- setLastUsedInParent();
- try {
- return statement.executeLargeUpdate(sql, autoGeneratedKeys);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::executeLargeUpdate, statement, sql, autoGeneratedKeys, 0L);
}
/**
@@ -296,14 +213,7 @@ public long executeLargeUpdate(final String sql, final int autoGeneratedKeys) th
*/
@Override
public long executeLargeUpdate(final String sql, final int[] columnIndexes) throws SQLException {
- checkOpen();
- setLastUsedInParent();
- try {
- return statement.executeLargeUpdate(sql, columnIndexes);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::executeLargeUpdate, statement, sql, columnIndexes, 0L);
}
/**
@@ -311,74 +221,32 @@ public long executeLargeUpdate(final String sql, final int[] columnIndexes) thro
*/
@Override
public long executeLargeUpdate(final String sql, final String[] columnNames) throws SQLException {
- checkOpen();
- setLastUsedInParent();
- try {
- return statement.executeLargeUpdate(sql, columnNames);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::executeLargeUpdate, statement, sql, columnNames, 0L);
}
@Override
public ResultSet executeQuery(final String sql) throws SQLException {
- checkOpen();
- setLastUsedInParent();
- try {
- return DelegatingResultSet.wrapResultSet(this, statement.executeQuery(sql));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(() -> DelegatingResultSet.wrapResultSet(this, statement.executeQuery(sql)));
}
@Override
public int executeUpdate(final String sql) throws SQLException {
- checkOpen();
- setLastUsedInParent();
- try {
- return statement.executeUpdate(sql);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::executeUpdate, statement, sql, 0);
}
@Override
public int executeUpdate(final String sql, final int autoGeneratedKeys) throws SQLException {
- checkOpen();
- setLastUsedInParent();
- try {
- return statement.executeUpdate(sql, autoGeneratedKeys);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::executeUpdate, statement, sql, autoGeneratedKeys, 0);
}
@Override
public int executeUpdate(final String sql, final int columnIndexes[]) throws SQLException {
- checkOpen();
- setLastUsedInParent();
- try {
- return statement.executeUpdate(sql, columnIndexes);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::executeUpdate, statement, sql, columnIndexes, 0);
}
@Override
public int executeUpdate(final String sql, final String columnNames[]) throws SQLException {
- checkOpen();
- setLastUsedInParent();
- try {
- return statement.executeUpdate(sql, columnNames);
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::executeUpdate, statement, sql, columnNames, 0);
}
@Override
@@ -417,35 +285,17 @@ public Statement getDelegate() {
@Override
public int getFetchDirection() throws SQLException {
- checkOpen();
- try {
- return statement.getFetchDirection();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::getFetchDirection, statement, 0);
}
@Override
public int getFetchSize() throws SQLException {
- checkOpen();
- try {
- return statement.getFetchSize();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::getFetchSize, statement, 0);
}
@Override
public ResultSet getGeneratedKeys() throws SQLException {
- checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(this, statement.getGeneratedKeys());
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(() -> DelegatingResultSet.wrapResultSet(this, statement.getGeneratedKeys()));
}
/**
@@ -481,13 +331,7 @@ public Statement getInnermostDelegate() {
*/
@Override
public long getLargeMaxRows() throws SQLException {
- checkOpen();
- try {
- return statement.getLargeMaxRows();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::getLargeMaxRows, statement, 0L);
}
/**
@@ -495,136 +339,65 @@ public long getLargeMaxRows() throws SQLException {
*/
@Override
public long getLargeUpdateCount() throws SQLException {
- checkOpen();
- try {
- return statement.getLargeUpdateCount();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::getLargeUpdateCount, statement, 0L);
}
@Override
public int getMaxFieldSize() throws SQLException {
- checkOpen();
- try {
- return statement.getMaxFieldSize();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::getMaxFieldSize, statement, 0);
}
@Override
public int getMaxRows() throws SQLException {
- checkOpen();
- try {
- return statement.getMaxRows();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::getMaxRows, statement, 0);
}
@Override
public boolean getMoreResults() throws SQLException {
- checkOpen();
- try {
- return statement.getMoreResults();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyTo(Statement::getMoreResults, statement, false);
}
@Override
public boolean getMoreResults(final int current) throws SQLException {
- checkOpen();
- try {
- return statement.getMoreResults(current);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyTo(Statement::getMoreResults, statement, current, false);
}
@Override
public int getQueryTimeout() throws SQLException {
- checkOpen();
- try {
- return statement.getQueryTimeout();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::getQueryTimeout, statement, 0);
}
@Override
public ResultSet getResultSet() throws SQLException {
- checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(this, statement.getResultSet());
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(() -> DelegatingResultSet.wrapResultSet(this, statement.getResultSet()));
}
@Override
public int getResultSetConcurrency() throws SQLException {
- checkOpen();
- try {
- return statement.getResultSetConcurrency();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::getResultSetConcurrency, statement, 0);
}
@Override
public int getResultSetHoldability() throws SQLException {
- checkOpen();
- try {
- return statement.getResultSetHoldability();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::getResultSetHoldability, statement, 0);
}
@Override
public int getResultSetType() throws SQLException {
- checkOpen();
- try {
- return statement.getResultSetType();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::getResultSetType, statement, 0);
}
@Override
public int getUpdateCount() throws SQLException {
- checkOpen();
- try {
- return statement.getUpdateCount();
- } catch (final SQLException e) {
- handleException(e);
- return 0;
- }
+ return applyTo(Statement::getUpdateCount, statement, 0);
}
@Override
public SQLWarning getWarnings() throws SQLException {
- checkOpen();
- try {
- return statement.getWarnings();
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ return apply(Statement::getWarnings, statement);
}
+ @Override
protected void handleException(final SQLException e) throws SQLException {
if (connection != null) {
connection.handleException(e);
@@ -647,24 +420,12 @@ protected boolean isClosedInternal() {
@Override
public boolean isCloseOnCompletion() throws SQLException {
- checkOpen();
- try {
- return Jdbc41Bridge.isCloseOnCompletion(statement);
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return apply(Jdbc41Bridge::isCloseOnCompletion, statement);
}
@Override
public boolean isPoolable() throws SQLException {
- checkOpen();
- try {
- return statement.isPoolable();
- } catch (final SQLException e) {
- handleException(e);
- return false;
- }
+ return applyTo(Statement::isPoolable, statement, false);
}
@Override
@@ -680,8 +441,7 @@ public boolean isWrapperFor(final Class> iface) throws SQLException {
/**
*
- * @throws SQLException
- * thrown by the delegating statement.
+ * @throws SQLException thrown by the delegating statement.
* @since 2.4.0 made public, was protected in 2.3.0.
*/
public void passivate() throws SQLException {
@@ -696,19 +456,13 @@ protected void setClosedInternal(final boolean closed) {
@Override
public void setCursorName(final String name) throws SQLException {
- checkOpen();
- try {
- statement.setCursorName(name);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(Statement::setCursorName, statement, name);
}
/**
* Sets my delegate.
*
- * @param statement
- * my delegate.
+ * @param statement my delegate.
*/
public void setDelegate(final Statement statement) {
this.statement = statement;
@@ -716,32 +470,17 @@ public void setDelegate(final Statement statement) {
@Override
public void setEscapeProcessing(final boolean enable) throws SQLException {
- checkOpen();
- try {
- statement.setEscapeProcessing(enable);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(Statement::setEscapeProcessing, statement, enable);
}
@Override
public void setFetchDirection(final int direction) throws SQLException {
- checkOpen();
- try {
- statement.setFetchDirection(direction);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(Statement::setFetchDirection, statement, direction);
}
@Override
public void setFetchSize(final int rows) throws SQLException {
- checkOpen();
- try {
- statement.setFetchSize(rows);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(Statement::setFetchSize, statement, rows);
}
/**
@@ -749,15 +488,11 @@ public void setFetchSize(final int rows) throws SQLException {
*/
@Override
public void setLargeMaxRows(final long max) throws SQLException {
- checkOpen();
- try {
- statement.setLargeMaxRows(max);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(Statement::setLargeMaxRows, statement, max);
}
- private void setLastUsedInParent() {
+ @Override
+ protected void markUse() {
if (connection != null) {
connection.setLastUsed();
}
@@ -765,42 +500,22 @@ private void setLastUsedInParent() {
@Override
public void setMaxFieldSize(final int max) throws SQLException {
- checkOpen();
- try {
- statement.setMaxFieldSize(max);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(Statement::setMaxFieldSize, statement, max);
}
@Override
public void setMaxRows(final int max) throws SQLException {
- checkOpen();
- try {
- statement.setMaxRows(max);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(Statement::setMaxRows, statement, max);
}
@Override
public void setPoolable(final boolean poolable) throws SQLException {
- checkOpen();
- try {
- statement.setPoolable(poolable);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(Statement::setPoolable, statement, poolable);
}
@Override
public void setQueryTimeout(final int seconds) throws SQLException {
- checkOpen();
- try {
- statement.setQueryTimeout(seconds);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(Statement::setQueryTimeout, statement, seconds);
}
/**
diff --git a/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java b/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
index d99ed22b93..9ddbffe0fe 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
@@ -22,6 +22,7 @@
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.NoSuchElementException;
+import java.util.concurrent.Callable;
import org.apache.commons.pool2.KeyedObjectPool;
import org.apache.commons.pool2.KeyedPooledObjectFactory;
@@ -63,7 +64,7 @@ public enum StatementType {
}
/** Pool of {@link PreparedStatement}s. and {@link CallableStatement}s */
- private KeyedObjectPool pstmtPool;
+ private KeyedObjectPool pStmtPool;
/**
* Constructor.
@@ -96,9 +97,9 @@ public void activateObject(final PStmtKey key, final PooledObject oldpool = pstmtPool;
- pstmtPool = null;
+ if (null != pStmtPool) {
+ final KeyedObjectPool oldpool = pStmtPool;
+ pStmtPool = null;
try {
oldpool.close();
} catch (final RuntimeException e) {
@@ -304,11 +305,11 @@ public PooledObject makeObject(final PStmtKey key)
if (key.getStmtType() == StatementType.PREPARED_STATEMENT) {
final PreparedStatement statement = (PreparedStatement) key.createStatement(getDelegate());
@SuppressWarnings({"rawtypes", "unchecked" }) // Unable to find way to avoid this
- final PoolablePreparedStatement pps = new PoolablePreparedStatement(statement, key, pstmtPool, this);
+ final PoolablePreparedStatement pps = new PoolablePreparedStatement(statement, key, pStmtPool, this);
return new DefaultPooledObject<>(pps);
}
final CallableStatement statement = (CallableStatement) key.createStatement(getDelegate());
- final PoolableCallableStatement pcs = new PoolableCallableStatement(statement, key, pstmtPool, this);
+ final PoolableCallableStatement pcs = new PoolableCallableStatement(statement, key, pStmtPool, this);
return new DefaultPooledObject<>(pcs);
}
@@ -341,6 +342,26 @@ public void passivateObject(final PStmtKey key, final PooledObject callableCreateKey)
+ throws SQLException {
+ if (null == pStmtPool) {
+ throw new SQLException("Statement pool is null - closed or invalid PoolingConnection.");
+ }
+ final PStmtKey pStmtKey;
+ StatementType stmtType = null;
+ try {
+ pStmtKey = callableCreateKey.call();
+ stmtType = pStmtKey.getStmtType();
+ return pStmtPool.borrowObject(pStmtKey);
+ } 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 " + stmtType + " from pool failed", e);
+ }
+ }
+
/**
* Creates or obtains a {@link CallableStatement} from the pool.
*
@@ -352,15 +373,7 @@ public void passivateObject(final PStmtKey key, final PooledObject createKey(sql, StatementType.CALLABLE_STATEMENT));
}
/**
@@ -379,16 +392,8 @@ public CallableStatement prepareCall(final String sql) throws SQLException {
@Override
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency)
throws SQLException {
- try {
- return (CallableStatement) pstmtPool.borrowObject(
- createKey(sql, resultSetType, resultSetConcurrency, StatementType.CALLABLE_STATEMENT));
- } 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);
- }
+ return (CallableStatement) borrow(
+ () -> createKey(sql, resultSetType, resultSetConcurrency, StatementType.CALLABLE_STATEMENT));
}
/**
@@ -409,16 +414,8 @@ public CallableStatement prepareCall(final String sql, final int resultSetType,
@Override
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability) throws SQLException {
- try {
- return (CallableStatement) pstmtPool.borrowObject(createKey(sql, resultSetType, resultSetConcurrency,
- resultSetHoldability, StatementType.CALLABLE_STATEMENT));
- } 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);
- }
+ return (CallableStatement) borrow(() -> createKey(sql, resultSetType, resultSetConcurrency,
+ resultSetHoldability, StatementType.CALLABLE_STATEMENT));
}
/**
@@ -430,34 +427,12 @@ public CallableStatement prepareCall(final String sql, final int resultSetType,
*/
@Override
public PreparedStatement prepareStatement(final String sql) throws SQLException {
- if (null == pstmtPool) {
- throw new SQLException("Statement pool is null - closed or invalid PoolingConnection.");
- }
- try {
- return pstmtPool.borrowObject(createKey(sql));
- } 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);
- }
+ return borrow(() -> createKey(sql));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException {
- if (null == pstmtPool) {
- throw new SQLException("Statement pool is null - closed or invalid PoolingConnection.");
- }
- try {
- return pstmtPool.borrowObject(createKey(sql, autoGeneratedKeys));
- } 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);
- }
+ return borrow(() -> createKey(sql, autoGeneratedKeys));
}
/**
@@ -471,18 +446,7 @@ public PreparedStatement prepareStatement(final String sql, final int autoGenera
*/
@Override
public PreparedStatement prepareStatement(final String sql, final int columnIndexes[]) throws SQLException {
- if (null == pstmtPool) {
- throw new SQLException("Statement pool is null - closed or invalid PoolingConnection.");
- }
- try {
- return pstmtPool.borrowObject(createKey(sql, columnIndexes));
- } 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);
- }
+ return borrow(() -> createKey(sql, columnIndexes));
}
/**
@@ -499,18 +463,7 @@ public PreparedStatement prepareStatement(final String sql, final int columnInde
@Override
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency)
throws SQLException {
- if (null == pstmtPool) {
- throw new SQLException("Statement pool is null - closed or invalid PoolingConnection.");
- }
- try {
- return pstmtPool.borrowObject(createKey(sql, resultSetType, resultSetConcurrency));
- } 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);
- }
+ return borrow(() -> createKey(sql, resultSetType, resultSetConcurrency));
}
/**
@@ -529,18 +482,7 @@ public PreparedStatement prepareStatement(final String sql, final int resultSetT
@Override
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability) throws SQLException {
- if (null == pstmtPool) {
- throw new SQLException("Statement pool is null - closed or invalid PoolingConnection.");
- }
- try {
- return pstmtPool.borrowObject(createKey(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
- } 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);
- }
+ return borrow(() -> createKey(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
}
/**
@@ -554,18 +496,7 @@ public PreparedStatement prepareStatement(final String sql, final int resultSetT
*/
@Override
public PreparedStatement prepareStatement(final String sql, final String columnNames[]) throws SQLException {
- if (null == pstmtPool) {
- throw new SQLException("Statement pool is null - closed or invalid PoolingConnection.");
- }
- try {
- return pstmtPool.borrowObject(createKey(sql, columnNames));
- } 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);
- }
+ return borrow(() -> createKey(sql, columnNames));
}
/**
@@ -575,13 +506,13 @@ public PreparedStatement prepareStatement(final String sql, final String columnN
* the prepared statement pool.
*/
public void setStatementPool(final KeyedObjectPool pool) {
- pstmtPool = pool;
+ pStmtPool = pool;
}
@Override
public synchronized String toString() {
- if (pstmtPool != null) {
- return "PoolingConnection: " + pstmtPool.toString();
+ if (pStmtPool != null) {
+ return "PoolingConnection: " + pStmtPool.toString();
}
return "PoolingConnection: null";
}
diff --git a/src/main/java/org/apache/commons/dbcp2/ResourceFunctions.java b/src/main/java/org/apache/commons/dbcp2/ResourceFunctions.java
new file mode 100644
index 0000000000..e32f5be67a
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/ResourceFunctions.java
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.dbcp2;
+
+import java.sql.SQLException;
+
+import org.apache.commons.dbcp2.function.SQLBooleanSupplier;
+import org.apache.commons.dbcp2.function.SQLConsumer0;
+import org.apache.commons.dbcp2.function.SQLConsumer1;
+import org.apache.commons.dbcp2.function.SQLConsumer2;
+import org.apache.commons.dbcp2.function.SQLConsumer3;
+import org.apache.commons.dbcp2.function.SQLConsumer4;
+import org.apache.commons.dbcp2.function.SQLConsumer5;
+import org.apache.commons.dbcp2.function.SQLFunction0;
+import org.apache.commons.dbcp2.function.SQLFunction1;
+import org.apache.commons.dbcp2.function.SQLFunction2;
+import org.apache.commons.dbcp2.function.SQLFunction3;
+import org.apache.commons.dbcp2.function.SQLIntConsumer;
+import org.apache.commons.dbcp2.function.SQLIntFunction;
+import org.apache.commons.dbcp2.function.SQLIntSupplier;
+
+/**
+ * Functional helpers.
+ *
+ * @since 2.8.0
+ */
+public class ResourceFunctions {
+
+ protected void accept(final SQLConsumer0 runnable) throws SQLException {
+ checkOpen();
+ markUse();
+ try {
+ runnable.accept();
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
+
+ protected void accept(final SQLConsumer1 consumer, final T value) throws SQLException {
+ checkOpen();
+ markUse();
+ try {
+ consumer.accept(value);
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
+
+ protected void accept(final SQLConsumer2 consumer, final T t, final U u) throws SQLException {
+ checkOpen();
+ markUse();
+ try {
+ consumer.accept(t, u);
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
+
+ protected void accept(final SQLConsumer3 consumer, final T t, final U u, final V v)
+ throws SQLException {
+ checkOpen();
+ markUse();
+ try {
+ consumer.accept(t, u, v);
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
+
+ protected void accept(final SQLConsumer4 consumer, final T t, final U u, final V v,
+ final W w) throws SQLException {
+ checkOpen();
+ markUse();
+ try {
+ consumer.accept(t, u, v, w);
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
+
+ protected void accept(final SQLConsumer5 consumer, final T t, final U u,
+ final V v, final W w, final X x) throws SQLException {
+ checkOpen();
+ markUse();
+ try {
+ consumer.accept(t, u, v, w, x);
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
+
+ protected void acceptInt(final SQLIntConsumer consumer, final int value) throws SQLException {
+ checkOpen();
+ markUse();
+ try {
+ consumer.accept(value);
+ } catch (final SQLException e) {
+ handleException(e);
+ }
+ }
+
+ protected T apply(final SQLFunction0 callable) throws SQLException {
+ return applyTo(callable, null);
+ }
+
+ protected R apply(final SQLFunction1 function, final T value) throws SQLException {
+ return applyTo(function, value, null);
+ }
+
+ protected R apply(final SQLFunction2 function, final T t, final U u) throws SQLException {
+ checkOpen();
+ markUse();
+ try {
+ return function.apply(t, u);
+ } catch (final SQLException e) {
+ handleException(e);
+ return null;
+ }
+ }
+
+ protected R apply(final SQLFunction3 function, final T t, final U u, final V v)
+ throws SQLException {
+ checkOpen();
+ markUse();
+ try {
+ return function.apply(t, u, v);
+ } catch (final SQLException e) {
+ handleException(e);
+ return null;
+ }
+ }
+
+ protected R apply(final SQLIntFunction function, final int value) throws SQLException {
+ return applyIntTo(function, value, null);
+ }
+
+ protected R applyIntTo(final SQLIntFunction function, final int value, final R onException)
+ throws SQLException {
+ checkOpen();
+ markUse();
+ try {
+ return function.apply(value);
+ } catch (final SQLException e) {
+ handleException(e);
+ return onException;
+ }
+ }
+
+ protected T applyTo(final SQLFunction0 callable, final T onException) throws SQLException {
+ checkOpen();
+ markUse();
+ try {
+ return callable.apply();
+ } catch (final SQLException e) {
+ handleException(e);
+ return onException;
+ }
+ }
+
+ protected R applyTo(final SQLFunction1 function, final T value, final R onException)
+ throws SQLException {
+ checkOpen();
+ markUse();
+ try {
+ return function.apply(value);
+ } catch (final SQLException e) {
+ handleException(e);
+ return onException;
+ }
+ }
+
+ protected R applyTo(final SQLFunction2 function, final T t, final U u,
+ final R onException) throws SQLException {
+ checkOpen();
+ markUse();
+ try {
+ return function.apply(t, u);
+ } catch (final SQLException e) {
+ handleException(e);
+ return onException;
+ }
+ }
+
+ protected R applyTo(final SQLFunction3 function, final T t, final U u,
+ final V v, final R onException) throws SQLException {
+ checkOpen();
+ markUse();
+ try {
+ return function.apply(t, u, v);
+ } catch (final SQLException e) {
+ handleException(e);
+ return onException;
+ }
+ }
+
+ protected int applyTo0(final SQLFunction0 callable) throws SQLException {
+ return applyTo(callable, 0);
+ }
+
+ protected long applyTo0L(final SQLFunction0 callable) throws SQLException {
+ return applyTo(callable, 0L);
+ }
+
+ protected boolean applyToFalse(final SQLFunction0 callable) throws SQLException {
+ return applyTo(callable, false);
+ }
+
+ @SuppressWarnings("unused")
+ protected void checkOpen() throws SQLException {
+ // empty
+ }
+
+ protected boolean getAsBoolean(final SQLBooleanSupplier supplier) throws SQLException {
+ checkOpen();
+ markUse();
+ try {
+ return supplier.getAsBoolean();
+ } catch (final SQLException e) {
+ handleException(e);
+ return false;
+ }
+ }
+
+ protected int getAsInt(final SQLIntSupplier supplier) throws SQLException {
+ checkOpen();
+ markUse();
+ try {
+ return supplier.getAsInt();
+ } catch (final SQLException e) {
+ handleException(e);
+ return 0;
+ }
+ }
+
+ @SuppressWarnings("unused")
+ protected void handleException(final SQLException e) throws SQLException {
+ // empty
+ }
+
+ protected void markUse() {
+ // empty
+
+ }
+
+}
diff --git a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/ConnectionImpl.java b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/ConnectionImpl.java
index 2226e8e06c..9ac586043c 100644
--- a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/ConnectionImpl.java
+++ b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/ConnectionImpl.java
@@ -98,13 +98,7 @@ public void close() throws SQLException {
*/
@Override
public CallableStatement prepareCall(final String sql) throws SQLException {
- checkOpen();
- try {
- return new DelegatingCallableStatement(this, pooledConnection.prepareCall(sql));
- } catch (final SQLException e) {
- handleException(e); // Does not return
- return null;
- }
+ return apply(() -> new DelegatingCallableStatement(this, pooledConnection.prepareCall(sql)) );
}
/**
@@ -130,14 +124,8 @@ public CallableStatement prepareCall(final String sql) throws SQLException {
@Override
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency)
throws SQLException {
- checkOpen();
- try {
- return new DelegatingCallableStatement(this,
- pooledConnection.prepareCall(sql, resultSetType, resultSetConcurrency));
- } catch (final SQLException e) {
- handleException(e); // Does not return
- return null;
- }
+ return apply(() -> new DelegatingCallableStatement(this,
+ pooledConnection.prepareCall(sql, resultSetType, resultSetConcurrency)));
}
/**
@@ -166,14 +154,8 @@ public CallableStatement prepareCall(final String sql, final int resultSetType,
@Override
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability) throws SQLException {
- checkOpen();
- try {
- return new DelegatingCallableStatement(this,
- pooledConnection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
- } catch (final SQLException e) {
- handleException(e); // Does not return
- return null;
- }
+ return apply(() -> new DelegatingCallableStatement(this,
+ pooledConnection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability)));
}
/**
@@ -188,13 +170,7 @@ public CallableStatement prepareCall(final String sql, final int resultSetType,
*/
@Override
public PreparedStatement prepareStatement(final String sql) throws SQLException {
- checkOpen();
- try {
- return new DelegatingPreparedStatement(this, pooledConnection.prepareStatement(sql));
- } catch (final SQLException e) {
- handleException(e); // Does not return
- return null;
- }
+ return apply(() -> new DelegatingPreparedStatement(this, pooledConnection.prepareStatement(sql)));
}
/**
@@ -207,60 +183,31 @@ public PreparedStatement prepareStatement(final String sql) throws SQLException
@Override
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency)
throws SQLException {
- checkOpen();
- try {
- return new DelegatingPreparedStatement(this,
- pooledConnection.prepareStatement(sql, resultSetType, resultSetConcurrency));
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(() -> new DelegatingPreparedStatement(this,
+ pooledConnection.prepareStatement(sql, resultSetType, resultSetConcurrency)));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability) throws SQLException {
- checkOpen();
- try {
- return new DelegatingPreparedStatement(this,
- pooledConnection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(() -> new DelegatingPreparedStatement(this,
+ pooledConnection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability)));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException {
- checkOpen();
- try {
- return new DelegatingPreparedStatement(this, pooledConnection.prepareStatement(sql, autoGeneratedKeys));
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(
+ () -> new DelegatingPreparedStatement(this, pooledConnection.prepareStatement(sql, autoGeneratedKeys)));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int columnIndexes[]) throws SQLException {
- checkOpen();
- try {
- return new DelegatingPreparedStatement(this, pooledConnection.prepareStatement(sql, columnIndexes));
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(() -> new DelegatingPreparedStatement(this, pooledConnection.prepareStatement(sql, columnIndexes)));
}
@Override
public PreparedStatement prepareStatement(final String sql, final String columnNames[]) throws SQLException {
- checkOpen();
- try {
- return new DelegatingPreparedStatement(this, pooledConnection.prepareStatement(sql, columnNames));
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(() -> new DelegatingPreparedStatement(this, pooledConnection.prepareStatement(sql, columnNames)));
}
//
diff --git a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java
index 1f74af4ad2..705ce3b62e 100644
--- a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java
+++ b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java
@@ -22,6 +22,7 @@
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Vector;
+import java.util.concurrent.Callable;
import javax.sql.ConnectionEvent;
import javax.sql.ConnectionEventListener;
@@ -35,6 +36,7 @@
import org.apache.commons.dbcp2.PoolableCallableStatement;
import org.apache.commons.dbcp2.PoolablePreparedStatement;
import org.apache.commons.dbcp2.PoolingConnection.StatementType;
+import org.apache.commons.dbcp2.function.SQLFunction0;
import org.apache.commons.pool2.KeyedObjectPool;
import org.apache.commons.pool2.KeyedPooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
@@ -476,6 +478,29 @@ public void passivateObject(final PStmtKey key, final PooledObject nullPoolFunction, Callable callableCreateKey)
+ throws SQLException {
+ if (pStmtPool == null) {
+ return nullPoolFunction.apply();
+ }
+ try {
+ return pStmtPool.borrowObject(callableCreateKey.call());
+ } catch (final RuntimeException e) {
+ throw e;
+ } catch (final Exception e) {
+ throw new SQLException("Borrow prepareCall from pool failed", e);
+ }
+ }
+
/**
* Creates or obtains a {@link CallableStatement} from my pool.
*
@@ -488,16 +513,8 @@ public void passivateObject(final PStmtKey key, final PooledObject connection.prepareCall(sql),
+ () -> createKey(sql, StatementType.CALLABLE_STATEMENT));
}
/**
@@ -521,17 +538,8 @@ CallableStatement prepareCall(final String sql) throws SQLException {
*/
CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency)
throws SQLException {
- if (pStmtPool == null) {
- return connection.prepareCall(sql, resultSetType, resultSetConcurrency);
- }
- try {
- return (CallableStatement) pStmtPool.borrowObject(
- createKey(sql, resultSetType, resultSetConcurrency, StatementType.CALLABLE_STATEMENT));
- } catch (final RuntimeException e) {
- throw e;
- } catch (final Exception e) {
- throw new SQLException("Borrow prepareCall from pool failed", e);
- }
+ return (CallableStatement) borrow(() -> connection.prepareCall(sql, resultSetType, resultSetConcurrency),
+ () -> createKey(sql, resultSetType, resultSetConcurrency, StatementType.CALLABLE_STATEMENT));
}
/**
@@ -558,17 +566,10 @@ CallableStatement prepareCall(final String sql, final int resultSetType, final i
*/
CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability) throws SQLException {
- if (pStmtPool == null) {
- return connection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
- }
- try {
- return (CallableStatement) pStmtPool.borrowObject(createKey(sql, resultSetType, resultSetConcurrency,
- resultSetHoldability, StatementType.CALLABLE_STATEMENT));
- } catch (final RuntimeException e) {
- throw e;
- } catch (final Exception e) {
- throw new SQLException("Borrow prepareCall from pool failed", e);
- }
+ return (CallableStatement) borrow(
+ () -> connection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability),
+ () -> createKey(sql, resultSetType, resultSetConcurrency, resultSetHoldability,
+ StatementType.CALLABLE_STATEMENT));
}
/**
@@ -579,16 +580,7 @@ CallableStatement prepareCall(final String sql, final int resultSetType, final i
* @return a {@link PoolablePreparedStatement}
*/
PreparedStatement prepareStatement(final String sql) throws SQLException {
- if (pStmtPool == null) {
- return connection.prepareStatement(sql);
- }
- try {
- return pStmtPool.borrowObject(createKey(sql));
- } catch (final RuntimeException e) {
- throw e;
- } catch (final Exception e) {
- throw new SQLException("Borrow prepareStatement from pool failed", e);
- }
+ return borrow(() -> connection.prepareStatement(sql), () -> createKey(sql));
}
/**
@@ -603,29 +595,12 @@ PreparedStatement prepareStatement(final String sql) throws SQLException {
* @see Connection#prepareStatement(String, int)
*/
PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException {
- if (pStmtPool == null) {
- return connection.prepareStatement(sql, autoGeneratedKeys);
- }
- try {
- return pStmtPool.borrowObject(createKey(sql, autoGeneratedKeys));
- } catch (final RuntimeException e) {
- throw e;
- } catch (final Exception e) {
- throw new SQLException("Borrow prepareStatement from pool failed", e);
- }
+ return borrow(() -> connection.prepareStatement(sql, autoGeneratedKeys),
+ () -> createKey(sql, autoGeneratedKeys));
}
PreparedStatement prepareStatement(final String sql, final int columnIndexes[]) throws SQLException {
- if (pStmtPool == null) {
- return connection.prepareStatement(sql, columnIndexes);
- }
- try {
- return pStmtPool.borrowObject(createKey(sql, columnIndexes));
- } catch (final RuntimeException e) {
- throw e;
- } catch (final Exception e) {
- throw new SQLException("Borrow prepareStatement from pool failed", e);
- }
+ return borrow(() -> connection.prepareStatement(sql, columnIndexes),() -> createKey(sql, columnIndexes));
}
/**
@@ -646,43 +621,18 @@ PreparedStatement prepareStatement(final String sql, final int columnIndexes[])
*/
PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency)
throws SQLException {
- if (pStmtPool == null) {
- return connection.prepareStatement(sql, resultSetType, resultSetConcurrency);
- }
- try {
- return pStmtPool.borrowObject(createKey(sql, resultSetType, resultSetConcurrency));
- } catch (final RuntimeException e) {
- throw e;
- } catch (final Exception e) {
- throw new SQLException("Borrow prepareStatement from pool failed", e);
- }
+ return borrow(() -> connection.prepareStatement(sql, resultSetType, resultSetConcurrency),
+ () -> createKey(sql, resultSetType, resultSetConcurrency));
}
PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability) throws SQLException {
- if (pStmtPool == null) {
- return connection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
- }
- try {
- return pStmtPool.borrowObject(createKey(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
- } catch (final RuntimeException e) {
- throw e;
- } catch (final Exception e) {
- throw new SQLException("Borrow prepareStatement from pool failed", e);
- }
+ return borrow(() -> connection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability),
+ () -> createKey(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
}
PreparedStatement prepareStatement(final String sql, final String columnNames[]) throws SQLException {
- if (pStmtPool == null) {
- return connection.prepareStatement(sql, columnNames);
- }
- try {
- return pStmtPool.borrowObject(createKey(sql, columnNames));
- } catch (final RuntimeException e) {
- throw e;
- } catch (final Exception e) {
- throw new SQLException("Borrow prepareStatement from pool failed", e);
- }
+ return borrow(() -> connection.prepareStatement(sql, columnNames), () -> createKey(sql, columnNames));
}
/**
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLBooleanSupplier.java b/src/main/java/org/apache/commons/dbcp2/function/SQLBooleanSupplier.java
new file mode 100644
index 0000000000..9156c0bf82
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLBooleanSupplier.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+import java.util.function.Supplier;
+
+/**
+ * Represents a supplier of SQL {@code boolean}-valued results. This is the {@code boolean}-producing primitive
+ * specialization of {@link Supplier}.
+ *
+ *
+ * There is no requirement that a distinct result be returned each time the supplier is invoked.
+ *
+ *
+ *
+ * This is a functional interface whose functional method is {@link #getAsBoolean()}.
+ *
+ *
+ * @see java.util.function.BooleanSupplier
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLBooleanSupplier {
+
+ /**
+ * Gets a result.
+ *
+ * @return a result
+ * @throws SQLException
+ */
+ boolean getAsBoolean() throws SQLException;
+}
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer0.java b/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer0.java
new file mode 100644
index 0000000000..b45bd0af2f
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer0.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+
+/**
+ * A SQL task that may throw a SQLException. Implementors define a method without arguments called {@code call()}.
+ *
+ *
+ * The {@code Callable} interface is similar to {@link java.lang.Runnable} but is specialized for SQL Exceptions.
+ *
+ *
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLConsumer0 {
+
+ /**
+ * Computes a result, or throws an exception if unable to do so.
+ *
+ * @throws SQLException if unable to compute a result
+ */
+ void accept() throws SQLException;
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer1.java b/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer1.java
new file mode 100644
index 0000000000..280075cc11
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer1.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+import java.util.Objects;
+import java.util.function.Consumer;
+
+/**
+ * Represents a SQL operation that accepts a single input argument and no result. Unlike most other functional
+ * interfaces, this is expected to operate via side-effects.
+ *
+ *
+ * This is a functional interface whose functional method is {@link #accept(Object)}.
+ *
+ *
+ * @param the type of the input to the operation
+ *
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLConsumer1 {
+
+ /**
+ * Performs this operation on the given argument.
+ *
+ * @param t the input argument
+ * @throws SQLException
+ */
+ void accept(T t) throws SQLException;
+
+ /**
+ * As {@link Consumer#andThen(Consumer)} but with a SQL Exception.
+ *
+ * @param after the operation to perform after this operation
+ * @return a composed {@code Consumer} that performs in sequence this operation followed by the {@code after}
+ * operation
+ * @throws NullPointerException if {@code after} is null
+ */
+ default SQLConsumer1 andThen(SQLConsumer1 super T> after) {
+ Objects.requireNonNull(after);
+ return (T t) -> {
+ accept(t);
+ after.accept(t);
+ };
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer2.java b/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer2.java
new file mode 100644
index 0000000000..7955d55309
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer2.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+import java.util.function.Consumer;
+
+/**
+ * Represents an operation that accepts two input arguments and returns no result. This is the two-arity specialization
+ * of {@link Consumer}. Unlike most other functional interfaces, this is expected to operate via side-effects.
+ *
+ *
+ * This is a functional interface whose functional method is
+ * {@link #accept(Object, Object)}.
+ *
+ *
+ * @param the type of the first argument to the operation
+ * @param the type of the second argument to the operation
+ *
+ * @see java.util.function.Consumer
+ * @see java.util.function.BiConsumer
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLConsumer2 {
+
+ /**
+ * Performs this operation on the given arguments.
+ *
+ * @param t the first input argument
+ * @param u the second input argument
+ * @throws SQLException
+ */
+ void accept(T t, U u) throws SQLException;
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer3.java b/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer3.java
new file mode 100644
index 0000000000..00f5ccfa6d
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer3.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+
+/**
+ * Represents an operation that accepts three input arguments and returns no result. This is the three-arity
+ * specialization of {@link SQLConsumer1}. Unlike most other functional interfaces, this is expected to operate via
+ * side-effects.
+ *
+ *
+ * This is a functional interface whose functional method is
+ * {@link #accept(Object, Object, Object)}.
+ *
+ *
+ * @param the type of the first argument to the operation
+ * @param the type of the second argument to the operation
+ * @param the type of the third argument to the operation
+ *
+ * @see java.util.function.Consumer
+ * @see java.util.function.BiConsumer
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLConsumer3 {
+
+ /**
+ * Performs this operation on the given arguments.
+ *
+ * @param t the first input argument
+ * @param u the second input argument
+ * @param v the third input argument
+ * @throws SQLException
+ */
+ void accept(T t, U u, V v) throws SQLException;
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer4.java b/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer4.java
new file mode 100644
index 0000000000..391c7961fd
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer4.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+
+/**
+ * Represents an operation that accepts four input arguments and returns no result. This is the four-arity
+ * specialization of {@link SQLConsumer1}. Unlike most other functional interfaces, this is expected to operate via
+ * side-effects.
+ *
+ *
+ * This is a functional interface whose functional method is
+ * {@link #accept(Object, Object, Object, Object)}.
+ *
+ *
+ * @param the type of the first argument to the operation
+ * @param the type of the second argument to the operation
+ * @param the type of the third argument to the operation
+ * @param the type of the fourth argument to the operation
+ *
+ * @see java.util.function.Consumer
+ * @see java.util.function.BiConsumer
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLConsumer4 {
+
+ /**
+ * Performs this operation on the given arguments.
+ *
+ * @param t the first input argument
+ * @param u the second input argument
+ * @param v the third input argument
+ * @param w the fourth input argument
+ * @throws SQLException
+ */
+ void accept(T t, U u, V v, W w) throws SQLException;
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer5.java b/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer5.java
new file mode 100644
index 0000000000..311a64dd4b
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLConsumer5.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+
+/**
+ * Represents an operation that accepts four input arguments and returns no result. This is the four-arity
+ * specialization of {@link SQLConsumer1}. Unlike most other functional interfaces, this is expected to operate via
+ * side-effects.
+ *
+ *
+ * This is a functional interface whose functional method is
+ * {@link #accept(Object, Object, Object, Object, Object)}.
+ *
+ *
+ * @param the type of the first argument to the operation
+ * @param the type of the second argument to the operation
+ * @param the type of the third argument to the operation
+ * @param the type of the fourth argument to the operation
+ * @param the type of the fifth argument to the operation
+ *
+ * @see java.util.function.Consumer
+ * @see java.util.function.BiConsumer
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLConsumer5 {
+
+ /**
+ * Performs this operation on the given arguments.
+ *
+ * @param t the first input argument
+ * @param u the second input argument
+ * @param v the third input argument
+ * @param w the fourth input argument
+ * @param x the fifth input argument
+ * @throws SQLException
+ */
+ void accept(T t, U u, V v, W w, X x) throws SQLException;
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLFunction0.java b/src/main/java/org/apache/commons/dbcp2/function/SQLFunction0.java
new file mode 100644
index 0000000000..0dad9b154c
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLFunction0.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+
+/**
+ * A SQL task that returns a result and may throw a SQLException. Implementors define a method without arguments called
+ * {@code call()}.
+ *
+ *
+ * The {@code Callable} interface is similar to {@link java.util.concurrent.Callable} but is specialized for SQL
+ * Exceptions.
+ *
+ *
+ * @param the result type of method {@link #apply()}
+ * @see java.util.concurrent.Callable
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLFunction0 {
+
+ /**
+ * Computes a result, or throws an exception if unable to do so.
+ *
+ * @return computed result
+ * @throws SQLException if unable to compute a result
+ */
+ R apply() throws SQLException;
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLFunction1.java b/src/main/java/org/apache/commons/dbcp2/function/SQLFunction1.java
new file mode 100644
index 0000000000..c69ff70957
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLFunction1.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * Represents a SQL function that accepts one argument and produces a result.
+ *
+ *
+ * This is a functional interface whose functional method is {@link #apply(Object)}.
+ *
+ *
+ * @param the type of the input to the function
+ * @param the type of the result of the function
+ *
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLFunction1 {
+
+ /**
+ * Applies this function to the given argument.
+ *
+ * @param t the function argument
+ * @return the function result
+ * @throws SQLException
+ */
+ R apply(T t) throws SQLException;
+
+ /**
+ * See {@link Function#compose(Function)}.
+ *
+ * @param the type of input to the {@code before} function, and to the composed function
+ * @param before the function to apply before this function is applied
+ * @return a composed function that first applies the {@code before} function and then applies this function
+ * @throws NullPointerException if before is null
+ *
+ * @see #andThen(SQLFunction1)
+ */
+ default SQLFunction1 compose(SQLFunction1 super V, ? extends T> before) {
+ Objects.requireNonNull(before);
+ return (V v) -> apply(before.apply(v));
+ }
+
+ /**
+ * See {@link Function#andThen(Function)}.
+ *
+ * @param the type of output of the {@code after} function, and of the composed function
+ * @param after the function to apply after this function is applied
+ * @return a composed function that first applies this function and then applies the {@code after} function
+ * @throws NullPointerException if after is null
+ *
+ * @see #compose(SQLFunction1)
+ */
+ default SQLFunction1 andThen(SQLFunction1 super R, ? extends V> after) {
+ Objects.requireNonNull(after);
+ return (T t) -> after.apply(apply(t));
+ }
+
+ /**
+ * Returns a function that always returns its input argument.
+ *
+ * @param the type of the input and output objects to the function
+ * @return a function that always returns its input argument
+ */
+ static SQLFunction1 identity() {
+ return t -> t;
+ }
+}
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLFunction2.java b/src/main/java/org/apache/commons/dbcp2/function/SQLFunction2.java
new file mode 100644
index 0000000000..5f10527940
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLFunction2.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+import java.util.function.Function;
+
+/**
+ * Represents a SQL function that accepts two arguments and produces a result. This is the two-arity specialization of
+ * {@link SQLFunction1}.
+ *
+ *
+ * This is a functional interface whose functional method is
+ * {@link #apply(Object, Object)}.
+ *
+ *
+ * @param the type of the first argument to the function
+ * @param the type of the second argument to the function
+ * @param the type of the result of the function
+ *
+ * @see Function
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLFunction2 {
+
+ /**
+ * Applies this function to the given arguments.
+ *
+ * @param t the first function argument
+ * @param u the second function argument
+ * @return the function result
+ * @throws SQLException
+ */
+ R apply(T t, U u) throws SQLException;
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLFunction3.java b/src/main/java/org/apache/commons/dbcp2/function/SQLFunction3.java
new file mode 100644
index 0000000000..b996e682cd
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLFunction3.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+import java.util.function.Function;
+
+/**
+ * Represents a SQL function that accepts three arguments and produces a result. This is the three-arity specialization of
+ * {@link SQLFunction1}.
+ *
+ *
+ * This is a functional interface whose functional method is
+ * {@link #apply(Object, Object, Object)}.
+ *
+ *
+ * @param the type of the first argument to the function
+ * @param the type of the second argument to the function
+ * @param the type of the third argument to the function
+ * @param the type of the result of the function
+ *
+ * @see Function
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLFunction3 {
+
+ /**
+ * Applies this function to the given arguments.
+ *
+ * @param t the first function argument
+ * @param u the second function argument
+ * @param v the third function argument
+ * @return the function result
+ * @throws SQLException
+ */
+ R apply(T t, U u, V v) throws SQLException;
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLFunction4.java b/src/main/java/org/apache/commons/dbcp2/function/SQLFunction4.java
new file mode 100644
index 0000000000..966d162d79
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLFunction4.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+import java.util.function.Function;
+
+/**
+ * Represents a SQL function that accepts four arguments and produces a result. This is the four-arity specialization of
+ * {@link SQLFunction1}.
+ *
+ *
+ * This is a functional interface whose functional method is
+ * {@link #apply(Object, Object, Object, Object)}.
+ *
+ *
+ * @param the type of the first argument to the function
+ * @param the type of the second argument to the function
+ * @param the type of the third argument to the function
+ * @param the type of the fourth argument to the function
+ * @param the type of the result of the function
+ *
+ * @see Function
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLFunction4 {
+
+ /**
+ * Applies this function to the given arguments.
+ *
+ * @param t the first function argument
+ * @param u the second function argument
+ * @param v the third function argument
+ * @param x the fourth function argument
+ * @return the function result
+ * @throws SQLException
+ */
+ R apply(T t, U u, V v, X x) throws SQLException;
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLFunction5.java b/src/main/java/org/apache/commons/dbcp2/function/SQLFunction5.java
new file mode 100644
index 0000000000..429717f838
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLFunction5.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+import java.util.function.Function;
+
+/**
+ * Represents a SQL function that accepts five arguments and produces a result. This is the five-arity specialization of
+ * {@link SQLFunction1}.
+ *
+ *
+ * This is a functional interface whose functional method is
+ * {@link #apply(Object, Object, Object, Object, Object)}.
+ *
+ *
+ * @param the type of the first argument to the function
+ * @param the type of the second argument to the function
+ * @param the type of the third argument to the function
+ * @param the type of the fourth argument to the function
+ * @param the type of the fourth argument to the function
+ * @param the type of the result of the function
+ *
+ * @see Function
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLFunction5 {
+
+ /**
+ * Applies this function to the given arguments.
+ *
+ * @param t the first function argument
+ * @param u the second function argument
+ * @param v the third function argument
+ * @param x the fourth function argument
+ * @param y the fourth function argument
+ * @return the function result
+ * @throws SQLException
+ */
+ R apply(T t, U u, V v, X x, Y y) throws SQLException;
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLFunction6.java b/src/main/java/org/apache/commons/dbcp2/function/SQLFunction6.java
new file mode 100644
index 0000000000..389b275c12
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLFunction6.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+import java.util.function.Function;
+
+/**
+ * Represents a SQL function that accepts six arguments and produces a result. This is the six-arity specialization of
+ * {@link SQLFunction1}.
+ *
+ *
+ * This is a functional interface whose functional method is
+ * {@link #apply(Object, Object, Object, Object, Object, Object)}.
+ *
+ *
+ * @param the type of the first argument to the function
+ * @param the type of the second argument to the function
+ * @param the type of the third argument to the function
+ * @param the type of the fourth argument to the function
+ * @param the type of the fifth argument to the function
+ * @param the type of the sixth argument to the function
+ * @param the type of the result of the function
+ *
+ * @see Function
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLFunction6 {
+
+ /**
+ * Applies this function to the given arguments.
+ *
+ * @param t the first function argument
+ * @param u the second function argument
+ * @param v the third function argument
+ * @param x the fourth function argument
+ * @param y the fifth function argument
+ * @param z the sixth function argument
+ * @return the function result
+ * @throws SQLException
+ */
+ R apply(T t, U u, V v, X x, Y y, Z z) throws SQLException;
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLIntConsumer.java b/src/main/java/org/apache/commons/dbcp2/function/SQLIntConsumer.java
new file mode 100644
index 0000000000..6a7a6fe250
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLIntConsumer.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+import java.util.Objects;
+import java.util.function.Consumer;
+
+/**
+ * Represents an operation that accepts a single {@code int}-valued argument and no result. This is the primitive type
+ * specialization of {@link Consumer} for {@code int}. Unlike most other functional interfaces, {@code IntConsumer} is
+ * expected to operate via side-effects.
+ *
+ *
+ * This is a functional interface whose functional method is {@link #accept(int)}.
+ *
+ *
+ * @see Consumer
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLIntConsumer {
+
+ /**
+ * Performs this operation on the given argument.
+ *
+ * @param value the input argument
+ * @throws SQLException
+ */
+ void accept(int value) throws SQLException;
+
+ /**
+ * As {@link Consumer#andThen(Consumer)} but with a SQL Exception.
+ *
+ * @param after the operation to perform after this operation
+ * @return a composed {@code Consumer} that performs in sequence this operation followed by the {@code after}
+ * operation
+ * @throws NullPointerException if {@code after} is null
+ */
+ default SQLIntConsumer andThen(SQLIntConsumer after) {
+ Objects.requireNonNull(after);
+ return (int t) -> {
+ accept(t);
+ after.accept(t);
+ };
+ }
+}
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLIntFunction.java b/src/main/java/org/apache/commons/dbcp2/function/SQLIntFunction.java
new file mode 100644
index 0000000000..cd250ac8b2
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLIntFunction.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+import java.util.function.Function;
+
+/**
+ * Represents a SQL function that accepts an int-valued argument and produces a result. This is the
+ * {@code int}-consuming primitive specialization for {@link Function}.
+ *
+ *
+ * This is a functional interface whose functional method is {@link #apply(int)}.
+ *
+ *
+ * @param the type of the result of the function
+ *
+ * @see Function
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLIntFunction {
+
+ /**
+ * Applies this function to the given argument.
+ *
+ * @param value the function argument
+ * @return the function result
+ * @throws SQLException
+ */
+ R apply(int value) throws SQLException;
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/dbcp2/function/SQLIntSupplier.java b/src/main/java/org/apache/commons/dbcp2/function/SQLIntSupplier.java
new file mode 100644
index 0000000000..94528ff915
--- /dev/null
+++ b/src/main/java/org/apache/commons/dbcp2/function/SQLIntSupplier.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.dbcp2.function;
+
+import java.sql.SQLException;
+
+/**
+ * Represents a supplier of SQL {@code int}-valued results. This is the SQL {@code int}-producing primitive
+ * specialization of {@link java.util.function.IntSupplier}.
+ *
+ *
+ * There is no requirement that a distinct result be returned each time the supplier is invoked.
+ *
+ *
+ *
+ * This is a functional interface whose functional method is {@link #getAsInt()}.
+ *
+ *
+ * @see java.util.function.IntSupplier
+ * @since 2.8.0
+ */
+@FunctionalInterface
+public interface SQLIntSupplier {
+
+ /**
+ * Gets a result.
+ *
+ * @return a result
+ * @throws SQLException
+ */
+ int getAsInt() throws SQLException;
+}
diff --git a/src/test/java/org/apache/commons/dbcp2/TestAbandonedBasicDataSource.java b/src/test/java/org/apache/commons/dbcp2/TestAbandonedBasicDataSource.java
index da83df6643..30466b9326 100644
--- a/src/test/java/org/apache/commons/dbcp2/TestAbandonedBasicDataSource.java
+++ b/src/test/java/org/apache/commons/dbcp2/TestAbandonedBasicDataSource.java
@@ -276,7 +276,7 @@ public void testGarbageCollectorCleanUp02() throws Exception {
@SuppressWarnings("unchecked")
final
GenericKeyedObjectPool gkop =
- (GenericKeyedObjectPool) TesterUtils.getField(poolingConn, "pstmtPool");
+ (GenericKeyedObjectPool) TesterUtils.getField(poolingConn, "pStmtPool");
Assertions.assertEquals(0, conn.getTrace().size());
Assertions.assertEquals(0, gkop.getNumActive());
createStatement(conn);
diff --git a/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java b/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java
index 6b0ed7c255..6863b9c4c3 100644
--- a/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java
+++ b/src/test/java/org/apache/commons/dbcp2/TestConnectionPool.java
@@ -685,6 +685,15 @@ protected boolean isClosed(final Statement statement) {
try {
statement.getWarnings();
return false;
+ } catch (final SQLException e) {
+ // getWarnings throws an exception if the statement is
+ // closed, but could throw an exception for other reasons
+ // in this case it is good enough to assume the statement
+ // is closed
+ }
+ try {
+ statement.getFetchSize();
+ return false;
} catch (final SQLException e) {
// getWarnings throws an exception if the statement is
// closed, but could throw an exception for other reasons
diff --git a/src/test/java/org/apache/commons/dbcp2/TestDelegatingResultSet.java b/src/test/java/org/apache/commons/dbcp2/TestDelegatingResultSet.java
index f0ce5c0b2d..a35ba3d5d9 100644
--- a/src/test/java/org/apache/commons/dbcp2/TestDelegatingResultSet.java
+++ b/src/test/java/org/apache/commons/dbcp2/TestDelegatingResultSet.java
@@ -45,7 +45,7 @@ public class TestDelegatingResultSet {
private DelegatingResultSet delegate;
@BeforeEach
- public void setUp() {
+ public void setUp() throws SQLException {
testConn = new TesterConnection("foo", "bar");
conn = new DelegatingConnection<>(testConn);
rs = mock(ResultSet.class);
From 620dccac0ca4baa9dbff5f9cac864c8390fac1fe Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Wed, 28 Aug 2019 20:34:52 -0400
Subject: [PATCH 6/9] Add missing ASL header.
---
.github/workflows/maven.yml | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index 92e93fe49b..b9587f323b 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -1,3 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
name: Java CI
on: [push]
From 9c90c7710135c193c75ad6ea8a46284a80c6d600 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Wed, 28 Aug 2019 21:07:19 -0400
Subject: [PATCH 7/9] Remove unused, a few more impls, and clean ups.
---
.../commons/dbcp2/DelegatingConnection.java | 53 +++++-------
.../dbcp2/DelegatingDatabaseMetaData.java | 84 +++++++++----------
.../dbcp2/DelegatingPreparedStatement.java | 42 ++++------
3 files changed, 75 insertions(+), 104 deletions(-)
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
index abdd253556..457cce76ea 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
@@ -61,7 +61,7 @@
public class DelegatingConnection extends AbandonedTrace implements Connection {
private static final Map EMPTY_FAILED_PROPERTIES = Collections
- .emptyMap();
+ .emptyMap();
/** My delegate {@link Connection}. */
private volatile C connection;
@@ -208,15 +208,15 @@ public Statement createStatement() throws SQLException {
@Override
public Statement createStatement(final int resultSetType, final int resultSetConcurrency) throws SQLException {
- return apply(() -> init(
- new DelegatingStatement(this, connection.createStatement(resultSetType, resultSetConcurrency))));
+ return apply(
+ () -> init(new DelegatingStatement(this, connection.createStatement(resultSetType, resultSetConcurrency))));
}
@Override
public Statement createStatement(final int resultSetType, final int resultSetConcurrency,
- final int resultSetHoldability) throws SQLException {
+ final int resultSetHoldability) throws SQLException {
return apply(() -> init(new DelegatingStatement(this,
- connection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability))));
+ connection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability))));
}
@Override
@@ -366,7 +366,7 @@ protected void handleException(final SQLException e) throws SQLException {
* Handles the given {@code SQLException}.
*
* @param The throwable type.
- * @param e The SQLException
+ * @param e The SQLException
* @return the given {@code SQLException}
* @since 2.7.0
*/
@@ -483,39 +483,23 @@ protected void passivate() throws SQLException {
setLastUsed(0);
}
- @SuppressWarnings("resource")
@Override
public CallableStatement prepareCall(final String sql) throws SQLException {
- checkOpen();
- try {
- final DelegatingCallableStatement dcs = new DelegatingCallableStatement(this, connection.prepareCall(sql));
- return init(dcs);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ return apply(() -> init(new DelegatingCallableStatement(this, connection.prepareCall(sql))));
}
- @SuppressWarnings("resource")
@Override
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency)
- throws SQLException {
- checkOpen();
- try {
- final DelegatingCallableStatement dcs = new DelegatingCallableStatement(this,
- connection.prepareCall(sql, resultSetType, resultSetConcurrency));
- return init(dcs);
- } catch (final SQLException e) {
- handleException(e);
- return null;
- }
+ throws SQLException {
+ return apply(() -> init(
+ new DelegatingCallableStatement(this, connection.prepareCall(sql, resultSetType, resultSetConcurrency))));
}
@Override
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency,
- final int resultSetHoldability) throws SQLException {
+ final int resultSetHoldability) throws SQLException {
return apply(() -> init(new DelegatingCallableStatement(this,
- connection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability))));
+ connection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability))));
}
@Override
@@ -526,26 +510,27 @@ public PreparedStatement prepareStatement(final String sql) throws SQLException
@Override
public PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException {
return apply(
- () -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, autoGeneratedKeys))));
+ () -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, autoGeneratedKeys))));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int columnIndexes[]) throws SQLException {
- return apply(() -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, columnIndexes))));
+ return apply(
+ () -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, columnIndexes))));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency)
- throws SQLException {
+ throws SQLException {
return apply(() -> init(new DelegatingPreparedStatement(this,
- connection.prepareStatement(sql, resultSetType, resultSetConcurrency))));
+ connection.prepareStatement(sql, resultSetType, resultSetConcurrency))));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency,
- final int resultSetHoldability) throws SQLException {
+ final int resultSetHoldability) throws SQLException {
return apply(() -> init(new DelegatingPreparedStatement(this,
- connection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability))));
+ connection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability))));
}
@Override
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java b/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java
index a0edcfb393..558568c4cc 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java
@@ -23,7 +23,6 @@
import java.sql.SQLException;
import org.apache.commons.dbcp2.function.SQLFunction0;
-import org.apache.commons.dbcp2.function.SQLFunction1;
import org.apache.commons.dbcp2.function.SQLFunction2;
import org.apache.commons.dbcp2.function.SQLFunction3;
import org.apache.commons.dbcp2.function.SQLFunction4;
@@ -52,11 +51,11 @@ public class DelegatingDatabaseMetaData extends ResourceFunctions implements Dat
/**
* Constructs a new instance for the given delegating connection and database meta data.
*
- * @param connection the delegating connection
+ * @param connection the delegating connection
* @param databaseMetaData the database meta data
*/
public DelegatingDatabaseMetaData(final DelegatingConnection> connection,
- final DatabaseMetaData databaseMetaData) {
+ final DatabaseMetaData databaseMetaData) {
super();
this.connection = connection;
this.databaseMetaData = databaseMetaData;
@@ -104,14 +103,14 @@ public boolean generatedKeyAlwaysReturned() throws SQLException {
@Override
public ResultSet getAttributes(final String catalog, final String schemaPattern, final String typeNamePattern,
- final String attributeNamePattern) throws SQLException {
+ final String attributeNamePattern) throws SQLException {
return toResultSet(databaseMetaData::getAttributes, catalog, schemaPattern, typeNamePattern,
- attributeNamePattern);
+ attributeNamePattern);
}
@Override
public ResultSet getBestRowIdentifier(final String catalog, final String schema, final String table,
- final int scope, final boolean nullable) throws SQLException {
+ final int scope, final boolean nullable) throws SQLException {
return toResultSet(databaseMetaData::getBestRowIdentifier, catalog, schema, table, scope, nullable);
}
@@ -137,13 +136,13 @@ public ResultSet getClientInfoProperties() throws SQLException {
@Override
public ResultSet getColumnPrivileges(final String catalog, final String schema, final String table,
- final String columnNamePattern) throws SQLException {
+ final String columnNamePattern) throws SQLException {
return toResultSet(databaseMetaData::getColumnPrivileges, catalog, schema, table, columnNamePattern);
}
@Override
public ResultSet getColumns(final String catalog, final String schemaPattern, final String tableNamePattern,
- final String columnNamePattern) throws SQLException {
+ final String columnNamePattern) throws SQLException {
return toResultSet(databaseMetaData::getColumns, catalog, schemaPattern, tableNamePattern, columnNamePattern);
}
@@ -154,9 +153,9 @@ public Connection getConnection() throws SQLException {
@Override
public ResultSet getCrossReference(final String parentCatalog, final String parentSchema, final String parentTable,
- final String foreignCatalog, final String foreignSchema, final String foreignTable) throws SQLException {
+ final String foreignCatalog, final String foreignSchema, final String foreignTable) throws SQLException {
return toResultSet(databaseMetaData::getCrossReference, parentCatalog, parentSchema, parentTable,
- foreignCatalog, foreignSchema, foreignTable);
+ foreignCatalog, foreignSchema, foreignTable);
}
@Override
@@ -215,7 +214,7 @@ public String getDriverVersion() throws SQLException {
@Override
public ResultSet getExportedKeys(final String catalog, final String schema, final String table)
- throws SQLException {
+ throws SQLException {
return toResultSet(databaseMetaData::getExportedKeys, catalog, schema, table);
}
@@ -226,14 +225,14 @@ public String getExtraNameCharacters() throws SQLException {
@Override
public ResultSet getFunctionColumns(final String catalog, final String schemaPattern,
- final String functionNamePattern, final String columnNamePattern) throws SQLException {
+ final String functionNamePattern, final String columnNamePattern) throws SQLException {
return toResultSet(databaseMetaData::getFunctionColumns, catalog, schemaPattern, functionNamePattern,
- columnNamePattern);
+ columnNamePattern);
}
@Override
public ResultSet getFunctions(final String catalog, final String schemaPattern, final String functionNamePattern)
- throws SQLException {
+ throws SQLException {
return toResultSet(databaseMetaData::getFunctions, catalog, schemaPattern, functionNamePattern);
}
@@ -244,13 +243,13 @@ public String getIdentifierQuoteString() throws SQLException {
@Override
public ResultSet getImportedKeys(final String catalog, final String schema, final String table)
- throws SQLException {
+ throws SQLException {
return toResultSet(databaseMetaData::getImportedKeys, catalog, schema, table);
}
@Override
public ResultSet getIndexInfo(final String catalog, final String schema, final String table, final boolean unique,
- final boolean approximate) throws SQLException {
+ final boolean approximate) throws SQLException {
return toResultSet(databaseMetaData::getIndexInfo, catalog, schema, table, unique, approximate);
}
@@ -409,14 +408,14 @@ public ResultSet getPrimaryKeys(final String catalog, final String schema, final
@Override
public ResultSet getProcedureColumns(final String catalog, final String schemaPattern,
- final String procedureNamePattern, final String columnNamePattern) throws SQLException {
+ final String procedureNamePattern, final String columnNamePattern) throws SQLException {
return toResultSet(databaseMetaData::getProcedureColumns, catalog, schemaPattern, procedureNamePattern,
- columnNamePattern);
+ columnNamePattern);
}
@Override
public ResultSet getProcedures(final String catalog, final String schemaPattern, final String procedureNamePattern)
- throws SQLException {
+ throws SQLException {
return toResultSet(databaseMetaData::getProcedures, catalog, schemaPattern, procedureNamePattern);
}
@@ -427,9 +426,9 @@ public String getProcedureTerm() throws SQLException {
@Override
public ResultSet getPseudoColumns(final String catalog, final String schemaPattern, final String tableNamePattern,
- final String columnNamePattern) throws SQLException {
+ final String columnNamePattern) throws SQLException {
return toResultSet(databaseMetaData::getPseudoColumns, catalog, schemaPattern, tableNamePattern,
- columnNamePattern);
+ columnNamePattern);
}
@Override
@@ -479,14 +478,14 @@ public String getStringFunctions() throws SQLException {
@Override
public ResultSet getSuperTables(final String catalog, final String schemaPattern, final String tableNamePattern)
- throws SQLException {
- return toResultSet(databaseMetaData::getSuperTables,catalog, schemaPattern, tableNamePattern);
+ throws SQLException {
+ return toResultSet(databaseMetaData::getSuperTables, catalog, schemaPattern, tableNamePattern);
}
@Override
public ResultSet getSuperTypes(final String catalog, final String schemaPattern, final String typeNamePattern)
- throws SQLException {
- return toResultSet(databaseMetaData::getSuperTypes,catalog, schemaPattern, typeNamePattern);
+ throws SQLException {
+ return toResultSet(databaseMetaData::getSuperTypes, catalog, schemaPattern, typeNamePattern);
}
@Override
@@ -496,14 +495,14 @@ public String getSystemFunctions() throws SQLException {
@Override
public ResultSet getTablePrivileges(final String catalog, final String schemaPattern, final String tableNamePattern)
- throws SQLException {
- return toResultSet(databaseMetaData::getTablePrivileges,catalog, schemaPattern, tableNamePattern);
+ throws SQLException {
+ return toResultSet(databaseMetaData::getTablePrivileges, catalog, schemaPattern, tableNamePattern);
}
@Override
public ResultSet getTables(final String catalog, final String schemaPattern, final String tableNamePattern,
- final String[] types) throws SQLException {
- return toResultSet(databaseMetaData::getTables,catalog, schemaPattern, tableNamePattern, types);
+ final String[] types) throws SQLException {
+ return toResultSet(databaseMetaData::getTables, catalog, schemaPattern, tableNamePattern, types);
}
@Override
@@ -523,8 +522,8 @@ public ResultSet getTypeInfo() throws SQLException {
@Override
public ResultSet getUDTs(final String catalog, final String schemaPattern, final String typeNamePattern,
- final int[] types) throws SQLException {
- return toResultSet(databaseMetaData::getUDTs,catalog, schemaPattern, typeNamePattern, types);
+ final int[] types) throws SQLException {
+ return toResultSet(databaseMetaData::getUDTs, catalog, schemaPattern, typeNamePattern, types);
}
@Override
@@ -539,8 +538,8 @@ public String getUserName() throws SQLException {
@Override
public ResultSet getVersionColumns(final String catalog, final String schema, final String table)
- throws SQLException {
- return toResultSet(databaseMetaData::getVersionColumns,catalog, schema, table);
+ throws SQLException {
+ return toResultSet(databaseMetaData::getVersionColumns, catalog, schema, table);
}
@Override
@@ -1018,39 +1017,32 @@ private ResultSet toResultSet(final SQLFunction0 callableResultSet) t
return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply()));
}
- private ResultSet toResultSet(final SQLFunction1 callableResultSet, final T t)
- throws SQLException {
- connection.checkOpen();
- return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t)));
- }
-
private ResultSet toResultSet(final SQLFunction2 callableResultSet, final T t, final U u)
- throws SQLException {
+ throws SQLException {
connection.checkOpen();
return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t, u)));
}
private ResultSet toResultSet(final SQLFunction3 callableResultSet, final T t,
- final U u, final V v) throws SQLException {
+ final U u, final V v) throws SQLException {
connection.checkOpen();
return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t, u, v)));
}
private ResultSet toResultSet(final SQLFunction4 callableResultSet, final T t,
- final U u, final V v, final X x) throws SQLException {
+ final U u, final V v, final X x) throws SQLException {
connection.checkOpen();
return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t, u, v, x)));
}
private ResultSet toResultSet(final SQLFunction5 callableResultSet,
- final T t, final U u, final V v, final X x, final Y y) throws SQLException {
+ final T t, final U u, final V v, final X x, final Y y) throws SQLException {
connection.checkOpen();
return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t, u, v, x, y)));
}
- private ResultSet toResultSet(
- final SQLFunction6 callableResultSet, final T t, final U u, final V v,
- final X x, final Y y, final Z z) throws SQLException {
+ private ResultSet toResultSet(final SQLFunction6 callableResultSet,
+ final T t, final U u, final V v, final X x, final Y y, final Z z) throws SQLException {
connection.checkOpen();
return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t, u, v, x, y, z)));
}
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java b/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java
index f1bc2848c2..d32baa84af 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java
@@ -57,7 +57,7 @@ public class DelegatingPreparedStatement extends DelegatingStatement implements
* Create a wrapper for the Statement which traces this Statement to the Connection which created it and the code
* which created it.
*
- * @param statement the {@link PreparedStatement} to delegate all calls to.
+ * @param statement the {@link PreparedStatement} to delegate all calls to.
* @param connection the {@link DelegatingConnection} that created this statement.
*/
public DelegatingPreparedStatement(final DelegatingConnection> connection, final PreparedStatement statement) {
@@ -122,13 +122,14 @@ public void setAsciiStream(final int parameterIndex, final InputStream value) th
}
@Override
- public void setAsciiStream(final int parameterIndex, final InputStream value, final int length) throws SQLException {
+ public void setAsciiStream(final int parameterIndex, final InputStream value, final int length)
+ throws SQLException {
accept(PreparedStatement::setAsciiStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
public void setAsciiStream(final int parameterIndex, final InputStream value, final long length)
- throws SQLException {
+ throws SQLException {
accept(PreparedStatement::setAsciiStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@@ -144,13 +145,13 @@ public void setBinaryStream(final int parameterIndex, final InputStream value) t
@Override
public void setBinaryStream(final int parameterIndex, final InputStream value, final int length)
- throws SQLException {
+ throws SQLException {
accept(PreparedStatement::setBinaryStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
public void setBinaryStream(final int parameterIndex, final InputStream value, final long length)
- throws SQLException {
+ throws SQLException {
accept(PreparedStatement::setBinaryStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@@ -165,8 +166,7 @@ public void setBlob(final int parameterIndex, final InputStream value) throws SQ
}
@Override
- public void setBlob(final int parameterIndex, final InputStream value, final long length)
- throws SQLException {
+ public void setBlob(final int parameterIndex, final InputStream value, final long length) throws SQLException {
accept(PreparedStatement::setBlob, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@@ -191,14 +191,13 @@ public void setCharacterStream(final int parameterIndex, final Reader value) thr
}
@Override
- public void setCharacterStream(final int parameterIndex, final Reader value, final int length)
- throws SQLException {
+ public void setCharacterStream(final int parameterIndex, final Reader value, final int length) throws SQLException {
accept(PreparedStatement::setCharacterStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
public void setCharacterStream(final int parameterIndex, final Reader value, final long length)
- throws SQLException {
+ throws SQLException {
accept(PreparedStatement::setCharacterStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@@ -254,7 +253,7 @@ public void setNCharacterStream(final int parameterIndex, final Reader value) th
@Override
public void setNCharacterStream(final int parameterIndex, final Reader value, final long length)
- throws SQLException {
+ throws SQLException {
accept(PreparedStatement::setNCharacterStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@@ -300,9 +299,9 @@ public void setObject(final int parameterIndex, final Object value, final int ta
@Override
public void setObject(final int parameterIndex, final Object value, final int targetSqlType, final int scale)
- throws SQLException {
+ throws SQLException {
accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value, targetSqlType,
- scale);
+ scale);
}
/**
@@ -310,7 +309,7 @@ public void setObject(final int parameterIndex, final Object value, final int ta
*/
@Override
public void setObject(final int parameterIndex, final Object value, final SQLType targetSqlType)
- throws SQLException {
+ throws SQLException {
accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value, targetSqlType);
}
@@ -319,9 +318,9 @@ public void setObject(final int parameterIndex, final Object value, final SQLTyp
*/
@Override
public void setObject(final int parameterIndex, final Object value, final SQLType targetSqlType,
- final int scaleOrLength) throws SQLException {
+ final int scaleOrLength) throws SQLException {
accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value, targetSqlType,
- scaleOrLength);
+ scaleOrLength);
}
@Override
@@ -346,12 +345,7 @@ public void setSQLXML(final int parameterIndex, final SQLXML value) throws SQLEx
@Override
public void setString(final int parameterIndex, final String value) throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setString(parameterIndex, value);
- } catch (final SQLException e) {
- handleException(e);
- }
+ accept(PreparedStatement::setString, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
@@ -371,7 +365,7 @@ public void setTimestamp(final int parameterIndex, final Timestamp value) throws
@Override
public void setTimestamp(final int parameterIndex, final Timestamp value, final Calendar calendar)
- throws SQLException {
+ throws SQLException {
accept(PreparedStatement::setTimestamp, getDelegatePreparedStatement(), parameterIndex, value, calendar);
}
@@ -379,7 +373,7 @@ public void setTimestamp(final int parameterIndex, final Timestamp value, final
@Deprecated
@Override
public void setUnicodeStream(final int parameterIndex, final InputStream value, final int length)
- throws SQLException {
+ throws SQLException {
accept(PreparedStatement::setUnicodeStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
From 2075df0f562f356c4bb94bdac531339bda65ae02 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Wed, 28 Aug 2019 21:43:33 -0400
Subject: [PATCH 8/9] Use generics instead of type casts. Also use generics in
::.
---
.../dbcp2/DelegatingCallableStatement.java | 296 +++++++++---------
.../commons/dbcp2/DelegatingConnection.java | 29 +-
.../dbcp2/DelegatingPreparedStatement.java | 128 ++++----
.../commons/dbcp2/DelegatingResultSet.java | 39 ++-
.../commons/dbcp2/DelegatingStatement.java | 110 +++----
.../dbcp2/PoolableCallableStatement.java | 10 +-
.../dbcp2/PoolablePreparedStatement.java | 2 +-
.../commons/dbcp2/PoolingConnection.java | 20 +-
.../dbcp2/cpdsadapter/ConnectionImpl.java | 116 ++++---
9 files changed, 366 insertions(+), 384 deletions(-)
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingCallableStatement.java b/src/main/java/org/apache/commons/dbcp2/DelegatingCallableStatement.java
index 2ac88526ea..2fccad0415 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingCallableStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingCallableStatement.java
@@ -48,212 +48,210 @@
* Statement ensures that the Connection which created it can close any open Statement's on Connection close.
*
*
+ * @param CallableStatement or a sub-type.
* @since 2.0
*/
-public class DelegatingCallableStatement extends DelegatingPreparedStatement implements CallableStatement {
+public class DelegatingCallableStatement extends DelegatingPreparedStatement
+ implements CallableStatement {
/**
* Creates a wrapper for the Statement which traces this Statement to the Connection which created it and the code
* which created it.
*
* @param connection the {@link DelegatingConnection} that created this statement
- * @param statement the {@link CallableStatement} to delegate all calls to
+ * @param statement the {@link CallableStatement} to delegate all calls to
*/
- public DelegatingCallableStatement(final DelegatingConnection> connection, final CallableStatement statement) {
+ public DelegatingCallableStatement(final DelegatingConnection> connection, final S statement) {
super(connection, statement);
}
@Override
public Array getArray(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getArray, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getArray, getDelegate(), parameterIndex);
}
@Override
public Array getArray(final String parameterName) throws SQLException {
- return apply(CallableStatement::getArray, getDelegateCallableStatement(), parameterName);
+ return apply(S::getArray, getDelegate(), parameterName);
}
@Override
public BigDecimal getBigDecimal(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getBigDecimal, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getBigDecimal, getDelegate(), parameterIndex);
}
/** @deprecated Use {@link #getBigDecimal(int)} or {@link #getBigDecimal(String)} */
@Override
@Deprecated
public BigDecimal getBigDecimal(final int parameterIndex, final int scale) throws SQLException {
- return apply(CallableStatement::getBigDecimal, getDelegateCallableStatement(), parameterIndex, scale);
+ return apply(S::getBigDecimal, getDelegate(), parameterIndex, scale);
}
@Override
public BigDecimal getBigDecimal(final String parameterName) throws SQLException {
- return apply(CallableStatement::getBigDecimal, getDelegateCallableStatement(), parameterName);
+ return apply(S::getBigDecimal, getDelegate(), parameterName);
}
@Override
public Blob getBlob(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getBlob, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getBlob, getDelegate(), parameterIndex);
}
@Override
public Blob getBlob(final String parameterName) throws SQLException {
- return apply(CallableStatement::getBlob, getDelegateCallableStatement(), parameterName);
+ return apply(S::getBlob, getDelegate(), parameterName);
}
@Override
public boolean getBoolean(final int parameterIndex) throws SQLException {
- return applyTo(CallableStatement::getBoolean, getDelegateCallableStatement(), parameterIndex, false);
+ return applyTo(S::getBoolean, getDelegate(), parameterIndex, false);
}
@Override
public boolean getBoolean(final String parameterName) throws SQLException {
- return applyTo(CallableStatement::getBoolean, getDelegateCallableStatement(), parameterName, false);
+ return applyTo(S::getBoolean, getDelegate(), parameterName, false);
}
@Override
public byte getByte(final int parameterIndex) throws SQLException {
- return applyTo(CallableStatement::getByte, getDelegateCallableStatement(), parameterIndex, (byte) 0);
+ return applyTo(S::getByte, getDelegate(), parameterIndex, (byte) 0);
}
@Override
public byte getByte(final String parameterName) throws SQLException {
- return applyTo(CallableStatement::getByte, getDelegateCallableStatement(), parameterName, (byte) 0);
+ return applyTo(S::getByte, getDelegate(), parameterName, (byte) 0);
}
@Override
public byte[] getBytes(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getBytes, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getBytes, getDelegate(), parameterIndex);
}
@Override
public byte[] getBytes(final String parameterName) throws SQLException {
- return apply(CallableStatement::getBytes, getDelegateCallableStatement(), parameterName);
+ return apply(S::getBytes, getDelegate(), parameterName);
}
@Override
public Reader getCharacterStream(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getCharacterStream, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getCharacterStream, getDelegate(), parameterIndex);
}
@Override
public Reader getCharacterStream(final String parameterName) throws SQLException {
- return apply(CallableStatement::getCharacterStream, getDelegateCallableStatement(), parameterName);
+ return apply(S::getCharacterStream, getDelegate(), parameterName);
}
@Override
public Clob getClob(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getClob, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getClob, getDelegate(), parameterIndex);
}
@Override
public Clob getClob(final String parameterName) throws SQLException {
- return apply(CallableStatement::getClob, getDelegateCallableStatement(), parameterName);
+ return apply(S::getClob, getDelegate(), parameterName);
}
@Override
public Date getDate(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getDate, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getDate, getDelegate(), parameterIndex);
}
@Override
public Date getDate(final int parameterIndex, final Calendar cal) throws SQLException {
- return apply(CallableStatement::getDate, getDelegateCallableStatement(), parameterIndex, cal);
+ return apply(S::getDate, getDelegate(), parameterIndex, cal);
}
@Override
public Date getDate(final String parameterName) throws SQLException {
- return apply(CallableStatement::getDate, getDelegateCallableStatement(), parameterName);
+ return apply(S::getDate, getDelegate(), parameterName);
}
@Override
public Date getDate(final String parameterName, final Calendar cal) throws SQLException {
- return apply(CallableStatement::getDate, getDelegateCallableStatement(), parameterName, cal);
- }
-
- private CallableStatement getDelegateCallableStatement() {
- return (CallableStatement) getDelegate();
+ return apply(S::getDate, getDelegate(), parameterName, cal);
}
@Override
public double getDouble(final int parameterIndex) throws SQLException {
- return applyTo(CallableStatement::getDouble, getDelegateCallableStatement(), parameterIndex, 0d);
+ return applyTo(S::getDouble, getDelegate(), parameterIndex, 0d);
}
@Override
public double getDouble(final String parameterName) throws SQLException {
- return applyTo(CallableStatement::getDouble, getDelegateCallableStatement(), parameterName, 0d);
+ return applyTo(S::getDouble, getDelegate(), parameterName, 0d);
}
@Override
public float getFloat(final int parameterIndex) throws SQLException {
- return applyTo(CallableStatement::getFloat, getDelegateCallableStatement(), parameterIndex, 0f);
+ return applyTo(S::getFloat, getDelegate(), parameterIndex, 0f);
}
@Override
public float getFloat(final String parameterName) throws SQLException {
- return applyTo(CallableStatement::getFloat, getDelegateCallableStatement(), parameterName, 0f);
+ return applyTo(S::getFloat, getDelegate(), parameterName, 0f);
}
@Override
public int getInt(final int parameterIndex) throws SQLException {
- return applyTo(CallableStatement::getInt, getDelegateCallableStatement(), parameterIndex, 0);
+ return applyTo(S::getInt, getDelegate(), parameterIndex, 0);
}
@Override
public int getInt(final String parameterName) throws SQLException {
- return applyTo(CallableStatement::getInt, getDelegateCallableStatement(), parameterName, 0);
+ return applyTo(S::getInt, getDelegate(), parameterName, 0);
}
@Override
public long getLong(final int parameterIndex) throws SQLException {
- return applyTo(CallableStatement::getLong, getDelegateCallableStatement(), parameterIndex, 0L);
+ return applyTo(S::getLong, getDelegate(), parameterIndex, 0L);
}
@Override
public long getLong(final String parameterName) throws SQLException {
- return applyTo(CallableStatement::getLong, getDelegateCallableStatement(), parameterName, 0L);
+ return applyTo(S::getLong, getDelegate(), parameterName, 0L);
}
@Override
public Reader getNCharacterStream(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getNCharacterStream, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getNCharacterStream, getDelegate(), parameterIndex);
}
@Override
public Reader getNCharacterStream(final String parameterName) throws SQLException {
- return apply(CallableStatement::getNCharacterStream, getDelegateCallableStatement(), parameterName);
+ return apply(S::getNCharacterStream, getDelegate(), parameterName);
}
@Override
public NClob getNClob(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getNClob, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getNClob, getDelegate(), parameterIndex);
}
@Override
public NClob getNClob(final String parameterName) throws SQLException {
- return apply(CallableStatement::getNClob, getDelegateCallableStatement(), parameterName);
+ return apply(S::getNClob, getDelegate(), parameterName);
}
@Override
public String getNString(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getNString, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getNString, getDelegate(), parameterIndex);
}
@Override
public String getNString(final String parameterName) throws SQLException {
- return apply(CallableStatement::getNString, getDelegateCallableStatement(), parameterName);
+ return apply(S::getNString, getDelegate(), parameterName);
}
@Override
public Object getObject(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getObject, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getObject, getDelegate(), parameterIndex);
}
@Override
public T getObject(final int parameterIndex, final Class type) throws SQLException {
checkOpen();
try {
- return getDelegateCallableStatement().getObject(parameterIndex, type);
+ return getDelegate().getObject(parameterIndex, type);
} catch (final SQLException e) {
handleException(e);
return null;
@@ -262,19 +260,19 @@ public T getObject(final int parameterIndex, final Class type) throws SQL
@Override
public Object getObject(final int parameterIndex, final Map> map) throws SQLException {
- return apply(CallableStatement::getObject, getDelegateCallableStatement(), parameterIndex, map);
+ return apply(S::getObject, getDelegate(), parameterIndex, map);
}
@Override
public Object getObject(final String parameterName) throws SQLException {
- return apply(CallableStatement::getObject, getDelegateCallableStatement(), parameterName);
+ return apply(S::getObject, getDelegate(), parameterName);
}
@Override
public T getObject(final String parameterName, final Class type) throws SQLException {
checkOpen();
try {
- return getDelegateCallableStatement().getObject(parameterName, type);
+ return getDelegate().getObject(parameterName, type);
} catch (final SQLException e) {
handleException(e);
return null;
@@ -285,7 +283,7 @@ public T getObject(final String parameterName, final Class type) throws S
public Object getObject(final String parameterName, final Map> map) throws SQLException {
checkOpen();
try {
- return getDelegateCallableStatement().getObject(parameterName, map);
+ return getDelegate().getObject(parameterName, map);
} catch (final SQLException e) {
handleException(e);
return null;
@@ -294,119 +292,118 @@ public Object getObject(final String parameterName, final Map>
@Override
public Ref getRef(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getRef, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getRef, getDelegate(), parameterIndex);
}
@Override
public Ref getRef(final String parameterName) throws SQLException {
- return apply(CallableStatement::getRef, getDelegateCallableStatement(), parameterName);
+ return apply(S::getRef, getDelegate(), parameterName);
}
@Override
public RowId getRowId(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getRowId, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getRowId, getDelegate(), parameterIndex);
}
@Override
public RowId getRowId(final String parameterName) throws SQLException {
- return apply(CallableStatement::getRowId, getDelegateCallableStatement(), parameterName);
+ return apply(S::getRowId, getDelegate(), parameterName);
}
@Override
public short getShort(final int parameterIndex) throws SQLException {
- return applyTo(CallableStatement::getShort, getDelegateCallableStatement(), parameterIndex, (short) 0);
+ return applyTo(S::getShort, getDelegate(), parameterIndex, (short) 0);
}
@Override
public short getShort(final String parameterName) throws SQLException {
- return applyTo(CallableStatement::getShort, getDelegateCallableStatement(), parameterName, (short) 0);
+ return applyTo(S::getShort, getDelegate(), parameterName, (short) 0);
}
@Override
public SQLXML getSQLXML(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getSQLXML, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getSQLXML, getDelegate(), parameterIndex);
}
@Override
public SQLXML getSQLXML(final String parameterName) throws SQLException {
- return apply(CallableStatement::getSQLXML, getDelegateCallableStatement(), parameterName);
+ return apply(S::getSQLXML, getDelegate(), parameterName);
}
@Override
public String getString(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getString, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getString, getDelegate(), parameterIndex);
}
@Override
public String getString(final String parameterName) throws SQLException {
- return apply(CallableStatement::getString, getDelegateCallableStatement(), parameterName);
+ return apply(S::getString, getDelegate(), parameterName);
}
@Override
public Time getTime(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getTime, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getTime, getDelegate(), parameterIndex);
}
@Override
public Time getTime(final int parameterIndex, final Calendar cal) throws SQLException {
- return apply(CallableStatement::getTime, getDelegateCallableStatement(), parameterIndex, cal);
+ return apply(S::getTime, getDelegate(), parameterIndex, cal);
}
@Override
public Time getTime(final String parameterName) throws SQLException {
- return apply(CallableStatement::getTime, getDelegateCallableStatement(), parameterName);
+ return apply(S::getTime, getDelegate(), parameterName);
}
@Override
public Time getTime(final String parameterName, final Calendar cal) throws SQLException {
- return apply(CallableStatement::getTime, getDelegateCallableStatement(), parameterName, cal);
+ return apply(S::getTime, getDelegate(), parameterName, cal);
}
@Override
public Timestamp getTimestamp(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getTimestamp, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getTimestamp, getDelegate(), parameterIndex);
}
@Override
public Timestamp getTimestamp(final int parameterIndex, final Calendar cal) throws SQLException {
- return apply(CallableStatement::getTimestamp, getDelegateCallableStatement(), parameterIndex, cal);
+ return apply(S::getTimestamp, getDelegate(), parameterIndex, cal);
}
@Override
public Timestamp getTimestamp(final String parameterName) throws SQLException {
- return apply(CallableStatement::getTimestamp, getDelegateCallableStatement(), parameterName);
+ return apply(S::getTimestamp, getDelegate(), parameterName);
}
@Override
public Timestamp getTimestamp(final String parameterName, final Calendar cal) throws SQLException {
- return apply(CallableStatement::getTimestamp, getDelegateCallableStatement(), parameterName, cal);
+ return apply(S::getTimestamp, getDelegate(), parameterName, cal);
}
@Override
public URL getURL(final int parameterIndex) throws SQLException {
- return apply(CallableStatement::getURL, getDelegateCallableStatement(), parameterIndex);
+ return apply(S::getURL, getDelegate(), parameterIndex);
}
@Override
public URL getURL(final String parameterName) throws SQLException {
- return apply(CallableStatement::getURL, getDelegateCallableStatement(), parameterName);
+ return apply(S::getURL, getDelegate(), parameterName);
}
@Override
public void registerOutParameter(final int parameterIndex, final int sqlType) throws SQLException {
- accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterIndex, sqlType);
+ accept(S::registerOutParameter, getDelegate(), parameterIndex, sqlType);
}
@Override
public void registerOutParameter(final int parameterIndex, final int sqlType, final int scale) throws SQLException {
- accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterIndex, sqlType, scale);
+ accept(S::registerOutParameter, getDelegate(), parameterIndex, sqlType, scale);
}
@Override
public void registerOutParameter(final int parameterIndex, final int sqlType, final String typeName)
- throws SQLException {
- accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterIndex, sqlType,
- typeName);
+ throws SQLException {
+ accept(S::registerOutParameter, getDelegate(), parameterIndex, sqlType, typeName);
}
/**
@@ -414,7 +411,7 @@ public void registerOutParameter(final int parameterIndex, final int sqlType, fi
*/
@Override
public void registerOutParameter(final int parameterIndex, final SQLType sqlType) throws SQLException {
- accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterIndex, sqlType);
+ accept(S::registerOutParameter, getDelegate(), parameterIndex, sqlType);
}
/**
@@ -422,8 +419,8 @@ public void registerOutParameter(final int parameterIndex, final SQLType sqlType
*/
@Override
public void registerOutParameter(final int parameterIndex, final SQLType sqlType, final int scale)
- throws SQLException {
- accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterIndex, sqlType, scale);
+ throws SQLException {
+ accept(S::registerOutParameter, getDelegate(), parameterIndex, sqlType, scale);
}
/**
@@ -431,27 +428,25 @@ public void registerOutParameter(final int parameterIndex, final SQLType sqlType
*/
@Override
public void registerOutParameter(final int parameterIndex, final SQLType sqlType, final String typeName)
- throws SQLException {
- accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterIndex, sqlType,
- typeName);
+ throws SQLException {
+ accept(S::registerOutParameter, getDelegate(), parameterIndex, sqlType, typeName);
}
@Override
public void registerOutParameter(final String parameterName, final int sqlType) throws SQLException {
- accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterName, sqlType);
+ accept(S::registerOutParameter, getDelegate(), parameterName, sqlType);
}
@Override
public void registerOutParameter(final String parameterName, final int sqlType, final int scale)
- throws SQLException {
- accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterName, sqlType, scale);
+ throws SQLException {
+ accept(S::registerOutParameter, getDelegate(), parameterName, sqlType, scale);
}
@Override
public void registerOutParameter(final String parameterName, final int sqlType, final String typeName)
- throws SQLException {
- accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterName, sqlType,
- typeName);
+ throws SQLException {
+ accept(S::registerOutParameter, getDelegate(), parameterName, sqlType, typeName);
}
/**
@@ -459,7 +454,7 @@ public void registerOutParameter(final String parameterName, final int sqlType,
*/
@Override
public void registerOutParameter(final String parameterName, final SQLType sqlType) throws SQLException {
- accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterName, sqlType);
+ accept(S::registerOutParameter, getDelegate(), parameterName, sqlType);
}
/**
@@ -467,8 +462,8 @@ public void registerOutParameter(final String parameterName, final SQLType sqlTy
*/
@Override
public void registerOutParameter(final String parameterName, final SQLType sqlType, final int scale)
- throws SQLException {
- accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterName, sqlType, scale);
+ throws SQLException {
+ accept(S::registerOutParameter, getDelegate(), parameterName, sqlType, scale);
}
/**
@@ -476,198 +471,196 @@ public void registerOutParameter(final String parameterName, final SQLType sqlTy
*/
@Override
public void registerOutParameter(final String parameterName, final SQLType sqlType, final String typeName)
- throws SQLException {
- accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterName, sqlType,
- typeName);
+ throws SQLException {
+ accept(S::registerOutParameter, getDelegate(), parameterName, sqlType, typeName);
}
@Override
public void setAsciiStream(final String parameterName, final InputStream value) throws SQLException {
- accept(CallableStatement::setAsciiStream, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setAsciiStream, getDelegate(), parameterName, value);
}
@Override
public void setAsciiStream(final String parameterName, final InputStream value, final int length)
- throws SQLException {
- accept(CallableStatement::setAsciiStream, getDelegateCallableStatement(), parameterName, value, length);
+ throws SQLException {
+ accept(S::setAsciiStream, getDelegate(), parameterName, value, length);
}
@Override
public void setAsciiStream(final String parameterName, final InputStream value, final long length)
- throws SQLException {
- accept(CallableStatement::setAsciiStream, getDelegateCallableStatement(), parameterName, value, length);
+ throws SQLException {
+ accept(S::setAsciiStream, getDelegate(), parameterName, value, length);
}
@Override
public void setBigDecimal(final String parameterName, final BigDecimal value) throws SQLException {
- accept(CallableStatement::setBigDecimal, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setBigDecimal, getDelegate(), parameterName, value);
}
@Override
public void setBinaryStream(final String parameterName, final InputStream value) throws SQLException {
- accept(CallableStatement::setBinaryStream, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setBinaryStream, getDelegate(), parameterName, value);
}
@Override
public void setBinaryStream(final String parameterName, final InputStream value, final int length)
- throws SQLException {
- accept(CallableStatement::setBinaryStream, getDelegateCallableStatement(), parameterName, value, length);
+ throws SQLException {
+ accept(S::setBinaryStream, getDelegate(), parameterName, value, length);
}
@Override
public void setBinaryStream(final String parameterName, final InputStream value, final long length)
- throws SQLException {
- accept(CallableStatement::setBinaryStream, getDelegateCallableStatement(), parameterName, value, length);
+ throws SQLException {
+ accept(S::setBinaryStream, getDelegate(), parameterName, value, length);
}
@Override
public void setBlob(final String parameterName, final Blob value) throws SQLException {
- accept(CallableStatement::setBlob, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setBlob, getDelegate(), parameterName, value);
}
@Override
public void setBlob(final String parameterName, final InputStream value) throws SQLException {
- accept(CallableStatement::setBlob, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setBlob, getDelegate(), parameterName, value);
}
@Override
public void setBlob(final String parameterName, final InputStream value, final long length) throws SQLException {
- accept(CallableStatement::setBlob, getDelegateCallableStatement(), parameterName, value, length);
+ accept(S::setBlob, getDelegate(), parameterName, value, length);
}
@Override
public void setBoolean(final String parameterName, final boolean value) throws SQLException {
- accept(CallableStatement::setBoolean, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setBoolean, getDelegate(), parameterName, value);
}
@Override
public void setByte(final String parameterName, final byte value) throws SQLException {
- accept(CallableStatement::setByte, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setByte, getDelegate(), parameterName, value);
}
@Override
public void setBytes(final String parameterName, final byte[] value) throws SQLException {
- accept(CallableStatement::setBytes, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setBytes, getDelegate(), parameterName, value);
}
@Override
public void setCharacterStream(final String parameterName, final Reader value) throws SQLException {
- accept(CallableStatement::setCharacterStream, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setCharacterStream, getDelegate(), parameterName, value);
}
@Override
public void setCharacterStream(final String parameterName, final Reader value, final int length)
- throws SQLException {
- accept(CallableStatement::setCharacterStream, getDelegateCallableStatement(), parameterName, value, length);
+ throws SQLException {
+ accept(S::setCharacterStream, getDelegate(), parameterName, value, length);
}
@Override
public void setCharacterStream(final String parameterName, final Reader value, final long length)
- throws SQLException {
- accept(CallableStatement::setCharacterStream, getDelegateCallableStatement(), parameterName, value, length);
+ throws SQLException {
+ accept(S::setCharacterStream, getDelegate(), parameterName, value, length);
}
@Override
public void setClob(final String parameterName, final Clob value) throws SQLException {
- accept(CallableStatement::setClob, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setClob, getDelegate(), parameterName, value);
}
@Override
public void setClob(final String parameterName, final Reader value) throws SQLException {
- accept(CallableStatement::setClob, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setClob, getDelegate(), parameterName, value);
}
@Override
public void setClob(final String parameterName, final Reader value, final long length) throws SQLException {
- accept(CallableStatement::setClob, getDelegateCallableStatement(), parameterName, value, length);
+ accept(S::setClob, getDelegate(), parameterName, value, length);
}
@Override
public void setDate(final String parameterName, final Date value) throws SQLException {
- accept(CallableStatement::setDate, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setDate, getDelegate(), parameterName, value);
}
@Override
public void setDate(final String parameterName, final Date value, final Calendar cal) throws SQLException {
- accept(CallableStatement::setDate, getDelegateCallableStatement(), parameterName, value, cal);
+ accept(S::setDate, getDelegate(), parameterName, value, cal);
}
@Override
public void setDouble(final String parameterName, final double value) throws SQLException {
- accept(CallableStatement::setDouble, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setDouble, getDelegate(), parameterName, value);
}
@Override
public void setFloat(final String parameterName, final float value) throws SQLException {
- accept(CallableStatement::setFloat, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setFloat, getDelegate(), parameterName, value);
}
@Override
public void setInt(final String parameterName, final int value) throws SQLException {
- accept(CallableStatement::setInt, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setInt, getDelegate(), parameterName, value);
}
@Override
public void setLong(final String parameterName, final long value) throws SQLException {
- accept(CallableStatement::setLong, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setLong, getDelegate(), parameterName, value);
}
@Override
public void setNCharacterStream(final String parameterName, final Reader value) throws SQLException {
- accept(CallableStatement::setNCharacterStream, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setNCharacterStream, getDelegate(), parameterName, value);
}
@Override
public void setNCharacterStream(final String parameterName, final Reader value, final long length)
- throws SQLException {
- accept(CallableStatement::setNCharacterStream, getDelegateCallableStatement(), parameterName, value, length);
+ throws SQLException {
+ accept(S::setNCharacterStream, getDelegate(), parameterName, value, length);
}
@Override
public void setNClob(final String parameterName, final NClob value) throws SQLException {
- accept(CallableStatement::setNClob, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setNClob, getDelegate(), parameterName, value);
}
@Override
public void setNClob(final String parameterName, final Reader value) throws SQLException {
- accept(CallableStatement::setNClob, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setNClob, getDelegate(), parameterName, value);
}
@Override
public void setNClob(final String parameterName, final Reader value, final long length) throws SQLException {
- accept(CallableStatement::setNClob, getDelegateCallableStatement(), parameterName, value, length);
+ accept(S::setNClob, getDelegate(), parameterName, value, length);
}
@Override
public void setNString(final String parameterName, final String value) throws SQLException {
- accept(CallableStatement::setNString, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setNString, getDelegate(), parameterName, value);
}
@Override
public void setNull(final String parameterName, final int sqlType) throws SQLException {
- accept(CallableStatement::setNull, getDelegateCallableStatement(), parameterName, sqlType);
+ accept(S::setNull, getDelegate(), parameterName, sqlType);
}
@Override
public void setNull(final String parameterName, final int sqlType, final String typeName) throws SQLException {
- accept(CallableStatement::setNull, getDelegateCallableStatement(), parameterName, sqlType, typeName);
+ accept(S::setNull, getDelegate(), parameterName, sqlType, typeName);
}
@Override
public void setObject(final String parameterName, final Object value) throws SQLException {
- accept(CallableStatement::setObject, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setObject, getDelegate(), parameterName, value);
}
@Override
public void setObject(final String parameterName, final Object value, final int targetSqlType) throws SQLException {
- accept(CallableStatement::setObject, getDelegateCallableStatement(), parameterName, value, targetSqlType);
+ accept(S::setObject, getDelegate(), parameterName, value, targetSqlType);
}
@Override
public void setObject(final String parameterName, final Object value, final int targetSqlType, final int scale)
- throws SQLException {
- accept(CallableStatement::setObject, getDelegateCallableStatement(), parameterName, value, targetSqlType,
- scale);
+ throws SQLException {
+ accept(S::setObject, getDelegate(), parameterName, value, targetSqlType, scale);
}
/**
@@ -675,8 +668,8 @@ public void setObject(final String parameterName, final Object value, final int
*/
@Override
public void setObject(final String parameterName, final Object value, final SQLType targetSqlType)
- throws SQLException {
- accept(CallableStatement::setObject, getDelegateCallableStatement(), parameterName, value, targetSqlType);
+ throws SQLException {
+ accept(S::setObject, getDelegate(), parameterName, value, targetSqlType);
}
/**
@@ -684,60 +677,59 @@ public void setObject(final String parameterName, final Object value, final SQLT
*/
@Override
public void setObject(final String parameterName, final Object value, final SQLType targetSqlType,
- final int scaleOrLength) throws SQLException {
- accept(CallableStatement::setObject, getDelegateCallableStatement(), parameterName, value, targetSqlType,
- scaleOrLength);
+ final int scaleOrLength) throws SQLException {
+ accept(S::setObject, getDelegate(), parameterName, value, targetSqlType, scaleOrLength);
}
@Override
public void setRowId(final String parameterName, final RowId value) throws SQLException {
- accept(CallableStatement::setRowId, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setRowId, getDelegate(), parameterName, value);
}
@Override
public void setShort(final String parameterName, final short value) throws SQLException {
- accept(CallableStatement::setShort, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setShort, getDelegate(), parameterName, value);
}
@Override
public void setSQLXML(final String parameterName, final SQLXML value) throws SQLException {
- accept(CallableStatement::setSQLXML, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setSQLXML, getDelegate(), parameterName, value);
}
@Override
public void setString(final String parameterName, final String value) throws SQLException {
- accept(CallableStatement::setString, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setString, getDelegate(), parameterName, value);
}
@Override
public void setTime(final String parameterName, final Time value) throws SQLException {
- accept(CallableStatement::setTime, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setTime, getDelegate(), parameterName, value);
}
@Override
public void setTime(final String parameterName, final Time value, final Calendar cal) throws SQLException {
- accept(CallableStatement::setTime, getDelegateCallableStatement(), parameterName, value, cal);
+ accept(S::setTime, getDelegate(), parameterName, value, cal);
}
@Override
public void setTimestamp(final String parameterName, final Timestamp value) throws SQLException {
- accept(CallableStatement::setTimestamp, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setTimestamp, getDelegate(), parameterName, value);
}
@Override
public void setTimestamp(final String parameterName, final Timestamp value, final Calendar cal)
- throws SQLException {
- accept(CallableStatement::setTimestamp, getDelegateCallableStatement(), parameterName, value, cal);
+ throws SQLException {
+ accept(S::setTimestamp, getDelegate(), parameterName, value, cal);
}
@Override
public void setURL(final String parameterName, final URL value) throws SQLException {
- accept(CallableStatement::setURL, getDelegateCallableStatement(), parameterName, value);
+ accept(S::setURL, getDelegate(), parameterName, value);
}
@Override
public boolean wasNull() throws SQLException {
- return apply(CallableStatement::wasNull, getDelegateCallableStatement());
+ return apply(S::wasNull, getDelegate());
}
}
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
index 457cce76ea..51b2dd58d8 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
@@ -203,19 +203,19 @@ public SQLXML createSQLXML() throws SQLException {
@Override
public Statement createStatement() throws SQLException {
- return apply(() -> init(new DelegatingStatement(this, connection.createStatement())));
+ return apply(() -> init(new DelegatingStatement<>(this, connection.createStatement())));
}
@Override
public Statement createStatement(final int resultSetType, final int resultSetConcurrency) throws SQLException {
- return apply(
- () -> init(new DelegatingStatement(this, connection.createStatement(resultSetType, resultSetConcurrency))));
+ return apply(() -> init(
+ new DelegatingStatement<>(this, connection.createStatement(resultSetType, resultSetConcurrency))));
}
@Override
public Statement createStatement(final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability) throws SQLException {
- return apply(() -> init(new DelegatingStatement(this,
+ return apply(() -> init(new DelegatingStatement<>(this,
connection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability))));
}
@@ -374,7 +374,7 @@ protected T handleExceptionNoThrow(final T e) {
return e;
}
- private T init(final T ds) throws SQLException {
+ private > T init(final T ds) throws SQLException {
if (defaultQueryTimeoutSeconds != null && defaultQueryTimeoutSeconds.intValue() != ds.getQueryTimeout()) {
ds.setQueryTimeout(defaultQueryTimeoutSeconds.intValue());
}
@@ -485,57 +485,58 @@ protected void passivate() throws SQLException {
@Override
public CallableStatement prepareCall(final String sql) throws SQLException {
- return apply(() -> init(new DelegatingCallableStatement(this, connection.prepareCall(sql))));
+ return apply(() -> init(new DelegatingCallableStatement<>(this, connection.prepareCall(sql))));
}
@Override
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency)
throws SQLException {
return apply(() -> init(
- new DelegatingCallableStatement(this, connection.prepareCall(sql, resultSetType, resultSetConcurrency))));
+ new DelegatingCallableStatement<>(this, connection.prepareCall(sql, resultSetType, resultSetConcurrency))));
}
@Override
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability) throws SQLException {
- return apply(() -> init(new DelegatingCallableStatement(this,
+ return apply(() -> init(new DelegatingCallableStatement<>(this,
connection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability))));
}
@Override
public PreparedStatement prepareStatement(final String sql) throws SQLException {
- return apply(() -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql))));
+ return apply(() -> init(new DelegatingPreparedStatement<>(this, connection.prepareStatement(sql))));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException {
return apply(
- () -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, autoGeneratedKeys))));
+ () -> init(new DelegatingPreparedStatement<>(this, connection.prepareStatement(sql, autoGeneratedKeys))));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int columnIndexes[]) throws SQLException {
return apply(
- () -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, columnIndexes))));
+ () -> init(new DelegatingPreparedStatement<>(this, connection.prepareStatement(sql, columnIndexes))));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency)
throws SQLException {
- return apply(() -> init(new DelegatingPreparedStatement(this,
+ return apply(() -> init(new DelegatingPreparedStatement<>(this,
connection.prepareStatement(sql, resultSetType, resultSetConcurrency))));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability) throws SQLException {
- return apply(() -> init(new DelegatingPreparedStatement(this,
+ return apply(() -> init(new DelegatingPreparedStatement<>(this,
connection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability))));
}
@Override
public PreparedStatement prepareStatement(final String sql, final String columnNames[]) throws SQLException {
- return apply(() -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, columnNames))));
+ return apply(
+ () -> init(new DelegatingPreparedStatement<>(this, connection.prepareStatement(sql, columnNames))));
}
@Override
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java b/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java
index d32baa84af..150506766b 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java
@@ -49,9 +49,11 @@
* Statement ensures that the Connection which created it can close any open Statement's on Connection close.
*
*
+ * @param PreparedStatement or a sub-type.
* @since 2.0
*/
-public class DelegatingPreparedStatement extends DelegatingStatement implements PreparedStatement {
+public class DelegatingPreparedStatement extends DelegatingStatement
+ implements PreparedStatement {
/**
* Create a wrapper for the Statement which traces this Statement to the Connection which created it and the code
@@ -60,23 +62,23 @@ public class DelegatingPreparedStatement extends DelegatingStatement implements
* @param statement the {@link PreparedStatement} to delegate all calls to.
* @param connection the {@link DelegatingConnection} that created this statement.
*/
- public DelegatingPreparedStatement(final DelegatingConnection> connection, final PreparedStatement statement) {
+ public DelegatingPreparedStatement(final DelegatingConnection> connection, final S statement) {
super(connection, statement);
}
@Override
public void addBatch() throws SQLException {
- accept(PreparedStatement::addBatch, getDelegatePreparedStatement());
+ accept(S::addBatch, getDelegate());
}
@Override
public void clearParameters() throws SQLException {
- accept(PreparedStatement::clearParameters, getDelegatePreparedStatement());
+ accept(S::clearParameters, getDelegate());
}
@Override
public boolean execute() throws SQLException {
- return applyTo(PreparedStatement::execute, getDelegatePreparedStatement(), false);
+ return applyTo(S::execute, getDelegate(), false);
}
/**
@@ -84,224 +86,219 @@ public boolean execute() throws SQLException {
*/
@Override
public long executeLargeUpdate() throws SQLException {
- return applyTo(PreparedStatement::executeLargeUpdate, getDelegatePreparedStatement(), 0L);
+ return applyTo(S::executeLargeUpdate, getDelegate(), 0L);
}
@Override
public ResultSet executeQuery() throws SQLException {
- return apply(() -> DelegatingResultSet.wrapResultSet(this, getDelegatePreparedStatement().executeQuery()));
+ return apply(() -> DelegatingResultSet.wrapResultSet(this, getDelegate().executeQuery()));
}
@Override
public int executeUpdate() throws SQLException {
- return applyTo(PreparedStatement::executeUpdate, getDelegatePreparedStatement(), 0);
- }
-
- private PreparedStatement getDelegatePreparedStatement() {
- return (PreparedStatement) getDelegate();
+ return applyTo(S::executeUpdate, getDelegate(), 0);
}
@Override
public ResultSetMetaData getMetaData() throws SQLException {
- return apply(PreparedStatement::getMetaData, getDelegatePreparedStatement());
+ return apply(S::getMetaData, getDelegate());
}
@Override
public java.sql.ParameterMetaData getParameterMetaData() throws SQLException {
- return apply(PreparedStatement::getParameterMetaData, getDelegatePreparedStatement());
+ return apply(S::getParameterMetaData, getDelegate());
}
@Override
public void setArray(final int inputStream, final Array value) throws SQLException {
- accept(PreparedStatement::setArray, getDelegatePreparedStatement(), inputStream, value);
+ accept(S::setArray, getDelegate(), inputStream, value);
}
@Override
public void setAsciiStream(final int parameterIndex, final InputStream value) throws SQLException {
- accept(PreparedStatement::setAsciiStream, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setAsciiStream, getDelegate(), parameterIndex, value);
}
@Override
public void setAsciiStream(final int parameterIndex, final InputStream value, final int length)
throws SQLException {
- accept(PreparedStatement::setAsciiStream, getDelegatePreparedStatement(), parameterIndex, value, length);
+ accept(S::setAsciiStream, getDelegate(), parameterIndex, value, length);
}
@Override
public void setAsciiStream(final int parameterIndex, final InputStream value, final long length)
throws SQLException {
- accept(PreparedStatement::setAsciiStream, getDelegatePreparedStatement(), parameterIndex, value, length);
+ accept(S::setAsciiStream, getDelegate(), parameterIndex, value, length);
}
@Override
public void setBigDecimal(final int parameterIndex, final BigDecimal value) throws SQLException {
- accept(PreparedStatement::setBigDecimal, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setBigDecimal, getDelegate(), parameterIndex, value);
}
@Override
public void setBinaryStream(final int parameterIndex, final InputStream value) throws SQLException {
- accept(PreparedStatement::setBinaryStream, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setBinaryStream, getDelegate(), parameterIndex, value);
}
@Override
public void setBinaryStream(final int parameterIndex, final InputStream value, final int length)
throws SQLException {
- accept(PreparedStatement::setBinaryStream, getDelegatePreparedStatement(), parameterIndex, value, length);
+ accept(S::setBinaryStream, getDelegate(), parameterIndex, value, length);
}
@Override
public void setBinaryStream(final int parameterIndex, final InputStream value, final long length)
throws SQLException {
- accept(PreparedStatement::setBinaryStream, getDelegatePreparedStatement(), parameterIndex, value, length);
+ accept(S::setBinaryStream, getDelegate(), parameterIndex, value, length);
}
@Override
public void setBlob(final int parameterIndex, final Blob value) throws SQLException {
- accept(PreparedStatement::setBlob, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setBlob, getDelegate(), parameterIndex, value);
}
@Override
public void setBlob(final int parameterIndex, final InputStream value) throws SQLException {
- accept(PreparedStatement::setBlob, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setBlob, getDelegate(), parameterIndex, value);
}
@Override
public void setBlob(final int parameterIndex, final InputStream value, final long length) throws SQLException {
- accept(PreparedStatement::setBlob, getDelegatePreparedStatement(), parameterIndex, value, length);
+ accept(S::setBlob, getDelegate(), parameterIndex, value, length);
}
@Override
public void setBoolean(final int parameterIndex, final boolean value) throws SQLException {
- accept(PreparedStatement::setBoolean, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setBoolean, getDelegate(), parameterIndex, value);
}
@Override
public void setByte(final int parameterIndex, final byte value) throws SQLException {
- accept(PreparedStatement::setByte, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setByte, getDelegate(), parameterIndex, value);
}
@Override
public void setBytes(final int parameterIndex, final byte[] value) throws SQLException {
- accept(PreparedStatement::setBytes, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setBytes, getDelegate(), parameterIndex, value);
}
@Override
public void setCharacterStream(final int parameterIndex, final Reader value) throws SQLException {
- accept(PreparedStatement::setCharacterStream, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setCharacterStream, getDelegate(), parameterIndex, value);
}
@Override
public void setCharacterStream(final int parameterIndex, final Reader value, final int length) throws SQLException {
- accept(PreparedStatement::setCharacterStream, getDelegatePreparedStatement(), parameterIndex, value, length);
+ accept(S::setCharacterStream, getDelegate(), parameterIndex, value, length);
}
@Override
public void setCharacterStream(final int parameterIndex, final Reader value, final long length)
throws SQLException {
- accept(PreparedStatement::setCharacterStream, getDelegatePreparedStatement(), parameterIndex, value, length);
+ accept(S::setCharacterStream, getDelegate(), parameterIndex, value, length);
}
@Override
public void setClob(final int parameterIndex, final Clob value) throws SQLException {
- accept(PreparedStatement::setClob, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setClob, getDelegate(), parameterIndex, value);
}
@Override
public void setClob(final int parameterIndex, final Reader value) throws SQLException {
- accept(PreparedStatement::setClob, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setClob, getDelegate(), parameterIndex, value);
}
@Override
public void setClob(final int parameterIndex, final Reader value, final long length) throws SQLException {
- accept(PreparedStatement::setClob, getDelegatePreparedStatement(), parameterIndex, value, length);
+ accept(S::setClob, getDelegate(), parameterIndex, value, length);
}
@Override
public void setDate(final int parameterIndex, final Date value) throws SQLException {
- accept(PreparedStatement::setDate, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setDate, getDelegate(), parameterIndex, value);
}
@Override
public void setDate(final int parameterIndex, final Date value, final Calendar calendar) throws SQLException {
- accept(PreparedStatement::setDate, getDelegatePreparedStatement(), parameterIndex, value, calendar);
+ accept(S::setDate, getDelegate(), parameterIndex, value, calendar);
}
@Override
public void setDouble(final int parameterIndex, final double value) throws SQLException {
- accept(PreparedStatement::setDouble, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setDouble, getDelegate(), parameterIndex, value);
}
@Override
public void setFloat(final int parameterIndex, final float value) throws SQLException {
- accept(PreparedStatement::setFloat, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setFloat, getDelegate(), parameterIndex, value);
}
@Override
public void setInt(final int parameterIndex, final int value) throws SQLException {
- accept(PreparedStatement::setInt, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setInt, getDelegate(), parameterIndex, value);
}
@Override
public void setLong(final int parameterIndex, final long value) throws SQLException {
- accept(PreparedStatement::setLong, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setLong, getDelegate(), parameterIndex, value);
}
@Override
public void setNCharacterStream(final int parameterIndex, final Reader value) throws SQLException {
- accept(PreparedStatement::setNCharacterStream, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setNCharacterStream, getDelegate(), parameterIndex, value);
}
@Override
public void setNCharacterStream(final int parameterIndex, final Reader value, final long length)
throws SQLException {
- accept(PreparedStatement::setNCharacterStream, getDelegatePreparedStatement(), parameterIndex, value, length);
+ accept(S::setNCharacterStream, getDelegate(), parameterIndex, value, length);
}
@Override
public void setNClob(final int parameterIndex, final NClob value) throws SQLException {
- accept(PreparedStatement::setNClob, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setNClob, getDelegate(), parameterIndex, value);
}
@Override
public void setNClob(final int parameterIndex, final Reader value) throws SQLException {
- accept(PreparedStatement::setNClob, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setNClob, getDelegate(), parameterIndex, value);
}
@Override
public void setNClob(final int parameterIndex, final Reader value, final long length) throws SQLException {
- accept(PreparedStatement::setNClob, getDelegatePreparedStatement(), parameterIndex, value, length);
+ accept(S::setNClob, getDelegate(), parameterIndex, value, length);
}
@Override
public void setNString(final int parameterIndex, final String value) throws SQLException {
- accept(PreparedStatement::setNString, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setNString, getDelegate(), parameterIndex, value);
}
@Override
public void setNull(final int parameterIndex, final int sqlType) throws SQLException {
- accept(PreparedStatement::setNull, getDelegatePreparedStatement(), parameterIndex, sqlType);
+ accept(S::setNull, getDelegate(), parameterIndex, sqlType);
}
@Override
public void setNull(final int parameterIndex, final int sqlType, final String typeName) throws SQLException {
- accept(PreparedStatement::setNull, getDelegatePreparedStatement(), parameterIndex, sqlType, typeName);
+ accept(S::setNull, getDelegate(), parameterIndex, sqlType, typeName);
}
@Override
public void setObject(final int parameterIndex, final Object value) throws SQLException {
- accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setObject, getDelegate(), parameterIndex, value);
}
@Override
public void setObject(final int parameterIndex, final Object value, final int targetSqlType) throws SQLException {
- accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value, targetSqlType);
+ accept(S::setObject, getDelegate(), parameterIndex, value, targetSqlType);
}
@Override
public void setObject(final int parameterIndex, final Object value, final int targetSqlType, final int scale)
throws SQLException {
- accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value, targetSqlType,
- scale);
+ accept(S::setObject, getDelegate(), parameterIndex, value, targetSqlType, scale);
}
/**
@@ -310,7 +307,7 @@ public void setObject(final int parameterIndex, final Object value, final int ta
@Override
public void setObject(final int parameterIndex, final Object value, final SQLType targetSqlType)
throws SQLException {
- accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value, targetSqlType);
+ accept(S::setObject, getDelegate(), parameterIndex, value, targetSqlType);
}
/**
@@ -319,54 +316,53 @@ public void setObject(final int parameterIndex, final Object value, final SQLTyp
@Override
public void setObject(final int parameterIndex, final Object value, final SQLType targetSqlType,
final int scaleOrLength) throws SQLException {
- accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value, targetSqlType,
- scaleOrLength);
+ accept(S::setObject, getDelegate(), parameterIndex, value, targetSqlType, scaleOrLength);
}
@Override
public void setRef(final int parameterIndex, final Ref value) throws SQLException {
- accept(PreparedStatement::setRef, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setRef, getDelegate(), parameterIndex, value);
}
@Override
public void setRowId(final int parameterIndex, final RowId value) throws SQLException {
- accept(PreparedStatement::setRowId, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setRowId, getDelegate(), parameterIndex, value);
}
@Override
public void setShort(final int parameterIndex, final short value) throws SQLException {
- accept(PreparedStatement::setShort, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setShort, getDelegate(), parameterIndex, value);
}
@Override
public void setSQLXML(final int parameterIndex, final SQLXML value) throws SQLException {
- accept(PreparedStatement::setSQLXML, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setSQLXML, getDelegate(), parameterIndex, value);
}
@Override
public void setString(final int parameterIndex, final String value) throws SQLException {
- accept(PreparedStatement::setString, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setString, getDelegate(), parameterIndex, value);
}
@Override
public void setTime(final int parameterIndex, final Time value) throws SQLException {
- accept(PreparedStatement::setTime, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setTime, getDelegate(), parameterIndex, value);
}
@Override
public void setTime(final int parameterIndex, final Time value, final Calendar calendar) throws SQLException {
- accept(PreparedStatement::setTime, getDelegatePreparedStatement(), parameterIndex, value, calendar);
+ accept(S::setTime, getDelegate(), parameterIndex, value, calendar);
}
@Override
public void setTimestamp(final int parameterIndex, final Timestamp value) throws SQLException {
- accept(PreparedStatement::setTimestamp, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setTimestamp, getDelegate(), parameterIndex, value);
}
@Override
public void setTimestamp(final int parameterIndex, final Timestamp value, final Calendar calendar)
throws SQLException {
- accept(PreparedStatement::setTimestamp, getDelegatePreparedStatement(), parameterIndex, value, calendar);
+ accept(S::setTimestamp, getDelegate(), parameterIndex, value, calendar);
}
/** @deprecated Use setAsciiStream(), setCharacterStream() or setNCharacterStream() */
@@ -374,12 +370,12 @@ public void setTimestamp(final int parameterIndex, final Timestamp value, final
@Override
public void setUnicodeStream(final int parameterIndex, final InputStream value, final int length)
throws SQLException {
- accept(PreparedStatement::setUnicodeStream, getDelegatePreparedStatement(), parameterIndex, value, length);
+ accept(S::setUnicodeStream, getDelegate(), parameterIndex, value, length);
}
@Override
public void setURL(final int parameterIndex, final java.net.URL value) throws SQLException {
- accept(PreparedStatement::setURL, getDelegatePreparedStatement(), parameterIndex, value);
+ accept(S::setURL, getDelegate(), parameterIndex, value);
}
/**
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java b/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java
index 875db1fc07..224927656c 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java
@@ -58,9 +58,8 @@ public final class DelegatingResultSet extends AbandonedTrace implements ResultS
/**
* Wraps the given result set in a delegate.
*
- * @param connection
- * The Connection which created the ResultSet.
- * @param resultSet The ResultSet to wrap.
+ * @param connection The Connection which created the ResultSet.
+ * @param resultSet The ResultSet to wrap.
* @return a new delegate.
*/
public static ResultSet wrapResultSet(final Connection connection, final ResultSet resultSet) {
@@ -101,7 +100,7 @@ public static ResultSet wrapResultSet(final Statement statement, final ResultSet
*
*
* @param conn Connection which created this ResultSet
- * @param res ResultSet to wrap
+ * @param res ResultSet to wrap
*/
private DelegatingResultSet(final Connection conn, final ResultSet res) {
super((AbandonedTrace) conn);
@@ -623,7 +622,7 @@ public SQLWarning getWarnings() throws SQLException {
@Override
protected void handleException(final SQLException e) throws SQLException {
if (statement != null && statement instanceof DelegatingStatement) {
- ((DelegatingStatement) statement).handleException(e);
+ ((DelegatingStatement>) statement).handleException(e);
} else if (connection != null && connection instanceof DelegatingConnection) {
((DelegatingConnection>) connection).handleException(e);
} else {
@@ -735,7 +734,7 @@ public void setFetchSize(final int rows) throws SQLException {
@Override
public synchronized String toString() {
return super.toString() + "[resultSet=" + resultSet + ", statement=" + statement + ", connection=" + connection
- + "]";
+ + "]";
}
@Override
@@ -771,7 +770,7 @@ public void updateAsciiStream(final int columnIndex, final InputStream x, final
@Override
public void updateAsciiStream(final int columnIndex, final InputStream inputStream, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateAsciiStream, columnIndex, inputStream, length);
}
@@ -787,7 +786,7 @@ public void updateAsciiStream(final String columnName, final InputStream x, fina
@Override
public void updateAsciiStream(final String columnLabel, final InputStream inputStream, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateAsciiStream, columnLabel, inputStream, length);
}
@@ -813,7 +812,7 @@ public void updateBinaryStream(final int columnIndex, final InputStream x, final
@Override
public void updateBinaryStream(final int columnIndex, final InputStream inputStream, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateBinaryStream, columnIndex, inputStream, length);
}
@@ -829,7 +828,7 @@ public void updateBinaryStream(final String columnName, final InputStream x, fin
@Override
public void updateBinaryStream(final String columnLabel, final InputStream inputStream, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateBinaryStream, columnLabel, inputStream, length);
}
@@ -845,7 +844,7 @@ public void updateBlob(final int columnIndex, final InputStream inputStream) thr
@Override
public void updateBlob(final int columnIndex, final InputStream inputStream, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateBlob, columnIndex, inputStream, length);
}
@@ -861,7 +860,7 @@ public void updateBlob(final String columnLabel, final InputStream inputStream)
@Override
public void updateBlob(final String columnLabel, final InputStream inputStream, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateBlob, columnLabel, inputStream, length);
}
@@ -907,7 +906,7 @@ public void updateCharacterStream(final int columnIndex, final Reader x, final i
@Override
public void updateCharacterStream(final int columnIndex, final Reader reader, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateCharacterStream, columnIndex, reader, length);
}
@@ -918,13 +917,13 @@ public void updateCharacterStream(final String columnLabel, final Reader reader)
@Override
public void updateCharacterStream(final String columnName, final Reader reader, final int length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateCharacterStream, columnName, reader, length);
}
@Override
public void updateCharacterStream(final String columnLabel, final Reader reader, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateCharacterStream, columnLabel, reader, length);
}
@@ -1015,7 +1014,7 @@ public void updateNCharacterStream(final int columnIndex, final Reader reader) t
@Override
public void updateNCharacterStream(final int columnIndex, final Reader reader, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateNCharacterStream, columnIndex, reader, length);
}
@@ -1026,7 +1025,7 @@ public void updateNCharacterStream(final String columnLabel, final Reader reader
@Override
public void updateNCharacterStream(final String columnLabel, final Reader reader, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateNCharacterStream, columnLabel, reader, length);
}
@@ -1103,7 +1102,7 @@ public void updateObject(final int columnIndex, final Object x, final SQLType ta
*/
@Override
public void updateObject(final int columnIndex, final Object x, final SQLType targetSqlType,
- final int scaleOrLength) throws SQLException {
+ final int scaleOrLength) throws SQLException {
accept(resultSet::updateObject, columnIndex, x, targetSqlType, scaleOrLength);
}
@@ -1122,7 +1121,7 @@ public void updateObject(final String columnName, final Object x, final int scal
*/
@Override
public void updateObject(final String columnLabel, final Object x, final SQLType targetSqlType)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateObject, columnLabel, x, targetSqlType);
}
@@ -1131,7 +1130,7 @@ public void updateObject(final String columnLabel, final Object x, final SQLType
*/
@Override
public void updateObject(final String columnLabel, final Object x, final SQLType targetSqlType,
- final int scaleOrLength) throws SQLException {
+ final int scaleOrLength) throws SQLException {
accept(resultSet::updateObject, columnLabel, x, targetSqlType, scaleOrLength);
}
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java b/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java
index 8059b97197..c2331fb7d2 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java
@@ -32,13 +32,15 @@
*
* 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.
+ *
+ * @param Statement or a sub-type.
*
* @since 2.0
*/
-public class DelegatingStatement extends AbandonedTrace implements Statement {
+public class DelegatingStatement extends AbandonedTrace implements Statement {
/** My delegate. */
- private Statement statement;
+ private S statement;
/** The connection that created me. **/
private DelegatingConnection> connection;
@@ -49,10 +51,10 @@ public class DelegatingStatement extends AbandonedTrace implements Statement {
* Create a wrapper for the Statement which traces this Statement to the Connection which created it and the code
* which created it.
*
- * @param statement the {@link Statement} to delegate all calls to.
+ * @param statement the {@link Statement} to delegate all calls to.
* @param connection the {@link DelegatingConnection} that created this statement.
*/
- public DelegatingStatement(final DelegatingConnection> connection, final Statement statement) {
+ public DelegatingStatement(final DelegatingConnection> connection, final S statement) {
super(connection);
this.statement = statement;
this.connection = connection;
@@ -65,18 +67,18 @@ public DelegatingStatement(final DelegatingConnection> connection, final State
*/
public void activate() throws SQLException {
if (statement instanceof DelegatingStatement) {
- ((DelegatingStatement) statement).activate();
+ ((DelegatingStatement>) statement).activate();
}
}
@Override
public void addBatch(final String sql) throws SQLException {
- accept(Statement::addBatch, statement, sql);
+ accept(S::addBatch, statement, sql);
}
@Override
public void cancel() throws SQLException {
- accept(Statement::cancel, statement);
+ accept(S::cancel, statement);
}
@Override
@@ -88,12 +90,12 @@ protected void checkOpen() throws SQLException {
@Override
public void clearBatch() throws SQLException {
- accept(Statement::clearBatch, statement);
+ accept(S::clearBatch, statement);
}
@Override
public void clearWarnings() throws SQLException {
- accept(Statement::clearWarnings, statement);
+ accept(S::clearWarnings, statement);
}
/**
@@ -161,27 +163,27 @@ public void closeOnCompletion() throws SQLException {
@Override
public boolean execute(final String sql) throws SQLException {
- return applyTo(Statement::execute, statement, sql, false);
+ return applyTo(S::execute, statement, sql, false);
}
@Override
public boolean execute(final String sql, final int autoGeneratedKeys) throws SQLException {
- return applyTo(Statement::execute, statement, sql, autoGeneratedKeys, false);
+ return applyTo(S::execute, statement, sql, autoGeneratedKeys, false);
}
@Override
public boolean execute(final String sql, final int columnIndexes[]) throws SQLException {
- return applyTo(Statement::execute, statement, sql, columnIndexes, false);
+ return applyTo(S::execute, statement, sql, columnIndexes, false);
}
@Override
public boolean execute(final String sql, final String columnNames[]) throws SQLException {
- return applyTo(Statement::execute, statement, sql, columnNames, false);
+ return applyTo(S::execute, statement, sql, columnNames, false);
}
@Override
public int[] executeBatch() throws SQLException {
- return apply(Statement::executeBatch, statement);
+ return apply(S::executeBatch, statement);
}
/**
@@ -189,7 +191,7 @@ public int[] executeBatch() throws SQLException {
*/
@Override
public long[] executeLargeBatch() throws SQLException {
- return apply(Statement::executeLargeBatch, statement);
+ return apply(S::executeLargeBatch, statement);
}
/**
@@ -197,7 +199,7 @@ public long[] executeLargeBatch() throws SQLException {
*/
@Override
public long executeLargeUpdate(final String sql) throws SQLException {
- return applyTo(Statement::executeLargeUpdate, statement, sql, 0L);
+ return applyTo(S::executeLargeUpdate, statement, sql, 0L);
}
/**
@@ -205,7 +207,7 @@ public long executeLargeUpdate(final String sql) throws SQLException {
*/
@Override
public long executeLargeUpdate(final String sql, final int autoGeneratedKeys) throws SQLException {
- return applyTo(Statement::executeLargeUpdate, statement, sql, autoGeneratedKeys, 0L);
+ return applyTo(S::executeLargeUpdate, statement, sql, autoGeneratedKeys, 0L);
}
/**
@@ -213,7 +215,7 @@ public long executeLargeUpdate(final String sql, final int autoGeneratedKeys) th
*/
@Override
public long executeLargeUpdate(final String sql, final int[] columnIndexes) throws SQLException {
- return applyTo(Statement::executeLargeUpdate, statement, sql, columnIndexes, 0L);
+ return applyTo(S::executeLargeUpdate, statement, sql, columnIndexes, 0L);
}
/**
@@ -221,7 +223,7 @@ public long executeLargeUpdate(final String sql, final int[] columnIndexes) thro
*/
@Override
public long executeLargeUpdate(final String sql, final String[] columnNames) throws SQLException {
- return applyTo(Statement::executeLargeUpdate, statement, sql, columnNames, 0L);
+ return applyTo(S::executeLargeUpdate, statement, sql, columnNames, 0L);
}
@Override
@@ -231,22 +233,22 @@ public ResultSet executeQuery(final String sql) throws SQLException {
@Override
public int executeUpdate(final String sql) throws SQLException {
- return applyTo(Statement::executeUpdate, statement, sql, 0);
+ return applyTo(S::executeUpdate, statement, sql, 0);
}
@Override
public int executeUpdate(final String sql, final int autoGeneratedKeys) throws SQLException {
- return applyTo(Statement::executeUpdate, statement, sql, autoGeneratedKeys, 0);
+ return applyTo(S::executeUpdate, statement, sql, autoGeneratedKeys, 0);
}
@Override
public int executeUpdate(final String sql, final int columnIndexes[]) throws SQLException {
- return applyTo(Statement::executeUpdate, statement, sql, columnIndexes, 0);
+ return applyTo(S::executeUpdate, statement, sql, columnIndexes, 0);
}
@Override
public int executeUpdate(final String sql, final String columnNames[]) throws SQLException {
- return applyTo(Statement::executeUpdate, statement, sql, columnNames, 0);
+ return applyTo(S::executeUpdate, statement, sql, columnNames, 0);
}
@Override
@@ -279,18 +281,18 @@ protected DelegatingConnection> getConnectionInternal() {
* @return my underlying {@link Statement}.
* @see #getInnermostDelegate
*/
- public Statement getDelegate() {
+ public S getDelegate() {
return statement;
}
@Override
public int getFetchDirection() throws SQLException {
- return applyTo(Statement::getFetchDirection, statement, 0);
+ return applyTo(S::getFetchDirection, statement, 0);
}
@Override
public int getFetchSize() throws SQLException {
- return applyTo(Statement::getFetchSize, statement, 0);
+ return applyTo(S::getFetchSize, statement, 0);
}
@Override
@@ -315,10 +317,10 @@ public ResultSet getGeneratedKeys() throws SQLException {
* @see #getDelegate
*/
@SuppressWarnings("resource")
- public Statement getInnermostDelegate() {
- Statement s = statement;
- while (s != null && s instanceof DelegatingStatement) {
- s = ((DelegatingStatement) s).getDelegate();
+ public S getInnermostDelegate() {
+ S s = statement;
+ while (s instanceof DelegatingStatement) {
+ s = ((DelegatingStatement) s).getDelegate();
if (this == s) {
return null;
}
@@ -331,7 +333,7 @@ public Statement getInnermostDelegate() {
*/
@Override
public long getLargeMaxRows() throws SQLException {
- return applyTo(Statement::getLargeMaxRows, statement, 0L);
+ return applyTo(S::getLargeMaxRows, statement, 0L);
}
/**
@@ -339,32 +341,32 @@ public long getLargeMaxRows() throws SQLException {
*/
@Override
public long getLargeUpdateCount() throws SQLException {
- return applyTo(Statement::getLargeUpdateCount, statement, 0L);
+ return applyTo(S::getLargeUpdateCount, statement, 0L);
}
@Override
public int getMaxFieldSize() throws SQLException {
- return applyTo(Statement::getMaxFieldSize, statement, 0);
+ return applyTo(S::getMaxFieldSize, statement, 0);
}
@Override
public int getMaxRows() throws SQLException {
- return applyTo(Statement::getMaxRows, statement, 0);
+ return applyTo(S::getMaxRows, statement, 0);
}
@Override
public boolean getMoreResults() throws SQLException {
- return applyTo(Statement::getMoreResults, statement, false);
+ return applyTo(S::getMoreResults, statement, false);
}
@Override
public boolean getMoreResults(final int current) throws SQLException {
- return applyTo(Statement::getMoreResults, statement, current, false);
+ return applyTo(S::getMoreResults, statement, current, false);
}
@Override
public int getQueryTimeout() throws SQLException {
- return applyTo(Statement::getQueryTimeout, statement, 0);
+ return applyTo(S::getQueryTimeout, statement, 0);
}
@Override
@@ -374,27 +376,27 @@ public ResultSet getResultSet() throws SQLException {
@Override
public int getResultSetConcurrency() throws SQLException {
- return applyTo(Statement::getResultSetConcurrency, statement, 0);
+ return applyTo(S::getResultSetConcurrency, statement, 0);
}
@Override
public int getResultSetHoldability() throws SQLException {
- return applyTo(Statement::getResultSetHoldability, statement, 0);
+ return applyTo(S::getResultSetHoldability, statement, 0);
}
@Override
public int getResultSetType() throws SQLException {
- return applyTo(Statement::getResultSetType, statement, 0);
+ return applyTo(S::getResultSetType, statement, 0);
}
@Override
public int getUpdateCount() throws SQLException {
- return applyTo(Statement::getUpdateCount, statement, 0);
+ return applyTo(S::getUpdateCount, statement, 0);
}
@Override
public SQLWarning getWarnings() throws SQLException {
- return apply(Statement::getWarnings, statement);
+ return apply(S::getWarnings, statement);
}
@Override
@@ -425,7 +427,7 @@ public boolean isCloseOnCompletion() throws SQLException {
@Override
public boolean isPoolable() throws SQLException {
- return applyTo(Statement::isPoolable, statement, false);
+ return applyTo(S::isPoolable, statement, false);
}
@Override
@@ -446,7 +448,7 @@ public boolean isWrapperFor(final Class> iface) throws SQLException {
*/
public void passivate() throws SQLException {
if (statement instanceof DelegatingStatement) {
- ((DelegatingStatement) statement).passivate();
+ ((DelegatingStatement>) statement).passivate();
}
}
@@ -456,7 +458,7 @@ protected void setClosedInternal(final boolean closed) {
@Override
public void setCursorName(final String name) throws SQLException {
- accept(Statement::setCursorName, statement, name);
+ accept(S::setCursorName, statement, name);
}
/**
@@ -464,23 +466,23 @@ public void setCursorName(final String name) throws SQLException {
*
* @param statement my delegate.
*/
- public void setDelegate(final Statement statement) {
+ public void setDelegate(final S statement) {
this.statement = statement;
}
@Override
public void setEscapeProcessing(final boolean enable) throws SQLException {
- accept(Statement::setEscapeProcessing, statement, enable);
+ accept(S::setEscapeProcessing, statement, enable);
}
@Override
public void setFetchDirection(final int direction) throws SQLException {
- accept(Statement::setFetchDirection, statement, direction);
+ accept(S::setFetchDirection, statement, direction);
}
@Override
public void setFetchSize(final int rows) throws SQLException {
- accept(Statement::setFetchSize, statement, rows);
+ accept(S::setFetchSize, statement, rows);
}
/**
@@ -488,7 +490,7 @@ public void setFetchSize(final int rows) throws SQLException {
*/
@Override
public void setLargeMaxRows(final long max) throws SQLException {
- accept(Statement::setLargeMaxRows, statement, max);
+ accept(S::setLargeMaxRows, statement, max);
}
@Override
@@ -500,22 +502,22 @@ protected void markUse() {
@Override
public void setMaxFieldSize(final int max) throws SQLException {
- accept(Statement::setMaxFieldSize, statement, max);
+ accept(S::setMaxFieldSize, statement, max);
}
@Override
public void setMaxRows(final int max) throws SQLException {
- accept(Statement::setMaxRows, statement, max);
+ accept(S::setMaxRows, statement, max);
}
@Override
public void setPoolable(final boolean poolable) throws SQLException {
- accept(Statement::setPoolable, statement, poolable);
+ accept(S::setPoolable, statement, poolable);
}
@Override
public void setQueryTimeout(final int seconds) throws SQLException {
- accept(Statement::setQueryTimeout, statement, seconds);
+ accept(S::setQueryTimeout, statement, seconds);
}
/**
diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java b/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java
index c161f3b5a3..1b0125edbb 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java
@@ -31,16 +31,18 @@
* {@link CallableStatement}s.
*
* The {@link #close} method returns this statement to its containing pool. (See {@link PoolingConnection}.)
+ *
*
+ * @param CallableStatement or a sub-type.
* @see PoolingConnection
* @since 2.0
*/
-public class PoolableCallableStatement extends DelegatingCallableStatement {
+public class PoolableCallableStatement extends DelegatingCallableStatement {
/**
* The {@link KeyedObjectPool} from which this CallableStatement was obtained.
*/
- private final KeyedObjectPool pool;
+ private final KeyedObjectPool> pool;
/**
* Key for this statement in the containing {@link KeyedObjectPool}.
@@ -59,8 +61,8 @@ public class PoolableCallableStatement extends DelegatingCallableStatement {
* @param connection
* the {@link DelegatingConnection} that created this CallableStatement
*/
- public PoolableCallableStatement(final CallableStatement callableStatement, final PStmtKey key,
- final KeyedObjectPool pool,
+ public PoolableCallableStatement(final S callableStatement, final PStmtKey key,
+ final KeyedObjectPool> pool,
final DelegatingConnection connection) {
super(connection, callableStatement);
this.pool = pool;
diff --git a/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java b/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
index 23c8c6b989..6058cf050c 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
@@ -38,7 +38,7 @@
* @see PoolingConnection
* @since 2.0
*/
-public class PoolablePreparedStatement extends DelegatingPreparedStatement {
+public class PoolablePreparedStatement extends DelegatingPreparedStatement {
/**
* The {@link KeyedObjectPool} from which I was obtained.
diff --git a/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java b/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
index 9ddbffe0fe..7e8131d525 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
@@ -41,8 +41,8 @@
* @see PoolablePreparedStatement
* @since 2.0
*/
-public class PoolingConnection extends DelegatingConnection
- implements KeyedPooledObjectFactory {
+public class PoolingConnection extends DelegatingConnection
+ implements KeyedPooledObjectFactory> {
/**
* Statement types.
@@ -64,7 +64,7 @@ public enum StatementType {
}
/** Pool of {@link PreparedStatement}s. and {@link CallableStatement}s */
- private KeyedObjectPool pStmtPool;
+ private KeyedObjectPool> pStmtPool;
/**
* Constructor.
@@ -85,7 +85,7 @@ public PoolingConnection(final Connection connection) {
* wrapped pooled statement to be activated
*/
@Override
- public void activateObject(final PStmtKey key, final PooledObject pooledObject)
+ public void activateObject(final PStmtKey key, final PooledObject> pooledObject)
throws Exception {
pooledObject.getObject().activate();
}
@@ -98,7 +98,7 @@ public void activateObject(final PStmtKey key, final PooledObject oldpool = pStmtPool;
+ final KeyedObjectPool> oldpool = pStmtPool;
pStmtPool = null;
try {
oldpool.close();
@@ -262,7 +262,7 @@ protected PStmtKey createKey(final String sql, final String columnNames[]) {
* the wrapped pooled statement to be destroyed.
*/
@Override
- public void destroyObject(final PStmtKey key, final PooledObject pooledObject)
+ public void destroyObject(final PStmtKey key, final PooledObject> pooledObject)
throws Exception {
pooledObject.getObject().getInnermostDelegate().close();
}
@@ -298,7 +298,7 @@ private String getSchemaOrNull() {
*/
@SuppressWarnings("resource")
@Override
- public PooledObject makeObject(final PStmtKey key) throws Exception {
+ public PooledObject> makeObject(final PStmtKey key) throws Exception {
if (null == key) {
throw new IllegalArgumentException("Prepared statement key is null or invalid.");
}
@@ -334,7 +334,7 @@ protected String normalizeSQL(final String sql) {
* a wrapped {@link PreparedStatement}
*/
@Override
- public void passivateObject(final PStmtKey key, final PooledObject pooledObject)
+ public void passivateObject(final PStmtKey key, final PooledObject> pooledObject)
throws Exception {
@SuppressWarnings("resource")
final DelegatingPreparedStatement dps = pooledObject.getObject();
@@ -505,7 +505,7 @@ public PreparedStatement prepareStatement(final String sql, final String columnN
* @param pool
* the prepared statement pool.
*/
- public void setStatementPool(final KeyedObjectPool pool) {
+ public void setStatementPool(final KeyedObjectPool> pool) {
pStmtPool = pool;
}
@@ -527,7 +527,7 @@ public synchronized String toString() {
* @return {@code true}
*/
@Override
- public boolean validateObject(final PStmtKey key, final PooledObject pooledObject) {
+ public boolean validateObject(final PStmtKey key, final PooledObject> pooledObject) {
return true;
}
}
diff --git a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/ConnectionImpl.java b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/ConnectionImpl.java
index 9ac586043c..b9138d6440 100644
--- a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/ConnectionImpl.java
+++ b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/ConnectionImpl.java
@@ -48,15 +48,12 @@ class ConnectionImpl extends DelegatingConnection {
/**
* Creates a ConnectionImpl.
*
- * @param pooledConnection
- * The PooledConnection that is calling the ctor.
- * @param connection
- * The JDBC 1.x Connection to wrap.
- * @param accessToUnderlyingConnectionAllowed
- * if true, then access is allowed to the underlying connection
+ * @param pooledConnection The PooledConnection that is calling the ctor.
+ * @param connection The JDBC 1.x Connection to wrap.
+ * @param accessToUnderlyingConnectionAllowed if true, then access is allowed to the underlying connection
*/
ConnectionImpl(final PooledConnectionImpl pooledConnection, final Connection connection,
- final boolean accessToUnderlyingConnectionAllowed) {
+ final boolean accessToUnderlyingConnectionAllowed) {
super(connection);
this.pooledConnection = pooledConnection;
this.accessToUnderlyingConnectionAllowed = accessToUnderlyingConnectionAllowed;
@@ -69,8 +66,7 @@ class ConnectionImpl extends DelegatingConnection {
* usage will result in an SQLException.
*
*
- * @throws SQLException
- * The database connection couldn't be closed.
+ * @throws SQLException The database connection couldn't be closed.
*/
@Override
public void close() throws SQLException {
@@ -88,126 +84,120 @@ public void close() throws SQLException {
* If pooling of CallableStatements is turned on in the {@link DriverAdapterCPDS}, a pooled object may
* be returned, otherwise delegate to the wrapped JDBC 1.x {@link java.sql.Connection}.
*
- * @param sql
- * an SQL statement that may contain one or more '?' parameter placeholders. Typically this statement is
+ * @param sql an SQL statement that may contain one or more '?' parameter placeholders. Typically this statement is
* specified using JDBC call escape syntax.
* @return a default CallableStatement object containing the pre-compiled SQL statement.
- * @exception SQLException
- * Thrown if a database access error occurs or this method is called on a closed connection.
+ * @exception SQLException Thrown if a database access error occurs or this method is called on a closed connection.
* @since 2.4.0
*/
@Override
public CallableStatement prepareCall(final String sql) throws SQLException {
- return apply(() -> new DelegatingCallableStatement(this, pooledConnection.prepareCall(sql)) );
+ return apply(() -> new DelegatingCallableStatement<>(this, pooledConnection.prepareCall(sql)));
}
/**
* If pooling of CallableStatements is turned on in the {@link DriverAdapterCPDS}, a pooled object may
* be returned, otherwise delegate to the wrapped JDBC 1.x {@link java.sql.Connection}.
*
- * @param sql
- * a String object that is the SQL statement to be sent to the database; may contain on or
- * more '?' parameters.
- * @param resultSetType
- * a result set type; one of ResultSet.TYPE_FORWARD_ONLY,
- * ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE.
- * @param resultSetConcurrency
- * a concurrency type; one of ResultSet.CONCUR_READ_ONLY or
- * ResultSet.CONCUR_UPDATABLE.
+ * @param sql a String object that is the SQL statement to be sent to the database;
+ * may contain on or more '?' parameters.
+ * @param resultSetType a result set type; one of ResultSet.TYPE_FORWARD_ONLY,
+ * ResultSet.TYPE_SCROLL_INSENSITIVE, or
+ * ResultSet.TYPE_SCROLL_SENSITIVE.
+ * @param resultSetConcurrency a concurrency type; one of ResultSet.CONCUR_READ_ONLY or
+ * ResultSet.CONCUR_UPDATABLE.
* @return a CallableStatement object containing the pre-compiled SQL statement that will produce
* ResultSet objects with the given type and concurrency.
- * @throws SQLException
- * Thrown if a database access error occurs, this method is called on a closed connection or the given
- * parameters are not ResultSet constants indicating type and concurrency.
+ * @throws SQLException Thrown if a database access error occurs, this method is called on a closed connection or
+ * the given parameters are not ResultSet constants indicating type and
+ * concurrency.
* @since 2.4.0
*/
@Override
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency)
- throws SQLException {
- return apply(() -> new DelegatingCallableStatement(this,
- pooledConnection.prepareCall(sql, resultSetType, resultSetConcurrency)));
+ throws SQLException {
+ return apply(() -> new DelegatingCallableStatement<>(this,
+ pooledConnection.prepareCall(sql, resultSetType, resultSetConcurrency)));
}
/**
* If pooling of CallableStatements is turned on in the {@link DriverAdapterCPDS}, a pooled object may
* be returned, otherwise delegate to the wrapped JDBC 1.x {@link java.sql.Connection}.
*
- * @param sql
- * a String object that is the SQL statement to be sent to the database; may contain on or
- * more '?' parameters.
- * @param resultSetType
- * one of the following ResultSet constants: ResultSet.TYPE_FORWARD_ONLY,
- * ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE.
- * @param resultSetConcurrency
- * one of the following ResultSet constants: ResultSet.CONCUR_READ_ONLY or
- * ResultSet.CONCUR_UPDATABLE.
- * @param resultSetHoldability
- * one of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT
- * or ResultSet.CLOSE_CURSORS_AT_COMMIT.
+ * @param sql a String object that is the SQL statement to be sent to the database;
+ * may contain on or more '?' parameters.
+ * @param resultSetType one of the following ResultSet constants:
+ * ResultSet.TYPE_FORWARD_ONLY,
+ * ResultSet.TYPE_SCROLL_INSENSITIVE, or
+ * ResultSet.TYPE_SCROLL_SENSITIVE.
+ * @param resultSetConcurrency one of the following ResultSet constants:
+ * ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE.
+ * @param resultSetHoldability one of the following ResultSet constants:
+ * ResultSet.HOLD_CURSORS_OVER_COMMIT or
+ * ResultSet.CLOSE_CURSORS_AT_COMMIT.
* @return a new CallableStatement object, containing the pre-compiled SQL statement, that will
* generate ResultSet objects with the given type, concurrency, and holdability.
- * @throws SQLException
- * Thrown if a database access error occurs, this method is called on a closed connection or the given
- * parameters are not ResultSet constants indicating type, concurrency, and holdability.
+ * @throws SQLException Thrown if a database access error occurs, this method is called on a closed connection or
+ * the given parameters are not ResultSet constants indicating type, concurrency,
+ * and holdability.
* @since 2.4.0
*/
@Override
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency,
- final int resultSetHoldability) throws SQLException {
- return apply(() -> new DelegatingCallableStatement(this,
- pooledConnection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability)));
+ final int resultSetHoldability) throws SQLException {
+ return apply(() -> new DelegatingCallableStatement<>(this,
+ pooledConnection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability)));
}
/**
* If pooling of PreparedStatements is turned on in the {@link DriverAdapterCPDS}, a pooled object may
* be returned, otherwise delegate to the wrapped JDBC 1.x {@link java.sql.Connection}.
*
- * @param sql
- * SQL statement to be prepared
+ * @param sql SQL statement to be prepared
* @return the prepared statement
- * @throws SQLException
- * if this connection is closed or an error occurs in the wrapped connection.
+ * @throws SQLException if this connection is closed or an error occurs in the wrapped connection.
*/
@Override
public PreparedStatement prepareStatement(final String sql) throws SQLException {
- return apply(() -> new DelegatingPreparedStatement(this, pooledConnection.prepareStatement(sql)));
+ return apply(() -> new DelegatingPreparedStatement<>(this, pooledConnection.prepareStatement(sql)));
}
/**
* If pooling of PreparedStatements is turned on in the {@link DriverAdapterCPDS}, a pooled object may
* be returned, otherwise delegate to the wrapped JDBC 1.x {@link java.sql.Connection}.
*
- * @throws SQLException
- * if this connection is closed or an error occurs in the wrapped connection.
+ * @throws SQLException if this connection is closed or an error occurs in the wrapped connection.
*/
@Override
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency)
- throws SQLException {
- return apply(() -> new DelegatingPreparedStatement(this,
- pooledConnection.prepareStatement(sql, resultSetType, resultSetConcurrency)));
+ throws SQLException {
+ return apply(() -> new DelegatingPreparedStatement<>(this,
+ pooledConnection.prepareStatement(sql, resultSetType, resultSetConcurrency)));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency,
- final int resultSetHoldability) throws SQLException {
- return apply(() -> new DelegatingPreparedStatement(this,
- pooledConnection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability)));
+ final int resultSetHoldability) throws SQLException {
+ return apply(() -> new DelegatingPreparedStatement<>(this,
+ pooledConnection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability)));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException {
return apply(
- () -> new DelegatingPreparedStatement(this, pooledConnection.prepareStatement(sql, autoGeneratedKeys)));
+ () -> new DelegatingPreparedStatement<>(this, pooledConnection.prepareStatement(sql, autoGeneratedKeys)));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int columnIndexes[]) throws SQLException {
- return apply(() -> new DelegatingPreparedStatement(this, pooledConnection.prepareStatement(sql, columnIndexes)));
+ return apply(
+ () -> new DelegatingPreparedStatement<>(this, pooledConnection.prepareStatement(sql, columnIndexes)));
}
@Override
public PreparedStatement prepareStatement(final String sql, final String columnNames[]) throws SQLException {
- return apply(() -> new DelegatingPreparedStatement(this, pooledConnection.prepareStatement(sql, columnNames)));
+ return apply(
+ () -> new DelegatingPreparedStatement<>(this, pooledConnection.prepareStatement(sql, columnNames)));
}
//
From 4d4bfe72175ddaafad6e4dc089c7b72b27cf2b25 Mon Sep 17 00:00:00 2001
From: Gary Gregory
Date: Thu, 29 Aug 2019 08:54:35 -0400
Subject: [PATCH 9/9] Revert "Use generics instead of type casts. Also use
generics in ::."
This reverts commit 2075df0f562f356c4bb94bdac531339bda65ae02.
---
.../dbcp2/DelegatingCallableStatement.java | 296 +++++++++---------
.../commons/dbcp2/DelegatingConnection.java | 29 +-
.../dbcp2/DelegatingPreparedStatement.java | 128 ++++----
.../commons/dbcp2/DelegatingResultSet.java | 39 +--
.../commons/dbcp2/DelegatingStatement.java | 110 ++++---
.../dbcp2/PoolableCallableStatement.java | 10 +-
.../dbcp2/PoolablePreparedStatement.java | 2 +-
.../commons/dbcp2/PoolingConnection.java | 20 +-
.../dbcp2/cpdsadapter/ConnectionImpl.java | 116 +++----
9 files changed, 384 insertions(+), 366 deletions(-)
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingCallableStatement.java b/src/main/java/org/apache/commons/dbcp2/DelegatingCallableStatement.java
index 2fccad0415..2ac88526ea 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingCallableStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingCallableStatement.java
@@ -48,210 +48,212 @@
* Statement ensures that the Connection which created it can close any open Statement's on Connection close.
*
*
- * @param CallableStatement or a sub-type.
* @since 2.0
*/
-public class DelegatingCallableStatement extends DelegatingPreparedStatement
- implements CallableStatement {
+public class DelegatingCallableStatement extends DelegatingPreparedStatement implements CallableStatement {
/**
* Creates a wrapper for the Statement which traces this Statement to the Connection which created it and the code
* which created it.
*
* @param connection the {@link DelegatingConnection} that created this statement
- * @param statement the {@link CallableStatement} to delegate all calls to
+ * @param statement the {@link CallableStatement} to delegate all calls to
*/
- public DelegatingCallableStatement(final DelegatingConnection> connection, final S statement) {
+ public DelegatingCallableStatement(final DelegatingConnection> connection, final CallableStatement statement) {
super(connection, statement);
}
@Override
public Array getArray(final int parameterIndex) throws SQLException {
- return apply(S::getArray, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getArray, getDelegateCallableStatement(), parameterIndex);
}
@Override
public Array getArray(final String parameterName) throws SQLException {
- return apply(S::getArray, getDelegate(), parameterName);
+ return apply(CallableStatement::getArray, getDelegateCallableStatement(), parameterName);
}
@Override
public BigDecimal getBigDecimal(final int parameterIndex) throws SQLException {
- return apply(S::getBigDecimal, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getBigDecimal, getDelegateCallableStatement(), parameterIndex);
}
/** @deprecated Use {@link #getBigDecimal(int)} or {@link #getBigDecimal(String)} */
@Override
@Deprecated
public BigDecimal getBigDecimal(final int parameterIndex, final int scale) throws SQLException {
- return apply(S::getBigDecimal, getDelegate(), parameterIndex, scale);
+ return apply(CallableStatement::getBigDecimal, getDelegateCallableStatement(), parameterIndex, scale);
}
@Override
public BigDecimal getBigDecimal(final String parameterName) throws SQLException {
- return apply(S::getBigDecimal, getDelegate(), parameterName);
+ return apply(CallableStatement::getBigDecimal, getDelegateCallableStatement(), parameterName);
}
@Override
public Blob getBlob(final int parameterIndex) throws SQLException {
- return apply(S::getBlob, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getBlob, getDelegateCallableStatement(), parameterIndex);
}
@Override
public Blob getBlob(final String parameterName) throws SQLException {
- return apply(S::getBlob, getDelegate(), parameterName);
+ return apply(CallableStatement::getBlob, getDelegateCallableStatement(), parameterName);
}
@Override
public boolean getBoolean(final int parameterIndex) throws SQLException {
- return applyTo(S::getBoolean, getDelegate(), parameterIndex, false);
+ return applyTo(CallableStatement::getBoolean, getDelegateCallableStatement(), parameterIndex, false);
}
@Override
public boolean getBoolean(final String parameterName) throws SQLException {
- return applyTo(S::getBoolean, getDelegate(), parameterName, false);
+ return applyTo(CallableStatement::getBoolean, getDelegateCallableStatement(), parameterName, false);
}
@Override
public byte getByte(final int parameterIndex) throws SQLException {
- return applyTo(S::getByte, getDelegate(), parameterIndex, (byte) 0);
+ return applyTo(CallableStatement::getByte, getDelegateCallableStatement(), parameterIndex, (byte) 0);
}
@Override
public byte getByte(final String parameterName) throws SQLException {
- return applyTo(S::getByte, getDelegate(), parameterName, (byte) 0);
+ return applyTo(CallableStatement::getByte, getDelegateCallableStatement(), parameterName, (byte) 0);
}
@Override
public byte[] getBytes(final int parameterIndex) throws SQLException {
- return apply(S::getBytes, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getBytes, getDelegateCallableStatement(), parameterIndex);
}
@Override
public byte[] getBytes(final String parameterName) throws SQLException {
- return apply(S::getBytes, getDelegate(), parameterName);
+ return apply(CallableStatement::getBytes, getDelegateCallableStatement(), parameterName);
}
@Override
public Reader getCharacterStream(final int parameterIndex) throws SQLException {
- return apply(S::getCharacterStream, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getCharacterStream, getDelegateCallableStatement(), parameterIndex);
}
@Override
public Reader getCharacterStream(final String parameterName) throws SQLException {
- return apply(S::getCharacterStream, getDelegate(), parameterName);
+ return apply(CallableStatement::getCharacterStream, getDelegateCallableStatement(), parameterName);
}
@Override
public Clob getClob(final int parameterIndex) throws SQLException {
- return apply(S::getClob, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getClob, getDelegateCallableStatement(), parameterIndex);
}
@Override
public Clob getClob(final String parameterName) throws SQLException {
- return apply(S::getClob, getDelegate(), parameterName);
+ return apply(CallableStatement::getClob, getDelegateCallableStatement(), parameterName);
}
@Override
public Date getDate(final int parameterIndex) throws SQLException {
- return apply(S::getDate, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getDate, getDelegateCallableStatement(), parameterIndex);
}
@Override
public Date getDate(final int parameterIndex, final Calendar cal) throws SQLException {
- return apply(S::getDate, getDelegate(), parameterIndex, cal);
+ return apply(CallableStatement::getDate, getDelegateCallableStatement(), parameterIndex, cal);
}
@Override
public Date getDate(final String parameterName) throws SQLException {
- return apply(S::getDate, getDelegate(), parameterName);
+ return apply(CallableStatement::getDate, getDelegateCallableStatement(), parameterName);
}
@Override
public Date getDate(final String parameterName, final Calendar cal) throws SQLException {
- return apply(S::getDate, getDelegate(), parameterName, cal);
+ return apply(CallableStatement::getDate, getDelegateCallableStatement(), parameterName, cal);
+ }
+
+ private CallableStatement getDelegateCallableStatement() {
+ return (CallableStatement) getDelegate();
}
@Override
public double getDouble(final int parameterIndex) throws SQLException {
- return applyTo(S::getDouble, getDelegate(), parameterIndex, 0d);
+ return applyTo(CallableStatement::getDouble, getDelegateCallableStatement(), parameterIndex, 0d);
}
@Override
public double getDouble(final String parameterName) throws SQLException {
- return applyTo(S::getDouble, getDelegate(), parameterName, 0d);
+ return applyTo(CallableStatement::getDouble, getDelegateCallableStatement(), parameterName, 0d);
}
@Override
public float getFloat(final int parameterIndex) throws SQLException {
- return applyTo(S::getFloat, getDelegate(), parameterIndex, 0f);
+ return applyTo(CallableStatement::getFloat, getDelegateCallableStatement(), parameterIndex, 0f);
}
@Override
public float getFloat(final String parameterName) throws SQLException {
- return applyTo(S::getFloat, getDelegate(), parameterName, 0f);
+ return applyTo(CallableStatement::getFloat, getDelegateCallableStatement(), parameterName, 0f);
}
@Override
public int getInt(final int parameterIndex) throws SQLException {
- return applyTo(S::getInt, getDelegate(), parameterIndex, 0);
+ return applyTo(CallableStatement::getInt, getDelegateCallableStatement(), parameterIndex, 0);
}
@Override
public int getInt(final String parameterName) throws SQLException {
- return applyTo(S::getInt, getDelegate(), parameterName, 0);
+ return applyTo(CallableStatement::getInt, getDelegateCallableStatement(), parameterName, 0);
}
@Override
public long getLong(final int parameterIndex) throws SQLException {
- return applyTo(S::getLong, getDelegate(), parameterIndex, 0L);
+ return applyTo(CallableStatement::getLong, getDelegateCallableStatement(), parameterIndex, 0L);
}
@Override
public long getLong(final String parameterName) throws SQLException {
- return applyTo(S::getLong, getDelegate(), parameterName, 0L);
+ return applyTo(CallableStatement::getLong, getDelegateCallableStatement(), parameterName, 0L);
}
@Override
public Reader getNCharacterStream(final int parameterIndex) throws SQLException {
- return apply(S::getNCharacterStream, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getNCharacterStream, getDelegateCallableStatement(), parameterIndex);
}
@Override
public Reader getNCharacterStream(final String parameterName) throws SQLException {
- return apply(S::getNCharacterStream, getDelegate(), parameterName);
+ return apply(CallableStatement::getNCharacterStream, getDelegateCallableStatement(), parameterName);
}
@Override
public NClob getNClob(final int parameterIndex) throws SQLException {
- return apply(S::getNClob, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getNClob, getDelegateCallableStatement(), parameterIndex);
}
@Override
public NClob getNClob(final String parameterName) throws SQLException {
- return apply(S::getNClob, getDelegate(), parameterName);
+ return apply(CallableStatement::getNClob, getDelegateCallableStatement(), parameterName);
}
@Override
public String getNString(final int parameterIndex) throws SQLException {
- return apply(S::getNString, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getNString, getDelegateCallableStatement(), parameterIndex);
}
@Override
public String getNString(final String parameterName) throws SQLException {
- return apply(S::getNString, getDelegate(), parameterName);
+ return apply(CallableStatement::getNString, getDelegateCallableStatement(), parameterName);
}
@Override
public Object getObject(final int parameterIndex) throws SQLException {
- return apply(S::getObject, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getObject, getDelegateCallableStatement(), parameterIndex);
}
@Override
public T getObject(final int parameterIndex, final Class type) throws SQLException {
checkOpen();
try {
- return getDelegate().getObject(parameterIndex, type);
+ return getDelegateCallableStatement().getObject(parameterIndex, type);
} catch (final SQLException e) {
handleException(e);
return null;
@@ -260,19 +262,19 @@ public T getObject(final int parameterIndex, final Class type) throws SQL
@Override
public Object getObject(final int parameterIndex, final Map> map) throws SQLException {
- return apply(S::getObject, getDelegate(), parameterIndex, map);
+ return apply(CallableStatement::getObject, getDelegateCallableStatement(), parameterIndex, map);
}
@Override
public Object getObject(final String parameterName) throws SQLException {
- return apply(S::getObject, getDelegate(), parameterName);
+ return apply(CallableStatement::getObject, getDelegateCallableStatement(), parameterName);
}
@Override
public T getObject(final String parameterName, final Class type) throws SQLException {
checkOpen();
try {
- return getDelegate().getObject(parameterName, type);
+ return getDelegateCallableStatement().getObject(parameterName, type);
} catch (final SQLException e) {
handleException(e);
return null;
@@ -283,7 +285,7 @@ public T getObject(final String parameterName, final Class type) throws S
public Object getObject(final String parameterName, final Map> map) throws SQLException {
checkOpen();
try {
- return getDelegate().getObject(parameterName, map);
+ return getDelegateCallableStatement().getObject(parameterName, map);
} catch (final SQLException e) {
handleException(e);
return null;
@@ -292,118 +294,119 @@ public Object getObject(final String parameterName, final Map>
@Override
public Ref getRef(final int parameterIndex) throws SQLException {
- return apply(S::getRef, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getRef, getDelegateCallableStatement(), parameterIndex);
}
@Override
public Ref getRef(final String parameterName) throws SQLException {
- return apply(S::getRef, getDelegate(), parameterName);
+ return apply(CallableStatement::getRef, getDelegateCallableStatement(), parameterName);
}
@Override
public RowId getRowId(final int parameterIndex) throws SQLException {
- return apply(S::getRowId, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getRowId, getDelegateCallableStatement(), parameterIndex);
}
@Override
public RowId getRowId(final String parameterName) throws SQLException {
- return apply(S::getRowId, getDelegate(), parameterName);
+ return apply(CallableStatement::getRowId, getDelegateCallableStatement(), parameterName);
}
@Override
public short getShort(final int parameterIndex) throws SQLException {
- return applyTo(S::getShort, getDelegate(), parameterIndex, (short) 0);
+ return applyTo(CallableStatement::getShort, getDelegateCallableStatement(), parameterIndex, (short) 0);
}
@Override
public short getShort(final String parameterName) throws SQLException {
- return applyTo(S::getShort, getDelegate(), parameterName, (short) 0);
+ return applyTo(CallableStatement::getShort, getDelegateCallableStatement(), parameterName, (short) 0);
}
@Override
public SQLXML getSQLXML(final int parameterIndex) throws SQLException {
- return apply(S::getSQLXML, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getSQLXML, getDelegateCallableStatement(), parameterIndex);
}
@Override
public SQLXML getSQLXML(final String parameterName) throws SQLException {
- return apply(S::getSQLXML, getDelegate(), parameterName);
+ return apply(CallableStatement::getSQLXML, getDelegateCallableStatement(), parameterName);
}
@Override
public String getString(final int parameterIndex) throws SQLException {
- return apply(S::getString, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getString, getDelegateCallableStatement(), parameterIndex);
}
@Override
public String getString(final String parameterName) throws SQLException {
- return apply(S::getString, getDelegate(), parameterName);
+ return apply(CallableStatement::getString, getDelegateCallableStatement(), parameterName);
}
@Override
public Time getTime(final int parameterIndex) throws SQLException {
- return apply(S::getTime, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getTime, getDelegateCallableStatement(), parameterIndex);
}
@Override
public Time getTime(final int parameterIndex, final Calendar cal) throws SQLException {
- return apply(S::getTime, getDelegate(), parameterIndex, cal);
+ return apply(CallableStatement::getTime, getDelegateCallableStatement(), parameterIndex, cal);
}
@Override
public Time getTime(final String parameterName) throws SQLException {
- return apply(S::getTime, getDelegate(), parameterName);
+ return apply(CallableStatement::getTime, getDelegateCallableStatement(), parameterName);
}
@Override
public Time getTime(final String parameterName, final Calendar cal) throws SQLException {
- return apply(S::getTime, getDelegate(), parameterName, cal);
+ return apply(CallableStatement::getTime, getDelegateCallableStatement(), parameterName, cal);
}
@Override
public Timestamp getTimestamp(final int parameterIndex) throws SQLException {
- return apply(S::getTimestamp, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getTimestamp, getDelegateCallableStatement(), parameterIndex);
}
@Override
public Timestamp getTimestamp(final int parameterIndex, final Calendar cal) throws SQLException {
- return apply(S::getTimestamp, getDelegate(), parameterIndex, cal);
+ return apply(CallableStatement::getTimestamp, getDelegateCallableStatement(), parameterIndex, cal);
}
@Override
public Timestamp getTimestamp(final String parameterName) throws SQLException {
- return apply(S::getTimestamp, getDelegate(), parameterName);
+ return apply(CallableStatement::getTimestamp, getDelegateCallableStatement(), parameterName);
}
@Override
public Timestamp getTimestamp(final String parameterName, final Calendar cal) throws SQLException {
- return apply(S::getTimestamp, getDelegate(), parameterName, cal);
+ return apply(CallableStatement::getTimestamp, getDelegateCallableStatement(), parameterName, cal);
}
@Override
public URL getURL(final int parameterIndex) throws SQLException {
- return apply(S::getURL, getDelegate(), parameterIndex);
+ return apply(CallableStatement::getURL, getDelegateCallableStatement(), parameterIndex);
}
@Override
public URL getURL(final String parameterName) throws SQLException {
- return apply(S::getURL, getDelegate(), parameterName);
+ return apply(CallableStatement::getURL, getDelegateCallableStatement(), parameterName);
}
@Override
public void registerOutParameter(final int parameterIndex, final int sqlType) throws SQLException {
- accept(S::registerOutParameter, getDelegate(), parameterIndex, sqlType);
+ accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterIndex, sqlType);
}
@Override
public void registerOutParameter(final int parameterIndex, final int sqlType, final int scale) throws SQLException {
- accept(S::registerOutParameter, getDelegate(), parameterIndex, sqlType, scale);
+ accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterIndex, sqlType, scale);
}
@Override
public void registerOutParameter(final int parameterIndex, final int sqlType, final String typeName)
- throws SQLException {
- accept(S::registerOutParameter, getDelegate(), parameterIndex, sqlType, typeName);
+ throws SQLException {
+ accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterIndex, sqlType,
+ typeName);
}
/**
@@ -411,7 +414,7 @@ public void registerOutParameter(final int parameterIndex, final int sqlType, fi
*/
@Override
public void registerOutParameter(final int parameterIndex, final SQLType sqlType) throws SQLException {
- accept(S::registerOutParameter, getDelegate(), parameterIndex, sqlType);
+ accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterIndex, sqlType);
}
/**
@@ -419,8 +422,8 @@ public void registerOutParameter(final int parameterIndex, final SQLType sqlType
*/
@Override
public void registerOutParameter(final int parameterIndex, final SQLType sqlType, final int scale)
- throws SQLException {
- accept(S::registerOutParameter, getDelegate(), parameterIndex, sqlType, scale);
+ throws SQLException {
+ accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterIndex, sqlType, scale);
}
/**
@@ -428,25 +431,27 @@ public void registerOutParameter(final int parameterIndex, final SQLType sqlType
*/
@Override
public void registerOutParameter(final int parameterIndex, final SQLType sqlType, final String typeName)
- throws SQLException {
- accept(S::registerOutParameter, getDelegate(), parameterIndex, sqlType, typeName);
+ throws SQLException {
+ accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterIndex, sqlType,
+ typeName);
}
@Override
public void registerOutParameter(final String parameterName, final int sqlType) throws SQLException {
- accept(S::registerOutParameter, getDelegate(), parameterName, sqlType);
+ accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterName, sqlType);
}
@Override
public void registerOutParameter(final String parameterName, final int sqlType, final int scale)
- throws SQLException {
- accept(S::registerOutParameter, getDelegate(), parameterName, sqlType, scale);
+ throws SQLException {
+ accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterName, sqlType, scale);
}
@Override
public void registerOutParameter(final String parameterName, final int sqlType, final String typeName)
- throws SQLException {
- accept(S::registerOutParameter, getDelegate(), parameterName, sqlType, typeName);
+ throws SQLException {
+ accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterName, sqlType,
+ typeName);
}
/**
@@ -454,7 +459,7 @@ public void registerOutParameter(final String parameterName, final int sqlType,
*/
@Override
public void registerOutParameter(final String parameterName, final SQLType sqlType) throws SQLException {
- accept(S::registerOutParameter, getDelegate(), parameterName, sqlType);
+ accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterName, sqlType);
}
/**
@@ -462,8 +467,8 @@ public void registerOutParameter(final String parameterName, final SQLType sqlTy
*/
@Override
public void registerOutParameter(final String parameterName, final SQLType sqlType, final int scale)
- throws SQLException {
- accept(S::registerOutParameter, getDelegate(), parameterName, sqlType, scale);
+ throws SQLException {
+ accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterName, sqlType, scale);
}
/**
@@ -471,196 +476,198 @@ public void registerOutParameter(final String parameterName, final SQLType sqlTy
*/
@Override
public void registerOutParameter(final String parameterName, final SQLType sqlType, final String typeName)
- throws SQLException {
- accept(S::registerOutParameter, getDelegate(), parameterName, sqlType, typeName);
+ throws SQLException {
+ accept(CallableStatement::registerOutParameter, getDelegateCallableStatement(), parameterName, sqlType,
+ typeName);
}
@Override
public void setAsciiStream(final String parameterName, final InputStream value) throws SQLException {
- accept(S::setAsciiStream, getDelegate(), parameterName, value);
+ accept(CallableStatement::setAsciiStream, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setAsciiStream(final String parameterName, final InputStream value, final int length)
- throws SQLException {
- accept(S::setAsciiStream, getDelegate(), parameterName, value, length);
+ throws SQLException {
+ accept(CallableStatement::setAsciiStream, getDelegateCallableStatement(), parameterName, value, length);
}
@Override
public void setAsciiStream(final String parameterName, final InputStream value, final long length)
- throws SQLException {
- accept(S::setAsciiStream, getDelegate(), parameterName, value, length);
+ throws SQLException {
+ accept(CallableStatement::setAsciiStream, getDelegateCallableStatement(), parameterName, value, length);
}
@Override
public void setBigDecimal(final String parameterName, final BigDecimal value) throws SQLException {
- accept(S::setBigDecimal, getDelegate(), parameterName, value);
+ accept(CallableStatement::setBigDecimal, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setBinaryStream(final String parameterName, final InputStream value) throws SQLException {
- accept(S::setBinaryStream, getDelegate(), parameterName, value);
+ accept(CallableStatement::setBinaryStream, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setBinaryStream(final String parameterName, final InputStream value, final int length)
- throws SQLException {
- accept(S::setBinaryStream, getDelegate(), parameterName, value, length);
+ throws SQLException {
+ accept(CallableStatement::setBinaryStream, getDelegateCallableStatement(), parameterName, value, length);
}
@Override
public void setBinaryStream(final String parameterName, final InputStream value, final long length)
- throws SQLException {
- accept(S::setBinaryStream, getDelegate(), parameterName, value, length);
+ throws SQLException {
+ accept(CallableStatement::setBinaryStream, getDelegateCallableStatement(), parameterName, value, length);
}
@Override
public void setBlob(final String parameterName, final Blob value) throws SQLException {
- accept(S::setBlob, getDelegate(), parameterName, value);
+ accept(CallableStatement::setBlob, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setBlob(final String parameterName, final InputStream value) throws SQLException {
- accept(S::setBlob, getDelegate(), parameterName, value);
+ accept(CallableStatement::setBlob, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setBlob(final String parameterName, final InputStream value, final long length) throws SQLException {
- accept(S::setBlob, getDelegate(), parameterName, value, length);
+ accept(CallableStatement::setBlob, getDelegateCallableStatement(), parameterName, value, length);
}
@Override
public void setBoolean(final String parameterName, final boolean value) throws SQLException {
- accept(S::setBoolean, getDelegate(), parameterName, value);
+ accept(CallableStatement::setBoolean, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setByte(final String parameterName, final byte value) throws SQLException {
- accept(S::setByte, getDelegate(), parameterName, value);
+ accept(CallableStatement::setByte, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setBytes(final String parameterName, final byte[] value) throws SQLException {
- accept(S::setBytes, getDelegate(), parameterName, value);
+ accept(CallableStatement::setBytes, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setCharacterStream(final String parameterName, final Reader value) throws SQLException {
- accept(S::setCharacterStream, getDelegate(), parameterName, value);
+ accept(CallableStatement::setCharacterStream, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setCharacterStream(final String parameterName, final Reader value, final int length)
- throws SQLException {
- accept(S::setCharacterStream, getDelegate(), parameterName, value, length);
+ throws SQLException {
+ accept(CallableStatement::setCharacterStream, getDelegateCallableStatement(), parameterName, value, length);
}
@Override
public void setCharacterStream(final String parameterName, final Reader value, final long length)
- throws SQLException {
- accept(S::setCharacterStream, getDelegate(), parameterName, value, length);
+ throws SQLException {
+ accept(CallableStatement::setCharacterStream, getDelegateCallableStatement(), parameterName, value, length);
}
@Override
public void setClob(final String parameterName, final Clob value) throws SQLException {
- accept(S::setClob, getDelegate(), parameterName, value);
+ accept(CallableStatement::setClob, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setClob(final String parameterName, final Reader value) throws SQLException {
- accept(S::setClob, getDelegate(), parameterName, value);
+ accept(CallableStatement::setClob, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setClob(final String parameterName, final Reader value, final long length) throws SQLException {
- accept(S::setClob, getDelegate(), parameterName, value, length);
+ accept(CallableStatement::setClob, getDelegateCallableStatement(), parameterName, value, length);
}
@Override
public void setDate(final String parameterName, final Date value) throws SQLException {
- accept(S::setDate, getDelegate(), parameterName, value);
+ accept(CallableStatement::setDate, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setDate(final String parameterName, final Date value, final Calendar cal) throws SQLException {
- accept(S::setDate, getDelegate(), parameterName, value, cal);
+ accept(CallableStatement::setDate, getDelegateCallableStatement(), parameterName, value, cal);
}
@Override
public void setDouble(final String parameterName, final double value) throws SQLException {
- accept(S::setDouble, getDelegate(), parameterName, value);
+ accept(CallableStatement::setDouble, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setFloat(final String parameterName, final float value) throws SQLException {
- accept(S::setFloat, getDelegate(), parameterName, value);
+ accept(CallableStatement::setFloat, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setInt(final String parameterName, final int value) throws SQLException {
- accept(S::setInt, getDelegate(), parameterName, value);
+ accept(CallableStatement::setInt, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setLong(final String parameterName, final long value) throws SQLException {
- accept(S::setLong, getDelegate(), parameterName, value);
+ accept(CallableStatement::setLong, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setNCharacterStream(final String parameterName, final Reader value) throws SQLException {
- accept(S::setNCharacterStream, getDelegate(), parameterName, value);
+ accept(CallableStatement::setNCharacterStream, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setNCharacterStream(final String parameterName, final Reader value, final long length)
- throws SQLException {
- accept(S::setNCharacterStream, getDelegate(), parameterName, value, length);
+ throws SQLException {
+ accept(CallableStatement::setNCharacterStream, getDelegateCallableStatement(), parameterName, value, length);
}
@Override
public void setNClob(final String parameterName, final NClob value) throws SQLException {
- accept(S::setNClob, getDelegate(), parameterName, value);
+ accept(CallableStatement::setNClob, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setNClob(final String parameterName, final Reader value) throws SQLException {
- accept(S::setNClob, getDelegate(), parameterName, value);
+ accept(CallableStatement::setNClob, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setNClob(final String parameterName, final Reader value, final long length) throws SQLException {
- accept(S::setNClob, getDelegate(), parameterName, value, length);
+ accept(CallableStatement::setNClob, getDelegateCallableStatement(), parameterName, value, length);
}
@Override
public void setNString(final String parameterName, final String value) throws SQLException {
- accept(S::setNString, getDelegate(), parameterName, value);
+ accept(CallableStatement::setNString, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setNull(final String parameterName, final int sqlType) throws SQLException {
- accept(S::setNull, getDelegate(), parameterName, sqlType);
+ accept(CallableStatement::setNull, getDelegateCallableStatement(), parameterName, sqlType);
}
@Override
public void setNull(final String parameterName, final int sqlType, final String typeName) throws SQLException {
- accept(S::setNull, getDelegate(), parameterName, sqlType, typeName);
+ accept(CallableStatement::setNull, getDelegateCallableStatement(), parameterName, sqlType, typeName);
}
@Override
public void setObject(final String parameterName, final Object value) throws SQLException {
- accept(S::setObject, getDelegate(), parameterName, value);
+ accept(CallableStatement::setObject, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setObject(final String parameterName, final Object value, final int targetSqlType) throws SQLException {
- accept(S::setObject, getDelegate(), parameterName, value, targetSqlType);
+ accept(CallableStatement::setObject, getDelegateCallableStatement(), parameterName, value, targetSqlType);
}
@Override
public void setObject(final String parameterName, final Object value, final int targetSqlType, final int scale)
- throws SQLException {
- accept(S::setObject, getDelegate(), parameterName, value, targetSqlType, scale);
+ throws SQLException {
+ accept(CallableStatement::setObject, getDelegateCallableStatement(), parameterName, value, targetSqlType,
+ scale);
}
/**
@@ -668,8 +675,8 @@ public void setObject(final String parameterName, final Object value, final int
*/
@Override
public void setObject(final String parameterName, final Object value, final SQLType targetSqlType)
- throws SQLException {
- accept(S::setObject, getDelegate(), parameterName, value, targetSqlType);
+ throws SQLException {
+ accept(CallableStatement::setObject, getDelegateCallableStatement(), parameterName, value, targetSqlType);
}
/**
@@ -677,59 +684,60 @@ public void setObject(final String parameterName, final Object value, final SQLT
*/
@Override
public void setObject(final String parameterName, final Object value, final SQLType targetSqlType,
- final int scaleOrLength) throws SQLException {
- accept(S::setObject, getDelegate(), parameterName, value, targetSqlType, scaleOrLength);
+ final int scaleOrLength) throws SQLException {
+ accept(CallableStatement::setObject, getDelegateCallableStatement(), parameterName, value, targetSqlType,
+ scaleOrLength);
}
@Override
public void setRowId(final String parameterName, final RowId value) throws SQLException {
- accept(S::setRowId, getDelegate(), parameterName, value);
+ accept(CallableStatement::setRowId, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setShort(final String parameterName, final short value) throws SQLException {
- accept(S::setShort, getDelegate(), parameterName, value);
+ accept(CallableStatement::setShort, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setSQLXML(final String parameterName, final SQLXML value) throws SQLException {
- accept(S::setSQLXML, getDelegate(), parameterName, value);
+ accept(CallableStatement::setSQLXML, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setString(final String parameterName, final String value) throws SQLException {
- accept(S::setString, getDelegate(), parameterName, value);
+ accept(CallableStatement::setString, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setTime(final String parameterName, final Time value) throws SQLException {
- accept(S::setTime, getDelegate(), parameterName, value);
+ accept(CallableStatement::setTime, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setTime(final String parameterName, final Time value, final Calendar cal) throws SQLException {
- accept(S::setTime, getDelegate(), parameterName, value, cal);
+ accept(CallableStatement::setTime, getDelegateCallableStatement(), parameterName, value, cal);
}
@Override
public void setTimestamp(final String parameterName, final Timestamp value) throws SQLException {
- accept(S::setTimestamp, getDelegate(), parameterName, value);
+ accept(CallableStatement::setTimestamp, getDelegateCallableStatement(), parameterName, value);
}
@Override
public void setTimestamp(final String parameterName, final Timestamp value, final Calendar cal)
- throws SQLException {
- accept(S::setTimestamp, getDelegate(), parameterName, value, cal);
+ throws SQLException {
+ accept(CallableStatement::setTimestamp, getDelegateCallableStatement(), parameterName, value, cal);
}
@Override
public void setURL(final String parameterName, final URL value) throws SQLException {
- accept(S::setURL, getDelegate(), parameterName, value);
+ accept(CallableStatement::setURL, getDelegateCallableStatement(), parameterName, value);
}
@Override
public boolean wasNull() throws SQLException {
- return apply(S::wasNull, getDelegate());
+ return apply(CallableStatement::wasNull, getDelegateCallableStatement());
}
}
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
index 51b2dd58d8..457cce76ea 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
@@ -203,19 +203,19 @@ public SQLXML createSQLXML() throws SQLException {
@Override
public Statement createStatement() throws SQLException {
- return apply(() -> init(new DelegatingStatement<>(this, connection.createStatement())));
+ return apply(() -> init(new DelegatingStatement(this, connection.createStatement())));
}
@Override
public Statement createStatement(final int resultSetType, final int resultSetConcurrency) throws SQLException {
- return apply(() -> init(
- new DelegatingStatement<>(this, connection.createStatement(resultSetType, resultSetConcurrency))));
+ return apply(
+ () -> init(new DelegatingStatement(this, connection.createStatement(resultSetType, resultSetConcurrency))));
}
@Override
public Statement createStatement(final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability) throws SQLException {
- return apply(() -> init(new DelegatingStatement<>(this,
+ return apply(() -> init(new DelegatingStatement(this,
connection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability))));
}
@@ -374,7 +374,7 @@ protected T handleExceptionNoThrow(final T e) {
return e;
}
- private > T init(final T ds) throws SQLException {
+ private T init(final T ds) throws SQLException {
if (defaultQueryTimeoutSeconds != null && defaultQueryTimeoutSeconds.intValue() != ds.getQueryTimeout()) {
ds.setQueryTimeout(defaultQueryTimeoutSeconds.intValue());
}
@@ -485,58 +485,57 @@ protected void passivate() throws SQLException {
@Override
public CallableStatement prepareCall(final String sql) throws SQLException {
- return apply(() -> init(new DelegatingCallableStatement<>(this, connection.prepareCall(sql))));
+ return apply(() -> init(new DelegatingCallableStatement(this, connection.prepareCall(sql))));
}
@Override
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency)
throws SQLException {
return apply(() -> init(
- new DelegatingCallableStatement<>(this, connection.prepareCall(sql, resultSetType, resultSetConcurrency))));
+ new DelegatingCallableStatement(this, connection.prepareCall(sql, resultSetType, resultSetConcurrency))));
}
@Override
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability) throws SQLException {
- return apply(() -> init(new DelegatingCallableStatement<>(this,
+ return apply(() -> init(new DelegatingCallableStatement(this,
connection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability))));
}
@Override
public PreparedStatement prepareStatement(final String sql) throws SQLException {
- return apply(() -> init(new DelegatingPreparedStatement<>(this, connection.prepareStatement(sql))));
+ return apply(() -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql))));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException {
return apply(
- () -> init(new DelegatingPreparedStatement<>(this, connection.prepareStatement(sql, autoGeneratedKeys))));
+ () -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, autoGeneratedKeys))));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int columnIndexes[]) throws SQLException {
return apply(
- () -> init(new DelegatingPreparedStatement<>(this, connection.prepareStatement(sql, columnIndexes))));
+ () -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, columnIndexes))));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency)
throws SQLException {
- return apply(() -> init(new DelegatingPreparedStatement<>(this,
+ return apply(() -> init(new DelegatingPreparedStatement(this,
connection.prepareStatement(sql, resultSetType, resultSetConcurrency))));
}
@Override
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability) throws SQLException {
- return apply(() -> init(new DelegatingPreparedStatement<>(this,
+ return apply(() -> init(new DelegatingPreparedStatement(this,
connection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability))));
}
@Override
public PreparedStatement prepareStatement(final String sql, final String columnNames[]) throws SQLException {
- return apply(
- () -> init(new DelegatingPreparedStatement<>(this, connection.prepareStatement(sql, columnNames))));
+ return apply(() -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, columnNames))));
}
@Override
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java b/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java
index 150506766b..d32baa84af 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingPreparedStatement.java
@@ -49,11 +49,9 @@
* Statement ensures that the Connection which created it can close any open Statement's on Connection close.
*
*
- * @param PreparedStatement or a sub-type.
* @since 2.0
*/
-public class DelegatingPreparedStatement extends DelegatingStatement
- implements PreparedStatement {
+public class DelegatingPreparedStatement extends DelegatingStatement implements PreparedStatement {
/**
* Create a wrapper for the Statement which traces this Statement to the Connection which created it and the code
@@ -62,23 +60,23 @@ public class DelegatingPreparedStatement extends De
* @param statement the {@link PreparedStatement} to delegate all calls to.
* @param connection the {@link DelegatingConnection} that created this statement.
*/
- public DelegatingPreparedStatement(final DelegatingConnection> connection, final S statement) {
+ public DelegatingPreparedStatement(final DelegatingConnection> connection, final PreparedStatement statement) {
super(connection, statement);
}
@Override
public void addBatch() throws SQLException {
- accept(S::addBatch, getDelegate());
+ accept(PreparedStatement::addBatch, getDelegatePreparedStatement());
}
@Override
public void clearParameters() throws SQLException {
- accept(S::clearParameters, getDelegate());
+ accept(PreparedStatement::clearParameters, getDelegatePreparedStatement());
}
@Override
public boolean execute() throws SQLException {
- return applyTo(S::execute, getDelegate(), false);
+ return applyTo(PreparedStatement::execute, getDelegatePreparedStatement(), false);
}
/**
@@ -86,219 +84,224 @@ public boolean execute() throws SQLException {
*/
@Override
public long executeLargeUpdate() throws SQLException {
- return applyTo(S::executeLargeUpdate, getDelegate(), 0L);
+ return applyTo(PreparedStatement::executeLargeUpdate, getDelegatePreparedStatement(), 0L);
}
@Override
public ResultSet executeQuery() throws SQLException {
- return apply(() -> DelegatingResultSet.wrapResultSet(this, getDelegate().executeQuery()));
+ return apply(() -> DelegatingResultSet.wrapResultSet(this, getDelegatePreparedStatement().executeQuery()));
}
@Override
public int executeUpdate() throws SQLException {
- return applyTo(S::executeUpdate, getDelegate(), 0);
+ return applyTo(PreparedStatement::executeUpdate, getDelegatePreparedStatement(), 0);
+ }
+
+ private PreparedStatement getDelegatePreparedStatement() {
+ return (PreparedStatement) getDelegate();
}
@Override
public ResultSetMetaData getMetaData() throws SQLException {
- return apply(S::getMetaData, getDelegate());
+ return apply(PreparedStatement::getMetaData, getDelegatePreparedStatement());
}
@Override
public java.sql.ParameterMetaData getParameterMetaData() throws SQLException {
- return apply(S::getParameterMetaData, getDelegate());
+ return apply(PreparedStatement::getParameterMetaData, getDelegatePreparedStatement());
}
@Override
public void setArray(final int inputStream, final Array value) throws SQLException {
- accept(S::setArray, getDelegate(), inputStream, value);
+ accept(PreparedStatement::setArray, getDelegatePreparedStatement(), inputStream, value);
}
@Override
public void setAsciiStream(final int parameterIndex, final InputStream value) throws SQLException {
- accept(S::setAsciiStream, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setAsciiStream, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setAsciiStream(final int parameterIndex, final InputStream value, final int length)
throws SQLException {
- accept(S::setAsciiStream, getDelegate(), parameterIndex, value, length);
+ accept(PreparedStatement::setAsciiStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
public void setAsciiStream(final int parameterIndex, final InputStream value, final long length)
throws SQLException {
- accept(S::setAsciiStream, getDelegate(), parameterIndex, value, length);
+ accept(PreparedStatement::setAsciiStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
public void setBigDecimal(final int parameterIndex, final BigDecimal value) throws SQLException {
- accept(S::setBigDecimal, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setBigDecimal, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setBinaryStream(final int parameterIndex, final InputStream value) throws SQLException {
- accept(S::setBinaryStream, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setBinaryStream, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setBinaryStream(final int parameterIndex, final InputStream value, final int length)
throws SQLException {
- accept(S::setBinaryStream, getDelegate(), parameterIndex, value, length);
+ accept(PreparedStatement::setBinaryStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
public void setBinaryStream(final int parameterIndex, final InputStream value, final long length)
throws SQLException {
- accept(S::setBinaryStream, getDelegate(), parameterIndex, value, length);
+ accept(PreparedStatement::setBinaryStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
public void setBlob(final int parameterIndex, final Blob value) throws SQLException {
- accept(S::setBlob, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setBlob, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setBlob(final int parameterIndex, final InputStream value) throws SQLException {
- accept(S::setBlob, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setBlob, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setBlob(final int parameterIndex, final InputStream value, final long length) throws SQLException {
- accept(S::setBlob, getDelegate(), parameterIndex, value, length);
+ accept(PreparedStatement::setBlob, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
public void setBoolean(final int parameterIndex, final boolean value) throws SQLException {
- accept(S::setBoolean, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setBoolean, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setByte(final int parameterIndex, final byte value) throws SQLException {
- accept(S::setByte, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setByte, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setBytes(final int parameterIndex, final byte[] value) throws SQLException {
- accept(S::setBytes, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setBytes, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setCharacterStream(final int parameterIndex, final Reader value) throws SQLException {
- accept(S::setCharacterStream, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setCharacterStream, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setCharacterStream(final int parameterIndex, final Reader value, final int length) throws SQLException {
- accept(S::setCharacterStream, getDelegate(), parameterIndex, value, length);
+ accept(PreparedStatement::setCharacterStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
public void setCharacterStream(final int parameterIndex, final Reader value, final long length)
throws SQLException {
- accept(S::setCharacterStream, getDelegate(), parameterIndex, value, length);
+ accept(PreparedStatement::setCharacterStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
public void setClob(final int parameterIndex, final Clob value) throws SQLException {
- accept(S::setClob, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setClob, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setClob(final int parameterIndex, final Reader value) throws SQLException {
- accept(S::setClob, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setClob, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setClob(final int parameterIndex, final Reader value, final long length) throws SQLException {
- accept(S::setClob, getDelegate(), parameterIndex, value, length);
+ accept(PreparedStatement::setClob, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
public void setDate(final int parameterIndex, final Date value) throws SQLException {
- accept(S::setDate, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setDate, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setDate(final int parameterIndex, final Date value, final Calendar calendar) throws SQLException {
- accept(S::setDate, getDelegate(), parameterIndex, value, calendar);
+ accept(PreparedStatement::setDate, getDelegatePreparedStatement(), parameterIndex, value, calendar);
}
@Override
public void setDouble(final int parameterIndex, final double value) throws SQLException {
- accept(S::setDouble, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setDouble, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setFloat(final int parameterIndex, final float value) throws SQLException {
- accept(S::setFloat, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setFloat, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setInt(final int parameterIndex, final int value) throws SQLException {
- accept(S::setInt, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setInt, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setLong(final int parameterIndex, final long value) throws SQLException {
- accept(S::setLong, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setLong, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setNCharacterStream(final int parameterIndex, final Reader value) throws SQLException {
- accept(S::setNCharacterStream, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setNCharacterStream, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setNCharacterStream(final int parameterIndex, final Reader value, final long length)
throws SQLException {
- accept(S::setNCharacterStream, getDelegate(), parameterIndex, value, length);
+ accept(PreparedStatement::setNCharacterStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
public void setNClob(final int parameterIndex, final NClob value) throws SQLException {
- accept(S::setNClob, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setNClob, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setNClob(final int parameterIndex, final Reader value) throws SQLException {
- accept(S::setNClob, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setNClob, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setNClob(final int parameterIndex, final Reader value, final long length) throws SQLException {
- accept(S::setNClob, getDelegate(), parameterIndex, value, length);
+ accept(PreparedStatement::setNClob, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
public void setNString(final int parameterIndex, final String value) throws SQLException {
- accept(S::setNString, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setNString, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setNull(final int parameterIndex, final int sqlType) throws SQLException {
- accept(S::setNull, getDelegate(), parameterIndex, sqlType);
+ accept(PreparedStatement::setNull, getDelegatePreparedStatement(), parameterIndex, sqlType);
}
@Override
public void setNull(final int parameterIndex, final int sqlType, final String typeName) throws SQLException {
- accept(S::setNull, getDelegate(), parameterIndex, sqlType, typeName);
+ accept(PreparedStatement::setNull, getDelegatePreparedStatement(), parameterIndex, sqlType, typeName);
}
@Override
public void setObject(final int parameterIndex, final Object value) throws SQLException {
- accept(S::setObject, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setObject(final int parameterIndex, final Object value, final int targetSqlType) throws SQLException {
- accept(S::setObject, getDelegate(), parameterIndex, value, targetSqlType);
+ accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value, targetSqlType);
}
@Override
public void setObject(final int parameterIndex, final Object value, final int targetSqlType, final int scale)
throws SQLException {
- accept(S::setObject, getDelegate(), parameterIndex, value, targetSqlType, scale);
+ accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value, targetSqlType,
+ scale);
}
/**
@@ -307,7 +310,7 @@ public void setObject(final int parameterIndex, final Object value, final int ta
@Override
public void setObject(final int parameterIndex, final Object value, final SQLType targetSqlType)
throws SQLException {
- accept(S::setObject, getDelegate(), parameterIndex, value, targetSqlType);
+ accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value, targetSqlType);
}
/**
@@ -316,53 +319,54 @@ public void setObject(final int parameterIndex, final Object value, final SQLTyp
@Override
public void setObject(final int parameterIndex, final Object value, final SQLType targetSqlType,
final int scaleOrLength) throws SQLException {
- accept(S::setObject, getDelegate(), parameterIndex, value, targetSqlType, scaleOrLength);
+ accept(PreparedStatement::setObject, getDelegatePreparedStatement(), parameterIndex, value, targetSqlType,
+ scaleOrLength);
}
@Override
public void setRef(final int parameterIndex, final Ref value) throws SQLException {
- accept(S::setRef, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setRef, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setRowId(final int parameterIndex, final RowId value) throws SQLException {
- accept(S::setRowId, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setRowId, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setShort(final int parameterIndex, final short value) throws SQLException {
- accept(S::setShort, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setShort, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setSQLXML(final int parameterIndex, final SQLXML value) throws SQLException {
- accept(S::setSQLXML, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setSQLXML, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setString(final int parameterIndex, final String value) throws SQLException {
- accept(S::setString, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setString, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setTime(final int parameterIndex, final Time value) throws SQLException {
- accept(S::setTime, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setTime, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setTime(final int parameterIndex, final Time value, final Calendar calendar) throws SQLException {
- accept(S::setTime, getDelegate(), parameterIndex, value, calendar);
+ accept(PreparedStatement::setTime, getDelegatePreparedStatement(), parameterIndex, value, calendar);
}
@Override
public void setTimestamp(final int parameterIndex, final Timestamp value) throws SQLException {
- accept(S::setTimestamp, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setTimestamp, getDelegatePreparedStatement(), parameterIndex, value);
}
@Override
public void setTimestamp(final int parameterIndex, final Timestamp value, final Calendar calendar)
throws SQLException {
- accept(S::setTimestamp, getDelegate(), parameterIndex, value, calendar);
+ accept(PreparedStatement::setTimestamp, getDelegatePreparedStatement(), parameterIndex, value, calendar);
}
/** @deprecated Use setAsciiStream(), setCharacterStream() or setNCharacterStream() */
@@ -370,12 +374,12 @@ public void setTimestamp(final int parameterIndex, final Timestamp value, final
@Override
public void setUnicodeStream(final int parameterIndex, final InputStream value, final int length)
throws SQLException {
- accept(S::setUnicodeStream, getDelegate(), parameterIndex, value, length);
+ accept(PreparedStatement::setUnicodeStream, getDelegatePreparedStatement(), parameterIndex, value, length);
}
@Override
public void setURL(final int parameterIndex, final java.net.URL value) throws SQLException {
- accept(S::setURL, getDelegate(), parameterIndex, value);
+ accept(PreparedStatement::setURL, getDelegatePreparedStatement(), parameterIndex, value);
}
/**
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java b/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java
index 224927656c..875db1fc07 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java
@@ -58,8 +58,9 @@ public final class DelegatingResultSet extends AbandonedTrace implements ResultS
/**
* Wraps the given result set in a delegate.
*
- * @param connection The Connection which created the ResultSet.
- * @param resultSet The ResultSet to wrap.
+ * @param connection
+ * The Connection which created the ResultSet.
+ * @param resultSet The ResultSet to wrap.
* @return a new delegate.
*/
public static ResultSet wrapResultSet(final Connection connection, final ResultSet resultSet) {
@@ -100,7 +101,7 @@ public static ResultSet wrapResultSet(final Statement statement, final ResultSet
*
*
* @param conn Connection which created this ResultSet
- * @param res ResultSet to wrap
+ * @param res ResultSet to wrap
*/
private DelegatingResultSet(final Connection conn, final ResultSet res) {
super((AbandonedTrace) conn);
@@ -622,7 +623,7 @@ public SQLWarning getWarnings() throws SQLException {
@Override
protected void handleException(final SQLException e) throws SQLException {
if (statement != null && statement instanceof DelegatingStatement) {
- ((DelegatingStatement>) statement).handleException(e);
+ ((DelegatingStatement) statement).handleException(e);
} else if (connection != null && connection instanceof DelegatingConnection) {
((DelegatingConnection>) connection).handleException(e);
} else {
@@ -734,7 +735,7 @@ public void setFetchSize(final int rows) throws SQLException {
@Override
public synchronized String toString() {
return super.toString() + "[resultSet=" + resultSet + ", statement=" + statement + ", connection=" + connection
- + "]";
+ + "]";
}
@Override
@@ -770,7 +771,7 @@ public void updateAsciiStream(final int columnIndex, final InputStream x, final
@Override
public void updateAsciiStream(final int columnIndex, final InputStream inputStream, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateAsciiStream, columnIndex, inputStream, length);
}
@@ -786,7 +787,7 @@ public void updateAsciiStream(final String columnName, final InputStream x, fina
@Override
public void updateAsciiStream(final String columnLabel, final InputStream inputStream, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateAsciiStream, columnLabel, inputStream, length);
}
@@ -812,7 +813,7 @@ public void updateBinaryStream(final int columnIndex, final InputStream x, final
@Override
public void updateBinaryStream(final int columnIndex, final InputStream inputStream, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateBinaryStream, columnIndex, inputStream, length);
}
@@ -828,7 +829,7 @@ public void updateBinaryStream(final String columnName, final InputStream x, fin
@Override
public void updateBinaryStream(final String columnLabel, final InputStream inputStream, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateBinaryStream, columnLabel, inputStream, length);
}
@@ -844,7 +845,7 @@ public void updateBlob(final int columnIndex, final InputStream inputStream) thr
@Override
public void updateBlob(final int columnIndex, final InputStream inputStream, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateBlob, columnIndex, inputStream, length);
}
@@ -860,7 +861,7 @@ public void updateBlob(final String columnLabel, final InputStream inputStream)
@Override
public void updateBlob(final String columnLabel, final InputStream inputStream, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateBlob, columnLabel, inputStream, length);
}
@@ -906,7 +907,7 @@ public void updateCharacterStream(final int columnIndex, final Reader x, final i
@Override
public void updateCharacterStream(final int columnIndex, final Reader reader, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateCharacterStream, columnIndex, reader, length);
}
@@ -917,13 +918,13 @@ public void updateCharacterStream(final String columnLabel, final Reader reader)
@Override
public void updateCharacterStream(final String columnName, final Reader reader, final int length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateCharacterStream, columnName, reader, length);
}
@Override
public void updateCharacterStream(final String columnLabel, final Reader reader, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateCharacterStream, columnLabel, reader, length);
}
@@ -1014,7 +1015,7 @@ public void updateNCharacterStream(final int columnIndex, final Reader reader) t
@Override
public void updateNCharacterStream(final int columnIndex, final Reader reader, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateNCharacterStream, columnIndex, reader, length);
}
@@ -1025,7 +1026,7 @@ public void updateNCharacterStream(final String columnLabel, final Reader reader
@Override
public void updateNCharacterStream(final String columnLabel, final Reader reader, final long length)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateNCharacterStream, columnLabel, reader, length);
}
@@ -1102,7 +1103,7 @@ public void updateObject(final int columnIndex, final Object x, final SQLType ta
*/
@Override
public void updateObject(final int columnIndex, final Object x, final SQLType targetSqlType,
- final int scaleOrLength) throws SQLException {
+ final int scaleOrLength) throws SQLException {
accept(resultSet::updateObject, columnIndex, x, targetSqlType, scaleOrLength);
}
@@ -1121,7 +1122,7 @@ public void updateObject(final String columnName, final Object x, final int scal
*/
@Override
public void updateObject(final String columnLabel, final Object x, final SQLType targetSqlType)
- throws SQLException {
+ throws SQLException {
accept(resultSet::updateObject, columnLabel, x, targetSqlType);
}
@@ -1130,7 +1131,7 @@ public void updateObject(final String columnLabel, final Object x, final SQLType
*/
@Override
public void updateObject(final String columnLabel, final Object x, final SQLType targetSqlType,
- final int scaleOrLength) throws SQLException {
+ final int scaleOrLength) throws SQLException {
accept(resultSet::updateObject, columnLabel, x, targetSqlType, scaleOrLength);
}
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java b/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java
index c2331fb7d2..8059b97197 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java
@@ -32,15 +32,13 @@
*
* 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.
- *
- * @param Statement or a sub-type.
*
* @since 2.0
*/
-public class DelegatingStatement extends AbandonedTrace implements Statement {
+public class DelegatingStatement extends AbandonedTrace implements Statement {
/** My delegate. */
- private S statement;
+ private Statement statement;
/** The connection that created me. **/
private DelegatingConnection> connection;
@@ -51,10 +49,10 @@ public class DelegatingStatement extends AbandonedTrace imp
* Create a wrapper for the Statement which traces this Statement to the Connection which created it and the code
* which created it.
*
- * @param statement the {@link Statement} to delegate all calls to.
+ * @param statement the {@link Statement} to delegate all calls to.
* @param connection the {@link DelegatingConnection} that created this statement.
*/
- public DelegatingStatement(final DelegatingConnection> connection, final S statement) {
+ public DelegatingStatement(final DelegatingConnection> connection, final Statement statement) {
super(connection);
this.statement = statement;
this.connection = connection;
@@ -67,18 +65,18 @@ public DelegatingStatement(final DelegatingConnection> connection, final S sta
*/
public void activate() throws SQLException {
if (statement instanceof DelegatingStatement) {
- ((DelegatingStatement>) statement).activate();
+ ((DelegatingStatement) statement).activate();
}
}
@Override
public void addBatch(final String sql) throws SQLException {
- accept(S::addBatch, statement, sql);
+ accept(Statement::addBatch, statement, sql);
}
@Override
public void cancel() throws SQLException {
- accept(S::cancel, statement);
+ accept(Statement::cancel, statement);
}
@Override
@@ -90,12 +88,12 @@ protected void checkOpen() throws SQLException {
@Override
public void clearBatch() throws SQLException {
- accept(S::clearBatch, statement);
+ accept(Statement::clearBatch, statement);
}
@Override
public void clearWarnings() throws SQLException {
- accept(S::clearWarnings, statement);
+ accept(Statement::clearWarnings, statement);
}
/**
@@ -163,27 +161,27 @@ public void closeOnCompletion() throws SQLException {
@Override
public boolean execute(final String sql) throws SQLException {
- return applyTo(S::execute, statement, sql, false);
+ return applyTo(Statement::execute, statement, sql, false);
}
@Override
public boolean execute(final String sql, final int autoGeneratedKeys) throws SQLException {
- return applyTo(S::execute, statement, sql, autoGeneratedKeys, false);
+ return applyTo(Statement::execute, statement, sql, autoGeneratedKeys, false);
}
@Override
public boolean execute(final String sql, final int columnIndexes[]) throws SQLException {
- return applyTo(S::execute, statement, sql, columnIndexes, false);
+ return applyTo(Statement::execute, statement, sql, columnIndexes, false);
}
@Override
public boolean execute(final String sql, final String columnNames[]) throws SQLException {
- return applyTo(S::execute, statement, sql, columnNames, false);
+ return applyTo(Statement::execute, statement, sql, columnNames, false);
}
@Override
public int[] executeBatch() throws SQLException {
- return apply(S::executeBatch, statement);
+ return apply(Statement::executeBatch, statement);
}
/**
@@ -191,7 +189,7 @@ public int[] executeBatch() throws SQLException {
*/
@Override
public long[] executeLargeBatch() throws SQLException {
- return apply(S::executeLargeBatch, statement);
+ return apply(Statement::executeLargeBatch, statement);
}
/**
@@ -199,7 +197,7 @@ public long[] executeLargeBatch() throws SQLException {
*/
@Override
public long executeLargeUpdate(final String sql) throws SQLException {
- return applyTo(S::executeLargeUpdate, statement, sql, 0L);
+ return applyTo(Statement::executeLargeUpdate, statement, sql, 0L);
}
/**
@@ -207,7 +205,7 @@ public long executeLargeUpdate(final String sql) throws SQLException {
*/
@Override
public long executeLargeUpdate(final String sql, final int autoGeneratedKeys) throws SQLException {
- return applyTo(S::executeLargeUpdate, statement, sql, autoGeneratedKeys, 0L);
+ return applyTo(Statement::executeLargeUpdate, statement, sql, autoGeneratedKeys, 0L);
}
/**
@@ -215,7 +213,7 @@ public long executeLargeUpdate(final String sql, final int autoGeneratedKeys) th
*/
@Override
public long executeLargeUpdate(final String sql, final int[] columnIndexes) throws SQLException {
- return applyTo(S::executeLargeUpdate, statement, sql, columnIndexes, 0L);
+ return applyTo(Statement::executeLargeUpdate, statement, sql, columnIndexes, 0L);
}
/**
@@ -223,7 +221,7 @@ public long executeLargeUpdate(final String sql, final int[] columnIndexes) thro
*/
@Override
public long executeLargeUpdate(final String sql, final String[] columnNames) throws SQLException {
- return applyTo(S::executeLargeUpdate, statement, sql, columnNames, 0L);
+ return applyTo(Statement::executeLargeUpdate, statement, sql, columnNames, 0L);
}
@Override
@@ -233,22 +231,22 @@ public ResultSet executeQuery(final String sql) throws SQLException {
@Override
public int executeUpdate(final String sql) throws SQLException {
- return applyTo(S::executeUpdate, statement, sql, 0);
+ return applyTo(Statement::executeUpdate, statement, sql, 0);
}
@Override
public int executeUpdate(final String sql, final int autoGeneratedKeys) throws SQLException {
- return applyTo(S::executeUpdate, statement, sql, autoGeneratedKeys, 0);
+ return applyTo(Statement::executeUpdate, statement, sql, autoGeneratedKeys, 0);
}
@Override
public int executeUpdate(final String sql, final int columnIndexes[]) throws SQLException {
- return applyTo(S::executeUpdate, statement, sql, columnIndexes, 0);
+ return applyTo(Statement::executeUpdate, statement, sql, columnIndexes, 0);
}
@Override
public int executeUpdate(final String sql, final String columnNames[]) throws SQLException {
- return applyTo(S::executeUpdate, statement, sql, columnNames, 0);
+ return applyTo(Statement::executeUpdate, statement, sql, columnNames, 0);
}
@Override
@@ -281,18 +279,18 @@ protected DelegatingConnection> getConnectionInternal() {
* @return my underlying {@link Statement}.
* @see #getInnermostDelegate
*/
- public S getDelegate() {
+ public Statement getDelegate() {
return statement;
}
@Override
public int getFetchDirection() throws SQLException {
- return applyTo(S::getFetchDirection, statement, 0);
+ return applyTo(Statement::getFetchDirection, statement, 0);
}
@Override
public int getFetchSize() throws SQLException {
- return applyTo(S::getFetchSize, statement, 0);
+ return applyTo(Statement::getFetchSize, statement, 0);
}
@Override
@@ -317,10 +315,10 @@ public ResultSet getGeneratedKeys() throws SQLException {
* @see #getDelegate
*/
@SuppressWarnings("resource")
- public S getInnermostDelegate() {
- S s = statement;
- while (s instanceof DelegatingStatement) {
- s = ((DelegatingStatement) s).getDelegate();
+ public Statement getInnermostDelegate() {
+ Statement s = statement;
+ while (s != null && s instanceof DelegatingStatement) {
+ s = ((DelegatingStatement) s).getDelegate();
if (this == s) {
return null;
}
@@ -333,7 +331,7 @@ public S getInnermostDelegate() {
*/
@Override
public long getLargeMaxRows() throws SQLException {
- return applyTo(S::getLargeMaxRows, statement, 0L);
+ return applyTo(Statement::getLargeMaxRows, statement, 0L);
}
/**
@@ -341,32 +339,32 @@ public long getLargeMaxRows() throws SQLException {
*/
@Override
public long getLargeUpdateCount() throws SQLException {
- return applyTo(S::getLargeUpdateCount, statement, 0L);
+ return applyTo(Statement::getLargeUpdateCount, statement, 0L);
}
@Override
public int getMaxFieldSize() throws SQLException {
- return applyTo(S::getMaxFieldSize, statement, 0);
+ return applyTo(Statement::getMaxFieldSize, statement, 0);
}
@Override
public int getMaxRows() throws SQLException {
- return applyTo(S::getMaxRows, statement, 0);
+ return applyTo(Statement::getMaxRows, statement, 0);
}
@Override
public boolean getMoreResults() throws SQLException {
- return applyTo(S::getMoreResults, statement, false);
+ return applyTo(Statement::getMoreResults, statement, false);
}
@Override
public boolean getMoreResults(final int current) throws SQLException {
- return applyTo(S::getMoreResults, statement, current, false);
+ return applyTo(Statement::getMoreResults, statement, current, false);
}
@Override
public int getQueryTimeout() throws SQLException {
- return applyTo(S::getQueryTimeout, statement, 0);
+ return applyTo(Statement::getQueryTimeout, statement, 0);
}
@Override
@@ -376,27 +374,27 @@ public ResultSet getResultSet() throws SQLException {
@Override
public int getResultSetConcurrency() throws SQLException {
- return applyTo(S::getResultSetConcurrency, statement, 0);
+ return applyTo(Statement::getResultSetConcurrency, statement, 0);
}
@Override
public int getResultSetHoldability() throws SQLException {
- return applyTo(S::getResultSetHoldability, statement, 0);
+ return applyTo(Statement::getResultSetHoldability, statement, 0);
}
@Override
public int getResultSetType() throws SQLException {
- return applyTo(S::getResultSetType, statement, 0);
+ return applyTo(Statement::getResultSetType, statement, 0);
}
@Override
public int getUpdateCount() throws SQLException {
- return applyTo(S::getUpdateCount, statement, 0);
+ return applyTo(Statement::getUpdateCount, statement, 0);
}
@Override
public SQLWarning getWarnings() throws SQLException {
- return apply(S::getWarnings, statement);
+ return apply(Statement::getWarnings, statement);
}
@Override
@@ -427,7 +425,7 @@ public boolean isCloseOnCompletion() throws SQLException {
@Override
public boolean isPoolable() throws SQLException {
- return applyTo(S::isPoolable, statement, false);
+ return applyTo(Statement::isPoolable, statement, false);
}
@Override
@@ -448,7 +446,7 @@ public boolean isWrapperFor(final Class> iface) throws SQLException {
*/
public void passivate() throws SQLException {
if (statement instanceof DelegatingStatement) {
- ((DelegatingStatement>) statement).passivate();
+ ((DelegatingStatement) statement).passivate();
}
}
@@ -458,7 +456,7 @@ protected void setClosedInternal(final boolean closed) {
@Override
public void setCursorName(final String name) throws SQLException {
- accept(S::setCursorName, statement, name);
+ accept(Statement::setCursorName, statement, name);
}
/**
@@ -466,23 +464,23 @@ public void setCursorName(final String name) throws SQLException {
*
* @param statement my delegate.
*/
- public void setDelegate(final S statement) {
+ public void setDelegate(final Statement statement) {
this.statement = statement;
}
@Override
public void setEscapeProcessing(final boolean enable) throws SQLException {
- accept(S::setEscapeProcessing, statement, enable);
+ accept(Statement::setEscapeProcessing, statement, enable);
}
@Override
public void setFetchDirection(final int direction) throws SQLException {
- accept(S::setFetchDirection, statement, direction);
+ accept(Statement::setFetchDirection, statement, direction);
}
@Override
public void setFetchSize(final int rows) throws SQLException {
- accept(S::setFetchSize, statement, rows);
+ accept(Statement::setFetchSize, statement, rows);
}
/**
@@ -490,7 +488,7 @@ public void setFetchSize(final int rows) throws SQLException {
*/
@Override
public void setLargeMaxRows(final long max) throws SQLException {
- accept(S::setLargeMaxRows, statement, max);
+ accept(Statement::setLargeMaxRows, statement, max);
}
@Override
@@ -502,22 +500,22 @@ protected void markUse() {
@Override
public void setMaxFieldSize(final int max) throws SQLException {
- accept(S::setMaxFieldSize, statement, max);
+ accept(Statement::setMaxFieldSize, statement, max);
}
@Override
public void setMaxRows(final int max) throws SQLException {
- accept(S::setMaxRows, statement, max);
+ accept(Statement::setMaxRows, statement, max);
}
@Override
public void setPoolable(final boolean poolable) throws SQLException {
- accept(S::setPoolable, statement, poolable);
+ accept(Statement::setPoolable, statement, poolable);
}
@Override
public void setQueryTimeout(final int seconds) throws SQLException {
- accept(S::setQueryTimeout, statement, seconds);
+ accept(Statement::setQueryTimeout, statement, seconds);
}
/**
diff --git a/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java b/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java
index 1b0125edbb..c161f3b5a3 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolableCallableStatement.java
@@ -31,18 +31,16 @@
* {@link CallableStatement}s.
*
* The {@link #close} method returns this statement to its containing pool. (See {@link PoolingConnection}.)
- *
*
- * @param CallableStatement or a sub-type.
* @see PoolingConnection
* @since 2.0
*/
-public class PoolableCallableStatement extends DelegatingCallableStatement {
+public class PoolableCallableStatement extends DelegatingCallableStatement {
/**
* The {@link KeyedObjectPool} from which this CallableStatement was obtained.
*/
- private final KeyedObjectPool> pool;
+ private final KeyedObjectPool pool;
/**
* Key for this statement in the containing {@link KeyedObjectPool}.
@@ -61,8 +59,8 @@ public class PoolableCallableStatement extends Dele
* @param connection
* the {@link DelegatingConnection} that created this CallableStatement
*/
- public PoolableCallableStatement(final S callableStatement, final PStmtKey key,
- final KeyedObjectPool> pool,
+ public PoolableCallableStatement(final CallableStatement callableStatement, final PStmtKey key,
+ final KeyedObjectPool pool,
final DelegatingConnection connection) {
super(connection, callableStatement);
this.pool = pool;
diff --git a/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java b/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
index 6058cf050c..23c8c6b989 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
@@ -38,7 +38,7 @@
* @see PoolingConnection
* @since 2.0
*/
-public class PoolablePreparedStatement extends DelegatingPreparedStatement {
+public class PoolablePreparedStatement extends DelegatingPreparedStatement {
/**
* The {@link KeyedObjectPool} from which I was obtained.
diff --git a/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java b/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
index 7e8131d525..9ddbffe0fe 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
@@ -41,8 +41,8 @@
* @see PoolablePreparedStatement
* @since 2.0
*/
-public class PoolingConnection extends DelegatingConnection
- implements KeyedPooledObjectFactory> {
+public class PoolingConnection extends DelegatingConnection
+ implements KeyedPooledObjectFactory {
/**
* Statement types.
@@ -64,7 +64,7 @@ public enum StatementType {
}
/** Pool of {@link PreparedStatement}s. and {@link CallableStatement}s */
- private KeyedObjectPool> pStmtPool;
+ private KeyedObjectPool pStmtPool;
/**
* Constructor.
@@ -85,7 +85,7 @@ public PoolingConnection(final Connection connection) {
* wrapped pooled statement to be activated
*/
@Override
- public void activateObject(final PStmtKey key, final PooledObject> pooledObject)
+ public void activateObject(final PStmtKey key, final PooledObject pooledObject)
throws Exception {
pooledObject.getObject().activate();
}
@@ -98,7 +98,7 @@ public void activateObject(final PStmtKey key, final PooledObject> oldpool = pStmtPool;
+ final KeyedObjectPool oldpool = pStmtPool;
pStmtPool = null;
try {
oldpool.close();
@@ -262,7 +262,7 @@ protected PStmtKey createKey(final String sql, final String columnNames[]) {
* the wrapped pooled statement to be destroyed.
*/
@Override
- public void destroyObject(final PStmtKey key, final PooledObject