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());
}
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();
}
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());
}
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());
}
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());
}
Aggregations