@Override protected void sendCloseMessage() throws IOException { pgStream.sendChar('X'); pgStream.sendInteger4(4); }
private void sendCloseStatement(String statementName) throws IOException { // // Send Close. // LOGGER.log(Level.FINEST, " FE=> CloseStatement({0})", statementName); byte[] encodedStatementName = Utils.encodeUTF8(statementName); // Total size = 4 (size field) + 1 (close type, 'S') + N + 1 (statement name) pgStream.sendChar('C'); // Close pgStream.sendInteger4(4 + 1 + encodedStatementName.length + 1); // message size pgStream.sendChar('S'); // Close (Statement) pgStream.send(encodedStatementName); // statement to close pgStream.sendChar(0); // statement name terminator }
private void sendClosePortal(String portalName) throws IOException { // // Send Close. // LOGGER.log(Level.FINEST, " FE=> ClosePortal({0})", portalName); byte[] encodedPortalName = (portalName == null ? null : Utils.encodeUTF8(portalName)); int encodedSize = (encodedPortalName == null ? 0 : encodedPortalName.length); // Total size = 4 (size field) + 1 (close type, 'P') + 1 + N (portal name) pgStream.sendChar('C'); // Close pgStream.sendInteger4(4 + 1 + 1 + encodedSize); // message size pgStream.sendChar('P'); // Close (Portal) if (encodedPortalName != null) { pgStream.send(encodedPortalName); } pgStream.sendChar(0); // unnamed portal }
private void sendDescribePortal(SimpleQuery query, Portal portal) throws IOException { // // Send Describe. // LOGGER.log(Level.FINEST, " FE=> Describe(portal={0})", portal); byte[] encodedPortalName = (portal == null ? null : portal.getEncodedPortalName()); // Total size = 4 (size field) + 1 (describe type, 'P') + N + 1 (portal name) int encodedSize = 4 + 1 + (encodedPortalName == null ? 0 : encodedPortalName.length) + 1; pgStream.sendChar('D'); // Describe pgStream.sendInteger4(encodedSize); // message size pgStream.sendChar('P'); // Describe (Portal) if (encodedPortalName != null) { pgStream.send(encodedPortalName); // portal name to close } pgStream.sendChar(0); // end of portal name pendingDescribePortalQueue.add(query); query.setPortalDescribed(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); }
private void sendExecute(SimpleQuery query, Portal portal, int limit) throws IOException { // // Send Execute. // if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.log(Level.FINEST, " FE=> Execute(portal={0},limit={1})", new Object[]{portal, limit}); } byte[] encodedPortalName = (portal == null ? null : portal.getEncodedPortalName()); int encodedSize = (encodedPortalName == null ? 0 : encodedPortalName.length); // Total size = 4 (size field) + 1 + N (source portal) + 4 (max rows) pgStream.sendChar('E'); // Execute pgStream.sendInteger4(4 + 1 + encodedSize + 4); // message size if (encodedPortalName != null) { pgStream.send(encodedPortalName); // portal name } pgStream.sendChar(0); // portal name terminator pgStream.sendInteger4(limit); // row limit pendingExecuteQueue.add(new ExecuteRequest(query, portal, false)); }
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 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 sendDescribeStatement(SimpleQuery query, SimpleParameterList params, boolean describeOnly) throws IOException { // Send Statement Describe LOGGER.log(Level.FINEST, " FE=> Describe(statement={0})", query.getStatementName()); byte[] encodedStatementName = query.getEncodedStatementName(); // Total size = 4 (size field) + 1 (describe type, 'S') + N + 1 (portal name) int encodedSize = 4 + 1 + (encodedStatementName == null ? 0 : encodedStatementName.length) + 1; pgStream.sendChar('D'); // Describe pgStream.sendInteger4(encodedSize); // Message size pgStream.sendChar('S'); // Describe (Statement); if (encodedStatementName != null) { pgStream.send(encodedStatementName); // Statement name } pgStream.sendChar(0); // end message // Note: statement name can change over time for the same query object // Thus we take a snapshot of the query name pendingDescribeStatementQueue.add( new DescribeRequest(query, params, describeOnly, query.getStatementName())); pendingDescribePortalQueue.add(query); query.setStatementDescribed(true); query.setPortalDescribed(true); }
public void sendScramClientFirstMessage() throws IOException { String clientFirstMessage = scramSession.clientFirstMessage(); LOGGER.log(Level.FINEST, " FE=> SASLInitialResponse( {0} )", clientFirstMessage); String scramMechanismName = scramClient.getScramMechanism().getName(); byte[] scramMechanismNameBytes = scramMechanismName.getBytes(StandardCharsets.UTF_8); byte[] clientFirstMessageBytes = clientFirstMessage.getBytes(StandardCharsets.UTF_8); sendAuthenticationMessage( (scramMechanismNameBytes.length + 1) + 4 + clientFirstMessageBytes.length, s -> { s.send(scramMechanismNameBytes); s.sendChar(0); // List terminated in '\0' s.sendInteger4(clientFirstMessageBytes.length); s.send(clientFirstMessageBytes); } ); }
/** * 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(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); } }
pgStream.sendChar('F'); pgStream.sendInteger4(4 + 4 + 2 + 2 * paramCount + 2 + encodedSize + 2); pgStream.sendInteger4(fnid);
LOGGER.log(Level.FINEST, " FE=> Password(GSS Authentication Token)"); pgStream.sendChar('p'); pgStream.sendInteger4(4 + outToken.length); pgStream.send(outToken);