本文整理汇总了Java中org.springframework.jdbc.datasource.DataSourceTransactionManager类的典型用法代码示例。如果您正苦于以下问题:Java DataSourceTransactionManager类的具体用法?Java DataSourceTransactionManager怎么用?Java DataSourceTransactionManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataSourceTransactionManager类属于org.springframework.jdbc.datasource包,在下文中一共展示了DataSourceTransactionManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AbstractDbDialect
import org.springframework.jdbc.datasource.DataSourceTransactionManager; //导入依赖的package包/类
public AbstractDbDialect(final JdbcTemplate jdbcTemplate, LobHandler lobHandler){
this.jdbcTemplate = jdbcTemplate;
this.lobHandler = lobHandler;
// 初始化transction
this.transactionTemplate = new TransactionTemplate();
transactionTemplate.setTransactionManager(new DataSourceTransactionManager(jdbcTemplate.getDataSource()));
transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
// 初始化一些数据
jdbcTemplate.execute(new ConnectionCallback() {
public Object doInConnection(Connection c) throws SQLException, DataAccessException {
DatabaseMetaData meta = c.getMetaData();
databaseName = meta.getDatabaseProductName();
databaseMajorVersion = meta.getDatabaseMajorVersion();
databaseMinorVersion = meta.getDatabaseMinorVersion();
return null;
}
});
initTables(jdbcTemplate);
}
示例2: testSpringLocalTx
import org.springframework.jdbc.datasource.DataSourceTransactionManager; //导入依赖的package包/类
@Test
public void testSpringLocalTx() throws Exception {
DataSource ds = wrap(createHsqlDataSource());
JdbcTemplate jdbc = new JdbcTemplate(ds);
TransactionTemplate tx = new TransactionTemplate(new DataSourceTransactionManager(ds));
jdbc.execute(DROP_USER);
jdbc.execute(CREATE_TABLE_USER);
tx.execute(ts -> jdbc.update(INSERT_INTO_USER, 1, "user1"));
User user = tx.execute(ts -> jdbc.queryForObject(SELECT_FROM_USER_BY_ID, new BeanPropertyRowMapper<>(User.class), 1));
assertEquals(new User(1, "user1"), user);
tx.execute(ts -> jdbc.update(DELETE_FROM_USER_BY_ID, 1));
tx.execute(ts -> {
int nb = jdbc.update(INSERT_INTO_USER, 1, "user1");
ts.setRollbackOnly();
return nb;
});
try {
user = tx.execute(ts -> jdbc.queryForObject(SELECT_FROM_USER_BY_ID, new BeanPropertyRowMapper<>(User.class), 1));
fail("Expected a EmptyResultDataAccessException");
} catch (EmptyResultDataAccessException e) {
// expected
}
}
示例3: testSpringLocalTx
import org.springframework.jdbc.datasource.DataSourceTransactionManager; //导入依赖的package包/类
@Test
public void testSpringLocalTx() throws Exception {
DataSource ds = wrap(createH2DataSource());
JdbcTemplate jdbc = new JdbcTemplate(ds);
TransactionTemplate tx = new TransactionTemplate(new DataSourceTransactionManager(ds));
jdbc.execute(DROP_USER);
jdbc.execute(CREATE_TABLE_USER);
tx.execute(ts -> jdbc.update(INSERT_INTO_USER, 1, "user1"));
User user = tx.execute(ts -> jdbc.queryForObject(SELECT_FROM_USER_BY_ID, new BeanPropertyRowMapper<>(User.class), 1));
assertEquals(new User(1, "user1"), user);
tx.execute(ts -> jdbc.update(DELETE_FROM_USER_BY_ID, 1));
tx.execute(ts -> {
int nb = jdbc.update(INSERT_INTO_USER, 1, "user1");
ts.setRollbackOnly();
return nb;
});
try {
user = tx.execute(ts -> jdbc.queryForObject(SELECT_FROM_USER_BY_ID, new BeanPropertyRowMapper<>(User.class), 1));
fail("Expected a EmptyResultDataAccessException");
} catch (EmptyResultDataAccessException e) {
// expected
}
}
示例4: createBean
import org.springframework.jdbc.datasource.DataSourceTransactionManager; //导入依赖的package包/类
private void createBean(ConfigurableListableBeanFactory configurableListableBeanFactory,
String prefixName, JdbcProperties jdbcProperties) {
String jdbcUrl = jdbcProperties.getJdbcUrl();
checkArgument(!Strings.isNullOrEmpty(jdbcUrl), prefixName + " url is null or empty");
log.info("prefixName is {}, jdbc properties is {}", prefixName, jdbcProperties);
HikariDataSource hikariDataSource = createHikariDataSource(jdbcProperties);
DataSourceSpy dataSource = new DataSourceSpy(hikariDataSource);
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);
AnnotationTransactionAspect.aspectOf().setTransactionManager(transactionManager);
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
register(configurableListableBeanFactory, dataSource, prefixName + "DataSource",
prefixName + "Ds");
register(configurableListableBeanFactory, jdbcTemplate, prefixName + "JdbcTemplate",
prefixName + "Jt");
register(configurableListableBeanFactory, transactionManager, prefixName + "TransactionManager",
prefixName + "Tx");
}
示例5: DataBaseTransactionLogWritterImpl
import org.springframework.jdbc.datasource.DataSourceTransactionManager; //导入依赖的package包/类
public DataBaseTransactionLogWritterImpl(ObjectSerializer objectSerializer,DataSource dataSource) {
super();
this.objectSerializer = objectSerializer;
this.dataSource = dataSource;
transactionManager = new DataSourceTransactionManager(dataSource);
transactionTemplate = new TransactionTemplate(transactionManager, new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW));
}
示例6: read2TransactionManager
import org.springframework.jdbc.datasource.DataSourceTransactionManager; //导入依赖的package包/类
/**
* 配置事物管理器
*
* @return
*/
@Bean(name = "read2TransactionManager")
public DataSourceTransactionManager read2TransactionManager(
@Qualifier("read2DataSource") DataSource dataSource
) {
DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
dataSourceTransactionManager.setDataSource(dataSource);
return dataSourceTransactionManager;
}
示例7: writeTransactionManager
import org.springframework.jdbc.datasource.DataSourceTransactionManager; //导入依赖的package包/类
/**
* 配置事物管理器
*
* @return
*/
@Bean(name = "writeTransactionManager")
public DataSourceTransactionManager writeTransactionManager(
@Qualifier("writeDataSource") DataSource dataSource
) {
DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
dataSourceTransactionManager.setDataSource(dataSource);
return dataSourceTransactionManager;
}
示例8: read1TransactionManager
import org.springframework.jdbc.datasource.DataSourceTransactionManager; //导入依赖的package包/类
/**
* 配置事物管理器
*
* @return
*/
@Bean(name = "read1TransactionManager")
public DataSourceTransactionManager read1TransactionManager(
@Qualifier("read1DataSource") DataSource dataSource
) {
DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
dataSourceTransactionManager.setDataSource(dataSource);
return dataSourceTransactionManager;
}
示例9: masterTransactionManager
import org.springframework.jdbc.datasource.DataSourceTransactionManager; //导入依赖的package包/类
/**
* 配置事物管理器
*
* @return
*/
@Bean(name = "masterTransactionManager")
@Primary
public DataSourceTransactionManager masterTransactionManager(
@Qualifier("masterDataSource") DataSource dataSource
) {
DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
dataSourceTransactionManager.setDataSource(dataSource);
return dataSourceTransactionManager;
}
示例10: clusterTransactionManager
import org.springframework.jdbc.datasource.DataSourceTransactionManager; //导入依赖的package包/类
/**
* 配置事物管理器
*
* @return
*/
@Bean(name = "clusterTransactionManager")
public DataSourceTransactionManager clusterTransactionManager(
@Qualifier("clusterDataSource") DataSource dataSource
) {
DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
dataSourceTransactionManager.setDataSource(dataSource);
return dataSourceTransactionManager;
}
示例11: cluster1TransactionManager
import org.springframework.jdbc.datasource.DataSourceTransactionManager; //导入依赖的package包/类
/**
* 配置事物管理器
*
* @return
*/
@Bean(name = "cluster1TransactionManager")
public DataSourceTransactionManager cluster1TransactionManager(
@Qualifier("cluster1DataSource") DataSource dataSource
) {
DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
dataSourceTransactionManager.setDataSource(dataSource);
return dataSourceTransactionManager;
}
示例12: transactionManager
import org.springframework.jdbc.datasource.DataSourceTransactionManager; //导入依赖的package包/类
/**
* 配置事物管理器
*
* @return
*/
@Bean
public DataSourceTransactionManager transactionManager() {
DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
dataSourceTransactionManager.setDataSource(dataSource);
return dataSourceTransactionManager;
}
示例13: annotationDrivenTransactionManager
import org.springframework.jdbc.datasource.DataSourceTransactionManager; //导入依赖的package包/类
@Bean
@Override
public PlatformTransactionManager annotationDrivenTransactionManager() {
try {
return new DataSourceTransactionManager(datasource());
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
示例14: PGSynchronizedQuery
import org.springframework.jdbc.datasource.DataSourceTransactionManager; //导入依赖的package包/类
PGSynchronizedQuery(@NonNull JdbcTemplate jdbcTemplate, @NonNull String sql,
@NonNull PreparedStatementSetter setter, @NonNull RowCallbackHandler rowHandler,
AtomicLong serialToContinueFrom, PGLatestSerialFetcher fetcher) {
this.serialToContinueFrom = serialToContinueFrom;
latestFetcher = fetcher;
this.jdbcTemplate = jdbcTemplate;
this.sql = sql;
this.setter = setter;
this.rowHandler = rowHandler;
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(
jdbcTemplate.getDataSource());
transactionTemplate = new TransactionTemplate(transactionManager);
}
示例15: put
import org.springframework.jdbc.datasource.DataSourceTransactionManager; //导入依赖的package包/类
/**
* puts the block into the database.
*
* @param blocks
* the blocks to use.
*/
@Override
public void put(final Block... blocks) {
synchronized (this) {
if (closed) {
return;
}
}
if (LOG.isInfoEnabled()) {
LOG.info("STARTED put, {} blocks", NumberFormat.getIntegerInstance().format(blocks.length));
}
final DataSourceTransactionManager tsMan = new DataSourceTransactionManager(ds);
final TransactionTemplate txTemplate = new TransactionTemplate(tsMan);
// set behavior
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
try {
txTemplate.execute(new TransactionCallback(blocks));
} catch (final DataAccessException e) {
if (LOG.isErrorEnabled()) {
LOG.error("data access exception", e);
}
}
if (LOG.isInfoEnabled()) {
LOG.info("SUCCESS put, {} blocks", NumberFormat.getIntegerInstance().format(blocks.length));
}
}