Java Code Examples for com.atomikos.jdbc.AtomikosDataSourceBean#setXaDataSource()

The following examples show how to use com.atomikos.jdbc.AtomikosDataSourceBean#setXaDataSource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomerConfig.java    From spring-boot-jta-atomikos-sample with Apache License 2.0 6 votes vote down vote up
@Primary
	@Bean(name = "customerDataSource", initMethod = "init", destroyMethod = "close")
//	@Qualifier("customerDataSource")
	public DataSource customerDataSource() {
		MysqlXADataSource mysqlXaDataSource = new MysqlXADataSource();
		mysqlXaDataSource.setUrl(customerDatasourceProperties.getUrl());
		mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
		mysqlXaDataSource.setPassword(customerDatasourceProperties.getPassword());
		mysqlXaDataSource.setUser(customerDatasourceProperties.getUsername());
		mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);

		AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
		xaDataSource.setXaDataSource(mysqlXaDataSource);
		xaDataSource.setUniqueResourceName("xads1");
		return xaDataSource;

	}
 
Example 2
Source File: DataSourceConfig.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@Bean("dataSource1")
@Primary
public AtomikosDataSourceBean dataSource1() {
	AtomikosDataSourceBean ds = new AtomikosDataSourceBean();
	ds.setXaDataSource(xaDataSource1());
	ds.setUniqueResourceName("testdb");
	ds.setMinPoolSize(1);
	ds.setMaxPoolSize(3);
	ds.setMaxIdleTime(60);
	return ds;
}
 
Example 3
Source File: DataSourceConfig.java    From mybatis.flying with Apache License 2.0 5 votes vote down vote up
@Bean("dataSource2")
public DataSource dataSource2() {
	AtomikosDataSourceBean ds = new AtomikosDataSourceBean();
	ds.setXaDataSource(xaDataSource2());
	ds.setUniqueResourceName("testdb2");
	ds.setMinPoolSize(1);
	ds.setMaxPoolSize(3);
	ds.setMaxIdleTime(60);
	return ds;
}
 
Example 4
Source File: AtomikosDataSourceConfig.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
@SneakyThrows
public void putProperties(AtomikosDataSourceBean atomikosDataSourceBean) {

    if (null != xaProperties) {
        xaProperties.entrySet().forEach(entry -> entry.setValue(String.valueOf(entry.getValue())));
    }
    //fix #87
    XADataSource dataSource = (XADataSource) Class.forName(getXaDataSourceClassName()).newInstance();
    FastBeanCopier.copy(xaProperties, dataSource);
    atomikosDataSourceBean.setXaDataSource(dataSource);

    atomikosDataSourceBean.setXaDataSourceClassName(getXaDataSourceClassName());
    atomikosDataSourceBean.setBorrowConnectionTimeout(getBorrowConnectionTimeout());
    if (loginTimeout != 0) {
        try {
            atomikosDataSourceBean.setLoginTimeout(getLoginTimeout());
        } catch (SQLException e) {
            log.warn(e.getMessage(), e);
        }
    }
    atomikosDataSourceBean.setMaxIdleTime(getMaxIdleTime());
    atomikosDataSourceBean.setMaxPoolSize(getMaxPoolSize());
    atomikosDataSourceBean.setMinPoolSize(getMinPoolSize());
    atomikosDataSourceBean.setDefaultIsolationLevel(getDefaultIsolationLevel());
    atomikosDataSourceBean.setMaintenanceInterval(getMaintenanceInterval());
    atomikosDataSourceBean.setReapTimeout(getReapTimeout());
    atomikosDataSourceBean.setTestQuery(getTestQuery());
    atomikosDataSourceBean.setXaProperties(getXaProperties());
    atomikosDataSourceBean.setMaxLifetime(getMaxLifetime());
}
 
Example 5
Source File: OrderConfig.java    From spring-boot-jta-atomikos-sample with Apache License 2.0 5 votes vote down vote up
@Bean(name = "orderDataSource", initMethod = "init", destroyMethod = "close")
public DataSource orderDataSource() {
	 MysqlXADataSource mysqlXaDataSource = new MysqlXADataSource();
	 mysqlXaDataSource.setUrl(orderDatasourceProperties.getUrl());
	 mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
	 mysqlXaDataSource.setPassword(orderDatasourceProperties.getPassword());
	 mysqlXaDataSource.setUser(orderDatasourceProperties.getUsername());
	 mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
	
	 AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
	 xaDataSource.setXaDataSource(mysqlXaDataSource);
	 xaDataSource.setUniqueResourceName("xads2");
	 return xaDataSource;
}
 
Example 6
Source File: AtomikosDatasourceProvider.java    From Mycat2 with GNU General Public License v3.0 4 votes vote down vote up
@SneakyThrows
  @Override
  public JdbcDataSource createDataSource(DatasourceRootConfig.DatasourceConfig config) {
    String username = config.getUser();
    String password = config.getPassword();
    String url = config.getUrl();
    String dbType = config.getDbType();
    int maxRetryCount = config.getMaxRetryCount();
    List<String> initSQL = config.getInitSqls();
    int maxCon = config.getMaxCon();
    int minCon = config.getMinCon();

    Properties p = new Properties();
    p.setProperty("pinGlobalTxToPhysicalConnection","true");
    p.setProperty("com.atomikos.icatch.serial_jta_transactions", "false");
    AtomikosDataSourceBean ds = new AtomikosDataSourceBean();
    ds.setXaProperties(p);
    ds.setConcurrentConnectionValidation(true);
    ds.setUniqueResourceName(config.getName());
    ds.setPoolSize(minCon);
    ds.setMaxPoolSize(maxCon);

    ds.setBorrowConnectionTimeout(60);
    ///////////////////////////////////////
    ds.setLocalTransactionMode(true);
    //////////////////////////////////////
    MysqlXADataSource mysqlXaDataSource = new MysqlXADataSource();
    mysqlXaDataSource.setUser(username);
    mysqlXaDataSource.setPassword(password);
    mysqlXaDataSource.setUrl(url);
    mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
    mysqlXaDataSource.setMaxReconnects(maxRetryCount);
    mysqlXaDataSource.setConnectTimeout((int) config.getMaxConnectTimeout());
//    DruidXADataSource   datasource = new DruidXADataSource();
//
//    if (maxRetryCount > 0) {
//      datasource.setConnectionErrorRetryAttempts(maxRetryCount);
//    }
//    if (dbType != null) {
//      datasource.setDbType(dbType);
//    }
//    if (initSQL != null) {
//      datasource.setConnectionInitSqls(
//          SQLParserUtils.createSQLStatementParser(initSQL, dbType).parseStatementList().stream()
//              .map(Object::toString).collect(
//              Collectors.toList()));
//    }
//    if (jdbcDriver != null) {
//      datasource.setD(jdbcDriver);
//    }
    ds.setXaDataSource(mysqlXaDataSource);
    return new JdbcDataSource(config,ds);
  }
 
Example 7
Source File: DataSourceUtils.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
private static AtomikosDataSourceBean createAtomikosDataSourceBean(final DatabaseType databaseType, final DataSource dataSource, final String databaseName) {
    AtomikosDataSourceBean result = new AtomikosDataSourceBean();
    result.setUniqueResourceName(databaseName);
    result.setXaDataSource(XADataSourceFactory.build(databaseType, dataSource));
    return result;
}