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 9aea2d30c..558568c4c 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java
@@ -22,6 +22,13 @@
import java.sql.RowIdLifetime;
import java.sql.SQLException;
+import org.apache.commons.dbcp2.function.SQLFunction0;
+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 +40,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,13 +51,11 @@ 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) {
+ final DatabaseMetaData databaseMetaData) {
super();
this.connection = connection;
this.databaseMetaData = databaseMetaData;
@@ -58,177 +63,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();
- }
+ final String attributeNamePattern) throws SQLException {
+ 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();
- }
+ final int scope, final boolean nullable) throws SQLException {
+ 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();
- }
+ 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 {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ final String columnNamePattern) throws SQLException {
+ return toResultSet(databaseMetaData::getColumns, catalog, schemaPattern, tableNamePattern, columnNamePattern);
}
@Override
@@ -238,65 +153,34 @@ 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();
- }
+ final String foreignCatalog, final String foreignSchema, final String foreignTable) throws SQLException {
+ 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 +204,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();
- }
+ throws SQLException {
+ 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();
- }
+ final String functionNamePattern, final String columnNamePattern) throws SQLException {
+ 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();
- }
+ throws SQLException {
+ 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();
- }
+ 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 {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getIndexInfo(catalog, schema, table, unique, approximate));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ final boolean approximate) throws SQLException {
+ return toResultSet(databaseMetaData::getIndexInfo, catalog, schema, table, unique, approximate);
}
/**
@@ -450,142 +280,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 +353,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();
- }
+ final String procedureNamePattern, final String columnNamePattern) throws SQLException {
+ 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();
- }
+ throws SQLException {
+ 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();
- }
+ final String columnNamePattern) throws SQLException {
+ 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();
- }
+ throws SQLException {
+ 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();
- }
+ throws SQLException {
+ 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();
- }
+ 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 {
- connection.checkOpen();
- try {
- return DelegatingResultSet.wrapResultSet(connection,
- databaseMetaData.getTables(catalog, schemaPattern, tableNamePattern, types));
- } catch (final SQLException e) {
- handleException(e);
- throw new AssertionError();
- }
+ final String[] types) throws SQLException {
+ 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();
- }
+ final int[] types) throws SQLException {
+ 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();
- }
+ throws SQLException {
+ return toResultSet(databaseMetaData::getVersionColumns, catalog, schema, table);
}
+ @Override
protected void handleException(final SQLException e) throws SQLException {
if (connection != null) {
connection.handleException(e);
@@ -994,32 +553,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 +579,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 +897,154 @@ 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 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 +1062,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 048687c05..d32baa84a 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,283 @@ 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)
- throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setAsciiStream(parameterIndex, inputStream, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setAsciiStream(final int parameterIndex, final InputStream value, final long length)
+ throws SQLException {
+ 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)
- throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setBinaryStream(parameterIndex, inputStream, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setBinaryStream(final int parameterIndex, final InputStream value, final long length)
+ throws SQLException {
+ 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)
- throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setBlob(parameterIndex, inputStream, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setBlob(final int parameterIndex, final InputStream value, final long length) throws SQLException {
+ 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)
- throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setCharacterStream(parameterIndex, reader, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ 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 reader, final long length)
- throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setCharacterStream(parameterIndex, reader, length);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setCharacterStream(final int parameterIndex, final Reader value, final long length)
+ throws SQLException {
+ 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);
- }
+ throws SQLException {
+ 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)
- throws SQLException {
- checkOpen();
- try {
- getDelegatePreparedStatement().setObject(parameterIndex, x, targetSqlType, scale);
- } catch (final SQLException e) {
- handleException(e);
- }
+ 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);
}
/**
* @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 {
- checkOpen();
- try {
- getDelegatePreparedStatement().setString(parameterIndex, x);
- } catch (final SQLException e) {
- handleException(e);
- }
+ public void setString(final int parameterIndex, final String value) throws SQLException {
+ accept(PreparedStatement::setString, getDelegatePreparedStatement(), parameterIndex, value);
}
@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 86e4d43ee..875db1fc0 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 95253e500..8059b9719 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 d99ed22b9..9ddbffe0f 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 000000000..e32f5be67
--- /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 2226e8e06..9ac586043 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 1f74af4ad..705ce3b62 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 000000000..9156c0bf8
--- /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 000000000..b45bd0af2
--- /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 000000000..280075cc1
--- /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 000000000..7955d5530
--- /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 000000000..00f5ccfa6
--- /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 000000000..391c7961f
--- /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 000000000..311a64dd4
--- /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 000000000..0dad9b154
--- /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 000000000..c69ff7095
--- /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 000000000..5f1052794
--- /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 000000000..b996e682c
--- /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 000000000..966d162d7
--- /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 000000000..429717f83
--- /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 000000000..389b275c1
--- /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 000000000..6a7a6fe25
--- /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 000000000..cd250ac8b
--- /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 000000000..94528ff91
--- /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 da83df664..30466b932 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 6b0ed7c25..6863b9c4c 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 f0ce5c0b2..a35ba3d5d 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);