本文整理匯總了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));
}
}