Search in sources :

Example 1 with JtaTransactionCoordinatorImpl

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

the class TransactionJoinHandlingChecker method validateExplicitJoiningHandling.

static void validateExplicitJoiningHandling(EntityManager entityManager) throws Exception {
    SharedSessionContractImplementor session = entityManager.unwrap(SharedSessionContractImplementor.class);
    ExtraAssertions.assertTyping(JtaTransactionCoordinatorImpl.class, session.getTransactionCoordinator());
    JtaTransactionCoordinatorImpl transactionCoordinator = (JtaTransactionCoordinatorImpl) session.getTransactionCoordinator();
    assertFalse(transactionCoordinator.isSynchronizationRegistered());
    assertFalse(transactionCoordinator.isJtaTransactionCurrentlyActive());
    assertFalse(transactionCoordinator.isJoined());
    session.getFlushMode();
    assertFalse(transactionCoordinator.isSynchronizationRegistered());
    assertFalse(transactionCoordinator.isJtaTransactionCurrentlyActive());
    assertFalse(transactionCoordinator.isJoined());
    TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
    assertTrue(JtaStatusHelper.isActive(TestingJtaPlatformImpl.INSTANCE.getTransactionManager()));
    assertTrue(transactionCoordinator.isJtaTransactionCurrentlyActive());
    assertFalse(transactionCoordinator.isJoined());
    assertFalse(transactionCoordinator.isSynchronizationRegistered());
    session.getFlushMode();
    assertTrue(JtaStatusHelper.isActive(TestingJtaPlatformImpl.INSTANCE.getTransactionManager()));
    assertTrue(transactionCoordinator.isJtaTransactionCurrentlyActive());
    assertFalse(transactionCoordinator.isJoined());
    assertFalse(transactionCoordinator.isSynchronizationRegistered());
    entityManager.joinTransaction();
    assertTrue(JtaStatusHelper.isActive(TestingJtaPlatformImpl.INSTANCE.getTransactionManager()));
    assertTrue(transactionCoordinator.isJtaTransactionCurrentlyActive());
    assertTrue(transactionCoordinator.isSynchronizationRegistered());
    assertTrue(transactionCoordinator.isJoined());
    assertTrue(entityManager.isOpen());
    assertTrue(session.isOpen());
    entityManager.close();
    assertFalse(entityManager.isOpen());
    assertFalse(session.isOpen());
    TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
    assertFalse(entityManager.isOpen());
    assertFalse(session.isOpen());
}
Also used : SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) JtaTransactionCoordinatorImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl)

Example 2 with JtaTransactionCoordinatorImpl

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

the class TransactionJoiningTest method testImplicitJoiningWithExtraSynchronization.

@Test
public void testImplicitJoiningWithExtraSynchronization() throws Exception {
    assertFalse(JtaStatusHelper.isActive(TestingJtaPlatformImpl.INSTANCE.getTransactionManager()));
    TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
    EntityManager entityManager = entityManagerFactory().createEntityManager();
    SharedSessionContractImplementor session = entityManager.unwrap(SharedSessionContractImplementor.class);
    ExtraAssertions.assertTyping(JtaTransactionCoordinatorImpl.class, session.getTransactionCoordinator());
    JtaTransactionCoordinatorImpl transactionCoordinator = (JtaTransactionCoordinatorImpl) session.getTransactionCoordinator();
    assertTrue(transactionCoordinator.isSynchronizationRegistered());
    assertTrue(transactionCoordinator.isActive());
    assertTrue(transactionCoordinator.isJoined());
    entityManager.close();
    TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) JtaTransactionCoordinatorImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl) Test(org.junit.Test)

Example 3 with JtaTransactionCoordinatorImpl

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

the class TransactionJoiningTest method testCloseAfterCommit.

