/** * @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(); }
RemoteTransaction getMatchingTransaction() { final AbstractTransaction transaction = ContextTransactionManager.getInstance().getTransaction(); return transaction instanceof RemoteTransaction ? (RemoteTransaction) transaction : null; }
@Override public void registerSynchronization(Synchronization synchronizedObserver) { try { final Synchronization synchronization; if (!jtsEnabled) { synchronization = synchronizedObserver; } else { synchronization = new JTSSynchronizationWrapper(synchronizedObserver); } ContextTransactionManager.getInstance().getTransaction().registerSynchronization(synchronization); } catch (IllegalStateException e) { throw new RuntimeException(e); } catch (RollbackException e) { throw new RuntimeException(e); } catch (SystemException e) { throw new RuntimeException(e); } }
protected Object never(InterceptorContext invocation, final EJBComponent component) throws Exception { final ContextTransactionManager tm = ContextTransactionManager.getInstance(); if (tm.getTransaction() != null || invocation.hasTransaction()) { throw EjbLogger.ROOT_LOGGER.txPresentForNeverTxAttribute(); } return invokeInNoTx(invocation, component); }
TransactionLogger.ROOT_LOGGER.preJcaSyncAfterCompletionFailed(preJcaSync, ContextTransactionManager.getInstance().getTransaction(), e); TransactionLogger.ROOT_LOGGER.jcaSyncAfterCompletionFailed(jcaSync, ContextTransactionManager.getInstance().getTransaction(), e);
protected Object mandatory(InterceptorContext invocation, final EJBComponent component) throws Exception { final ContextTransactionManager tm = ContextTransactionManager.getInstance(); Transaction tx = tm.getTransaction(); if (tx == null) { if (invocation.hasTransaction()) { return invokeInImportedTx(invocation, component); } throw EjbLogger.ROOT_LOGGER.txRequiredForInvocation(invocation); } return invokeInCallerTx(invocation, tx, component); }
@Override protected Object notSupported(InterceptorContext invocation, EJBComponent component) throws Exception { Transaction tx = ContextTransactionManager.getInstance().getTransaction(); int status = (tx != null) ? tx.getStatus() : Status.STATUS_NO_TRANSACTION; // If invocation was triggered from Synchronization.afterCompletion(...) // then skip suspend/resume of associated tx since JTS refuses to resume a completed tx switch (status) { case Status.STATUS_NO_TRANSACTION: case Status.STATUS_COMMITTED: case Status.STATUS_ROLLEDBACK: { return invokeInNoTx(invocation, component); } default: { return super.notSupported(invocation, component); } } }
/** * Marks the transaction for rollback * NOTE: This method will soon be removed, once this timer service * implementation becomes "managed" */ private void setRollbackOnly() { try { Transaction tx = ContextTransactionManager.getInstance().getTransaction(); if (tx != null) { tx.setRollbackOnly(); } } catch (IllegalStateException ise) { EJB3_TIMER_LOGGER.ignoringException(ise); } catch (SystemException se) { EJB3_TIMER_LOGGER.ignoringException(se); } }
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)); }
protected Object supports(InterceptorContext invocation, final EJBComponent component) throws Exception { final ContextTransactionManager tm = ContextTransactionManager.getInstance(); Transaction tx = tm.getTransaction(); if (tx == null) { if (invocation.hasTransaction()) { return invokeInImportedTx(invocation, component); } return invokeInNoTx(invocation, component); } else { return invokeInCallerTx(invocation, tx, component); } } }
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); } }
@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); } }
protected Object notSupported(InterceptorContext invocation, final EJBComponent component) throws Exception { final ContextTransactionManager tm = ContextTransactionManager.getInstance(); Transaction tx = tm.getTransaction(); if (tx != null) { safeSuspend(); final Object result; try { result = invokeInNoTx(invocation, component); } catch (Throwable t) { safeResume(tx, t); throw t; } safeResume(tx); return result; } else { return invokeInNoTx(invocation, component); } }
@Override public void registerInterposedSynchronization(Synchronization sync) throws IllegalStateException { try { AbstractTransaction tx = ContextTransactionManager.getInstance().getTransaction(); JCAOrderedLastSynchronizationList jcaOrderedLastSynchronization = (JCAOrderedLastSynchronizationList) tx.getResource(key); if (jcaOrderedLastSynchronization == null) { final ContextTransactionSynchronizationRegistry tsr = ContextTransactionSynchronizationRegistry.getInstance(); synchronized (key) { jcaOrderedLastSynchronization = (JCAOrderedLastSynchronizationList) tx.getResource(key); if (jcaOrderedLastSynchronization == null) { jcaOrderedLastSynchronization = new JCAOrderedLastSynchronizationList(); tx.putResource(key, jcaOrderedLastSynchronization); tsr.registerInterposedSynchronization(jcaOrderedLastSynchronization); } } } jcaOrderedLastSynchronization.registerInterposedSynchronization(sync); } catch (SystemException e) { throw new IllegalStateException(e); } }
protected Object requiresNew(InterceptorContext invocation, final EJBComponent component, final int timeout) throws Exception { final ContextTransactionManager tm = ContextTransactionManager.getInstance(); if (timeout != -1) { tm.setTransactionTimeout(timeout); } Transaction tx = tm.getTransaction(); if (tx != null) { safeSuspend(); final Object result; try { result = invokeInOurTx(invocation, component); } catch (Throwable t) { safeResume(tx, t); throw t; } safeResume(tx); return result; } else { return invokeInOurTx(invocation, component); } }
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 {
ContextTransactionManager tm = ContextTransactionManager.getInstance(); try { if (! tx.equals(tm.getTransaction())) { throw EjbLogger.ROOT_LOGGER.wrongTxOnThread(tx, tm.getTransaction());
private Object execute(final Interceptor interceptor, final Method method, final Object... parameters) { if (interceptor == null) return null; final InterceptorContext interceptorContext = new InterceptorContext(); //we need the method so this does not count as a lifecycle invocation interceptorContext.setMethod(method); interceptorContext.putPrivateData(Component.class, getComponent()); interceptorContext.putPrivateData(ComponentInstance.class, this); interceptorContext.putPrivateData(InvokeMethodOnTargetInterceptor.PARAMETERS_KEY, parameters); interceptorContext.setContextData(new HashMap<String, Object>()); interceptorContext.setTarget(getInstance()); final AbstractTransaction transaction = ContextTransactionManager.getInstance().getTransaction(); interceptorContext.setTransactionSupplier(() -> transaction); try { return interceptor.processInvocation(interceptorContext); } catch (Error e) { throw e; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new EJBException(e); } }
Transaction clientTX = transactionManager.getTransaction(); if (newTimer || timer.isCanceled()) { if( clientTX == null ){
public void handleInvocation(final EJBClientInvocationContext context) throws Exception { final ClientTransactionPolicy transactionPolicy = context.getTransactionPolicy(); AbstractTransaction transaction = context.getTransaction(); // Always prefer the context TX, as the caller TX might be wrong // (e.g. retries happen in worker thread, not caller thread) if (transaction == null) { transaction = transactionManager.getTransaction(); } setupStickinessIfRequired(context, transactionPolicy.propagate(), transaction); if (transactionPolicy.failIfTransactionAbsent()) { if (transaction == null) { throw Logs.TXN.txNotActiveForThread(); } } if (transactionPolicy.failIfTransactionPresent()) { if (transaction != null) { throw Logs.TXN.txAlreadyAssociatedWithThread(); } } if (transactionPolicy.propagate()) { context.setTransaction(transaction); } // Hide any caller TX from other interceptors Transaction old = transactionManager.suspend(); try { context.sendRequest(); } finally { transactionManager.resume(old); } }