protected int getCurrentTransactionTimeout(final EJBComponent component) throws SystemException { final TransactionManager tm = component.getTransactionManager(); if (tm instanceof TransactionTimeoutConfiguration) { return ((TransactionTimeoutConfiguration) tm).getTransactionTimeout(); } return 0; }
public void setRollbackOnly() throws IllegalStateException { if (isBeanManagedTransaction()) { throw EjbLogger.ROOT_LOGGER.failToCallSetRollbackOnlyOnNoneCMB(); } try { // get the transaction manager TransactionManager tm = getTransactionManager(); // check if there's a tx in progress. If not, then it's an error to call setRollbackOnly() if (tm.getTransaction() == null) { throw EjbLogger.ROOT_LOGGER.failToCallSetRollbackOnlyWithNoTx(); } // set rollback tm.setRollbackOnly(); } catch (SystemException se) { EjbLogger.ROOT_LOGGER.setRollbackOnlyFailed(se); } }
@Override protected Object handleInvocation(final InterceptorContext invocation) throws Exception { final EJBComponent ejbComponent = getComponent(); TransactionManager tm = ejbComponent.getTransactionManager(); assert tm.getTransaction() == null : "can't handle BMT transaction, there is a transaction active"; boolean exceptionThrown = false; try { return invocation.proceed(); } catch (Throwable ex) { exceptionThrown = true; checkStatelessDone(ejbComponent, invocation, tm, ex); //we should never get here, as checkStatelessDone should re-throw throw (Exception)ex; } finally { try { if (!exceptionThrown) checkStatelessDone(ejbComponent, invocation, tm, null); } finally { tm.suspend(); } } }
private void checkBadStateful() { int status = Status.STATUS_NO_TRANSACTION; TransactionManager tm = getComponent().getTransactionManager(); try { status = tm.getStatus(); } catch (SystemException ex) { EjbLogger.ROOT_LOGGER.failedToGetStatus(ex); } switch (status) { case Status.STATUS_COMMITTING: case Status.STATUS_MARKED_ROLLBACK: case Status.STATUS_PREPARING: case Status.STATUS_ROLLING_BACK: try { tm.rollback(); } catch (Exception ex) { EjbLogger.ROOT_LOGGER.failedToRollback(ex); } EjbLogger.ROOT_LOGGER.transactionNotComplete(getComponent().getComponentName(), statusAsString(status)); } }
public boolean getRollbackOnly() throws IllegalStateException { if (isBeanManagedTransaction()) { throw EjbLogger.ROOT_LOGGER.failToCallgetRollbackOnly(); } try { TransactionManager tm = this.getTransactionManager(); // The getRollbackOnly method should be used only in the context of a transaction. if (tm.getTransaction() == null) { throw EjbLogger.ROOT_LOGGER.failToCallgetRollbackOnlyOnNoneTransaction(); } // EJBTHREE-805, consider an asynchronous rollback due to timeout // This is counter to EJB 3.1 where an asynchronous call does not inherit the transaction context! int status = tm.getStatus(); EjbLogger.ROOT_LOGGER.tracef("Current transaction status is %d", status); switch (status) { case Status.STATUS_COMMITTED: case Status.STATUS_ROLLEDBACK: throw EjbLogger.ROOT_LOGGER.failToCallgetRollbackOnlyAfterTxcompleted(); case Status.STATUS_MARKED_ROLLBACK: case Status.STATUS_ROLLING_BACK: return true; } return false; } catch (SystemException se) { EjbLogger.ROOT_LOGGER.getTxManagerStatusFailed(se); return true; } }
@Override public Object processInvocation(final InterceptorContext context) throws Exception { TransactionManager tm = component.getTransactionManager(); int oldTimeout = getCurrentTransactionTimeout(component); try { Transaction oldTx = tm.suspend(); try { return handleInvocation(context); } finally { if (oldTx != null) tm.resume(oldTx); } } finally { tm.setTransactionTimeout(oldTimeout == -1 ? 0 : oldTimeout); } }
final StatefulSessionComponentInstance instance = (StatefulSessionComponentInstance) invocation.getPrivateData(ComponentInstance.class); TransactionManager tm = getComponent().getTransactionManager(); assert tm.getTransaction() == null : "can't handle BMT transaction, there is a transaction active";
protected int getCurrentTransactionTimeout(final EJBComponent component) throws SystemException { final TransactionManager tm = component.getTransactionManager(); if (tm instanceof TransactionTimeoutConfiguration) { return ((TransactionTimeoutConfiguration) tm).getTransactionTimeout(); } return 0; }
protected Object mandatory(InterceptorContext invocation, final EJBComponent component) throws Exception { final TransactionManager tm = component.getTransactionManager(); Transaction tx = tm.getTransaction(); if (tx == null) { throw EjbMessages.MESSAGES.txRequiredForInvocation(invocation); } return invokeInCallerTx(invocation, tx, component); }
protected Object supports(InterceptorContext invocation, final EJBComponent component) throws Exception { final TransactionManager tm = component.getTransactionManager(); Transaction tx = tm.getTransaction(); if (tx == null) { return invokeInNoTx(invocation, component); } else { return invokeInCallerTx(invocation, tx, component); } } }
protected Object never(InterceptorContext invocation, final EJBComponent component) throws Exception { final TransactionManager tm = component.getTransactionManager(); if (tm.getTransaction() != null) { throw EjbMessages.MESSAGES.txPresentForNeverTxAttribute(); } return invokeInNoTx(invocation, component); }
@Override public Object processInvocation(final InterceptorContext context) throws Exception { TransactionManager tm = component.getTransactionManager(); Transaction oldTx = tm.suspend(); try { return handleInvocation(context); } finally { if (oldTx != null) tm.resume(oldTx); } }
protected Object notSupported(InterceptorContext invocation, final EJBComponent component) throws Exception { final TransactionManager tm = component.getTransactionManager(); Transaction tx = tm.getTransaction(); if (tx != null) { tm.suspend(); try { return invokeInNoTx(invocation, component); } finally { tm.resume(tx); } } else { return invokeInNoTx(invocation, component); } }
@Override public synchronized void start(final StartContext context) throws StartException { logger.debug("Starting timerservice for timedObjectId: " + getInvoker().getTimedObjectId()); final EJBComponent component = ejbComponentInjectedValue.getValue(); this.transactionManager = component.getTransactionManager(); final TimedObjectInvoker invoker = timedObjectInvoker.getValue(); if (invoker == null) { throw MESSAGES.invokerIsNull(); } final List<ScheduleTimer> timers = new ArrayList<ScheduleTimer>(); for (Map.Entry<Method, List<AutoTimer>> entry : autoTimers.entrySet()) { for (AutoTimer timer : entry.getValue()) { timers.add(new ScheduleTimer(entry.getKey(), timer.getScheduleExpression(), timer.getTimerConfig())); } } // restore the timers restoreTimers(timers); started = true; }
public void setRollbackOnly() throws IllegalStateException { if (isBeanManagedTransaction()) { throw MESSAGES.failToCallSetRollbackOnlyOnNoneCMB(); } try { // get the transaction manager TransactionManager tm = getTransactionManager(); // check if there's a tx in progress. If not, then it's an error to call setRollbackOnly() if (tm.getTransaction() == null) { throw MESSAGES.failToCallSetRollbackOnlyWithNoTx(); } // set rollback tm.setRollbackOnly(); } catch (SystemException se) { ROOT_LOGGER.setRollbackOnlyFailed(se); } }
protected Object required(final InterceptorContext invocation, final EJBComponent component, final int timeout) throws Exception { final TransactionManager tm = component.getTransactionManager(); final int oldTimeout = getCurrentTransactionTimeout(component); try { if (timeout != -1) { tm.setTransactionTimeout(timeout); } final Transaction tx = tm.getTransaction(); if (tx == null) { return invokeInOurTx(invocation, tm, component); } else { return invokeInCallerTx(invocation, tx, component); } } finally { if (tm != null) { tm.setTransactionTimeout(oldTimeout); } } }
@Override protected Object handleInvocation(final InterceptorContext invocation) throws Exception { final EJBComponent ejbComponent = getComponent(); TransactionManager tm = ejbComponent.getTransactionManager(); assert tm.getTransaction() == null : "can't handle BMT transaction, there is a transaction active"; boolean exceptionThrown = false; try { return invocation.proceed(); } catch (Throwable ex) { exceptionThrown = true; checkStatelessDone(ejbComponent, invocation, tm, ex); //we should never get here, as checkStatelessDone should re-throw throw (Exception)ex; } finally { try { if (!exceptionThrown) checkStatelessDone(ejbComponent, invocation, tm, null); } finally { tm.suspend(); } } }
@Override protected Object handleInvocation(final InterceptorContext invocation) throws Exception { TransactionManager tm = getComponent().getTransactionManager(); assert tm.getTransaction() == null : "can't handle BMT transaction, there is a transaction active";
private void checkBadStateful() { int status = Status.STATUS_NO_TRANSACTION; TransactionManager tm = getComponent().getTransactionManager(); try { status = tm.getStatus(); } catch (SystemException ex) { EjbLogger.ROOT_LOGGER.failedToGetStatus(ex); } switch (status) { case Status.STATUS_COMMITTING: case Status.STATUS_MARKED_ROLLBACK: case Status.STATUS_PREPARING: case Status.STATUS_ROLLING_BACK: try { tm.rollback(); } catch (Exception ex) { EjbLogger.ROOT_LOGGER.failedToRollback(ex); } EjbLogger.ROOT_LOGGER.transactionNotComplete(getComponent().getComponentName(), statusAsString(status)); } }
protected Object requiresNew(InterceptorContext invocation, final EJBComponent component, final int timeout) throws Exception { final TransactionManager tm = component.getTransactionManager(); int oldTimeout = getCurrentTransactionTimeout(component); try { if (timeout != -1 && tm != null) { tm.setTransactionTimeout(timeout); } Transaction tx = tm.getTransaction(); if (tx != null) { tm.suspend(); try { return invokeInOurTx(invocation, tm, component); } finally { tm.resume(tx); } } else { return invokeInOurTx(invocation, tm, component); } } finally { if (tm != null) { tm.setTransactionTimeout(oldTimeout); } } }