public void debug(String str, Throwable t) { if (logDebug()) log(str, t); }
private SQLWarning receiveNotification() throws IOException { String warnMsg = pgStream.ReceiveString(); // Strip out the severity field so we have consistency with // the V3 protocol. SQLWarning.getMessage should return just // the actual message. // int severityMark = warnMsg.indexOf(":"); warnMsg = warnMsg.substring(severityMark+1).trim(); if (logger.logDebug()) logger.debug(" <=BE NoticeResponse(" + warnMsg + ")"); return new SQLWarning(warnMsg); }
/**** XAConnection interface ****/ public Connection getConnection() throws SQLException { if (logger.logDebug()) debug("PGXAConnection.getConnection called"); Connection conn = super.getConnection(); // When we're outside an XA transaction, autocommit // is supposed to be true, per usual JDBC convention. // When an XA transaction is in progress, it should be // false. if(state == STATE_IDLE) conn.setAutoCommit(true); /* * Wrap the connection in a proxy to forbid application from * fiddling with transaction state directly during an XA transaction */ ConnectionHandler handler = new ConnectionHandler(conn); return (Connection)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Connection.class, PGConnection.class}, handler); }
private SQLException receiveErrorMessage() throws IOException { String errorMsg = pgStream.ReceiveString().trim(); if (logger.logDebug()) logger.debug(" <=BE ErrorResponse(" + errorMsg + ")"); return new PSQLException(errorMsg, PSQLState.UNKNOWN_STATE); }
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 sendSync() throws IOException { if (logger.logDebug()) logger.debug(" FE=> Sync"); pgStream.SendChar('S'); // Sync pgStream.SendInteger4(4); // Length pgStream.flush(); }
private String receiveCommandStatus() throws IOException { //TODO: better handle the msg len int l_len = pgStream.ReceiveInteger4(); //read l_len -5 bytes (-4 for l_len and -1 for trailing \0) String status = pgStream.ReceiveString(l_len - 5); //now read and discard the trailing \0 pgStream.Receive(1); if (logger.logDebug()) logger.debug(" <=BE CommandStatus(" + status + ")"); return status; }
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(); }
private void receiveAsyncNotify() throws IOException { int pid = pgStream.ReceiveInteger4(); String msg = pgStream.ReceiveString(); if (logger.logDebug()) logger.debug(" <=BE AsyncNotify(pid=" + pid + ",msg=" + msg + ")"); protoConnection.addNotification(new org.postgresql.core.Notification(msg, pid)); }
public void commit(Xid xid, boolean onePhase) throws XAException { if (logger.logDebug()) debug("committing xid = " + xid + (onePhase ? " (one phase) " : " (two phase)")); if (xid == null) throw new PGXAException(GT.tr("xid must not be null"), XAException.XAER_INVAL); if (onePhase) commitOnePhase(xid); else commitPrepared(xid); }
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 receiveAsyncNotify() throws IOException { int msglen = pgStream.ReceiveInteger4(); int pid = pgStream.ReceiveInteger4(); String msg = pgStream.ReceiveString(); String param = pgStream.ReceiveString(); protoConnection.addNotification(new org.postgresql.core.Notification(msg, pid, param)); if (logger.logDebug()) logger.debug(" <=BE AsyncNotify(" + pid + "," + msg + "," + param + ")"); }
private SQLException receiveErrorResponse() throws IOException { // it's possible to get more than one error message for a query // see libpq comments wrt backend closing a connection // so, append messages to a string buffer and keep processing // check at the bottom to see if we need to throw an exception int elen = pgStream.ReceiveInteger4(); String totalMessage = pgStream.ReceiveString(elen - 4); ServerErrorMessage errorMsg = new ServerErrorMessage(totalMessage, logger.getLogLevel()); if (logger.logDebug()) logger.debug(" <=BE ErrorMessage(" + errorMsg.toString() + ")"); return new PSQLException(errorMsg); }
private SQLWarning receiveNoticeResponse() throws IOException { int nlen = pgStream.ReceiveInteger4(); ServerErrorMessage warnMsg = new ServerErrorMessage(pgStream.ReceiveString(nlen - 4), logger.getLogLevel()); if (logger.logDebug()) logger.debug(" <=BE NoticeResponse(" + warnMsg.toString() + ")"); return new PSQLWarning(warnMsg); }
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(); }
private Field[] receiveFields() throws IOException { int size = pgStream.ReceiveInteger2(); Field[] fields = new Field[size]; if (logger.logDebug()) logger.debug(" <=BE RowDescription(" + fields.length + ")"); for (int i = 0; i < fields.length; i++) { String columnLabel = pgStream.ReceiveString(); int typeOid = pgStream.ReceiveInteger4(); int typeLength = pgStream.ReceiveInteger2(); int typeModifier = pgStream.ReceiveInteger4(); fields[i] = new Field(columnLabel, columnLabel, typeOid, typeLength, typeModifier, 0, 0); } return fields; }
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 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 }