public void setTransactionTimeout(int seconds) throws SystemException { userTransaction.setTransactionTimeout(seconds); } }
public void setTransactionTimeout(int seconds) throws SystemException { userTransaction.setTransactionTimeout(seconds); } }
@Override protected void doCleanupAfterCompletion(Object transaction) { JtaTransactionObject txObject = (JtaTransactionObject) transaction; if (txObject.resetTransactionTimeout) { try { txObject.getUserTransaction().setTransactionTimeout(0); } catch (SystemException ex) { logger.debug("Failed to reset transaction timeout after JTA completion", ex); } } }
/** * Apply the given transaction timeout. The default implementation will call * {@code UserTransaction.setTransactionTimeout} for a non-default timeout value. * @param txObject the JtaTransactionObject containing the UserTransaction * @param timeout timeout value taken from transaction definition * @throws SystemException if thrown by the JTA implementation * @see #doJtaBegin * @see JtaTransactionObject#getUserTransaction() * @see javax.transaction.UserTransaction#setTransactionTimeout(int) */ protected void applyTimeout(JtaTransactionObject txObject, int timeout) throws SystemException { if (timeout > TransactionDefinition.TIMEOUT_DEFAULT) { txObject.getUserTransaction().setTransactionTimeout(timeout); if (timeout > 0) { txObject.resetTransactionTimeout = true; } } }
@Override public void setTimeOut(int seconds) { if ( seconds > 0 ) { try { userTransaction.setTransactionTimeout( seconds ); } catch (SystemException e) { throw new TransactionException( "Unable to apply requested transaction timeout", e ); } } } }
@Override protected void doCleanupAfterCompletion(Object transaction) { JtaTransactionObject txObject = (JtaTransactionObject) transaction; if (txObject.resetTransactionTimeout) { try { txObject.getUserTransaction().setTransactionTimeout(0); } catch (SystemException ex) { logger.debug("Failed to reset transaction timeout after JTA completion", ex); } } }
/** * Apply the given transaction timeout. The default implementation will call * {@code UserTransaction.setTransactionTimeout} for a non-default timeout value. * @param txObject the JtaTransactionObject containing the UserTransaction * @param timeout timeout value taken from transaction definition * @throws SystemException if thrown by the JTA implementation * @see #doJtaBegin * @see JtaTransactionObject#getUserTransaction() * @see javax.transaction.UserTransaction#setTransactionTimeout(int) */ protected void applyTimeout(JtaTransactionObject txObject, int timeout) throws SystemException { if (timeout > TransactionDefinition.TIMEOUT_DEFAULT) { txObject.getUserTransaction().setTransactionTimeout(timeout); if (timeout > 0) { txObject.resetTransactionTimeout = true; } } }
@Override protected void begin() throws SchedulerException { // Don't get a new UserTransaction w/o making sure we cleaned up the old // one. This is necessary because there are paths through JobRunShell.run() // where begin() can be called multiple times w/o complete being called in // between. cleanupUserTransaction(); boolean beganSuccessfully = false; try { getLog().debug("Looking up UserTransaction."); ut = UserTransactionHelper.lookupUserTransaction(); if (transactionTimeout != null) { ut.setTransactionTimeout(transactionTimeout); } getLog().debug("Beginning UserTransaction."); ut.begin(); beganSuccessfully = true; } catch (SchedulerException se) { throw se; } catch (Exception nse) { throw new SchedulerException( "JTAJobRunShell could not start UserTransaction.", nse); } finally { if (beganSuccessfully == false) { cleanupUserTransaction(); } } }
@Override protected void begin() throws SchedulerException { // Don't get a new UserTransaction w/o making sure we cleaned up the old // one. This is necessary because there are paths through JobRunShell.run() // where begin() can be called multiple times w/o complete being called in // between. cleanupUserTransaction(); boolean beganSuccessfully = false; try { getLog().debug("Looking up UserTransaction."); ut = UserTransactionHelper.lookupUserTransaction(); if (transactionTimeout != null) { ut.setTransactionTimeout(transactionTimeout); } getLog().debug("Beginning UserTransaction."); ut.begin(); beganSuccessfully = true; } catch (SchedulerException se) { throw se; } catch (Exception nse) { throw new SchedulerException( "JTAJobRunShell could not start UserTransaction.", nse); } finally { if (beganSuccessfully == false) { cleanupUserTransaction(); } } }
@Test public void jtaTransactionManagerWithRollbackAndSynchronizationNever() throws Exception { UserTransaction ut = mock(UserTransaction.class); given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE); JtaTransactionManager ptm = newJtaTransactionManager(ut); TransactionTemplate tt = new TransactionTemplate(ptm); ptm.setTransactionSynchronizationName("SYNCHRONIZATION_NEVER"); tt.setTimeout(10); ptm.afterPropertiesSet(); assertFalse(TransactionSynchronizationManager.isSynchronizationActive()); tt.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { assertFalse(TransactionSynchronizationManager.isSynchronizationActive()); status.setRollbackOnly(); } }); assertFalse(TransactionSynchronizationManager.isSynchronizationActive()); verify(ut).setTransactionTimeout(10); verify(ut).begin(); verify(ut, atLeastOnce()).getStatus(); verify(ut).rollback(); }
@Test public void jtaTransactionManagerWithRollbackAndSynchronizationOnActual() throws Exception { UserTransaction ut = mock(UserTransaction.class); given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE); final TransactionSynchronization synch = mock(TransactionSynchronization.class); JtaTransactionManager ptm = newJtaTransactionManager(ut); TransactionTemplate tt = new TransactionTemplate(ptm); ptm.setTransactionSynchronization(JtaTransactionManager.SYNCHRONIZATION_ON_ACTUAL_TRANSACTION); tt.setTimeout(10); assertFalse(TransactionSynchronizationManager.isSynchronizationActive()); tt.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { assertTrue(TransactionSynchronizationManager.isSynchronizationActive()); TransactionSynchronizationManager.registerSynchronization(synch); status.setRollbackOnly(); } }); assertFalse(TransactionSynchronizationManager.isSynchronizationActive()); verify(ut).setTransactionTimeout(10); verify(ut).begin(); verify(ut).rollback(); verify(synch).beforeCompletion(); verify(synch).afterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK); }
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly()); verify(ut).setTransactionTimeout(10); verify(ut).begin(); verify(ut).rollback();
@Test public void testTransactionTimeOut() throws SystemException, NotSupportedException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException { Assert.assertNotNull(utx); Assert.assertSame(KunderaJTAUserTransaction.class, utx.getClass()); // set timeout before running transaction. utx.setTransactionTimeout(20); Assert.assertEquals(20, ((KunderaJTAUserTransaction) utx).getTransactionTimeout()); utx.setTransactionTimeout(0); // try after beginning transaction. utx.begin(); utx.setTransactionTimeout(202); Assert.assertEquals(0, ((KunderaJTAUserTransaction) utx).getTransactionTimeout()); utx.commit(); }
public void setTransactionTimeout(int seconds) throws SystemException { checkUserTransactionMethods(); ut.setTransactionTimeout(seconds); } };
public void setTransactionTimeout(final int i) throws SystemException { if (!isUserTransactionAccessAllowed()) { throw new IllegalStateException(); } userTransaction.setTransactionTimeout(i); } }
public void setTimeout(int seconds) { try { ut.setTransactionTimeout(seconds); } catch (SystemException se) { throw new TransactionException("could not set transaction timeout", se); } }
public void setTransactionTimeout(final int i) throws SystemException { if (!isUserTransactionAccessAllowed()) { throw new IllegalStateException(); } userTransaction.setTransactionTimeout(i); } }
@Override protected void doCleanupAfterCompletion(Object transaction) { JtaTransactionObject txObject = (JtaTransactionObject) transaction; if (txObject.resetTransactionTimeout) { try { txObject.getUserTransaction().setTransactionTimeout(0); } catch (SystemException ex) { logger.debug("Failed to reset transaction timeout after JTA completion", ex); } } }
@Override public void setTransactionTimeout(int seconds) throws TransactionManagementException { logger.entering(CLASSNAME, "setTransactionTimeout", seconds); try { userTran.setTransactionTimeout(seconds); } catch (SystemException e) { throw new TransactionManagementException(e); } logger.exiting(CLASSNAME, "setTransactionTimeout"); }
@Override public void setTransactionTimeout(int seconds) throws TransactionManagementException { logger.entering(CLASSNAME, "setTransactionTimeout", seconds); try { userTran.setTransactionTimeout(seconds); } catch (SystemException e) { throw new TransactionManagementException(e); } logger.exiting(CLASSNAME, "setTransactionTimeout"); }