当前位置: 首页>>代码示例>>Java>>正文


Java ProtocolConnection类代码示例

本文整理汇总了Java中org.postgresql.core.ProtocolConnection的典型用法代码示例。如果您正苦于以下问题:Java ProtocolConnection类的具体用法?Java ProtocolConnection怎么用?Java ProtocolConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ProtocolConnection类属于org.postgresql.core包,在下文中一共展示了ProtocolConnection类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: receiveRFQ

import org.postgresql.core.ProtocolConnection; //导入依赖的package包/类
private void receiveRFQ() throws IOException {
    if (pgStream.ReceiveInteger4() != 5)
        throw new IOException("unexpected length of ReadyForQuery message");

    char tStatus = (char)pgStream.ReceiveChar();
    if (logger.logDebug())
        logger.debug(" <=BE ReadyForQuery(" + tStatus + ")");

    // Update connection state.
    switch (tStatus)
    {
    case 'I':
        protoConnection.setTransactionState(ProtocolConnection.TRANSACTION_IDLE);
        break;
    case 'T':
        protoConnection.setTransactionState(ProtocolConnection.TRANSACTION_OPEN);
        break;
    case 'E':
        protoConnection.setTransactionState(ProtocolConnection.TRANSACTION_FAILED);
        break;
    default:
        throw new IOException("unexpected transaction state in ReadyForQuery message: " + (int)tStatus);
    }
}
 
开发者ID:yngui,项目名称:jephyr,代码行数:25,代码来源:QueryExecutorImpl.java

示例2: processNotifies

import org.postgresql.core.ProtocolConnection; //导入依赖的package包/类
public synchronized void processNotifies() throws SQLException {
    lock.lock();
    try {
        // Asynchronous notifies only arrive when we are not in a transaction
        if (protoConnection.getTransactionState() != ProtocolConnection.TRANSACTION_IDLE)
            return;

        try {
            while (pgStream.hasMessagePending()) {
                int c = pgStream.ReceiveChar();
                switch (c) {
                case 'A':  // Asynchronous Notify
                    receiveAsyncNotify();
                    break;
                case 'E':  // Error Message
                    throw receiveErrorMessage();
                    // break;
                case 'N':  // Error Notification
                    protoConnection.addWarning(receiveNotification());
                    break;
                default:
                    throw new PSQLException(GT.tr("Unknown Response Type {0}.", (char) c), PSQLState.CONNECTION_FAILURE);
                }
            }
        } catch (IOException ioe) {
            throw new PSQLException(GT.tr("An I/O error occurred while sending to the backend."), PSQLState.CONNECTION_FAILURE, ioe);
        }
    } finally {
        lock.unlock();
    }
}
 
开发者ID:yngui,项目名称:jephyr,代码行数:32,代码来源:QueryExecutorImpl.java

示例3: commitPrepared

import org.postgresql.core.ProtocolConnection; //导入依赖的package包/类
/**
 * Preconditions:
 * 1. xid must be in prepared state in the server
 *
 * Implementation deficiency preconditions:
 * 1. Connection must be in idle state
 * 
 * Postconditions:
 * 1. Transaction is committed
 */
private void commitPrepared(Xid xid) throws XAException {
    try
    {
        // Check preconditions. The connection mustn't be used for another
        // other XA or local transaction, or the COMMIT PREPARED command
        // would mess it up.
        if (state != STATE_IDLE || conn.getTransactionState() != ProtocolConnection.TRANSACTION_IDLE)
            throw new PGXAException(GT.tr("Not implemented: 2nd phase commit must be issued using an idle connection"),
                                    XAException.XAER_RMERR);

        String s = RecoveredXid.xidToString(xid);

        localAutoCommitMode = conn.getAutoCommit();
        conn.setAutoCommit(true);
        Statement stmt = conn.createStatement();
        try
        {
            stmt.executeUpdate("COMMIT PREPARED '" + s + "'");
        }
        finally
        {
            stmt.close();
            conn.setAutoCommit(localAutoCommitMode);
        }
    }
    catch (SQLException ex)
    {
        throw new PGXAException(GT.tr("Error committing prepared transaction"), ex, XAException.XAER_RMERR);
    }
}
 
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:41,代码来源:PGXAConnection.java

