Search in sources :

Example 16 with JtaTransactionCoordinatorImpl

use of org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl 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());
}
Also used : SynchronizationCollectorImpl(org.hibernate.test.resource.common.SynchronizationCollectorImpl) TransactionManager(javax.transaction.TransactionManager) JtaTransactionCoordinatorImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl) Test(org.junit.Test)

Example 17 with JtaTransactionCoordinatorImpl

use of org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl 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());
}
Also used : SynchronizationCollectorImpl(org.hibernate.test.resource.common.SynchronizationCollectorImpl) TransactionManager(javax.transaction.TransactionManager) JtaTransactionCoordinatorImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl) Test(org.junit.Test)

Example 18 with JtaTransactionCoordinatorImpl

use of org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl 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());
}
Also used : SynchronizationCollectorImpl(org.hibernate.test.resource.common.SynchronizationCollectorImpl) TransactionManager(javax.transaction.TransactionManager) JtaTransactionCoordinatorImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl) Test(org.junit.Test)

Example 19 with JtaTransactionCoordinatorImpl

use of org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl in project hibernate-orm by hibernate.

the class AbstractBasicJtaTestScenarios method basicThreadCheckingUsage.

@Test
public void basicThreadCheckingUsage() throws Exception {
    JtaTransactionCoordinatorImpl transactionCoordinator = new JtaTransactionCoordinatorImpl(transactionCoordinatorBuilder, owner, true, JtaPlatformStandardTestingImpl.INSTANCE, preferUserTransactions(), true);
    // pre conditions
    final TransactionManager tm = JtaPlatformStandardTestingImpl.INSTANCE.transactionManager();
    assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
    // begin the transaction
    tm.begin();
    transactionCoordinator.explicitJoin();
    assertEquals(SynchronizationCallbackCoordinatorTrackingImpl.class, transactionCoordinator.getSynchronizationCallbackCoordinator().getClass());
    tm.commit();
    assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
    assertFalse(transactionCoordinator.isJoined());
    tm.begin();
    transactionCoordinator.explicitJoin();
    assertEquals(SynchronizationCallbackCoordinatorTrackingImpl.class, transactionCoordinator.getSynchronizationCallbackCoordinator().getClass());
    tm.rollback();
}
Also used : TransactionManager(javax.transaction.TransactionManager) JtaTransactionCoordinatorImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl) Test(org.junit.Test)

Example 20 with JtaTransactionCoordinatorImpl

use of org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl in project hibernate-orm by hibernate.

the class AbstractBasicJtaTestScenarios method rollbackCmtUsageTest.

@Test
public void rollbackCmtUsageTest() 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(true);
    // NOTE : because of auto-join
    assertTrue(transactionCoordinator.isSynchronizationRegistered());
    // create and add a local Synchronization
    SynchronizationCollectorImpl localSync = new SynchronizationCollectorImpl();
    transactionCoordinator.getLocalSynchronizations().registerSynchronization(localSync);
    // rollback the transaction
    tm.rollback();
    // post conditions
    assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
    assertFalse(transactionCoordinator.isSynchronizationRegistered());
    assertEquals(0, localSync.getBeforeCompletionCount());
    assertEquals(0, localSync.getSuccessfulCompletionCount());
    assertEquals(1, localSync.getFailedCompletionCount());
}
Also used : SynchronizationCollectorImpl(org.hibernate.test.resource.common.SynchronizationCollectorImpl) TransactionManager(javax.transaction.TransactionManager) JtaTransactionCoordinatorImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl) Test(org.junit.Test)

Aggregations

JtaTransactionCoordinatorImpl (org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl)23 Test (org.junit.Test)22 TransactionManager (javax.transaction.TransactionManager)12 SynchronizationCollectorImpl (org.hibernate.test.resource.common.SynchronizationCollectorImpl)8 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)7 EntityManager (javax.persistence.EntityManager)6 Session (org.hibernate.Session)2 TransactionException (org.hibernate.TransactionException)2 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)2 TransactionRequiredForJoinException (org.hibernate.resource.transaction.TransactionRequiredForJoinException)2 JtaPlatformInaccessibleException (org.hibernate.resource.transaction.backend.jta.internal.JtaPlatformInaccessibleException)2 TransactionCoordinator (org.hibernate.resource.transaction.spi.TransactionCoordinator)2 AbstractJPATest (org.hibernate.test.jpa.AbstractJPATest)2 TestForIssue (org.hibernate.testing.TestForIssue)2 SystemException (javax.transaction.SystemException)1