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();
}
}
}
}
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);
}
}
}
}
}
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;
}
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));
}
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);
}
Aggregations