/** * @return Returns the current transaction, if any. Else returns null. * @throws javax.ejb.EJBException If there is any system level exception */ protected Transaction getTransaction() { return ContextTransactionManager.getInstance().getTransaction(); }
public void begin() throws NotSupportedException, SystemException { final ContextTransactionManager transactionManager = ContextTransactionManager.getInstance(); if (transactionManager.getTransaction() != null) { throw Log.log.nestedNotSupported(); } final RemoteTransactionContext context = RemoteTransactionContext.getInstancePrivate(); int timeout = stateRef.get().timeout; if (timeout == 0) timeout = ContextTransactionManager.getGlobalDefaultTransactionTimeout(); transactionManager.resume(context.notifyCreationListeners(new RemoteTransaction(authenticationContext, timeout), CreationListener.CreatedBy.USER_TRANSACTION)); }
private void safeSuspend(final Throwable t) { try { ContextTransactionManager.getInstance().suspend(); } catch (SystemException e) { t.addSuppressed(e); } }
public int getTransactionStatus() { try { return ContextTransactionManager.getInstance().getStatus(); } catch (SystemException e) { return Status.STATUS_UNKNOWN; } }
void persistTimer() { final ContextTransactionManager transactionManager = ContextTransactionManager.getInstance(); try { transactionManager.begin(); timerPersistence.getValue().persistTimer(timer); transactionManager.commit(); } catch (Exception e) { try { transactionManager.rollback(); } catch (Exception ee) { // omit; } EJB3_TIMER_LOGGER.exceptionPersistTimerState(timer, e); long nextExpirationDelay; if (nextExpirationPristine > 0 && timer.timerState != TimerState.RETRY_TIMEOUT && (nextExpirationDelay = nextExpirationPristine - System.currentTimeMillis()) > delta) { if (delta == 0L) { delta = nextExpirationDelay / (1L + MAX_RETRY.longValue()); } timerInjectedValue .getValue() .schedule(new TaskPostPersist(timer, delta, nextExpirationPristine), delta); } else { EJB3_TIMER_LOGGER.exceptionPersistPostTimerState(timer, e); } } } }
@Override public SessionID handleSessionCreation(EJBSessionCreationInvocationContext context) throws Exception { AbstractTransaction transaction = context.getTransaction(); // While session requests currently only utilize the caller thread, // this will support any future use of a worker. Additionally hides // TX from other interceptors, providing consistency with standard // invocation handling. if (transaction == null) { transaction = transactionManager.getTransaction(); context.setTransaction(transaction); } setupStickinessIfRequired(context, true, transaction); Transaction old = transactionManager.suspend(); try { return context.proceed(); } finally { transactionManager.resume(old); } }
private void safeResume(final Transaction tx, final Throwable t) { try { ContextTransactionManager.getInstance().resume(tx); } catch (Exception e) { t.addSuppressed(e); } }
ContextTransactionManager tm = ContextTransactionManager.getInstance(); try { if (! tx.equals(tm.getTransaction())) { throw EjbLogger.ROOT_LOGGER.wrongTxOnThread(tx, tm.getTransaction()); tm.commit(); } else if (txStatus == Status.STATUS_MARKED_ROLLBACK) { tm.rollback(); } else if (txStatus == Status.STATUS_ROLLEDBACK || txStatus == Status.STATUS_ROLLING_BACK) { tm.rollback(); throw EjbLogger.ROOT_LOGGER.transactionAlreadyRolledBack(tx); } else if (txStatus == Status.STATUS_UNKNOWN) { tm.rollback(); tm.suspend(); // clear current tx state and throw EJBException throw EjbLogger.ROOT_LOGGER.transactionInUnexpectedState(tx, statusAsString(txStatus));
protected Object required(final InterceptorContext invocation, final EJBComponent component, final int timeout) throws Exception { final ContextTransactionManager tm = ContextTransactionManager.getInstance(); if (timeout != -1) { tm.setTransactionTimeout(timeout); } final Transaction tx = tm.getTransaction(); if (tx == null) { if (invocation.hasTransaction()) { return invokeInImportedTx(invocation, component); } return invokeInOurTx(invocation, component); } else { return invokeInCallerTx(invocation, tx, component); } }
public Object getResource(final Object key) throws IllegalStateException { final AbstractTransaction transaction = ContextTransactionManager.getInstance().getStateRef().get().transaction; if (transaction == null) { throw Log.log.noTransaction(); } return transaction.getResource(key); }
protected Object invokeInOurTx(InterceptorContext invocation, final EJBComponent component) throws Exception { final ContextTransactionManager tm = ContextTransactionManager.getInstance(); tm.begin(); final AbstractTransaction tx = tm.getTransaction(); final Object result; try {
public void begin() throws NotSupportedException, SystemException { checkTransactionStateAvailability(); ContextTransactionManager.getInstance().begin(CreationListener.CreatedBy.USER_TRANSACTION); }
public void setRollbackOnly() throws IllegalStateException { try { ContextTransactionManager.getInstance().setRollbackOnly(); } catch (SystemException e) { // ignored } }
@Override public TransactionManager getValue() throws IllegalStateException { return ContextTransactionManager.getInstance(); } }
public Object processInvocation(InterceptorContext invocation) throws Exception { final EJBComponent component = (EJBComponent) invocation.getPrivateData(Component.class); final ContextTransactionManager tm = ContextTransactionManager.getInstance(); final int oldTimeout = tm.getTransactionTimeout(); try { final MethodIntf methodIntf = MethodIntfHelper.of(invocation); final TransactionAttributeType attr = component.getTransactionAttributeType(methodIntf, invocation.getMethod()); final int timeoutInSeconds = component.getTransactionTimeout(methodIntf, invocation.getMethod()); switch (attr) { case MANDATORY: return mandatory(invocation, component); case NEVER: return never(invocation, component); case NOT_SUPPORTED: return notSupported(invocation, component); case REQUIRED: return required(invocation, component, timeoutInSeconds); case REQUIRES_NEW: return requiresNew(invocation, component, timeoutInSeconds); case SUPPORTS: return supports(invocation, component); default: throw EjbLogger.ROOT_LOGGER.unknownTxAttributeOnInvocation(attr, invocation); } } finally { // See also https://issues.jboss.org/browse/WFTC-44 tm.setTransactionTimeout(oldTimeout == ContextTransactionManager.getGlobalDefaultTransactionTimeout() ? 0 : oldTimeout); } }
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException { checkTransactionStateAvailability(); ContextTransactionManager.getInstance().commit(); }
public boolean isAvailable() { return ContextTransactionManager.getInstance().isAvailable(); }
public void setTransactionTimeout(final int seconds) throws SystemException { checkTransactionStateAvailability(); ContextTransactionManager.getInstance().setTransactionTimeout(seconds); }
public void rollback() throws IllegalStateException, SecurityException, SystemException { ContextTransactionManager transactionManager = ContextTransactionManager.getInstance(); final RemoteTransaction remoteTransaction = getMatchingTransaction(); if (remoteTransaction == null) { throw Log.log.invalidTxnState(); } else { transactionManager.rollback(); } }