Search in sources :

Example 1 with Session

use of org.apache.qpid.protonj2.engine.Session in project SpringStudy by myounghaklee.

the class Command method executeQuery.

/**
 * Execute a query and return the result.
 * This method prepares everything and calls {@link #query(long)} finally.
 *
 * @param maxrows the maximum number of rows to return
 * @param scrollable if the result set must be scrollable (ignored)
 * @return the result set
 */
@Override
public ResultInterface executeQuery(long maxrows, boolean scrollable) {
    startTimeNanos = 0L;
    long start = 0L;
    Database database = session.getDatabase();
    session.waitIfExclusiveModeEnabled();
    boolean callStop = true;
    // noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (session) {
        session.startStatementWithinTransaction(this);
        Session oldSession = session.setThreadLocalSession();
        try {
            while (true) {
                database.checkPowerOff();
                try {
                    ResultInterface result = query(maxrows);
                    callStop = !result.isLazy();
                    if (database.getMode().charPadding == CharPadding.IN_RESULT_SETS) {
                        return ResultWithPaddedStrings.get(result);
                    }
                    return result;
                } catch (DbException e) {
                    // cannot retry DDL
                    if (isCurrentCommandADefineCommand()) {
                        throw e;
                    }
                    start = filterConcurrentUpdate(e, start);
                } catch (OutOfMemoryError e) {
                    callStop = false;
                    // there is a serious problem:
                    // the transaction may be applied partially
                    // in this case we need to panic:
                    // close the database
                    database.shutdownImmediately();
                    throw DbException.convert(e);
                } catch (Throwable e) {
                    throw DbException.convert(e);
                }
            }
        } catch (DbException e) {
            e = e.addSQL(sql);
            SQLException s = e.getSQLException();
            database.exceptionThrown(s, sql);
            if (s.getErrorCode() == ErrorCode.OUT_OF_MEMORY) {
                callStop = false;
                database.shutdownImmediately();
                throw e;
            }
            database.checkPowerOff();
            throw e;
        } finally {
            session.resetThreadLocalSession(oldSession);
            session.endStatement();
            if (callStop) {
                stop();
            }
        }
    }
}
Also used : ResultInterface(org.h2.result.ResultInterface) SQLException(java.sql.SQLException) Database(org.h2.engine.Database) Session(org.h2.engine.Session) DbException(org.h2.message.DbException)

Example 2 with Session

use of org.apache.qpid.protonj2.engine.Session in project SpringStudy by myounghaklee.

the class Command method executeUpdate.

@Override
public ResultWithGeneratedKeys executeUpdate(Object generatedKeysRequest) {
    long start = 0;
    Database database = session.getDatabase();
    session.waitIfExclusiveModeEnabled();
    boolean callStop = true;
    // noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (session) {
        commitIfNonTransactional();
        SessionLocal.Savepoint rollback = session.setSavepoint();
        session.startStatementWithinTransaction(this);
        DbException ex = null;
        Session oldSession = session.setThreadLocalSession();
        try {
            while (true) {
                database.checkPowerOff();
                try {
                    return update(generatedKeysRequest);
                } catch (DbException e) {
                    // cannot retry DDL
                    if (isCurrentCommandADefineCommand()) {
                        throw e;
                    }
                    start = filterConcurrentUpdate(e, start);
                } catch (OutOfMemoryError e) {
                    callStop = false;
                    database.shutdownImmediately();
                    throw DbException.convert(e);
                } catch (Throwable e) {
                    throw DbException.convert(e);
                }
            }
        } catch (DbException e) {
            e = e.addSQL(sql);
            SQLException s = e.getSQLException();
            database.exceptionThrown(s, sql);
            if (s.getErrorCode() == ErrorCode.OUT_OF_MEMORY) {
                callStop = false;
                database.shutdownImmediately();
                throw e;
            }
            try {
                database.checkPowerOff();
                if (s.getErrorCode() == ErrorCode.DEADLOCK_1) {
                    session.rollback();
                } else {
                    session.rollbackTo(rollback);
                }
            } catch (Throwable nested) {
                e.addSuppressed(nested);
            }
            ex = e;
            throw e;
        } finally {
            session.resetThreadLocalSession(oldSession);
            try {
                session.endStatement();
                if (callStop) {
                    stop();
                }
            } catch (Throwable nested) {
                if (ex == null) {
                    throw nested;
                } else {
                    ex.addSuppressed(nested);
                }
            }
        }
    }
}
Also used : SessionLocal(org.h2.engine.SessionLocal) SQLException(java.sql.SQLException) Database(org.h2.engine.Database) DbException(org.h2.message.DbException) Session(org.h2.engine.Session)

