@Override public void close() { if (closed) { return; } try { LOGGER.log(Level.FINEST, " FE=> Terminate"); sendCloseMessage(); pgStream.flush(); pgStream.close(); } catch (IOException ioe) { LOGGER.log(Level.FINEST, "Discarding IOException on close:", ioe); } closed = true; }
private void sendSync() throws IOException { LOGGER.log(Level.FINEST, " FE=> Sync"); pgStream.sendChar('S'); // Sync pgStream.sendInteger4(4); // Length pgStream.flush(); // Below "add queues" are likely not required at all pendingExecuteQueue.add(new ExecuteRequest(sync, null, true)); pendingDescribePortalQueue.add(sync); }
pgStream.flush();
private void sendAuthenticationMessage(int bodyLength, BodySender bodySender) throws IOException { pgStream.sendChar('p'); pgStream.sendInteger4(Integer.BYTES + bodyLength); bodySender.sendBody(pgStream); pgStream.flush(); }
private void sendSSPIResponse(byte[] outToken) throws IOException { /* * The sspiContext now contains a token we can send to the server to start the handshake. Send a * 'password' message containing the required data; the server knows we're doing SSPI * negotiation and will deal with it appropriately. */ pgStream.sendChar('p'); pgStream.sendInteger4(4 + outToken.length); pgStream.send(outToken); pgStream.flush(); }
private void sendSimpleQuery(SimpleQuery query, SimpleParameterList params) throws IOException { String nativeSql = query.toString(params); LOGGER.log(Level.FINEST, " FE=> SimpleQuery(query=\"{0}\")", nativeSql); Encoding encoding = pgStream.getEncoding(); byte[] encoded = encoding.encode(nativeSql); pgStream.sendChar('Q'); pgStream.sendInteger4(encoded.length + 4 + 1); pgStream.send(encoded); pgStream.sendChar(0); pgStream.flush(); pendingExecuteQueue.add(new ExecuteRequest(query, null, true)); pendingDescribePortalQueue.add(query); }
private void sendSync() throws IOException { if (logger.logDebug()) logger.debug(" FE=> Sync"); pgStream.SendChar('S'); // Sync pgStream.SendInteger4(4); // Length pgStream.flush(); }
protected void sendQuery(V2Query query, SimpleParameterList params, String queryPrefix) throws IOException { if (logger.logDebug()) logger.debug(" FE=> Query(\"" + (queryPrefix == null ? "" : queryPrefix) + query.toString(params) + "\")"); pgStream.SendChar('Q'); Writer encodingWriter = pgStream.getEncodingWriter(); if (queryPrefix != null) encodingWriter.write(queryPrefix); String[] fragments = query.getFragments(); for (int i = 0 ; i < fragments.length; ++i) { encodingWriter.write(fragments[i]); if (i < params.getParameterCount()) params.writeV2Value(i + 1, encodingWriter); } encodingWriter.write(0); pgStream.flush(); }
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(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); } }
cancelStream.sendInteger4(cancelPid); cancelStream.sendInteger4(cancelKey); cancelStream.flush(); cancelStream.receiveEOF(); } catch (IOException e) {
private void sendStartupPacket(PGStream pgStream, String user, String database, Logger logger) throws IOException { // 4: total size including self // 2: protocol major // 2: protocol minor // 64: database name // 32: user name // 64: options // 64: unused // 64: tty if (logger.logDebug()) logger.debug(" FE=> StartupPacket(user=" + user + ",database=" + database + ")"); pgStream.SendInteger4(4 + 4 + 64 + 32 + 64 + 64 + 64); pgStream.SendInteger2(2); // protocol major pgStream.SendInteger2(0); // protocol minor pgStream.Send(database.getBytes("UTF-8"), 64); pgStream.Send(user.getBytes("UTF-8"), 32); pgStream.Send(new byte[64]); // options pgStream.Send(new byte[64]); // unused pgStream.Send(new byte[64]); // tty pgStream.flush(); }
public void close() { if (closed) return ; try { if (logger.logDebug()) logger.debug(" FE=> Terminate"); pgStream.SendChar('X'); pgStream.flush(); pgStream.close(); } catch (IOException ioe) { // Forget it. if (logger.logDebug()) logger.debug("Discarding IOException on close:", ioe); } closed = true; }
private void sendFastpathCall(int fnid, FastpathParameterList params) throws IOException { // Send call. int count = params.getParameterCount(); if (logger.logDebug()) logger.debug(" FE=> FastpathCall(fnid=" + fnid + ",paramCount=" + count + ")"); pgStream.SendChar('F'); pgStream.SendChar(0); pgStream.SendInteger4(fnid); pgStream.SendInteger4(count); for (int i = 1; i <= count; ++i) params.writeV2FastpathValue(i, pgStream); pgStream.flush(); }
public void close() { if (closed) return ; try { if (logger.logDebug()) logger.debug(" FE=> Terminate"); pgStream.SendChar('X'); pgStream.SendInteger4(4); pgStream.flush(); pgStream.close(); } catch (IOException ioe) { // Forget it. if (logger.logDebug()) logger.debug("Discarding IOException on close:", ioe); } closed = true; }
/** * 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); } }
/** * 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); } }
pgStream.SendInteger2(1234); pgStream.SendInteger2(5679); pgStream.flush();