Skip to content

Commit

Permalink
refactor: remove ClassCastException catch
Browse files Browse the repository at this point in the history
CopyManager has two catches for ClassCastException. This ins't very
nice and can easily be changed to do a check before the cast.

closes #527
  • Loading branch information
marschall authored and vlsi committed Mar 4, 2016
1 parent a274321 commit 8bee06b
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions pgjdbc/src/main/java/org/postgresql/copy/CopyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,24 @@ public CopyManager(BaseConnection connection) throws SQLException {
}

public CopyIn copyIn(String sql) throws SQLException {
CopyOperation op = null;
try {
op = queryExecutor.startCopy(sql, connection.getAutoCommit());
CopyOperation op = queryExecutor.startCopy(sql, connection.getAutoCommit());
if (op == null || op instanceof CopyIn) {
return (CopyIn) op;
} catch (ClassCastException cce) {
} else {
op.cancelCopy();
throw new PSQLException(GT.tr("Requested CopyIn but got {0}", op.getClass().getName()),
PSQLState.WRONG_OBJECT_TYPE, cce);
PSQLState.WRONG_OBJECT_TYPE);
}
}

public CopyOut copyOut(String sql) throws SQLException {
CopyOperation op = null;
try {
op = queryExecutor.startCopy(sql, connection.getAutoCommit());
CopyOperation op = queryExecutor.startCopy(sql, connection.getAutoCommit());
if (op == null || op instanceof CopyOut) {
return (CopyOut) op;
} catch (ClassCastException cce) {
} else {
op.cancelCopy();
throw new PSQLException(GT.tr("Requested CopyOut but got {0}", op.getClass().getName()),
PSQLState.WRONG_OBJECT_TYPE, cce);
PSQLState.WRONG_OBJECT_TYPE);
}
}

Expand Down

0 comments on commit 8bee06b

Please sign in to comment.