List of usage examples for org.springframework.transaction.support TransactionTemplate TransactionTemplate
public TransactionTemplate(PlatformTransactionManager transactionManager)
From source file:mojo.core.test.BaseTest.java
protected TransactionTemplate createTransactionTemplate() { return new TransactionTemplate(transactionManager); }
From source file:com.teradata.benchto.service.IntegrationTestBase.java
protected void withinTransaction(Runnable runnable) { new TransactionTemplate(transactionManager).execute(transactionStatus -> { runnable.run();/*from w w w .j a v a 2s . c om*/ return new Object(); }); }
From source file:org.dalesbred.integration.spring.SpringConfigurationTest.java
@Test public void dalesbredUsesConnectionBoundToSpringTransactions() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SimpleConfiguration.class); DataSource dataSource = ctx.getBean(DataSource.class); Database db = ctx.getBean(Database.class); new TransactionTemplate(new DataSourceTransactionManager(dataSource)) .execute(status -> db.withTransaction(Propagation.MANDATORY, tx -> { assertThat(tx.getConnection(), is(DataSourceUtils.getConnection(dataSource))); return "ok"; }));/*from www . ja v a 2 s. c o m*/ }
From source file:com.fusesource.examples.horo.rssReader.IdempotentRepositoryBuilder.java
public IdempotentRepository getRepository(String processorName) { Validate.notEmpty(processorName, "processorName is empty"); IdempotentRepository repository;/*from w w w .j a va2s . c o m*/ if (dataSource == null) { log.info("Initialising in-memory idempotent repository for {}", processorName); repository = new MemoryIdempotentRepository(); } else { log.info("Initialising JDBC idempotent repository for {}", processorName); if (transactionManager == null) { repository = new JdbcMessageIdRepository(dataSource, processorName); } else { repository = new JdbcMessageIdRepository(dataSource, new TransactionTemplate(transactionManager), processorName); } } return repository; }
From source file:dk.nsi.sdm4.ydelse.config.YdelseimporterApplicationConfig.java
@Bean public TransactionTemplate templateForNewTransactions(PlatformTransactionManager transactionManager) { TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager); transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); return transactionTemplate; }
From source file:ru.apertum.qsystem.server.Spring.java
/** * ? ?? ? ? * * @return */ public TransactionTemplate getTt() { return new TransactionTemplate(getTxManager()); }
From source file:org.cleverbus.core.common.asynch.queue.MessagesPoolDbImpl.java
@Required public void setTransactionManager(JpaTransactionManager transactionManager) { Assert.notNull(transactionManager, "the transactionManager must not be null"); this.transactionTemplate = new TransactionTemplate(transactionManager); }
From source file:com.mothsoft.alexis.web.security.AlexisWebAuthenticationProvider.java
public AlexisWebAuthenticationProvider(UserDetailsService userDetailsService, PasswordEncoder passwordEncoder, UserDao userDao, PlatformTransactionManager transactionManager) { this.userDetailsService = userDetailsService; this.passwordEncoder = passwordEncoder; this.userDao = userDao; this.transactionManager = transactionManager; this.transactionTemplate = new TransactionTemplate(this.transactionManager); }
From source file:me.doshou.admin.monitor.web.controller.JPAQLExecutorController.java
@PageableDefaults(pageNumber = 0, value = 10) @RequestMapping(value = "/ql", method = RequestMethod.POST) public String executeQL(final @RequestParam("ql") String ql, final Model model, final Pageable pageable) { model.addAttribute("sessionFactory", HibernateUtils.getSessionFactory(em)); try {/*from www . j a va 2 s . c om*/ new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() { @Override public Void doInTransaction(TransactionStatus status) { //1?ql try { Query query = em.createQuery(ql); int updateCount = query.executeUpdate(); model.addAttribute("updateCount", updateCount); return null; } catch (Exception e) { } //2 ?ql String findQL = ql; String alias = QueryUtils.detectAlias(findQL); if (StringUtils.isEmpty(alias)) { Pattern pattern = Pattern.compile("^(.*\\s*from\\s+)(.*)(\\s*.*)", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); findQL = pattern.matcher(findQL).replaceFirst("$1$2 o $3"); } String countQL = QueryUtils.createCountQueryFor(findQL); Query countQuery = em.createQuery(countQL); Query findQuery = em.createQuery(findQL); findQuery.setFirstResult(pageable.getOffset()); findQuery.setMaxResults(pageable.getPageSize()); Page page = new PageImpl(findQuery.getResultList(), pageable, (Long) countQuery.getSingleResult()); model.addAttribute("resultPage", page); return null; } }); } catch (Exception e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); model.addAttribute(Constants.ERROR, sw.toString()); } return showQLForm(); }
From source file:net.collegeman.grails.e3db.Template.java
protected static final void setApplicationContext(ApplicationContext applicationContext) { ctx = applicationContext;// w w w. j av a 2s .c o m // first, go for grails default "dataSource" try { defaultDataSource = (DataSource) ctx.getBean("dataSource"); defaultSimpleJdbcTemplate = new SimpleJdbcTemplate(defaultDataSource); } catch (NoSuchBeanDefinitionException e) { log.warn( "No default DataSource bean named [dataSource] found in application context - a DataSource will need to be created manually for E3DB."); } // then, try to setup the transaction template if (defaultDataSource != null) { try { defaultTransactionTemplate = new TransactionTemplate( (PlatformTransactionManager) ctx.getBean("transactionManager")); } catch (NoSuchBeanDefinitionException e) { defaultTransactionTemplate = new TransactionTemplate( new DataSourceTransactionManager(defaultDataSource)); log.info("DataSourceTranactionManager created by and for E3DB."); } } }