use of javax.transaction.Synchronization in project hibernate-orm by hibernate.
the class XaTransactionImpl method commit.
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, IllegalStateException, SystemException {
if (status == Status.STATUS_MARKED_ROLLBACK) {
log.trace("on commit, status was marked for rollback-only");
rollback();
} else {
status = Status.STATUS_PREPARING;
if (synchronizations != null) {
for (int i = 0; i < synchronizations.size(); i++) {
Synchronization s = (Synchronization) synchronizations.get(i);
s.beforeCompletion();
}
}
if (!runXaResourcePrepare()) {
status = Status.STATUS_ROLLING_BACK;
} else {
status = Status.STATUS_PREPARED;
}
status = Status.STATUS_COMMITTING;
if (connection != null) {
try {
connection.commit();
connectionProvider.closeConnection(connection);
connection = null;
} catch (SQLException sqle) {
status = Status.STATUS_UNKNOWN;
throw new SystemException();
}
}
runXaResourceCommitTx();
status = Status.STATUS_COMMITTED;
if (synchronizations != null) {
for (int i = 0; i < synchronizations.size(); i++) {
Synchronization s = (Synchronization) synchronizations.get(i);
s.afterCompletion(status);
}
}
// status = Status.STATUS_NO_TRANSACTION;
jtaTransactionManager.endCurrent(this);
}
}
use of javax.transaction.Synchronization in project hibernate-orm by hibernate.
the class DualNodeJtaTransactionImpl method commit.
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, IllegalStateException, SystemException {
if (status == Status.STATUS_MARKED_ROLLBACK) {
log.trace("on commit, status was marked for rollback-only");
rollback();
} else {
status = Status.STATUS_PREPARING;
if (synchronizations != null) {
for (int i = 0; i < synchronizations.size(); i++) {
Synchronization s = (Synchronization) synchronizations.get(i);
s.beforeCompletion();
}
}
if (!runXaResourcePrepare()) {
status = Status.STATUS_ROLLING_BACK;
} else {
status = Status.STATUS_PREPARED;
}
status = Status.STATUS_COMMITTING;
if (connection != null) {
try {
connection.commit();
connection.close();
} catch (SQLException sqle) {
status = Status.STATUS_UNKNOWN;
throw new SystemException();
}
}
runXaResourceCommitTx();
status = Status.STATUS_COMMITTED;
if (synchronizations != null) {
for (int i = 0; i < synchronizations.size(); i++) {
Synchronization s = (Synchronization) synchronizations.get(i);
s.afterCompletion(status);
}
}
// status = Status.STATUS_NO_TRANSACTION;
jtaTransactionManager.endCurrent(this);
}
}
use of javax.transaction.Synchronization in project hibernate-orm by hibernate.
the class DualNodeJtaTransactionImpl method rollback.
public void rollback() throws IllegalStateException, SystemException {
status = Status.STATUS_ROLLING_BACK;
runXaResourceRollback();
status = Status.STATUS_ROLLEDBACK;
if (connection != null) {
try {
connection.rollback();
connection.close();
} catch (SQLException sqle) {
status = Status.STATUS_UNKNOWN;
throw new SystemException();
}
}
if (synchronizations != null) {
for (int i = 0; i < synchronizations.size(); i++) {
Synchronization s = (Synchronization) synchronizations.get(i);
s.afterCompletion(status);
}
}
// status = Status.STATUS_NO_TRANSACTION;
jtaTransactionManager.endCurrent(this);
}
use of javax.transaction.Synchronization in project wildfly by wildfly.
the class InfinispanBatcherTestCase method createBatchDiscard.
@Test
public void createBatchDiscard() throws Exception {
Transaction tx = mock(Transaction.class);
ArgumentCaptor<Synchronization> capturedSync = ArgumentCaptor.forClass(Synchronization.class);
when(this.tm.getTransaction()).thenReturn(tx);
try (TransactionBatch batch = this.batcher.createBatch()) {
verify(this.tm).begin();
verify(tx).registerSynchronization(capturedSync.capture());
assertSame(tx, batch.getTransaction());
batch.discard();
} finally {
capturedSync.getValue().afterCompletion(Status.STATUS_ROLLEDBACK);
}
verify(tx, never()).commit();
verify(tx).rollback();
assertNull(InfinispanBatcher.CURRENT_BATCH.get());
}
use of javax.transaction.Synchronization in project wildfly by wildfly.
the class InfinispanBatcherTestCase method createNestedBatchDiscard.
@Test
public void createNestedBatchDiscard() throws Exception {
Transaction tx = mock(Transaction.class);
ArgumentCaptor<Synchronization> capturedSync = ArgumentCaptor.forClass(Synchronization.class);
when(this.tm.getTransaction()).thenReturn(tx);
try (TransactionBatch outerBatch = this.batcher.createBatch()) {
verify(this.tm).begin();
verify(tx).registerSynchronization(capturedSync.capture());
reset(this.tm);
assertSame(tx, outerBatch.getTransaction());
when(tx.getStatus()).thenReturn(Status.STATUS_ACTIVE);
when(this.tm.getTransaction()).thenReturn(tx);
try (TransactionBatch innerBatch = this.batcher.createBatch()) {
verify(this.tm, never()).begin();
innerBatch.discard();
}
verify(tx, never()).commit();
verify(tx, never()).rollback();
} finally {
capturedSync.getValue().afterCompletion(Status.STATUS_ROLLEDBACK);
}
verify(tx).rollback();
verify(tx, never()).commit();
assertNull(InfinispanBatcher.CURRENT_BATCH.get());
}
Aggregations