diff --git a/pgjdbc/src/main/java/org/postgresql/copy/PGCopyInputStream.java b/pgjdbc/src/main/java/org/postgresql/copy/PGCopyInputStream.java index 0a166a98d1..c0f8891de9 100644 --- a/pgjdbc/src/main/java/org/postgresql/copy/PGCopyInputStream.java +++ b/pgjdbc/src/main/java/org/postgresql/copy/PGCopyInputStream.java @@ -69,20 +69,24 @@ 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; @@ -93,15 +97,14 @@ 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]; - for (int i = at; i < len; i++) { - ba[i - at] = buf[i]; - } + System.arraycopy(buf, at, ba, 0, len - at); result = ba; } at = len; // either partly or fully returned, buffer is exhausted @@ -117,6 +120,7 @@ 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) { @@ -127,34 +131,38 @@ public void close() throws IOException { try { op.cancelCopy(); } catch (SQLException se) { - IOException ioe = new IOException("Failed to close copy reader."); - ioe.initCause(se); - throw ioe; + throw new IOException("Failed to close copy reader.", se); } } 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 5f420e52e8..92653a477e 100644 --- a/pgjdbc/src/main/java/org/postgresql/copy/PGCopyOutputStream.java +++ b/pgjdbc/src/main/java/org/postgresql/copy/PGCopyOutputStream.java @@ -65,6 +65,7 @@ public PGCopyOutputStream(CopyIn op, int bufferSize) { copyBuffer = new byte[bufferSize]; } + @Override public void write(int b) throws IOException { checkClosed(); if (b < 0 || b > 255) { @@ -74,18 +75,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) { - IOException ioe = new IOException("Write to copy failed."); - ioe.initCause(se); - throw ioe; + throw new IOException("Write to copy failed.", se); } } @@ -95,6 +96,7 @@ private void checkClosed() throws IOException { } } + @Override public void close() throws IOException { // Don't complain about a double close. if (op == null) { @@ -104,25 +106,23 @@ public void close() throws IOException { try { endCopy(); } catch (SQLException se) { - IOException ioe = new IOException("Ending write to copy failed."); - ioe.initCause(se); - throw ioe; + throw new IOException("Ending write to copy failed.", se); } op = null; } + @Override public void flush() throws IOException { try { op.writeToCopy(copyBuffer, 0, at); at = 0; op.flushCopy(); } catch (SQLException e) { - IOException ioe = new IOException("Unable to flush stream"); - ioe.initCause(e); - throw ioe; + throw new IOException("Unable to flush stream", e); } } + @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,30 +137,37 @@ 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); @@ -169,6 +176,7 @@ 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 5cf84ff3fb..18bf4fe983 100644 --- a/pgjdbc/src/main/java/org/postgresql/jdbc/BatchResultHandler.java +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/BatchResultHandler.java @@ -51,6 +51,7 @@ 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 @@ -73,6 +74,7 @@ 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 @@ -125,6 +127,7 @@ private void updateGeneratedKeys() { allGeneratedRows.clear(); } + @Override public void handleWarning(SQLWarning warning) { pgStatement.addWarning(warning); } @@ -145,8 +148,7 @@ 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()); - batchException.initCause(newError); + newError.getSQLState(), uncompressUpdateCount(), newError); super.handleError(batchException); } resultIndex++; @@ -154,6 +156,7 @@ public void handleError(SQLException newError) { super.handleError(newError); } + @Override public void handleCompletion() throws SQLException { updateGeneratedKeys(); SQLException batchException = getException(); @@ -163,9 +166,8 @@ public void handleCompletion() throws SQLException { BatchUpdateException newException = new BatchUpdateException( batchException.getMessage(), batchException.getSQLState(), - uncompressUpdateCount() - ); - newException.initCause(batchException.getCause()); + uncompressUpdateCount(), + 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 ac24ad8f03..ef79c57845 100644 --- a/pgjdbc/src/main/java/org/postgresql/jdbc/CallableBatchResultHandler.java +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/CallableBatchResultHandler.java @@ -17,6 +17,7 @@ class CallableBatchResultHandler extends BatchResultHandler { super(statement, queries, parameterLists, false); } + @Override public void handleResultRows(Query fromQuery, Field[] fields, List tuples, ResultCursor cursor) { /* ignore */ }