List of usage examples for org.springframework.jdbc.datasource DataSourceTransactionManager DataSourceTransactionManager
public DataSourceTransactionManager(DataSource dataSource)
From source file:org.works.common.data.layer.datasource.InitializingDataSourceFactoryBean.java
private void doExecuteScript(final Resource scriptResource) { if (scriptResource == null || !scriptResource.exists()) return;//w w w. j av a2s . c om TransactionTemplate transactionTemplate = new TransactionTemplate( new DataSourceTransactionManager(dataSource)); transactionTemplate.execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus status) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String[] scripts; try { scripts = StringUtils.delimitedListToStringArray( stripComments(IOUtils.readLines(scriptResource.getInputStream())), ";"); } catch (IOException e) { throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e); } for (int i = 0; i < scripts.length; i++) { String script = scripts[i].trim(); if (StringUtils.hasText(script)) { try { jdbcTemplate.execute(script); } catch (DataAccessException e) { if (ignoreFailedDrop && script.toLowerCase().startsWith("drop")) { logger.debug("DROP script failed (ignoring): " + script); } else { throw e; } } } } return null; } }); }
From source file:hub.config.connectors.PanAuditConfig.java
@Bean public DataSourceTransactionManager panAuditTransactionManager() { return new DataSourceTransactionManager(panAuditLazyConnectionDataSource()); }
From source file:org.mybatis.spring.SqlSessionTemplateTest.java
@Test public void testExecutorType() { SqlSessionTemplate template = new SqlSessionTemplate(sqlSessionFactory, ExecutorType.BATCH); assertEquals(ExecutorType.BATCH, template.getExecutorType()); DataSourceTransactionManager manager = new DataSourceTransactionManager(dataSource); TransactionStatus status = null;/*from w ww .j av a2 s . c om*/ try { status = manager.getTransaction(new DefaultTransactionDefinition()); // will synchronize the template with the current tx template.getConnection(); SqlSessionHolder holder = (SqlSessionHolder) TransactionSynchronizationManager .getResource(sqlSessionFactory); assertEquals(ExecutorType.BATCH, holder.getExecutorType()); } finally { // rollback required to close connection txManager.rollback(status); } }
From source file:ask.springboot.conf.MyBatisConfig.java
@Bean @Override public PlatformTransactionManager annotationDrivenTransactionManager() { return new DataSourceTransactionManager(dataSource); }
From source file:com.khs.test.jdbc.datasource.DSInitializer.java
private void doExecuteScript(final Resource scriptResource) { if (scriptResource == null || !scriptResource.exists()) return;/* w w w.j a v a2s. c om*/ TransactionTemplate transactionTemplate = new TransactionTemplate( new DataSourceTransactionManager(dataSource)); transactionTemplate.execute(new TransactionCallback() { @SuppressWarnings("unchecked") public Object doInTransaction(TransactionStatus status) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String[] scripts; try { scripts = StringUtils.delimitedListToStringArray( stripComments(IOUtils.readLines(scriptResource.getInputStream())), ";"); } catch (IOException e) { throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e); } for (int i = 0; i < scripts.length; i++) { String script = scripts[i].trim(); if (StringUtils.hasText(script)) { try { jdbcTemplate.execute(script); } catch (DataAccessException e) { if (ignoreFailedDrop && script.toLowerCase().startsWith("drop")) { logger.debug("DROP script failed (ignoring): " + script); } else { throw e; } } } } return null; } }); }
From source file:com.github.ferstl.spring.jdbc.oracle.DatabaseConfiguration.java
@Bean
PlatformTransactionManager transactionManager() {
return new DataSourceTransactionManager(this.dataSource);
}
From source file:springbatch.test.jdbc.datasource.DataSourceInitializer.java
private void doExecuteScript(final Resource scriptResource) { if (scriptResource == null || !scriptResource.exists()) return;//from w w w . ja v a 2s .c om TransactionTemplate transactionTemplate = new TransactionTemplate( new DataSourceTransactionManager(dataSource)); transactionTemplate.execute(new TransactionCallback() { @SuppressWarnings("unchecked") public Object doInTransaction(TransactionStatus status) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String[] scripts; try { scripts = StringUtils.delimitedListToStringArray( stripComments(IOUtils.readLines(scriptResource.getInputStream())), ";"); } catch (IOException e) { throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e); } for (int i = 0; i < scripts.length; i++) { String script = scripts[i].trim(); if (StringUtils.hasText(script)) { try { jdbcTemplate.execute(scripts[i]); } catch (DataAccessException e) { if (!script.toUpperCase().startsWith("DROP")) { throw e; } } } } return null; } }); }
From source file:hub.config.connectors.ProjectDbConfig.java
@Bean public DataSourceTransactionManager projectDbTransactionManager() { return new DataSourceTransactionManager(projectDbLazyConnectionDataSource()); }
From source file:org.deshang.content.indexing.config.SpringConfig.java
@Bean public PlatformTransactionManager transactionManager(DataSource dataSource) throws Exception { return new DataSourceTransactionManager(dataSource); }
From source file:com.bleum.canton.jms.dao.impl.JMSTaskDao.java
/** * Set data source for JMS task table.//from w ww .j a va 2 s. c o m * * @param dataSource */ public void setDataSource(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); this.platformTransactionManager = new DataSourceTransactionManager(dataSource); }