use of org.springframework.transaction.PlatformTransactionManager in project uPortal by Jasig.
the class TransactionManagerCachingTransactionInterceptor method determineTransactionManager.
protected PlatformTransactionManager determineTransactionManager(TransactionAttribute txAttr) {
if (txAttr == null) {
return super.determineTransactionManager(txAttr);
}
final String qualifier = txAttr.getQualifier();
if (StringUtils.hasLength(qualifier)) {
PlatformTransactionManager platformTransactionManager = platformTransactionManagerCache.get(qualifier);
if (platformTransactionManager == null) {
platformTransactionManager = super.determineTransactionManager(txAttr);
platformTransactionManagerCache.put(qualifier, platformTransactionManager);
}
return platformTransactionManager;
}
return super.determineTransactionManager(txAttr);
}
use of org.springframework.transaction.PlatformTransactionManager in project camel by apache.
the class TransactionErrorHandlerBuilder method createErrorHandler.
public Processor createErrorHandler(RouteContext routeContext, Processor processor) throws Exception {
if (transactionTemplate == null) {
// lookup in context if no transaction template has been configured
LOG.debug("No TransactionTemplate configured on TransactionErrorHandlerBuilder. Will try find it in the registry.");
Map<String, TransactedPolicy> mapPolicy = routeContext.lookupByType(TransactedPolicy.class);
if (mapPolicy != null && mapPolicy.size() == 1) {
TransactedPolicy policy = mapPolicy.values().iterator().next();
if (policy != null && policy instanceof SpringTransactionPolicy) {
transactionTemplate = ((SpringTransactionPolicy) policy).getTransactionTemplate();
}
}
if (transactionTemplate == null) {
TransactedPolicy policy = routeContext.lookup(PROPAGATION_REQUIRED, TransactedPolicy.class);
if (policy != null && policy instanceof SpringTransactionPolicy) {
transactionTemplate = ((SpringTransactionPolicy) policy).getTransactionTemplate();
}
}
if (transactionTemplate == null) {
Map<String, TransactionTemplate> mapTemplate = routeContext.lookupByType(TransactionTemplate.class);
if (mapTemplate == null || mapTemplate.isEmpty()) {
LOG.trace("No TransactionTemplate found in registry.");
} else if (mapTemplate.size() == 1) {
transactionTemplate = mapTemplate.values().iterator().next();
} else {
LOG.debug("Found {} TransactionTemplate in registry. Cannot determine which one to use. " + "Please configure a TransactionTemplate on the TransactionErrorHandlerBuilder", mapTemplate.size());
}
}
if (transactionTemplate == null) {
Map<String, PlatformTransactionManager> mapManager = routeContext.lookupByType(PlatformTransactionManager.class);
if (mapManager == null || mapManager.isEmpty()) {
LOG.trace("No PlatformTransactionManager found in registry.");
} else if (mapManager.size() == 1) {
transactionTemplate = new TransactionTemplate(mapManager.values().iterator().next());
} else {
LOG.debug("Found {} PlatformTransactionManager in registry. Cannot determine which one to use for TransactionTemplate. " + "Please configure a TransactionTemplate on the TransactionErrorHandlerBuilder", mapManager.size());
}
}
if (transactionTemplate != null) {
LOG.debug("Found TransactionTemplate in registry to use: " + transactionTemplate);
}
}
ObjectHelper.notNull(transactionTemplate, "transactionTemplate", this);
TransactionErrorHandler answer = new TransactionErrorHandler(routeContext.getCamelContext(), processor, getLogger(), getOnRedelivery(), getRedeliveryPolicy(), getExceptionPolicyStrategy(), transactionTemplate, getRetryWhilePolicy(routeContext.getCamelContext()), getExecutorService(routeContext.getCamelContext()), getRollbackLoggingLevel(), getOnExceptionOccurred());
// configure error handler before we can use it
configure(routeContext, answer);
return answer;
}
use of org.springframework.transaction.PlatformTransactionManager in project cucumber-jvm by cucumber.
the class SpringTransactionHooksTest method setUp.
@Before
public void setUp() {
target = new SpringTransactionHooks() {
@Override
public PlatformTransactionManager obtainPlatformTransactionManager() {
return mockedPlatformTransactionManager;
}
};
target.setBeanFactory(mockedBeanFactory);
}
use of org.springframework.transaction.PlatformTransactionManager in project grails-core by grails.
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.PlatformTransactionManager in project grails-core by grails.
the class ChainedTransactionManagerTests method shouldCompleteSuccessfully.
@Test
public void shouldCompleteSuccessfully() throws Exception {
PlatformTransactionManager transactionManager = createNonFailingTransactionManager("single");
setupTransactionManagers(transactionManager);
createAndCommitTransaction();
assertThat(transactionManager, isCommitted());
}
Aggregations