use of org.springframework.transaction.PlatformTransactionManager in project spring-framework by spring-projects.
the class TransactionInterceptorTests method determineTransactionManagerWithQualifierAndDefaultName.
@Test
public void determineTransactionManagerWithQualifierAndDefaultName() {
BeanFactory beanFactory = mock(BeanFactory.class);
associateTransactionManager(beanFactory, "defaultTransactionManager");
TransactionInterceptor ti = transactionInterceptorWithTransactionManagerName("defaultTransactionManager", beanFactory);
PlatformTransactionManager fooTransactionManager = associateTransactionManager(beanFactory, "fooTransactionManager");
DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
attribute.setQualifier("fooTransactionManager");
assertThat(ti.determineTransactionManager(attribute)).isSameAs(fooTransactionManager);
}
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.isNewSynchronization()) {
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 uPortal by Jasig.
the class JdbcAuthDao method createToken.
protected void createToken(final String serviceName) {
try {
this.jdbcOperations.execute(new ConnectionCallback<Object>() {
@Override
public Object doInConnection(Connection con) throws SQLException, DataAccessException {
// This is horribly hacky but we can't rely on the main uPortal TM
// directly or we get
// into a circular dependency loop from JPA to Ehcache to jGroups and
// back to JPA
final DataSource ds = new SingleConnectionDataSource(con, true);
final PlatformTransactionManager ptm = new DataSourceTransactionManager(ds);
final TransactionOperations to = new TransactionTemplate(ptm);
to.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
logger.info("Creating jGroups auth token");
final String authToken = RandomTokenGenerator.INSTANCE.generateRandomToken(authTokenLength);
final ImmutableMap<String, String> params = ImmutableMap.of(PRM_SERVICE_NAME, serviceName, PRM_RANDOM_TOKEN, authToken);
namedParameterJdbcOperations.update(INSERT_SQL, params);
}
});
return null;
}
});
} catch (ConstraintViolationException e) {
// Ignore, just means a concurrent token creation
} catch (DataIntegrityViolationException e) {
// Ignore, just means a concurrent token creation
}
}
use of org.springframework.transaction.PlatformTransactionManager in project spring-boot by spring-projects.
the class BatchAutoConfigurationTests method testUsingJpa.
@Test
void testUsingJpa() {
this.contextRunner.withUserConfiguration(TestConfiguration.class, EmbeddedDataSourceConfiguration.class, HibernateJpaAutoConfiguration.class).run((context) -> {
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
// It's a lazy proxy, but it does render its target if you ask for
// toString():
assertThat(transactionManager.toString().contains("JpaTransactionManager")).isTrue();
assertThat(context).hasSingleBean(EntityManagerFactory.class);
// Ensure the JobRepository can be used (no problem with isolation
// level)
assertThat(context.getBean(JobRepository.class).getLastJobExecution("job", new JobParameters())).isNull();
});
}
Aggregations