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

The following examples show how to use com.atomikos.jdbc.AtomikosDataSourceBean#setLocalTransactionMode() . 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: OrderConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean(initMethod = "init", destroyMethod = "close")
public AtomikosDataSourceBean orderDataSource() {
    AtomikosDataSourceBean dataSource = new AtomikosDataSourceBean();
    dataSource.setLocalTransactionMode(true);
    dataSource.setUniqueResourceName("db2");
    dataSource.setXaDataSourceClassName("org.apache.derby.jdbc.EmbeddedXADataSource");
    Properties xaProperties = new Properties();
    xaProperties.put("databaseName", "db2");
    xaProperties.put("createDatabase", "create");
    dataSource.setXaProperties(xaProperties);
    dataSource.setPoolSize(10);
    return dataSource;
}
 
Example 2
Source File: InventoryConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean(initMethod = "init", destroyMethod = "close")
public AtomikosDataSourceBean inventoryDataSource() {
    AtomikosDataSourceBean dataSource = new AtomikosDataSourceBean();
    dataSource.setLocalTransactionMode(true);
    dataSource.setUniqueResourceName("db1");
    dataSource.setXaDataSourceClassName("org.apache.derby.jdbc.EmbeddedXADataSource");
    Properties xaProperties = new Properties();
    xaProperties.put("databaseName", "db1");
    xaProperties.put("createDatabase", "create");
    dataSource.setXaProperties(xaProperties);
    dataSource.setPoolSize(10);
    return dataSource;
}
 
Example 3
Source File: Config.java    From tutorials with MIT License 5 votes vote down vote up
@Bean(initMethod = "init", destroyMethod = "close")
public AtomikosDataSourceBean inventoryDataSource() {
    AtomikosDataSourceBean dataSource = new AtomikosDataSourceBean();
    dataSource.setLocalTransactionMode(true);
    dataSource.setUniqueResourceName("db1");
    dataSource.setXaDataSourceClassName("org.apache.derby.jdbc.EmbeddedXADataSource");
    Properties xaProperties = new Properties();
    xaProperties.put("databaseName", "db1");
    xaProperties.put("createDatabase", "create");
    dataSource.setXaProperties(xaProperties);
    dataSource.setPoolSize(10);
    return dataSource;
}
 
Example 4
Source File: Config.java    From tutorials with MIT License 5 votes vote down vote up
@Bean(initMethod = "init", destroyMethod = "close")
public AtomikosDataSourceBean orderDataSource() {
    AtomikosDataSourceBean dataSource = new AtomikosDataSourceBean();
    dataSource.setLocalTransactionMode(true);
    dataSource.setUniqueResourceName("db2");
    dataSource.setXaDataSourceClassName("org.apache.derby.jdbc.EmbeddedXADataSource");
    Properties xaProperties = new Properties();
    xaProperties.put("databaseName", "db2");
    xaProperties.put("createDatabase", "create");
    dataSource.setXaProperties(xaProperties);
    dataSource.setPoolSize(10);
    return dataSource;
}
 
Example 5
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);
  }