Example 3 with Session

use of org.apache.qpid.protonj2.engine.Session in project qpid-protonj2 by apache.

the class ClientExceptionSupport method convertToSessionClosedException.

/**
 * Given an ErrorCondition instance create a new Exception that best matches
 * the error type that indicates the session creation failed for some reason.
 *
 * @param errorCondition
 *      The ErrorCondition returned from the remote peer.
 *
 * @return a new Exception instance that best matches the ErrorCondition value.
 */
public static ClientSessionRemotelyClosedException convertToSessionClosedException(ErrorCondition errorCondition) {
    final ClientSessionRemotelyClosedException remoteError;
    if (errorCondition != null && errorCondition.getCondition() != null) {
        String message = extractErrorMessage(errorCondition);
        if (message == null) {
            message = "Session remotely closed without explanation";
        }
        remoteError = new ClientSessionRemotelyClosedException(message, new ClientErrorCondition(errorCondition));
    } else {
        remoteError = new ClientSessionRemotelyClosedException("Session remotely closed without explanation");
    }
    return remoteError;
}
Also used : ClientSessionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientSessionRemotelyClosedException)

Example 4 with Session

use of org.apache.qpid.protonj2.engine.Session in project qpid-protonj2 by apache.

the class ClientLocalTransactionContext method handleTransactionDischargeFailed.

private void handleTransactionDischargeFailed(Transaction<TransactionController> transaction) {
    ClientFuture<Session> future = transaction.getAttachments().get(DISCHARGE_FUTURE_NAME);
    LOG.trace("Discharge of transaction:{} failed", transaction);
    ClientException cause = ClientExceptionSupport.convertToNonFatalException(transaction.getCondition());
    future.failed(new ClientTransactionRolledBackException(cause.getMessage(), cause));
}
Also used : ClientTransactionRolledBackException(org.apache.qpid.protonj2.client.exceptions.ClientTransactionRolledBackException) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) Session(org.apache.qpid.protonj2.client.Session)

Example 5 with Session

use of org.apache.qpid.protonj2.engine.Session in project qpid-protonj2 by apache.

the class ClientReceiverBuilder method receiver.

public ClientReceiver receiver(String address, ReceiverOptions receiverOptions) throws ClientException {
    final ReceiverOptions rcvOptions = receiverOptions != null ? receiverOptions : getDefaultReceiverOptions();
    final String receiverId = nextReceiverId();
    final Receiver protonReceiver = createReceiver(address, rcvOptions, receiverId);
    protonReceiver.setSource(createSource(address, rcvOptions));
    protonReceiver.setTarget(createTarget(address, rcvOptions));
    return new ClientReceiver(session, rcvOptions, receiverId, protonReceiver);
}
Also used : ReceiverOptions(org.apache.qpid.protonj2.client.ReceiverOptions) StreamReceiverOptions(org.apache.qpid.protonj2.client.StreamReceiverOptions) Receiver(org.apache.qpid.protonj2.engine.Receiver)

Aggregations

Test (org.junit.jupiter.api.Test)306 Connection (org.apache.qpid.protonj2.engine.Connection)248 Engine (org.apache.qpid.protonj2.engine.Engine)247 ProtonTestConnector (org.apache.qpid.protonj2.test.driver.ProtonTestConnector)247 Session (org.apache.qpid.protonj2.engine.Session)241 Client (org.apache.qpid.protonj2.client.Client)180 Connection (org.apache.qpid.protonj2.client.Connection)180 URI (java.net.URI)178 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)178 Session (org.apache.qpid.protonj2.client.Session)167 Sender (org.apache.qpid.protonj2.engine.Sender)95 Receiver (org.apache.qpid.protonj2.engine.Receiver)88 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)85 AtomicReference (java.util.concurrent.atomic.AtomicReference)71 Sender (org.apache.qpid.protonj2.client.Sender)66 Receiver (org.apache.qpid.protonj2.client.Receiver)64 OutgoingDelivery (org.apache.qpid.protonj2.engine.OutgoingDelivery)52 ConnectionOptions (org.apache.qpid.protonj2.client.ConnectionOptions)45 Session (org.h2.engine.Session)43 ProtonBuffer (org.apache.qpid.protonj2.buffer.ProtonBuffer)37