public synchronized void flushCopy(CopyInImpl op) throws SQLException { if(!hasLock(op)) throw new PSQLException(GT.tr("Tried to write to an inactive copy operation"), PSQLState.OBJECT_NOT_IN_STATE); try { pgStream.flush(); processCopyResults(op, false); // collect any pending notifications without blocking } catch(IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when writing to copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
/** * Blocks to wait for a row of data to be received from server on an active copy operation * Connection gets unlocked by processCopyResults() at end of operation * @param op the copy operation presumably currently holding lock on this connection * @throws SQLException on any failure */ synchronized void readFromCopy(CopyOutImpl op) throws SQLException { if(!hasLock(op)) throw new PSQLException(GT.tr("Tried to read from inactive copy"), PSQLState.OBJECT_NOT_IN_STATE); try { processCopyResults(op, true); // expect a call to handleCopydata() to store the data } catch(IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when reading from copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
public synchronized void flushCopy(CopyOperationImpl op) throws SQLException { if (!hasLock(op)) { throw new PSQLException(GT.tr("Tried to write to an inactive copy operation"), PSQLState.OBJECT_NOT_IN_STATE); } try { pgStream.flush(); processCopyResults(op, false); // collect any pending notifications without blocking } catch (IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when writing to copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
/** * Wait for a row of data to be received from server on an active copy operation * Connection gets unlocked by processCopyResults() at end of operation. * * @param op the copy operation presumably currently holding lock on this connection * @param block whether to block waiting for input * @throws SQLException on any failure */ synchronized void readFromCopy(CopyOperationImpl op, boolean block) throws SQLException { if (!hasLock(op)) { throw new PSQLException(GT.tr("Tried to read from inactive copy"), PSQLState.OBJECT_NOT_IN_STATE); } try { processCopyResults(op, block); // expect a call to handleCopydata() to store the data } catch (IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when reading from copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
/** * Sends data during a live COPY IN operation. Only unlocks the connection if server suddenly * returns CommandComplete, which should not happen * * @param op the CopyIn operation presumably currently holding lock on this connection * @param data bytes to send * @param off index of first byte to send (usually 0) * @param siz number of bytes to send (usually data.length) * @throws SQLException on failure */ public synchronized void writeToCopy(CopyOperationImpl op, byte[] data, int off, int siz) throws SQLException { if (!hasLock(op)) { throw new PSQLException(GT.tr("Tried to write to an inactive copy operation"), PSQLState.OBJECT_NOT_IN_STATE); } LOGGER.log(Level.FINEST, " FE=> CopyData({0})", siz); try { pgStream.sendChar('d'); pgStream.sendInteger4(siz + 4); pgStream.send(data, off, siz); processCopyResults(op, false); // collect any pending notifications without blocking } catch (IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when writing to copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
/** * Finishes writing to copy and unlocks connection. * * @param op the copy operation presumably currently holding lock on this connection * @return number of rows updated for server versions 8.2 or newer * @throws SQLException on failure */ public synchronized long endCopy(CopyOperationImpl op) throws SQLException { if (!hasLock(op)) { throw new PSQLException(GT.tr("Tried to end inactive copy"), PSQLState.OBJECT_NOT_IN_STATE); } try { LOGGER.log(Level.FINEST, " FE=> CopyDone"); pgStream.sendChar('c'); // CopyDone pgStream.sendInteger4(4); pgStream.flush(); do { processCopyResults(op, true); } while (hasLock(op)); return op.getHandledRowCount(); } catch (IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when ending copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
/** * Sends given query to BE to start, initialize and lock connection for a CopyOperation. * * @param sql COPY FROM STDIN / COPY TO STDOUT statement * @return CopyIn or CopyOut operation object * @throws SQLException on failure */ public synchronized CopyOperation startCopy(String sql, boolean suppressBegin) throws SQLException { waitOnLock(); if (!suppressBegin) { doSubprotocolBegin(); } byte[] buf = Utils.encodeUTF8(sql); try { LOGGER.log(Level.FINEST, " FE=> Query(CopyStart)"); pgStream.sendChar('Q'); pgStream.sendInteger4(buf.length + 4 + 1); pgStream.send(buf); pgStream.sendChar(0); pgStream.flush(); return processCopyResults(null, true); // expect a CopyInResponse or CopyOutResponse to our query above } catch (IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when starting copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
/** * Sends data during a live COPY IN operation. Only unlocks the connection if server * suddenly returns CommandComplete, which should not happen * @param op the CopyIn operation presumably currently holding lock on this connection * @param data bytes to send * @param off index of first byte to send (usually 0) * @param siz number of bytes to send (usually data.length) * @throws SQLException on failure */ public synchronized void writeToCopy(CopyInImpl op, byte[] data, int off, int siz) throws SQLException { if(!hasLock(op)) throw new PSQLException(GT.tr("Tried to write to an inactive copy operation"), PSQLState.OBJECT_NOT_IN_STATE); if (logger.logDebug()) logger.debug(" FE=> CopyData(" + siz + ")"); try { pgStream.SendChar('d'); pgStream.SendInteger4(siz + 4); pgStream.Send(data, off, siz); processCopyResults(op, false); // collect any pending notifications without blocking } catch(IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when writing to copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
/** * Finishes writing to copy and unlocks connection * @param op the copy operation presumably currently holding lock on this connection * @return number of rows updated for server versions 8.2 or newer * @throws SQLException on failure */ public synchronized long endCopy(CopyInImpl op) throws SQLException { if(!hasLock(op)) throw new PSQLException(GT.tr("Tried to end inactive copy"), PSQLState.OBJECT_NOT_IN_STATE); try { if (logger.logDebug()) logger.debug(" FE=> CopyDone"); pgStream.SendChar('c'); // CopyDone pgStream.SendInteger4(4); pgStream.flush(); processCopyResults(op, true); return op.getHandledRowCount(); } catch(IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when ending copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
/** * Sends given query to BE to start, initialize and lock connection for a CopyOperation. * @param sql COPY FROM STDIN / COPY TO STDOUT statement * @return CopyIn or CopyOut operation object * @throws SQLException on failure */ public synchronized CopyOperation startCopy(String sql, boolean suppressBegin) throws SQLException { waitOnLock(); if (!suppressBegin) { doSubprotocolBegin(); } byte buf[] = Utils.encodeUTF8(sql); try { if (logger.logDebug()) logger.debug(" FE=> Query(CopyStart)"); pgStream.SendChar('Q'); pgStream.SendInteger4(buf.length + 4 + 1); pgStream.Send(buf); pgStream.SendChar(0); pgStream.flush(); return processCopyResults(null, true); // expect a CopyInResponse or CopyOutResponse to our query above } catch(IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when starting copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
do { try { processCopyResults(op, true); // discard rest of input } catch (SQLException se) { // expected error response to failing copy errors++;
do { try { processCopyResults(op, true); // discard rest of input } catch(SQLException se) { // expected error response to failing copy errors++;
/** * Blocks to wait for a row of data to be received from server on an active copy operation * Connection gets unlocked by processCopyResults() at end of operation * @param op the copy operation presumably currently holding lock on this connection * @throws SQLException on any failure */ synchronized void readFromCopy(CopyOutImpl op) throws SQLException { if(!hasLock(op)) throw new PSQLException(GT.tr("Tried to read from inactive copy"), PSQLState.OBJECT_NOT_IN_STATE); try { processCopyResults(op, true); // expect a call to handleCopydata() to store the data } catch(IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when reading from copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
/** * Blocks to wait for a row of data to be received from server on an active copy operation * Connection gets unlocked by processCopyResults() at end of operation * @param op the copy operation presumably currently holding lock on this connection * @throws SQLException on any failure */ synchronized void readFromCopy(CopyOutImpl op) throws SQLException { if(!hasLock(op)) throw new PSQLException(GT.tr("Tried to read from inactive copy"), PSQLState.OBJECT_NOT_IN_STATE); try { processCopyResults(op, true); // expect a call to handleCopydata() to store the data } catch(IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when reading from copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
public synchronized void flushCopy(CopyInImpl op) throws SQLException { if(!hasLock(op)) throw new PSQLException(GT.tr("Tried to write to an inactive copy operation"), PSQLState.OBJECT_NOT_IN_STATE); try { pgStream.flush(); processCopyResults(op, false); // collect any pending notifications without blocking } catch(IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when writing to copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
public synchronized void flushCopy(CopyInImpl op) throws SQLException { if(!hasLock(op)) throw new PSQLException(GT.tr("Tried to write to an inactive copy operation"), PSQLState.OBJECT_NOT_IN_STATE); try { pgStream.flush(); processCopyResults(op, false); // collect any pending notifications without blocking } catch(IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when writing to copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
/** * Finishes writing to copy and unlocks connection * @param op the copy operation presumably currently holding lock on this connection * @return number of rows updated for server versions 8.2 or newer * @throws SQLException on failure */ public synchronized long endCopy(CopyInImpl op) throws SQLException { if(!hasLock(op)) throw new PSQLException(GT.tr("Tried to end inactive copy"), PSQLState.OBJECT_NOT_IN_STATE); try { pgStream.SendChar('c'); // CopyDone pgStream.SendInteger4(4); pgStream.flush(); processCopyResults(op, true); return op.getHandledRowCount(); } catch(IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when ending copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
/** * Sends data during a live COPY IN operation. Only unlocks the connection if server * suddenly returns CommandComplete, which should not happen * @param op the CopyIn operation presumably currently holding lock on this connection * @param data bytes to send * @param off index of first byte to send (usually 0) * @param siz number of bytes to send (usually data.length) * @throws SQLException on failure */ public synchronized void writeToCopy(CopyInImpl op, byte[] data, int off, int siz) throws SQLException { if(!hasLock(op)) throw new PSQLException(GT.tr("Tried to write to an inactive copy operation"), PSQLState.OBJECT_NOT_IN_STATE); if (logger.logDebug()) logger.debug(" FE=> CopyData(" + (siz-off) + ")"); try { pgStream.SendChar('d'); pgStream.SendInteger4(siz + 4); pgStream.Send(data, off, siz); processCopyResults(op, false); // collect any pending notifications without blocking } catch(IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when writing to copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
/** * Finishes writing to copy and unlocks connection * @param op the copy operation presumably currently holding lock on this connection * @return number of rows updated for server versions 8.2 or newer * @throws SQLException on failure */ public synchronized long endCopy(CopyInImpl op) throws SQLException { if(!hasLock(op)) throw new PSQLException(GT.tr("Tried to end inactive copy"), PSQLState.OBJECT_NOT_IN_STATE); try { if (logger.logDebug()) logger.debug(" FE=> CopyDone"); pgStream.SendChar('c'); // CopyDone pgStream.SendInteger4(4); pgStream.flush(); processCopyResults(op, true); return op.getHandledRowCount(); } catch(IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when ending copy"), PSQLState.CONNECTION_FAILURE, ioe); } }
/** * Sends given query to BE to start, initialize and lock connection for a CopyOperation. * @param sql COPY FROM STDIN / COPY TO STDOUT statement * @return CopyIn or CopyOut operation object * @throws SQLException on failure */ public synchronized CopyOperation startCopy(String sql, boolean suppressBegin) throws SQLException { waitOnLock(); if (!suppressBegin) { doSubprotocolBegin(); } byte buf[] = Utils.encodeUTF8(sql); try { if (logger.logDebug()) logger.debug(" FE=> Query(CopyStart)"); pgStream.SendChar('Q'); pgStream.SendInteger4(buf.length + 4 + 1); pgStream.Send(buf); pgStream.SendChar(0); pgStream.flush(); return processCopyResults(null, true); // expect a CopyInResponse or CopyOutResponse to our query above } catch(IOException ioe) { throw new PSQLException(GT.tr("Database connection failed when starting copy"), PSQLState.CONNECTION_FAILURE, ioe); } }