示例4: interpretCommandStatus

import org.postgresql.core.ProtocolConnection; //导入依赖的package包/类
private void interpretCommandStatus(String status, ResultHandler handler) throws IOException {
    int update_count = 0;
    long insert_oid = 0;

    if (status.equals("BEGIN"))
        protoConnection.setTransactionState(ProtocolConnection.TRANSACTION_OPEN);
    else if (status.equals("COMMIT") || status.equals("ROLLBACK"))
        protoConnection.setTransactionState(ProtocolConnection.TRANSACTION_IDLE);
    else if (status.startsWith("INSERT") || status.startsWith("UPDATE") || status.startsWith("DELETE") || status.startsWith("MOVE"))
    {
        try
        {
            long updates = Long.parseLong(status.substring(1 + status.lastIndexOf(' ')));

            // deal with situations where the update modifies more than 2^32 rows
            if ( updates > Integer.MAX_VALUE )
                update_count = Statement.SUCCESS_NO_INFO;
            else
                update_count = (int)updates;
            
            if (status.startsWith("INSERT"))
                insert_oid = Long.parseLong(status.substring(1 + status.indexOf(' '),
                                            status.lastIndexOf(' ')));
        }
        catch (NumberFormatException nfe)
        {
            handler.handleError(new PSQLException(GT.tr("Unable to interpret the update count in command completion tag: {0}.", status), PSQLState.CONNECTION_FAILURE));
            return ;
        }
    }

    handler.handleCommandStatus(status, update_count, insert_oid);
}
 
开发者ID:yngui,项目名称:jephyr,代码行数:34,代码来源:QueryExecutorImpl.java

示例5: sendQueryPreamble

import org.postgresql.core.ProtocolConnection; //导入依赖的package包/类
private ResultHandler sendQueryPreamble(final ResultHandler delegateHandler, int flags) throws IOException {
    // First, send CloseStatements for finalized SimpleQueries that had statement names assigned.
    processDeadParsedQueries();
    processDeadPortals();

    // Send BEGIN on first statement in transaction.
    if ((flags & QueryExecutor.QUERY_SUPPRESS_BEGIN) != 0 ||
            protoConnection.getTransactionState() != ProtocolConnection.TRANSACTION_IDLE)
        return delegateHandler;

    int beginFlags = QueryExecutor.QUERY_NO_METADATA;
    if ((flags & QueryExecutor.QUERY_ONESHOT) != 0) {
      beginFlags |= QueryExecutor.QUERY_ONESHOT;
    }
    sendOneQuery(beginTransactionQuery, SimpleQuery.NO_PARAMETERS, 0, 0, beginFlags);

    // Insert a handler that intercepts the BEGIN.
    return new ResultHandler() {
               private boolean sawBegin = false;

               public void handleResultRows(Query fromQuery, Field[] fields, List tuples, ResultCursor cursor) {
                   if (sawBegin)
                       delegateHandler.handleResultRows(fromQuery, fields, tuples, cursor);
               }

               public void handleCommandStatus(String status, int updateCount, long insertOID) {
                   if (!sawBegin)
                   {
                       sawBegin = true;
                       if (!status.equals("BEGIN"))
                           handleError(new PSQLException(GT.tr("Expected command status BEGIN, got {0}.", status),
                                                         PSQLState.PROTOCOL_VIOLATION));
                   }
                   else
                   {
                       delegateHandler.handleCommandStatus(status, updateCount, insertOID);
                   }
               }

               public void handleWarning(SQLWarning warning) {
                   delegateHandler.handleWarning(warning);
               }

               public void handleError(SQLException error) {
                   delegateHandler.handleError(error);
               }

               public void handleCompletion() throws SQLException{
                   delegateHandler.handleCompletion();
               }
           };
}
 
