ProtocolConnectionImpl(PGStream pgStream, String user, String database, Properties info, Logger logger) { this.pgStream = pgStream; this.user = user; this.database = database; this.logger = logger; this.executor = new QueryExecutorImpl(this, pgStream, info, logger); // default value for server versions that don't report standard_conforming_strings this.standardConformingStrings = false; }
public void cancelCopy() throws SQLException { queryExecutor.cancelCopy(this); }
public synchronized byte[] fastpathCall(int fnid, ParameterList parameters, boolean suppressBegin) throws SQLException { waitOnLock(); if (!suppressBegin) { doSubprotocolBegin(); } try { sendFastpathCall(fnid, (SimpleParameterList) parameters); return receiveFastpathResult(); } catch (IOException ioe) { abort(); throw new PSQLException(GT.tr("An I/O error occurred while sending to the backend."), 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); } }
receiveAsyncNotify(); break; registerParsedQuery(parsedQuery, parsedStatementName); break; registerOpenPortal(boundPortal); break; String status = receiveCommandStatus(); interpretCommandStatus(status, handler); interpretCommandStatus(status, handler); SQLException error = receiveErrorResponse(); handler.handleError(error); SQLWarning warning = receiveNoticeResponse(); handler.handleWarning(warning); break; Field[] fields = receiveFields(); tuples = new Vector(); receiveRFQ(); endQuery = true; pgStream.SendChar(0);
receiveAsyncNotify(); break; addWarning(receiveNoticeResponse()); break; String status = receiveCommandStatus(); error = receiveErrorResponse(); initCopy(op); endReceiving = true; break; initCopy(op); endReceiving = true; break; initCopy(op); endReceiving = true; break; case 'S': // Parameter Status try { receiveParameterStatus(); } catch (SQLException e) { error = e; receiveRFQ();
switch (c) { case 'A': // Asynchronous Notify receiveAsyncNotify(); break; registerOpenPortal(boundPortal); break; String status = receiveCommandStatus(); if (isFlushCacheOnDeallocate() && (status.startsWith("DEALLOCATE ALL") || status.startsWith("DISCARD ALL"))) { deallocateEpoch++; interpretCommandStatus(status, handler); interpretCommandStatus(status, handler); SQLException error = receiveErrorResponse(); handler.handleError(error); if (willHealViaReparse(error)) { SQLWarning warning = receiveNoticeResponse(); handler.handleWarning(warning); break; receiveParameterStatus(); } catch (SQLException e) { handler.handleError(e);
/** * 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); } }
if (!hasLock(op)) { throw new PSQLException(GT.tr("Tried to cancel an inactive copy operation"), PSQLState.OBJECT_NOT_IN_STATE); do { try { processCopyResults(op, true); // discard rest of input } catch (SQLException se) { // expected error response to failing copy errors++; } while (hasLock(op)); sendQueryCancel(); if (hasLock(op)) { unlock(op);
public long endCopy() throws SQLException { return queryExecutor.endCopy(this); }
public void flushCopy() throws SQLException { queryExecutor.flushCopy(this); }
public boolean isActive() { synchronized (queryExecutor) { return queryExecutor.hasLock(this); } }
/** * Locks connection and calls initializer for a new CopyOperation Called via startCopy -> * processCopyResults. * * @param op an uninitialized CopyOperation * @throws SQLException on locking failure * @throws IOException on database connection failure */ private synchronized void initCopy(CopyOperationImpl op) throws SQLException, IOException { pgStream.receiveInteger4(); // length not used int rowFormat = pgStream.receiveChar(); int numFields = pgStream.receiveInteger2(); int[] fieldFormats = new int[numFields]; for (int i = 0; i < numFields; i++) { fieldFormats[i] = pgStream.receiveInteger2(); } lock(op); op.init(this, rowFormat, fieldFormats); }
receiveAsyncNotify(); break; registerParsedQuery(parsedQuery, parsedStatementName); break; registerOpenPortal(boundPortal); break; String status = receiveCommandStatus(); interpretCommandStatus(status, handler); interpretCommandStatus(status, handler); SQLException error = receiveErrorResponse(); handler.handleError(error); SQLWarning warning = receiveNoticeResponse(); handler.handleWarning(warning); break; Field[] fields = receiveFields(); tuples = new Vector(); receiveRFQ(); endQuery = true; pgStream.SendChar(0);
receiveAsyncNotify(); break; protoConnection.addWarning(receiveNoticeResponse()); break; String status = receiveCommandStatus(); error = receiveErrorResponse(); initCopy(op); endReceiving = true; break; initCopy(op); endReceiving = true; break; receiveRFQ(); if(hasLock(op)) unlock(op); op = null; endReceiving = true; skipMessage(); break; skipMessage(); break;
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); } }
/** * 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); } }
public long endCopy() throws SQLException { return queryExecutor.endCopy(this); }
public void flushCopy() throws SQLException { queryExecutor.flushCopy(this); }
public boolean isActive() { synchronized(queryExecutor) { return queryExecutor.hasLock(this); } }