use of org.springframework.transaction.TransactionException in project spring-data-commons by spring-projects.
the class ChainedTransactionManager method rollback.
/*
* (non-Javadoc)
* @see org.springframework.transaction.PlatformTransactionManager#rollback(org.springframework.transaction.TransactionStatus)
*/
public void rollback(TransactionStatus status) throws TransactionException {
Exception rollbackException = null;
PlatformTransactionManager rollbackExceptionTransactionManager = null;
MultiTransactionStatus multiTransactionStatus = (MultiTransactionStatus) status;
for (PlatformTransactionManager transactionManager : reverse(transactionManagers)) {
try {
multiTransactionStatus.rollback(transactionManager);
} catch (Exception ex) {
if (rollbackException == null) {
rollbackException = ex;
rollbackExceptionTransactionManager = transactionManager;
} else {
LOGGER.warn("Rollback exception (" + transactionManager + ") " + ex.getMessage(), ex);
}
}
}
if (multiTransactionStatus.isNewSynchonization()) {
synchronizationManager.clearSynchronization();
}
if (rollbackException != null) {
throw new UnexpectedRollbackException("Rollback exception, originated at (" + rollbackExceptionTransactionManager + ") " + rollbackException.getMessage(), rollbackException);
}
}
use of org.springframework.transaction.TransactionException in project spring-data-commons by spring-projects.
the class ChainedTransactionManager method commit.
/*
* (non-Javadoc)
* @see org.springframework.transaction.PlatformTransactionManager#commit(org.springframework.transaction.TransactionStatus)
*/
public void commit(TransactionStatus status) throws TransactionException {
MultiTransactionStatus multiTransactionStatus = (MultiTransactionStatus) status;
boolean commit = true;
Exception commitException = null;
PlatformTransactionManager commitExceptionTransactionManager = null;
for (PlatformTransactionManager transactionManager : reverse(transactionManagers)) {
if (commit) {
try {
multiTransactionStatus.commit(transactionManager);
} catch (Exception ex) {
commit = false;
commitException = ex;
commitExceptionTransactionManager = transactionManager;
}
} else {
try {
multiTransactionStatus.rollback(transactionManager);
} catch (Exception ex) {
LOGGER.warn("Rollback exception (after commit) (" + transactionManager + ") " + ex.getMessage(), ex);
}
}
}
if (multiTransactionStatus.isNewSynchonization()) {
synchronizationManager.clearSynchronization();
}
if (commitException != null) {
boolean firstTransactionManagerFailed = commitExceptionTransactionManager == getLastTransactionManager();
int transactionState = firstTransactionManagerFailed ? HeuristicCompletionException.STATE_ROLLED_BACK : HeuristicCompletionException.STATE_MIXED;
throw new HeuristicCompletionException(transactionState, commitException);
}
}
use of org.springframework.transaction.TransactionException in project spring-data-commons by spring-projects.
the class ChainedTransactionManager method getTransaction.
/*
* (non-Javadoc)
* @see org.springframework.transaction.PlatformTransactionManager#getTransaction(org.springframework.transaction.TransactionDefinition)
*/
public MultiTransactionStatus getTransaction(@Nullable TransactionDefinition definition) throws TransactionException {
MultiTransactionStatus mts = new MultiTransactionStatus(transactionManagers.get(0));
if (definition == null) {
return mts;
}
if (!synchronizationManager.isSynchronizationActive()) {
synchronizationManager.initSynchronization();
mts.setNewSynchonization();
}
try {
for (PlatformTransactionManager transactionManager : transactionManagers) {
mts.registerTransactionManager(definition, transactionManager);
}
} catch (Exception ex) {
Map<PlatformTransactionManager, TransactionStatus> transactionStatuses = mts.getTransactionStatuses();
for (PlatformTransactionManager transactionManager : transactionManagers) {
try {
if (transactionStatuses.get(transactionManager) != null) {
transactionManager.rollback(transactionStatuses.get(transactionManager));
}
} catch (Exception ex2) {
LOGGER.warn("Rollback exception (" + transactionManager + ") " + ex2.getMessage(), ex2);
}
}
if (mts.isNewSynchonization()) {
synchronizationManager.clearSynchronization();
}
throw new CannotCreateTransactionException(ex.getMessage(), ex);
}
return mts;
}
use of org.springframework.transaction.TransactionException in project molgenis by molgenis.
the class JobTest method testTransactionTimeout.
@Test
public void testTransactionTimeout() {
TransactionException transactionException = new TransactionTimedOutException("Transaction timeout test.");
when(transactionOperations.execute(any())).thenThrow(transactionException);
try {
job.call();
fail("TransactionException should be thrown");
} catch (TransactionException expected) {
assertSame(expected, transactionException);
}
verify(transactionOperations).execute(any());
verify(progress).failed(transactionException);
verifyNoMoreInteractions(callable, progress, transactionOperations);
}
use of org.springframework.transaction.TransactionException in project nakadi by zalando.
the class TimelineService method switchTimelines.
private void switchTimelines(final Timeline activeTimeline, final Timeline nextTimeline) throws InconsistentStateException, RepositoryProblemException, TimelineException, ConflictException {
LOG.info("Switching timelines from {} to {}", activeTimeline, nextTimeline);
try {
timelineSync.startTimelineUpdate(activeTimeline.getEventType(), nakadiSettings.getTimelineWaitTimeoutMs());
} catch (final InterruptedException ie) {
Thread.currentThread().interrupt();
throw new TimelineException("Failed to switch timeline for: " + activeTimeline.getEventType());
} catch (final IllegalStateException ie) {
throw new ConflictException("Timeline is already being created for: " + activeTimeline.getEventType(), ie);
}
try {
transactionTemplate.execute(status -> {
timelineDbRepository.createTimeline(nextTimeline);
nextTimeline.setSwitchedAt(new Date());
final Timeline.StoragePosition sp = topicRepositoryHolder.createStoragePosition(activeTimeline);
activeTimeline.setLatestPosition(sp);
scheduleTimelineCleanup(activeTimeline);
timelineDbRepository.updateTimelime(activeTimeline);
timelineDbRepository.updateTimelime(nextTimeline);
return null;
});
} catch (final TransactionException tx) {
LOG.error(tx.getMessage(), tx);
throw new TimelineException("Failed to create timeline in DB for: " + activeTimeline.getEventType(), tx);
} finally {
finishTimelineUpdate(activeTimeline.getEventType());
}
}
Aggregations