开发者ID:yngui,项目名称:jephyr,代码行数:53,代码来源:QueryExecutorImpl.java

示例6: doSubprotocolBegin

import org.postgresql.core.ProtocolConnection; //导入依赖的package包/类
public void doSubprotocolBegin() throws SQLException {
    if (protoConnection.getTransactionState() == ProtocolConnection.TRANSACTION_IDLE)
    {

        if (logger.logDebug())
            logger.debug("Issuing BEGIN before fastpath or copy call.");

        ResultHandler handler = new ResultHandler() {
                                    private boolean sawBegin = false;
                                    private SQLException sqle = null;

                                    public void handleResultRows(Query fromQuery, Field[] fields, List tuples, ResultCursor cursor) {
                                    }

                                    public void handleCommandStatus(String status, int updateCount, long insertOID) {
                                        if (!sawBegin)
                                        {
                                            if (!status.equals("BEGIN"))
                                                handleError(new PSQLException(GT.tr("Expected command status BEGIN, got {0}.", status),
                                                                              PSQLState.PROTOCOL_VIOLATION));
                                            sawBegin = true;
                                        }
                                        else
                                        {
                                            handleError(new PSQLException(GT.tr("Unexpected command status: {0}.", status),
                                                                          PSQLState.PROTOCOL_VIOLATION));
                                        }
                                    }

                                    public void handleWarning(SQLWarning warning) {
                                        // we don't want to ignore warnings and it would be tricky
                                        // to chain them back to the connection, so since we don't
                                        // expect to get them in the first place, we just consider
                                        // them errors.
                                        handleError(warning);
                                    }

                                    public void handleError(SQLException error) {
                                        if (sqle == null)
                                        {
                                            sqle = error;
                                        }
                                        else
                                        {
                                            sqle.setNextException(error);
                                        }
                                    }

                                    public void handleCompletion() throws SQLException{
                                        if (sqle != null)
                                            throw sqle;
                                    }
                                };

        try
        {
            sendOneQuery(beginTransactionQuery, SimpleQuery.NO_PARAMETERS, 0, 0, QueryExecutor.QUERY_NO_METADATA);
            sendSync();
            processResults(handler, 0);
            estimatedReceiveBufferBytes = 0;
        }
        catch (IOException ioe)
        {
            throw new PSQLException(GT.tr("An I/O error occurred while sending to the backend."), PSQLState.CONNECTION_FAILURE, ioe);
        }
    }

}
 
开发者ID:yngui,项目名称:jephyr,代码行数:69,代码来源:QueryExecutorImpl.java

示例7: processNotifies

import org.postgresql.core.ProtocolConnection; //导入依赖的package包/类
public void processNotifies() throws SQLException {
    lock.lock();
    try {
        waitOnLock();
        // Asynchronous notifies only arrive when we are not in a transaction
        if (protoConnection.getTransactionState() != ProtocolConnection.TRANSACTION_IDLE)
            return;

        try {
            while (pgStream.hasMessagePending()) {
                int c = pgStream.ReceiveChar();
                switch (c) {
                case 'A':  // Asynchronous Notify
                    receiveAsyncNotify();
                    break;
                case 'E':  // Error Response (response to pretty much everything; backend then skips until Sync)
                    throw receiveErrorResponse();
                    // break;
                case 'N':  // Notice Response (warnings / info)
                    SQLWarning warning = receiveNoticeResponse();
                    protoConnection.addWarning(warning);
                    break;
                default:
                    throw new PSQLException(GT.tr("Unknown Response Type {0}.", (char) c), PSQLState.CONNECTION_FAILURE);
                }
            }
        } catch (IOException ioe) {
            throw new PSQLException(GT.tr("An I/O error occurred while sending to the backend."), PSQLState.CONNECTION_FAILURE, ioe);
        }
    } finally {
        lock.unlock();
    }
}
 
开发者ID:yngui,项目名称:jephyr,代码行数:34,代码来源:QueryExecutorImpl.java


注:本文中的org.postgresql.core.ProtocolConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。