diff --git a/pgjdbc/src/main/java/org/postgresql/copy/PGCopyInputStream.java b/pgjdbc/src/main/java/org/postgresql/copy/PGCopyInputStream.java index c0f8891de9..0a166a98d1 100644 --- a/pgjdbc/src/main/java/org/postgresql/copy/PGCopyInputStream.java +++ b/pgjdbc/src/main/java/org/postgresql/copy/PGCopyInputStream.java @@ -69,24 +69,20 @@ private void checkClosed() throws IOException { } - @Override public int available() throws IOException { checkClosed(); return (buf != null ? len - at : 0); } - @Override public int read() throws IOException { checkClosed(); return gotBuf() ? buf[at++] : -1; } - @Override public int read(byte[] buf) throws IOException { return read(buf, 0, buf.length); } - @Override public int read(byte[] buf, int off, int siz) throws IOException { checkClosed(); int got = 0; @@ -97,14 +93,15 @@ public int read(byte[] buf, int off, int siz) throws IOException { return got == 0 && !didReadSomething ? -1 : got; } - @Override public byte[] readFromCopy() throws SQLException { byte[] result = buf; try { if (gotBuf()) { if (at > 0 || len < buf.length) { byte[] ba = new byte[len - at]; - System.arraycopy(buf, at, ba, 0, len - at); + for (int i = at; i < len; i++) { + ba[i - at] = buf[i]; + } result = ba; } at = len; // either partly or fully returned, buffer is exhausted @@ -120,7 +117,6 @@ public byte[] readFromCopy(boolean block) throws SQLException { return readFromCopy(); } - @Override public void close() throws IOException { // Don't complain about a double close. if (op == null) { @@ -131,38 +127,34 @@ public void close() throws IOException { try { op.cancelCopy(); } catch (SQLException se) { - throw new IOException("Failed to close copy reader.", se); + IOException ioe = new IOException("Failed to close copy reader."); + ioe.initCause(se); + throw ioe; } } op = null; } - @Override public void cancelCopy() throws SQLException { op.cancelCopy(); } - @Override public int getFormat() { return op.getFormat(); } - @Override public int getFieldFormat(int field) { return op.getFieldFormat(field); } - @Override public int getFieldCount() { return op.getFieldCount(); } - @Override public boolean isActive() { return op != null && op.isActive(); } - @Override public long getHandledRowCount() { return op.getHandledRowCount(); } diff --git a/pgjdbc/src/main/java/org/postgresql/copy/PGCopyOutputStream.java b/pgjdbc/src/main/java/org/postgresql/copy/PGCopyOutputStream.java index 92653a477e..5f420e52e8 100644 --- a/pgjdbc/src/main/java/org/postgresql/copy/PGCopyOutputStream.java +++ b/pgjdbc/src/main/java/org/postgresql/copy/PGCopyOutputStream.java @@ -65,7 +65,6 @@ public PGCopyOutputStream(CopyIn op, int bufferSize) { copyBuffer = new byte[bufferSize]; } - @Override public void write(int b) throws IOException { checkClosed(); if (b < 0 || b > 255) { @@ -75,18 +74,18 @@ public void write(int b) throws IOException { write(singleByteBuffer, 0, 1); } - @Override public void write(byte[] buf) throws IOException { write(buf, 0, buf.length); } - @Override public void write(byte[] buf, int off, int siz) throws IOException { checkClosed(); try { writeToCopy(buf, off, siz); } catch (SQLException se) { - throw new IOException("Write to copy failed.", se); + IOException ioe = new IOException("Write to copy failed."); + ioe.initCause(se); + throw ioe; } } @@ -96,7 +95,6 @@ private void checkClosed() throws IOException { } } - @Override public void close() throws IOException { // Don't complain about a double close. if (op == null) { @@ -106,23 +104,25 @@ public void close() throws IOException { try { endCopy(); } catch (SQLException se) { - throw new IOException("Ending write to copy failed.", se); + IOException ioe = new IOException("Ending write to copy failed."); + ioe.initCause(se); + throw ioe; } op = null; } - @Override public void flush() throws IOException { try { op.writeToCopy(copyBuffer, 0, at); at = 0; op.flushCopy(); } catch (SQLException e) { - throw new IOException("Unable to flush stream", e); + IOException ioe = new IOException("Unable to flush stream"); + ioe.initCause(e); + throw ioe; } } - @Override public void writeToCopy(byte[] buf, int off, int siz) throws SQLException { if (at > 0 && siz > copyBuffer.length - at) { // would not fit into rest of our buf, so flush buf @@ -137,37 +137,30 @@ public void writeToCopy(byte[] buf, int off, int siz) throws SQLException { } } - @Override public int getFormat() { return op.getFormat(); } - @Override public int getFieldFormat(int field) { return op.getFieldFormat(field); } - @Override public void cancelCopy() throws SQLException { op.cancelCopy(); } - @Override public int getFieldCount() { return op.getFieldCount(); } - @Override public boolean isActive() { return op.isActive(); } - @Override public void flushCopy() throws SQLException { op.flushCopy(); } - @Override public long endCopy() throws SQLException { if (at > 0) { op.writeToCopy(copyBuffer, 0, at); @@ -176,7 +169,6 @@ public long endCopy() throws SQLException { return getHandledRowCount(); } - @Override public long getHandledRowCount() { return op.getHandledRowCount(); } diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/BatchResultHandler.java b/pgjdbc/src/main/java/org/postgresql/jdbc/BatchResultHandler.java index 18bf4fe983..5cf84ff3fb 100644 --- a/pgjdbc/src/main/java/org/postgresql/jdbc/BatchResultHandler.java +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/BatchResultHandler.java @@ -51,7 +51,6 @@ public class BatchResultHandler extends ResultHandlerBase { this.allGeneratedRows = !expectGeneratedKeys ? null : new ArrayList>(); } - @Override public void handleResultRows(Query fromQuery, Field[] fields, List tuples, ResultCursor cursor) { // If SELECT, then handleCommandStatus call would just be missing @@ -74,7 +73,6 @@ public void handleResultRows(Query fromQuery, Field[] fields, List tup latestGeneratedRows = tuples; } - @Override public void handleCommandStatus(String status, int updateCount, long insertOID) { if (latestGeneratedRows != null) { // We have DML. Decrease resultIndex that was just increased in handleResultRows @@ -127,7 +125,6 @@ private void updateGeneratedKeys() { allGeneratedRows.clear(); } - @Override public void handleWarning(SQLWarning warning) { pgStatement.addWarning(warning); } @@ -148,7 +145,8 @@ public void handleError(SQLException newError) { BatchUpdateException batchException = new BatchUpdateException( GT.tr("Batch entry {0} {1} was aborted: {2} Call getNextException to see other errors in the batch.", resultIndex, queryString, newError.getMessage()), - newError.getSQLState(), uncompressUpdateCount(), newError); + newError.getSQLState(), uncompressUpdateCount()); + batchException.initCause(newError); super.handleError(batchException); } resultIndex++; @@ -156,7 +154,6 @@ public void handleError(SQLException newError) { super.handleError(newError); } - @Override public void handleCompletion() throws SQLException { updateGeneratedKeys(); SQLException batchException = getException(); @@ -166,8 +163,9 @@ public void handleCompletion() throws SQLException { BatchUpdateException newException = new BatchUpdateException( batchException.getMessage(), batchException.getSQLState(), - uncompressUpdateCount(), - batchException.getCause()); + uncompressUpdateCount() + ); + newException.initCause(batchException.getCause()); SQLException next = batchException.getNextException(); if (next != null) { newException.setNextException(next); diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/CallableBatchResultHandler.java b/pgjdbc/src/main/java/org/postgresql/jdbc/CallableBatchResultHandler.java index ef79c57845..ac24ad8f03 100644 --- a/pgjdbc/src/main/java/org/postgresql/jdbc/CallableBatchResultHandler.java +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/CallableBatchResultHandler.java @@ -17,7 +17,6 @@ class CallableBatchResultHandler extends BatchResultHandler { super(statement, queries, parameterLists, false); } - @Override public void handleResultRows(Query fromQuery, Field[] fields, List tuples, ResultCursor cursor) { /* ignore */ }