public void registerSynchronization(Synchronization synchronization) throws RollbackException, IllegalStateException, SystemException { if (status == Status.STATUS_NO_TRANSACTION) throw new IllegalStateException("transaction hasn't started yet"); if (status == Status.STATUS_MARKED_ROLLBACK) throw new BitronixRollbackException("transaction has been marked as rollback only"); if (isDone()) throw new IllegalStateException("transaction is done, cannot register any more synchronization"); if (log.isDebugEnabled()) log.debug("registering synchronization " + synchronization); synchronizationScheduler.add(synchronization, Scheduler.DEFAULT_POSITION); }
@Override public void registerSynchronization(Synchronization synchronization) throws RollbackException, IllegalStateException, SystemException { if (status == Status.STATUS_NO_TRANSACTION) throw new IllegalStateException("transaction hasn't started yet"); if (status == Status.STATUS_MARKED_ROLLBACK) throw new BitronixRollbackException("transaction has been marked as rollback only"); if (isDone()) throw new IllegalStateException("transaction is done, cannot register any more synchronization"); if (log.isDebugEnabled()) { log.debug("registering synchronization " + synchronization); } synchronizationScheduler.add(synchronization, Scheduler.DEFAULT_POSITION); }
@Override public void registerSynchronization(Synchronization synchronization) throws RollbackException, IllegalStateException, SystemException { if (status == Status.STATUS_NO_TRANSACTION) throw new IllegalStateException("transaction hasn't started yet"); if (status == Status.STATUS_MARKED_ROLLBACK) throw new BitronixRollbackException("transaction has been marked as rollback only"); if (isDone()) throw new IllegalStateException("transaction is done, cannot register any more synchronization"); if (log.isDebugEnabled()) { log.debug("registering synchronization " + synchronization); } synchronizationScheduler.add(synchronization, Scheduler.DEFAULT_POSITION); }
public void registerSynchronization(Synchronization synchronization) throws RollbackException, IllegalStateException, SystemException { if (status == Status.STATUS_NO_TRANSACTION) throw new IllegalStateException("transaction hasn't started yet"); if (status == Status.STATUS_MARKED_ROLLBACK) throw new BitronixRollbackException("transaction has been marked as rollback only"); if (isDone()) throw new IllegalStateException("transaction is done, cannot register any more synchronization"); if (log.isDebugEnabled()) log.debug("registering synchronization " + synchronization); synchronizationScheduler.add(synchronization, Scheduler.DEFAULT_POSITION); }
public void beforeCompletion() { try { transaction.getSynchronizationScheduler().add(new Synchronization() { public void beforeCompletion() { } public void afterCompletion(int i) { } }, 10); } catch (Exception e) { fail("unexpected exception: " + e); } }
public void beforeCompletion() { try { transaction.getSynchronizationScheduler().add(new Synchronization() { public void beforeCompletion() { } public void afterCompletion(int i) { } }, 10); } catch (Exception e) { fail("unexpected exception: " + e); } }
@Override public void putResource(Object key, Object value) { try { if (key == null) throw new NullPointerException("key cannot be null"); if (currentTransaction() == null || currentTransaction().getStatus() == Status.STATUS_NO_TRANSACTION) throw new IllegalStateException("no transaction started on current thread"); Object oldValue = getResources().put(key, value); if (oldValue == null && getResources().size() == 1) { if (log.isDebugEnabled()) { log.debug("first resource put in synchronization registry, registering a ClearRegistryResourcesSynchronization"); } Synchronization synchronization = new ClearRegistryResourcesSynchronization(); currentTransaction().getSynchronizationScheduler().add(synchronization, Scheduler.ALWAYS_LAST_POSITION); } } catch (SystemException ex) { throw new BitronixRuntimeException("cannot get current transaction status", ex); } }
@Override public void putResource(Object key, Object value) { try { if (key == null) throw new NullPointerException("key cannot be null"); if (currentTransaction() == null || currentTransaction().getStatus() == Status.STATUS_NO_TRANSACTION) throw new IllegalStateException("no transaction started on current thread"); Object oldValue = getResources().put(key, value); if (oldValue == null && getResources().size() == 1) { if (log.isDebugEnabled()) { log.debug("first resource put in synchronization registry, registering a ClearRegistryResourcesSynchronization"); } Synchronization synchronization = new ClearRegistryResourcesSynchronization(); currentTransaction().getSynchronizationScheduler().add(synchronization, Scheduler.ALWAYS_LAST_POSITION); } } catch (SystemException ex) { throw new BitronixRuntimeException("cannot get current transaction status", ex); } }
public void testRemove() { Scheduler<XAResourceHolderState> resourceScheduler = new Scheduler<XAResourceHolderState>(); XAResourceHolderState xarhs0 = new XAResourceHolderState(null, new MockResourceBean(0)); XAResourceHolderState xarhs1 = new XAResourceHolderState(null, new MockResourceBean(1)); resourceScheduler.add(xarhs0, xarhs0.getTwoPcOrderingPosition()); resourceScheduler.add(xarhs1, xarhs1.getTwoPcOrderingPosition()); resourceScheduler.remove(xarhs0); resourceScheduler.add(xarhs0, xarhs0.getTwoPcOrderingPosition()); Iterator<XAResourceHolderState> it = resourceScheduler.iterator(); assertTrue(it.hasNext()); assertTrue(xarhs0 == it.next()); it.remove(); assertTrue(xarhs1 == it.next()); it.remove(); }
public void testReverseRemove() { Scheduler<XAResourceHolderState> resourceScheduler = new Scheduler<XAResourceHolderState>(); XAResourceHolderState xarhs0 = new XAResourceHolderState(null, new MockResourceBean(0)); XAResourceHolderState xarhs1 = new XAResourceHolderState(null, new MockResourceBean(1)); resourceScheduler.add(xarhs0, xarhs0.getTwoPcOrderingPosition()); resourceScheduler.add(xarhs1, xarhs1.getTwoPcOrderingPosition()); resourceScheduler.remove(xarhs0); resourceScheduler.add(xarhs0, xarhs0.getTwoPcOrderingPosition()); Iterator<XAResourceHolderState> it = resourceScheduler.reverseIterator(); assertTrue(it.hasNext()); assertTrue(xarhs1 == it.next()); it.remove(); assertTrue(xarhs0 == it.next()); it.remove(); }
public void testReverseRemove() { Scheduler<XAResourceHolderState> resourceScheduler = new Scheduler<XAResourceHolderState>(); XAResourceHolderState xarhs0 = new XAResourceHolderState(null, new MockResourceBean(0)); XAResourceHolderState xarhs1 = new XAResourceHolderState(null, new MockResourceBean(1)); resourceScheduler.add(xarhs0, xarhs0.getTwoPcOrderingPosition()); resourceScheduler.add(xarhs1, xarhs1.getTwoPcOrderingPosition()); resourceScheduler.remove(xarhs0); resourceScheduler.add(xarhs0, xarhs0.getTwoPcOrderingPosition()); Iterator<XAResourceHolderState> it = resourceScheduler.reverseIterator(); assertTrue(it.hasNext()); assertTrue(xarhs1 == it.next()); it.remove(); assertTrue(xarhs0 == it.next()); it.remove(); }
public void testRemove() { Scheduler<XAResourceHolderState> resourceScheduler = new Scheduler<XAResourceHolderState>(); XAResourceHolderState xarhs0 = new XAResourceHolderState(null, new MockResourceBean(0)); XAResourceHolderState xarhs1 = new XAResourceHolderState(null, new MockResourceBean(1)); resourceScheduler.add(xarhs0, xarhs0.getTwoPcOrderingPosition()); resourceScheduler.add(xarhs1, xarhs1.getTwoPcOrderingPosition()); resourceScheduler.remove(xarhs0); resourceScheduler.add(xarhs0, xarhs0.getTwoPcOrderingPosition()); Iterator<XAResourceHolderState> it = resourceScheduler.iterator(); assertTrue(it.hasNext()); assertTrue(xarhs0 == it.next()); it.remove(); assertTrue(xarhs1 == it.next()); it.remove(); }
public void registerInterposedSynchronization(Synchronization synchronization) { try { if (currentTransaction() == null || currentTransaction().getStatus() == Status.STATUS_NO_TRANSACTION) throw new IllegalStateException("no transaction started on current thread"); if ( currentTransaction().getStatus() == Status.STATUS_PREPARING || currentTransaction().getStatus() == Status.STATUS_PREPARED || currentTransaction().getStatus() == Status.STATUS_COMMITTING || currentTransaction().getStatus() == Status.STATUS_COMMITTED || currentTransaction().getStatus() == Status.STATUS_ROLLING_BACK || currentTransaction().getStatus() == Status.STATUS_ROLLEDBACK ) throw new IllegalStateException("transaction is done, cannot register an interposed synchronization"); currentTransaction().getSynchronizationScheduler().add(synchronization, Scheduler.DEFAULT_POSITION -1); } catch (SystemException ex) { throw new BitronixRuntimeException("cannot get current transaction status", ex); } }
public void testReverseIterator() { Scheduler<XAResourceHolderState> resourceScheduler = new Scheduler<XAResourceHolderState>(); XAResourceHolderState xarhs0 = new XAResourceHolderState(null, new MockResourceBean(1)); XAResourceHolderState xarhs1 = new XAResourceHolderState(null, new MockResourceBean(1)); XAResourceHolderState xarhs2 = new XAResourceHolderState(null, new MockResourceBean(1)); XAResourceHolderState xarhs3 = new XAResourceHolderState(null, new MockResourceBean(0)); XAResourceHolderState xarhs4 = new XAResourceHolderState(null, new MockResourceBean(10)); resourceScheduler.add(xarhs0, xarhs0.getTwoPcOrderingPosition()); resourceScheduler.add(xarhs1, xarhs1.getTwoPcOrderingPosition()); resourceScheduler.add(xarhs2, xarhs2.getTwoPcOrderingPosition()); resourceScheduler.add(xarhs3, xarhs3.getTwoPcOrderingPosition()); resourceScheduler.add(xarhs4, xarhs4.getTwoPcOrderingPosition()); assertEquals("a Scheduler with 5 object(s) in 3 position(s)", resourceScheduler.toString()); Iterator it = resourceScheduler.reverseIterator(); assertTrue(it.hasNext()); assertTrue(xarhs4 == it.next()); assertTrue(xarhs0 == it.next()); assertTrue(xarhs1 == it.next()); assertTrue(xarhs2 == it.next()); assertTrue(xarhs3 == it.next()); assertFalse(it.hasNext()); }
public void registerInterposedSynchronization(Synchronization synchronization) { try { if (currentTransaction() == null || currentTransaction().getStatus() == Status.STATUS_NO_TRANSACTION) throw new IllegalStateException("no transaction started on current thread"); if ( currentTransaction().getStatus() == Status.STATUS_PREPARING || currentTransaction().getStatus() == Status.STATUS_PREPARED || currentTransaction().getStatus() == Status.STATUS_COMMITTING || currentTransaction().getStatus() == Status.STATUS_COMMITTED || currentTransaction().getStatus() == Status.STATUS_ROLLING_BACK || currentTransaction().getStatus() == Status.STATUS_ROLLEDBACK ) throw new IllegalStateException("transaction is done, cannot register an interposed synchronization"); currentTransaction().getSynchronizationScheduler().add(synchronization, Scheduler.DEFAULT_POSITION -1); } catch (SystemException ex) { throw new BitronixRuntimeException("cannot get current transaction status", ex); } }
@Override public void registerInterposedSynchronization(Synchronization synchronization) { try { if (currentTransaction() == null || currentTransaction().getStatus() == Status.STATUS_NO_TRANSACTION) throw new IllegalStateException("no transaction started on current thread"); if ( currentTransaction().getStatus() == Status.STATUS_PREPARING || currentTransaction().getStatus() == Status.STATUS_PREPARED || currentTransaction().getStatus() == Status.STATUS_COMMITTING || currentTransaction().getStatus() == Status.STATUS_COMMITTED || currentTransaction().getStatus() == Status.STATUS_ROLLING_BACK || currentTransaction().getStatus() == Status.STATUS_ROLLEDBACK ) throw new IllegalStateException("transaction is done, cannot register an interposed synchronization"); currentTransaction().getSynchronizationScheduler().add(synchronization, Scheduler.DEFAULT_POSITION -1); } catch (SystemException ex) { throw new BitronixRuntimeException("cannot get current transaction status", ex); } }
public void testReverseIterator() { Scheduler<XAResourceHolderState> resourceScheduler = new Scheduler<XAResourceHolderState>(); XAResourceHolderState xarhs0 = new XAResourceHolderState(null, new MockResourceBean(1)); XAResourceHolderState xarhs1 = new XAResourceHolderState(null, new MockResourceBean(1)); XAResourceHolderState xarhs2 = new XAResourceHolderState(null, new MockResourceBean(1)); XAResourceHolderState xarhs3 = new XAResourceHolderState(null, new MockResourceBean(0)); XAResourceHolderState xarhs4 = new XAResourceHolderState(null, new MockResourceBean(10)); resourceScheduler.add(xarhs0, xarhs0.getTwoPcOrderingPosition()); resourceScheduler.add(xarhs1, xarhs1.getTwoPcOrderingPosition()); resourceScheduler.add(xarhs2, xarhs2.getTwoPcOrderingPosition()); resourceScheduler.add(xarhs3, xarhs3.getTwoPcOrderingPosition()); resourceScheduler.add(xarhs4, xarhs4.getTwoPcOrderingPosition()); assertEquals("a Scheduler with 5 object(s) in 3 position(s)", resourceScheduler.toString()); Iterator it = resourceScheduler.reverseIterator(); assertTrue(it.hasNext()); assertTrue(xarhs4 == it.next()); assertTrue(xarhs0 == it.next()); assertTrue(xarhs1 == it.next()); assertTrue(xarhs2 == it.next()); assertTrue(xarhs3 == it.next()); assertFalse(it.hasNext()); }
@Override public void registerInterposedSynchronization(Synchronization synchronization) { try { if (currentTransaction() == null || currentTransaction().getStatus() == Status.STATUS_NO_TRANSACTION) throw new IllegalStateException("no transaction started on current thread"); if ( currentTransaction().getStatus() == Status.STATUS_PREPARING || currentTransaction().getStatus() == Status.STATUS_PREPARED || currentTransaction().getStatus() == Status.STATUS_COMMITTING || currentTransaction().getStatus() == Status.STATUS_COMMITTED || currentTransaction().getStatus() == Status.STATUS_ROLLING_BACK || currentTransaction().getStatus() == Status.STATUS_ROLLEDBACK ) throw new IllegalStateException("transaction is done, cannot register an interposed synchronization"); currentTransaction().getSynchronizationScheduler().add(synchronization, Scheduler.DEFAULT_POSITION -1); } catch (SystemException ex) { throw new BitronixRuntimeException("cannot get current transaction status", ex); } }
public void testBeforeCompletionAddsExtraSynchronizationInDifferentPriority() throws Exception { btm.begin(); btm.getCurrentTransaction().getSynchronizationScheduler().add(new SynchronizationRegisteringSynchronization(btm.getCurrentTransaction()), 5); btm.commit(); }
public void testBeforeCompletionAddsExtraSynchronizationInDifferentPriority() throws Exception { btm.begin(); btm.getCurrentTransaction().getSynchronizationScheduler().add(new SynchronizationRegisteringSynchronization(btm.getCurrentTransaction()), 5); btm.commit(); }