use of javax.transaction.TransactionManager in project hibernate-orm by hibernate.
the class AbstractBasicJtaTestScenarios method basicBmtUsageTest.
@Test
public void basicBmtUsageTest() throws Exception {
final JtaTransactionCoordinatorImpl transactionCoordinator = buildTransactionCoordinator(true);
// pre conditions
final TransactionManager tm = JtaPlatformStandardTestingImpl.INSTANCE.transactionManager();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
assertFalse(transactionCoordinator.isSynchronizationRegistered());
// begin the transaction
transactionCoordinator.getTransactionDriverControl().begin();
assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
assertTrue(transactionCoordinator.isSynchronizationRegistered());
// create and add a local Synchronization
SynchronizationCollectorImpl localSync = new SynchronizationCollectorImpl();
transactionCoordinator.getLocalSynchronizations().registerSynchronization(localSync);
// commit the transaction
transactionCoordinator.getTransactionDriverControl().commit();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
assertFalse(transactionCoordinator.isSynchronizationRegistered());
assertEquals(1, localSync.getBeforeCompletionCount());
assertEquals(1, localSync.getSuccessfulCompletionCount());
assertEquals(0, localSync.getFailedCompletionCount());
}
use of javax.transaction.TransactionManager in project hibernate-orm by hibernate.
the class AbstractBasicJtaTestScenarios method basicCmtUsageTest.
@Test
public void basicCmtUsageTest() throws Exception {
// pre conditions
final TransactionManager tm = JtaPlatformStandardTestingImpl.INSTANCE.transactionManager();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
// begin the transaction
tm.begin();
final JtaTransactionCoordinatorImpl transactionCoordinator = buildTransactionCoordinator(true);
assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
// NOTE : because of auto-join
assertTrue(transactionCoordinator.isSynchronizationRegistered());
// create and add a local Synchronization
SynchronizationCollectorImpl localSync = new SynchronizationCollectorImpl();
transactionCoordinator.getLocalSynchronizations().registerSynchronization(localSync);
// commit the transaction
tm.commit();
// post conditions
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
assertFalse(transactionCoordinator.isSynchronizationRegistered());
assertEquals(1, localSync.getBeforeCompletionCount());
assertEquals(1, localSync.getSuccessfulCompletionCount());
assertEquals(0, localSync.getFailedCompletionCount());
}
use of javax.transaction.TransactionManager in project hibernate-orm by hibernate.
the class AbstractBasicJtaTestScenarios method basicCmtUsageWithPulseTest.
@Test
public void basicCmtUsageWithPulseTest() throws Exception {
// pre conditions
final TransactionManager tm = JtaPlatformStandardTestingImpl.INSTANCE.transactionManager();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
final JtaTransactionCoordinatorImpl transactionCoordinator = buildTransactionCoordinator(true);
// begin the transaction
tm.begin();
assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
transactionCoordinator.pulse();
// NOTE : because of auto-join
assertTrue(transactionCoordinator.isSynchronizationRegistered());
transactionCoordinator.pulse();
assertTrue(transactionCoordinator.isSynchronizationRegistered());
// create and add a local Synchronization
SynchronizationCollectorImpl localSync = new SynchronizationCollectorImpl();
transactionCoordinator.getLocalSynchronizations().registerSynchronization(localSync);
// commit the transaction
tm.commit();
// post conditions
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
assertFalse(transactionCoordinator.isSynchronizationRegistered());
assertEquals(1, localSync.getBeforeCompletionCount());
assertEquals(1, localSync.getSuccessfulCompletionCount());
assertEquals(0, localSync.getFailedCompletionCount());
}
use of javax.transaction.TransactionManager in project hibernate-orm by hibernate.
the class AbstractBasicJtaTestScenarios method jpaExplicitJoiningTest.
@Test
public void jpaExplicitJoiningTest() throws Exception {
// pre conditions
final TransactionManager tm = JtaPlatformStandardTestingImpl.INSTANCE.transactionManager();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
// begin the transaction
tm.begin();
assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
final JtaTransactionCoordinatorImpl transactionCoordinator = buildTransactionCoordinator(false);
// no auto-join now
assertFalse(transactionCoordinator.isSynchronizationRegistered());
transactionCoordinator.explicitJoin();
assertTrue(transactionCoordinator.isSynchronizationRegistered());
// create and add a local Synchronization
SynchronizationCollectorImpl localSync = new SynchronizationCollectorImpl();
transactionCoordinator.getLocalSynchronizations().registerSynchronization(localSync);
// commit the transaction
tm.commit();
// post conditions
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
assertFalse(transactionCoordinator.isSynchronizationRegistered());
assertEquals(1, localSync.getBeforeCompletionCount());
assertEquals(1, localSync.getSuccessfulCompletionCount());
assertEquals(0, localSync.getFailedCompletionCount());
}
use of javax.transaction.TransactionManager in project hibernate-orm by hibernate.
the class AbstractBasicJtaTestScenarios method explicitJoiningTest.
@Test
public void explicitJoiningTest() throws Exception {
// pre conditions
final TransactionManager tm = JtaPlatformStandardTestingImpl.INSTANCE.transactionManager();
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
final JtaTransactionCoordinatorImpl transactionCoordinator = buildTransactionCoordinator(false);
// begin the transaction
tm.begin();
assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
// no auto-join now
assertFalse(transactionCoordinator.isSynchronizationRegistered());
transactionCoordinator.explicitJoin();
assertTrue(transactionCoordinator.isSynchronizationRegistered());
// create and add a local Synchronization
SynchronizationCollectorImpl localSync = new SynchronizationCollectorImpl();
transactionCoordinator.getLocalSynchronizations().registerSynchronization(localSync);
// commit the transaction
tm.commit();
// post conditions
assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
assertFalse(transactionCoordinator.isSynchronizationRegistered());
assertEquals(1, localSync.getBeforeCompletionCount());
assertEquals(1, localSync.getSuccessfulCompletionCount());
assertEquals(0, localSync.getFailedCompletionCount());
}
Aggregations