Skip to content

Commit 9c90c77

Browse files
Remove unused, a few more impls, and clean ups.
1 parent 620dcca commit 9c90c77

File tree

3 files changed

+75
-104
lines changed

3 files changed

+75
-104
lines changed

src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
public class DelegatingConnection<C extends Connection> extends AbandonedTrace implements Connection {
6262

6363
private static final Map<String, ClientInfoStatus> EMPTY_FAILED_PROPERTIES = Collections
64-
.<String, ClientInfoStatus>emptyMap();
64+
.<String, ClientInfoStatus>emptyMap();
6565

6666
/** My delegate {@link Connection}. */
6767
private volatile C connection;
@@ -208,15 +208,15 @@ public Statement createStatement() throws SQLException {
208208

209209
@Override
210210
public Statement createStatement(final int resultSetType, final int resultSetConcurrency) throws SQLException {
211-
return apply(() -> init(
212-
new DelegatingStatement(this, connection.createStatement(resultSetType, resultSetConcurrency))));
211+
return apply(
212+
() -> init(new DelegatingStatement(this, connection.createStatement(resultSetType, resultSetConcurrency))));
213213
}
214214

215215
@Override
216216
public Statement createStatement(final int resultSetType, final int resultSetConcurrency,
217-
final int resultSetHoldability) throws SQLException {
217+
final int resultSetHoldability) throws SQLException {
218218
return apply(() -> init(new DelegatingStatement(this,
219-
connection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability))));
219+
connection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability))));
220220
}
221221

222222
@Override
@@ -366,7 +366,7 @@ protected void handleException(final SQLException e) throws SQLException {
366366
* Handles the given {@code SQLException}.
367367
*
368368
* @param <T> The throwable type.
369-
* @param e The SQLException
369+
* @param e The SQLException
370370
* @return the given {@code SQLException}
371371
* @since 2.7.0
372372
*/
@@ -483,39 +483,23 @@ protected void passivate() throws SQLException {
483483
setLastUsed(0);
484484
}
485485

486-
@SuppressWarnings("resource")
487486
@Override
488487
public CallableStatement prepareCall(final String sql) throws SQLException {
489-
checkOpen();
490-
try {
491-
final DelegatingCallableStatement dcs = new DelegatingCallableStatement(this, connection.prepareCall(sql));
492-
return init(dcs);
493-
} catch (final SQLException e) {
494-
handleException(e);
495-
return null;
496-
}
488+
return apply(() -> init(new DelegatingCallableStatement(this, connection.prepareCall(sql))));
497489
}
498490

499-
@SuppressWarnings("resource")
500491
@Override
501492
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency)
502-
throws SQLException {
503-
checkOpen();
504-
try {
505-
final DelegatingCallableStatement dcs = new DelegatingCallableStatement(this,
506-
connection.prepareCall(sql, resultSetType, resultSetConcurrency));
507-
return init(dcs);
508-
} catch (final SQLException e) {
509-
handleException(e);
510-
return null;
511-
}
493+
throws SQLException {
494+
return apply(() -> init(
495+
new DelegatingCallableStatement(this, connection.prepareCall(sql, resultSetType, resultSetConcurrency))));
512496
}
513497

514498
@Override
515499
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency,
516-
final int resultSetHoldability) throws SQLException {
500+
final int resultSetHoldability) throws SQLException {
517501
return apply(() -> init(new DelegatingCallableStatement(this,
518-
connection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability))));
502+
connection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability))));
519503
}
520504

521505
@Override
@@ -526,26 +510,27 @@ public PreparedStatement prepareStatement(final String sql) throws SQLException
526510
@Override
527511
public PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException {
528512
return apply(
529-
() -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, autoGeneratedKeys))));
513+
() -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, autoGeneratedKeys))));
530514
}
531515

532516
@Override
533517
public PreparedStatement prepareStatement(final String sql, final int columnIndexes[]) throws SQLException {
534-
return apply(() -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, columnIndexes))));
518+
return apply(
519+
() -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, columnIndexes))));
535520
}
536521

537522
@Override
538523
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency)
539-
throws SQLException {
524+
throws SQLException {
540525
return apply(() -> init(new DelegatingPreparedStatement(this,
541-
connection.prepareStatement(sql, resultSetType, resultSetConcurrency))));
526+
connection.prepareStatement(sql, resultSetType, resultSetConcurrency))));
542527
}
543528

