Skip to content

Commit 2075df0

Browse files
Use generics instead of type casts. Also use generics in ::.
1 parent 9c90c77 commit 2075df0

File tree

9 files changed

+366
-384
lines changed

9 files changed

+366
-384
lines changed

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

Lines changed: 144 additions & 152 deletions
Large diffs are not rendered by default.

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,19 @@ public SQLXML createSQLXML() throws SQLException {
203203

204204
@Override
205205
public Statement createStatement() throws SQLException {
206-
return apply(() -> init(new DelegatingStatement(this, connection.createStatement())));
206+
return apply(() -> init(new DelegatingStatement<>(this, connection.createStatement())));
207207
}
208208

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

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

@@ -374,7 +374,7 @@ protected <T extends Throwable> T handleExceptionNoThrow(final T e) {
374374
return e;
375375
}
376376

377-
private <T extends DelegatingStatement> T init(final T ds) throws SQLException {
377+
private <T extends DelegatingStatement<?>> T init(final T ds) throws SQLException {
378378
if (defaultQueryTimeoutSeconds != null && defaultQueryTimeoutSeconds.intValue() != ds.getQueryTimeout()) {
379379
ds.setQueryTimeout(defaultQueryTimeoutSeconds.intValue());
380380
}
@@ -485,57 +485,58 @@ protected void passivate() throws SQLException {
485485

486486
@Override
487487
public CallableStatement prepareCall(final String sql) throws SQLException {
488-
return apply(() -> init(new DelegatingCallableStatement(this, connection.prepareCall(sql))));
488+
return apply(() -> init(new DelegatingCallableStatement<>(this, connection.prepareCall(sql))));
489489
}
490490

491491
@Override
492492
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency)
493493
throws SQLException {
494494
return apply(() -> init(
495-
new DelegatingCallableStatement(this, connection.prepareCall(sql, resultSetType, resultSetConcurrency))));
495+
new DelegatingCallableStatement<>(this, connection.prepareCall(sql, resultSetType, resultSetConcurrency))));
496496
}
497497

498498
@Override
499499
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency,
500500
final int resultSetHoldability) throws SQLException {
501-
return apply(() -> init(new DelegatingCallableStatement(this,
501+
return apply(() -> init(new DelegatingCallableStatement<>(this,
502502
connection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability))));
503503
}
504504

505505
@Override
506506
public PreparedStatement prepareStatement(final String sql) throws SQLException {
507-
return apply(() -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql))));
507+
return apply(() -> init(new DelegatingPreparedStatement<>(this, connection.prepareStatement(sql))));
508508
}
509509

510510
@Override
511511
public PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException {
512512
return apply(
513-
() -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, autoGeneratedKeys))));
513+
() -> init(new DelegatingPreparedStatement<>(this, connection.prepareStatement(sql, autoGeneratedKeys))));
514514
}
515515

516516
@Override
517517
public PreparedStatement prepareStatement(final String sql, final int columnIndexes[]) throws SQLException {
518518
return apply(
519-
() -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, columnIndexes))));
519+
() -> init(new DelegatingPreparedStatement<>(this, connection.prepareStatement(sql, columnIndexes))));
520520
}
521521

522522
@Override
523523
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency)
524524
throws SQLException {
525-
return apply(() -> init(new DelegatingPreparedStatement(this,
525+
return apply(() -> init(new DelegatingPreparedStatement<>(this,
526526
connection.prepareStatement(sql, resultSetType, resultSetConcurrency))));
527527
}
528528

529529
@Override
530530
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency,
531531
final int resultSetHoldability) throws SQLException {
532-
return apply(() -> init(new DelegatingPreparedStatement(this,
532+
return apply(() -> init(new DelegatingPreparedStatement<>(this,
533533
connection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability))));
534534
}
535535

536536
@Override
537537
public PreparedStatement prepareStatement(final String sql, final String columnNames[]) throws SQLException {
538-
return apply(() -> init(new DelegatingPreparedStatement(this, connection.prepareStatement(sql, columnNames))));
538+
return apply(
539+
() -> init(new DelegatingPreparedStatement<>(this, connection.prepareStatement(sql, columnNames))));
539540
}
540541

541542
@Override

0 commit comments

Comments
 (0)