use of org.springframework.transaction.support.TransactionTemplate in project cas by apereo.
the class CasSupportJdbcAuditConfiguration method inspektrAuditTransactionTemplate.
@Bean
public TransactionTemplate inspektrAuditTransactionTemplate() {
final TransactionTemplate t = new TransactionTemplate(inspektrAuditTransactionManager());
t.setIsolationLevelName(casProperties.getAudit().getJdbc().getIsolationLevelName());
t.setPropagationBehaviorName(casProperties.getAudit().getJdbc().getPropagationBehaviorName());
return t;
}
use of org.springframework.transaction.support.TransactionTemplate in project cas by apereo.
the class JpaTicketRegistryTests method grantServiceTicketInTransaction.
private ServiceTicket grantServiceTicketInTransaction(final TicketGrantingTicket parent) {
return new TransactionTemplate(txManager).execute(status -> {
final ServiceTicket st = newST(parent);
ticketRegistry.addTicket(st);
return st;
});
}
use of org.springframework.transaction.support.TransactionTemplate in project cas by apereo.
the class JpaTicketRegistryTests method grantProxyGrantingTicketInTransaction.
private ProxyGrantingTicket grantProxyGrantingTicketInTransaction(final ServiceTicket parent) {
return new TransactionTemplate(txManager).execute(status -> {
final ProxyGrantingTicket pgt = newPGT(parent);
ticketRegistry.addTicket(pgt);
return pgt;
});
}
use of org.springframework.transaction.support.TransactionTemplate in project opennms by OpenNMS.
the class InsSession method getEventsByCriteria.
private void getEventsByCriteria() {
LOG.debug("clearing events");
clearEvents();
final BeanFactoryReference bf = BeanUtils.getBeanFactory("daoContext");
final EventDao eventDao = BeanUtils.getBean(bf, "eventDao", EventDao.class);
final TransactionTemplate transTemplate = BeanUtils.getBean(bf, "transactionTemplate", TransactionTemplate.class);
try {
transTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
LOG.debug("Entering transaction call back: selection with criteria: {}", criteriaRestriction);
final OnmsCriteria criteria = new OnmsCriteria(OnmsEvent.class);
criteria.add(Restrictions.sqlRestriction(criteriaRestriction));
final List<OnmsEvent> events = eventDao.findMatching(criteria);
LOG.info("Found {} event(s) with criteria: {}", events.size(), criteriaRestriction);
for (final OnmsEvent onmsEvent : events) {
final Event xmlEvent = getXMLEvent(onmsEvent);
if (xmlEvent != null)
addEvent(xmlEvent);
}
}
});
} catch (final RuntimeException e) {
LOG.error("Error while getting events.", e);
}
}
use of org.springframework.transaction.support.TransactionTemplate in project spring-framework by spring-projects.
the class PersistenceContextTransactionTests method setUp.
@Before
public void setUp() throws Exception {
factory = mock(EntityManagerFactory.class);
manager = mock(EntityManager.class);
tx = mock(EntityTransaction.class);
JpaTransactionManager tm = new JpaTransactionManager(factory);
tt = new TransactionTemplate(tm);
given(factory.createEntityManager()).willReturn(manager);
given(manager.getTransaction()).willReturn(tx);
given(manager.isOpen()).willReturn(true);
bean = new EntityManagerHoldingBean();
@SuppressWarnings("serial") PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor() {
@Override
protected EntityManagerFactory findEntityManagerFactory(String unitName, String requestingBeanName) {
return factory;
}
};
pabpp.postProcessPropertyValues(null, null, bean, "bean");
assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty());
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
}
Aggregations