544529
@Override
545530
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency,
546-
final int resultSetHoldability) throws SQLException {
531+
final int resultSetHoldability) throws SQLException {
547532
return apply(() -> init(new DelegatingPreparedStatement(this,
548-
connection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability))));
533+
connection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability))));
549534
}
550535

551536
@Override

src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.sql.SQLException;
2424

2525
import org.apache.commons.dbcp2.function.SQLFunction0;
26-
import org.apache.commons.dbcp2.function.SQLFunction1;
2726
import org.apache.commons.dbcp2.function.SQLFunction2;
2827
import org.apache.commons.dbcp2.function.SQLFunction3;
2928
import org.apache.commons.dbcp2.function.SQLFunction4;
@@ -52,11 +51,11 @@ public class DelegatingDatabaseMetaData extends ResourceFunctions implements Dat
5251
/**
5352
* Constructs a new instance for the given delegating connection and database meta data.
5453
*
55-
* @param connection the delegating connection
54+
* @param connection the delegating connection
5655
* @param databaseMetaData the database meta data
5756
*/
5857
public DelegatingDatabaseMetaData(final DelegatingConnection<?> connection,
59-
final DatabaseMetaData databaseMetaData) {
58+
final DatabaseMetaData databaseMetaData) {
6059
super();
6160
this.connection = connection;
6261
this.databaseMetaData = databaseMetaData;
@@ -104,14 +103,14 @@ public boolean generatedKeyAlwaysReturned() throws SQLException {
104103

105104
@Override
106105
public ResultSet getAttributes(final String catalog, final String schemaPattern, final String typeNamePattern,
107-
final String attributeNamePattern) throws SQLException {
106+
final String attributeNamePattern) throws SQLException {
108107
return toResultSet(databaseMetaData::getAttributes, catalog, schemaPattern, typeNamePattern,
109-
attributeNamePattern);
108+
attributeNamePattern);
110109
}
111110

112111
@Override
113112
public ResultSet getBestRowIdentifier(final String catalog, final String schema, final String table,
114-
final int scope, final boolean nullable) throws SQLException {
113+
final int scope, final boolean nullable) throws SQLException {
115114
return toResultSet(databaseMetaData::getBestRowIdentifier, catalog, schema, table, scope, nullable);
116115
}
117116

@@ -137,13 +136,13 @@ public ResultSet getClientInfoProperties() throws SQLException {
137136

138137
@Override
139138
public ResultSet getColumnPrivileges(final String catalog, final String schema, final String table,
140-
final String columnNamePattern) throws SQLException {
139+
final String columnNamePattern) throws SQLException {
141140
return toResultSet(databaseMetaData::getColumnPrivileges, catalog, schema, table, columnNamePattern);
142141
}
143142

144143
@Override
145144
public ResultSet getColumns(final String catalog, final String schemaPattern, final String tableNamePattern,
146-
final String columnNamePattern) throws SQLException {
145+
final String columnNamePattern) throws SQLException {
147146
return toResultSet(databaseMetaData::getColumns, catalog, schemaPattern, tableNamePattern, columnNamePattern);
148147
}
149148

@@ -154,9 +153,9 @@ public Connection getConnection() throws SQLException {
154153

155154
@Override
156155
public ResultSet getCrossReference(final String parentCatalog, final String parentSchema, final String parentTable,
157-
final String foreignCatalog, final String foreignSchema, final String foreignTable) throws SQLException {
156+
final String foreignCatalog, final String foreignSchema, final String foreignTable) throws SQLException {
158157
return toResultSet(databaseMetaData::getCrossReference, parentCatalog, parentSchema, parentTable,
159-
foreignCatalog, foreignSchema, foreignTable);
158+
foreignCatalog, foreignSchema, foreignTable);
160159
}
161160

162161
@Override
@@ -215,7 +214,7 @@ public String getDriverVersion() throws SQLException {
215214

216215
@Override
217216
public ResultSet getExportedKeys(final String catalog, final String schema, final String table)
218-
throws SQLException {
217+
throws SQLException {
219218
return toResultSet(databaseMetaData::getExportedKeys, catalog, schema, table);
220219
}
221220

@@ -226,14 +225,14 @@ public String getExtraNameCharacters() throws SQLException {
226225

227226
@Override
228227
public ResultSet getFunctionColumns(final String catalog, final String schemaPattern,
229-
final String functionNamePattern, final String columnNamePattern) throws SQLException {
228+
final String functionNamePattern, final String columnNamePattern) throws SQLException {
230229
return toResultSet(databaseMetaData::getFunctionColumns, catalog, schemaPattern, functionNamePattern,
231-
columnNamePattern);
230+
columnNamePattern);
232231
}
233232

234233
@Override
235234
public ResultSet getFunctions(final String catalog, final String schemaPattern, final String functionNamePattern)
236-
throws SQLException {
235+
throws SQLException {
237236
return toResultSet(databaseMetaData::getFunctions, catalog, schemaPattern, functionNamePattern);
238237
}
239238

@@ -244,13 +243,13 @@ public String getIdentifierQuoteString() throws SQLException {
244243

245244
@Override
246245
public ResultSet getImportedKeys(final String catalog, final String schema, final String table)
247-
throws SQLException {
246+
throws SQLException {
248247
return toResultSet(databaseMetaData::getImportedKeys, catalog, schema, table);
249248
}
250249

251250
@Override
252251
public ResultSet getIndexInfo(final String catalog, final String schema, final String table, final boolean unique,
253-
final boolean approximate) throws SQLException {
252+
final boolean approximate) throws SQLException {
254253
return toResultSet(databaseMetaData::getIndexInfo, catalog, schema, table, unique, approximate);
255254
}
256255

@@ -409,14 +408,14 @@ public ResultSet getPrimaryKeys(final String catalog, final String schema, final
409408

410409
@Override
411410
public ResultSet getProcedureColumns(final String catalog, final String schemaPattern,
412-
final String procedureNamePattern, final String columnNamePattern) throws SQLException {
411+
final String procedureNamePattern, final String columnNamePattern) throws SQLException {
413412
return toResultSet(databaseMetaData::getProcedureColumns, catalog, schemaPattern, procedureNamePattern,
414-
columnNamePattern);
413+
columnNamePattern);
415414
}
416415

417416
@Override
418417
public ResultSet getProcedures(final String catalog, final String schemaPattern, final String procedureNamePattern)
419-
throws SQLException {
418+
throws SQLException {
420419
return toResultSet(databaseMetaData::getProcedures, catalog, schemaPattern, procedureNamePattern);
421420
}
422421

@@ -427,9 +426,9 @@ public String getProcedureTerm() throws SQLException {
427426

428427
@Override
429428
public ResultSet getPseudoColumns(final String catalog, final String schemaPattern, final String tableNamePattern,
430-
final String columnNamePattern) throws SQLException {
429+
final String columnNamePattern) throws SQLException {
431430
return toResultSet(databaseMetaData::getPseudoColumns, catalog, schemaPattern, tableNamePattern,
432-
columnNamePattern);
431+
columnNamePattern);
433432
}
434433

435434
@Override
@@ -479,14 +478,14 @@ public String getStringFunctions() throws SQLException {
479478

480479
@Override
481480
public ResultSet getSuperTables(final String catalog, final String schemaPattern, final String tableNamePattern)
482-
throws SQLException {
483-
return toResultSet(databaseMetaData::getSuperTables,catalog, schemaPattern, tableNamePattern);
481+
throws SQLException {
482+
return toResultSet(databaseMetaData::getSuperTables, catalog, schemaPattern, tableNamePattern);
484483
}
485484

486485
@Override
487486
public ResultSet getSuperTypes(final String catalog, final String schemaPattern, final String typeNamePattern)
488-
throws SQLException {
489-
return toResultSet(databaseMetaData::getSuperTypes,catalog, schemaPattern, typeNamePattern);
487+
throws SQLException {
488+
return toResultSet(databaseMetaData::getSuperTypes, catalog, schemaPattern, typeNamePattern);
490489
}
491490

492491
@Override
@@ -496,14 +495,14 @@ public String getSystemFunctions() throws SQLException {
496495

497496
@Override
498497
public ResultSet getTablePrivileges(final String catalog, final String schemaPattern, final String tableNamePattern)
499-
throws SQLException {
500-
return toResultSet(databaseMetaData::getTablePrivileges,catalog, schemaPattern, tableNamePattern);
498+
throws SQLException {
499+
return toResultSet(databaseMetaData::getTablePrivileges, catalog, schemaPattern, tableNamePattern);
501500
}
502501

503502
@Override
504503
public ResultSet getTables(final String catalog, final String schemaPattern, final String tableNamePattern,
505-
final String[] types) throws SQLException {
506-
return toResultSet(databaseMetaData::getTables,catalog, schemaPattern, tableNamePattern, types);
504+
final String[] types) throws SQLException {
505+
return toResultSet(databaseMetaData::getTables, catalog, schemaPattern, tableNamePattern, types);
507506
}
508507

509508
@Override
@@ -523,8 +522,8 @@ public ResultSet getTypeInfo() throws SQLException {
523522

524523
@Override
525524
public ResultSet getUDTs(final String catalog, final String schemaPattern, final String typeNamePattern,
526-
final int[] types) throws SQLException {
527-
return toResultSet(databaseMetaData::getUDTs,catalog, schemaPattern, typeNamePattern, types);
525+
final int[] types) throws SQLException {
526+
return toResultSet(databaseMetaData::getUDTs, catalog, schemaPattern, typeNamePattern, types);
528527
}
529528

530529
@Override
@@ -539,8 +538,8 @@ public String getUserName() throws SQLException {
539538

540539
@Override
541540
public ResultSet getVersionColumns(final String catalog, final String schema, final String table)
542-
throws SQLException {
543-
return toResultSet(databaseMetaData::getVersionColumns,catalog, schema, table);
541+
throws SQLException {
542+
return toResultSet(databaseMetaData::getVersionColumns, catalog, schema, table);
544543
}
545544

546545
@Override
@@ -1018,39 +1017,32 @@ private ResultSet toResultSet(final SQLFunction0<ResultSet> callableResultSet) t
10181017
return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply()));
10191018
}
10201019

1021-
private <T> ResultSet toResultSet(final SQLFunction1<T, ResultSet> callableResultSet, final T t)
1022-
throws SQLException {
1023-
connection.checkOpen();
1024-
return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t)));
1025-
}
1026-
10271020
private <T, U> ResultSet toResultSet(final SQLFunction2<T, U, ResultSet> callableResultSet, final T t, final U u)
1028-
throws SQLException {
1021+
throws SQLException {
10291022
connection.checkOpen();
10301023
return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t, u)));
10311024
}
10321025

10331026
private <T, U, V> ResultSet toResultSet(final SQLFunction3<T, U, V, ResultSet> callableResultSet, final T t,
1034-
final U u, final V v) throws SQLException {
1027+
final U u, final V v) throws SQLException {
10351028
connection.checkOpen();
10361029
return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t, u, v)));
10371030
}
10381031

10391032
private <T, U, V, X> ResultSet toResultSet(final SQLFunction4<T, U, V, X, ResultSet> callableResultSet, final T t,
1040-
final U u, final V v, final X x) throws SQLException {
1033+
final U u, final V v, final X x) throws SQLException {
10411034
connection.checkOpen();
10421035
return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t, u, v, x)));
10431036
}
10441037

10451038
private <T, U, V, X, Y> ResultSet toResultSet(final SQLFunction5<T, U, V, X, Y, ResultSet> callableResultSet,
1046-
final T t, final U u, final V v, final X x, final Y y) throws SQLException {
1039+
final T t, final U u, final V v, final X x, final Y y) throws SQLException {
10471040
connection.checkOpen();
10481041
return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t, u, v, x, y)));
10491042
}
10501043

1051-
private <T, U, V, X, Y, Z> ResultSet toResultSet(
1052-
final SQLFunction6<T, U, V, X, Y, Z, ResultSet> callableResultSet, final T t, final U u, final V v,
1053-
final X x, final Y y, final Z z) throws SQLException {
1044+
private <T, U, V, X, Y, Z> ResultSet toResultSet(final SQLFunction6<T, U, V, X, Y, Z, ResultSet> callableResultSet,
1045+
final T t, final U u, final V v, final X x, final Y y, final Z z) throws SQLException {
10541046
connection.checkOpen();
10551047
return apply(() -> DelegatingResultSet.wrapResultSet(connection, callableResultSet.apply(t, u, v, x, y, z)));
10561048
}

0 commit comments

Comments
 (0)