@Test
public void testCloseAfterCommit() throws Exception {
    assertFalse(JtaStatusHelper.isActive(TestingJtaPlatformImpl.INSTANCE.getTransactionManager()));
    TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
    EntityManager entityManager = entityManagerFactory().createEntityManager();
    SharedSessionContractImplementor session = entityManager.unwrap(SharedSessionContractImplementor.class);
    ExtraAssertions.assertTyping(JtaTransactionCoordinatorImpl.class, session.getTransactionCoordinator());
    JtaTransactionCoordinatorImpl transactionCoordinator = (JtaTransactionCoordinatorImpl) session.getTransactionCoordinator();
    assertTrue(transactionCoordinator.isSynchronizationRegistered());
    assertTrue(transactionCoordinator.isActive());
    assertTrue(transactionCoordinator.isJoined());
    assertTrue(entityManager.isOpen());
    assertTrue(session.isOpen());
    TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
    assertTrue(entityManager.isOpen());
    assertTrue(session.isOpen());
    entityManager.close();
    assertFalse(entityManager.isOpen());
    assertFalse(session.isOpen());
}
Also used : EntityManager(javax.persistence.EntityManager) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) JtaTransactionCoordinatorImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl) Test(org.junit.Test)

Example 4 with JtaTransactionCoordinatorImpl

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

the class TransactionJoiningTest method testIsJoinedAfterMarkedForRollbackExplicit.

@Test
@TestForIssue(jiraKey = "HHH-10807")
public void testIsJoinedAfterMarkedForRollbackExplicit() throws Exception {
    assertFalse(JtaStatusHelper.isActive(TestingJtaPlatformImpl.INSTANCE.getTransactionManager()));
    EntityManager entityManager = entityManagerFactory().createEntityManager(SynchronizationType.UNSYNCHRONIZED);
    SharedSessionContractImplementor session = entityManager.unwrap(SharedSessionContractImplementor.class);
    assertTrue(entityManager.isOpen());
    assertTrue(session.isOpen());
    ExtraAssertions.assertTyping(JtaTransactionCoordinatorImpl.class, session.getTransactionCoordinator());
    JtaTransactionCoordinatorImpl transactionCoordinator = (JtaTransactionCoordinatorImpl) session.getTransactionCoordinator();
    TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
    entityManager.joinTransaction();
    assertTrue(transactionCoordinator.isSynchronizationRegistered());
    assertTrue(transactionCoordinator.isActive());
    assertTrue(transactionCoordinator.isJoined());
    transactionCoordinator.getTransactionDriverControl().markRollbackOnly();
    assertTrue(transactionCoordinator.isActive());
    assertTrue(transactionCoordinator.isJoined());
    assertTrue(entityManager.isJoinedToTransaction());
    TestingJtaPlatformImpl.INSTANCE.getTransactionManager().rollback();
    entityManager.close();
    assertFalse(entityManager.isOpen());
    assertFalse(session.isOpen());
}
Also used : EntityManager(javax.persistence.EntityManager) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) JtaTransactionCoordinatorImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 5 with JtaTransactionCoordinatorImpl

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

the class TransactionJoiningTest method testIsJoinedAfterMarkedForRollbackImplict.

@Test
@TestForIssue(jiraKey = "HHH-10807")
public void testIsJoinedAfterMarkedForRollbackImplict() throws Exception {
    assertFalse(JtaStatusHelper.isActive(TestingJtaPlatformImpl.INSTANCE.getTransactionManager()));
    TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
    EntityManager entityManager = entityManagerFactory().createEntityManager();
    SharedSessionContractImplementor session = entityManager.unwrap(SharedSessionContractImplementor.class);
    ExtraAssertions.assertTyping(JtaTransactionCoordinatorImpl.class, session.getTransactionCoordinator());
    JtaTransactionCoordinatorImpl transactionCoordinator = (JtaTransactionCoordinatorImpl) session.getTransactionCoordinator();
    assertTrue(transactionCoordinator.isSynchronizationRegistered());
    assertTrue(transactionCoordinator.isActive());
    assertTrue(transactionCoordinator.isJoined());
    assertTrue(entityManager.isOpen());
    assertTrue(session.isOpen());
    transactionCoordinator.getTransactionDriverControl().markRollbackOnly();
    assertTrue(transactionCoordinator.isActive());
    assertTrue(transactionCoordinator.isJoined());
    assertTrue(entityManager.isJoinedToTransaction());
    TestingJtaPlatformImpl.INSTANCE.getTransactionManager().rollback();
    entityManager.close();
    assertFalse(entityManager.isOpen());
    assertFalse(session.isOpen());
}
Also used : EntityManager(javax.persistence.EntityManager) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) JtaTransactionCoordinatorImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

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