private void sendCloseStatement(String statementName) throws IOException { // // Send Close. // if (logger.logDebug()) { logger.debug(" FE=> CloseStatement(" + 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. // if (logger.logDebug()) { logger.debug(" FE=> ClosePortal(" + 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. // if (logger.logDebug()) { logger.debug(" FE=> Describe(portal=" + 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 sendDescribeStatement(SimpleQuery query, SimpleParameterList params, boolean describeOnly) throws IOException { // Send Statement Describe if (logger.logDebug()) { logger.debug(" FE=> Describe(statement=" + 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 pendingDescribeStatementQueue.add(new Object[]{query, params, new Boolean(describeOnly), query.getStatementName()}); pendingDescribePortalQueue.add(query); query.setStatementDescribed(true); query.setPortalDescribed(true); }
private void sendExecute(SimpleQuery query, Portal portal, int limit) throws IOException { // // Send Execute. // if (logger.logDebug()) { logger.debug(" FE=> Execute(portal=" + portal + ",limit=" + 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 Object[] { query, portal }); }
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(); }
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 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; }
/** * 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); } }
+ 2 + 4 * params.getParameterCount(); pgStream.SendChar('P'); // Parse pgStream.SendInteger4(encodedSize); if (encodedStatementName != null) pgStream.Send(encodedStatementName); pgStream.SendChar(0); // End of statement name for (int i = 0; i < parts.length; ++i) pgStream.SendChar(0); // End of query string.
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; }
/** * 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); } }
pgStream.SendChar('F'); pgStream.SendInteger4(4 + 4 + 2 + 2 * paramCount + 2 + encodedSize + 2); pgStream.SendInteger4(fnid);
logger.debug(" FE=> Password(GSS Authentication Token)"); pgStream.SendChar('p'); pgStream.SendInteger4(4 + outToken.length); pgStream.Send(outToken);