当前位置: 首页>>代码示例>>Java>>正文


Java DataSourceTransactionManager类代码示例

本文整理汇总了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);
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:24,代码来源:AbstractDbDialect.java

示例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
    }
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.transx,代码行数:27,代码来源:HsqlTest.java

示例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
    }
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.transx,代码行数:27,代码来源:H2Test.java

示例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");
}
 
开发者ID:lord-of-code,项目名称:loc-framework,代码行数:22,代码来源:LocDataSourceAutoConfiguration.java

示例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));

}
 
开发者ID:QNJR-GROUP,项目名称:EasyTransaction,代码行数:10,代码来源:DataBaseTransactionLogWritterImpl.java

示例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;
}
 
开发者ID:Lengchuan,项目名称:SpringBoot-Study,代码行数:14,代码来源:Read2DruidDataSourceConfig.java

示例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;
}
 
开发者ID:Lengchuan,项目名称:SpringBoot-Study,代码行数:14,代码来源:WriteDruidDataSourceConfig.java

示例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;
}
 
开发者ID:Lengchuan,项目名称:SpringBoot-Study,代码行数:14,代码来源:Read1DruidDataSourceConfig.java

示例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;
}
 
开发者ID:Lengchuan,项目名称:SpringBoot-Study,代码行数:15,代码来源:MasterDruidDataSourceConfig.java

示例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;
}
 
开发者ID:Lengchuan,项目名称:SpringBoot-Study,代码行数:14,代码来源:ClusterDruidDataSourceConfig.java

示例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;
}
 
开发者ID:Lengchuan,项目名称:SpringBoot-Study,代码行数:14,代码来源:Cluster1DruidDataSourceConfig.java

示例12: transactionManager

import org.springframework.jdbc.datasource.DataSourceTransactionManager; //导入依赖的package包/类
/**
 * 配置事物管理器
 *
 * @return
 */
@Bean
public DataSourceTransactionManager transactionManager() {
    DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
    dataSourceTransactionManager.setDataSource(dataSource);
    return dataSourceTransactionManager;
}
 
开发者ID:Lengchuan,项目名称:SpringBoot-Study,代码行数:12,代码来源:MybatisConfig.java

示例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;
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:11,代码来源:MybatisConfiguration.java

示例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);
}
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:15,代码来源:PGSynchronizedQuery.java

示例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));
	}
}
 
开发者ID:coranos,项目名称:neo-java,代码行数:33,代码来源:BlockDbH2Impl.java


注:本文中的org.springframework.jdbc.datasource.DataSourceTransactionManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。