use of org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder in project hibernate-orm by hibernate.
the class BasicJdbcTransactionTests method basicUsageTest.
@Test
public void basicUsageTest() throws Exception {
final TransactionCoordinatorOwnerTestingImpl owner = new TransactionCoordinatorOwnerTestingImpl();
final JdbcResourceLocalTransactionCoordinatorBuilderImpl transactionCoordinatorBuilder = new JdbcResourceLocalTransactionCoordinatorBuilderImpl();
final TransactionCoordinator transactionCoordinator = transactionCoordinatorBuilder.buildTransactionCoordinator(owner, new TransactionCoordinatorBuilder.Options() {
@Override
public boolean shouldAutoJoinTransaction() {
return false;
}
});
SynchronizationCollectorImpl sync = new SynchronizationCollectorImpl();
transactionCoordinator.getLocalSynchronizations().registerSynchronization(sync);
transactionCoordinator.getTransactionDriverControl().begin();
assertEquals(0, sync.getBeforeCompletionCount());
assertEquals(0, sync.getSuccessfulCompletionCount());
assertEquals(0, sync.getFailedCompletionCount());
transactionCoordinator.getTransactionDriverControl().commit();
assertEquals(1, sync.getBeforeCompletionCount());
assertEquals(1, sync.getSuccessfulCompletionCount());
assertEquals(0, sync.getFailedCompletionCount());
}
use of org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder in project hibernate-orm by hibernate.
the class BasicJdbcTransactionTests method testSynchronizationFailure.
@Test
@SuppressWarnings("EmptyCatchBlock")
public void testSynchronizationFailure() {
final TransactionCoordinatorOwnerTestingImpl owner = new TransactionCoordinatorOwnerTestingImpl();
final JdbcResourceLocalTransactionCoordinatorBuilderImpl transactionCoordinatorBuilder = new JdbcResourceLocalTransactionCoordinatorBuilderImpl();
final TransactionCoordinator transactionCoordinator = transactionCoordinatorBuilder.buildTransactionCoordinator(owner, new TransactionCoordinatorBuilder.Options() {
@Override
public boolean shouldAutoJoinTransaction() {
return false;
}
});
assertEquals(TransactionStatus.NOT_ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
transactionCoordinator.getLocalSynchronizations().registerSynchronization(SynchronizationErrorImpl.forBefore());
transactionCoordinator.getTransactionDriverControl().begin();
assertEquals(TransactionStatus.ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
try {
transactionCoordinator.getTransactionDriverControl().commit();
} catch (Exception expected) {
} finally {
assertEquals(TransactionStatus.NOT_ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
}
}
use of org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder in project hibernate-orm by hibernate.
the class LegacySettingInitiatorTest method testLegacySettingSelection.
@Test
public void testLegacySettingSelection() {
final TransactionCoordinatorBuilderInitiator initiator = new TransactionCoordinatorBuilderInitiator();
TransactionCoordinatorBuilder builder = initiator.initiateService(Collections.singletonMap(TransactionCoordinatorBuilderInitiator.LEGACY_SETTING_NAME, "org.hibernate.transaction.JDBCTransactionFactory"), bsr);
assertThat(builder, instanceOf(JdbcResourceLocalTransactionCoordinatorBuilderImpl.class));
builder = initiator.initiateService(Collections.singletonMap(TransactionCoordinatorBuilderInitiator.LEGACY_SETTING_NAME, "org.hibernate.transaction.JTATransactionFactory"), bsr);
assertThat(builder, instanceOf(JtaTransactionCoordinatorBuilderImpl.class));
builder = initiator.initiateService(Collections.singletonMap(TransactionCoordinatorBuilderInitiator.LEGACY_SETTING_NAME, "org.hibernate.transaction.CMTTransactionFactory"), bsr);
assertThat(builder, instanceOf(JtaTransactionCoordinatorBuilderImpl.class));
}
use of org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder in project hibernate-orm by hibernate.
the class BasicJdbcTransactionTests method testMarkRollbackOnly.
@Test
@SuppressWarnings("EmptyCatchBlock")
public void testMarkRollbackOnly() {
final TransactionCoordinatorOwnerTestingImpl owner = new TransactionCoordinatorOwnerTestingImpl();
final JdbcResourceLocalTransactionCoordinatorBuilderImpl transactionCoordinatorBuilder = new JdbcResourceLocalTransactionCoordinatorBuilderImpl();
final TransactionCoordinator transactionCoordinator = transactionCoordinatorBuilder.buildTransactionCoordinator(owner, new TransactionCoordinatorBuilder.Options() {
@Override
public boolean shouldAutoJoinTransaction() {
return false;
}
});
assertEquals(TransactionStatus.NOT_ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
transactionCoordinator.getTransactionDriverControl().begin();
assertEquals(TransactionStatus.ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
transactionCoordinator.getTransactionDriverControl().markRollbackOnly();
assertEquals(TransactionStatus.MARKED_ROLLBACK, transactionCoordinator.getTransactionDriverControl().getStatus());
try {
transactionCoordinator.getTransactionDriverControl().commit();
} catch (TransactionException expected) {
} finally {
assertEquals(TransactionStatus.NOT_ACTIVE, transactionCoordinator.getTransactionDriverControl().getStatus());
}
}
Aggregations