當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。