Java Code Examples for com.atomikos.jdbc.AtomikosDataSourceBean

The following examples show how to use com.atomikos.jdbc.AtomikosDataSourceBean. These examples are extracted from open source projects. 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
@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 Project: bearchoke   Source File: JpaLocalConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Bean(initMethod = "init", destroyMethod = "close")
public DataSource dataSource() {
    AtomikosDataSourceBean ds = new AtomikosDataSourceBean();
    ds.setUniqueResourceName(environment.getProperty("jpa.unique.resource.name"));
    ds.setXaDataSourceClassName(environment.getProperty("jpa.xa.datasource.classname"));
    ds.setMinPoolSize(environment.getProperty("jpa.ds.minpoolsize", Integer.class));
    ds.setMaxPoolSize(environment.getProperty("jpa.ds.maxpoolsize", Integer.class));

    Properties props = new Properties();
    props.put("databaseName", environment.getProperty("jpa.db.name"));
    props.put("createDatabase", environment.getProperty("jpa.db.create.strategy"));
    ds.setXaProperties(props);

    ds.setPoolSize(1);


    return ds;
}
 
Example 3
Source Project: tutorials   Source File: ApplicationUnitTest.java    License: MIT License 6 votes vote down vote up
private static DataSource getDataSource(String db) {

        DataSource ds;
        AtomikosDataSourceBean ads = new AtomikosDataSourceBean();
        ads.setXaDataSourceClassName("org.apache.derby.jdbc.EmbeddedXADataSource");
        Properties properties = new Properties();
        properties.put("databaseName", db);
        properties.put("createDatabase", "create");
        ads.setXaProperties(properties);
        ads.setUniqueResourceName(db);
        ads.setPoolSize(10); // optional
        ads.setBorrowConnectionTimeout(10); // optional
        ds = ads;
        return ds;

    }
 
Example 4
Source Project: micro-integrator   Source File: SQLConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Check the given datasource object type for XA support.
 *
 * @param tds Datasource object constructed from the configuraiton
 * @return array of two booleans [0] - IsXADataSource, [1] - IsAtomikosXADataSource
 */
private boolean[] isXADataSource(Object tds) {
    boolean[] result = new boolean[2];
    result[0] = tds instanceof XADataSource;
    if (tds instanceof AtomikosDataSourceBean) {
        AtomikosDataSourceBean atb = (AtomikosDataSourceBean) tds;
        if (atb.getXaDataSource() != null) {
            result[1] = true;
        }
    }
    return result;
}
 
Example 5
Source Project: sbp   Source File: PluginSecurityTest.java    License: Apache License 2.0 5 votes vote down vote up
@After
public void afterTest() {
    ((AtomikosDataSourceBean)dataSource).close();
    SpringBootPlugin plugin = (SpringBootPlugin)
            pluginManager.getPlugin("demo-plugin-library").getPlugin();
    plugin.releaseResource();
}
 
Example 6
Source Project: sbp   Source File: PluginIntegrationTest.java    License: Apache License 2.0 5 votes vote down vote up
@After
public void afterTest() {
    ((AtomikosDataSourceBean)dataSource).close();
    SpringBootPlugin plugin = (SpringBootPlugin)
            pluginManager.getPlugin("demo-plugin-library").getPlugin();
    plugin.releaseResource();
}
 
Example 7
Source Project: JPPF   Source File: NodeListener.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get or initialize the XA data source.
 * @return a {@link DataSource} instance.
 */
private static DataSource createXADataSource() {
  final AtomikosDataSourceBean ds = new AtomikosDataSourceBean();
  final Properties props = ds.getXaProperties();
  /*
  // PostgreSQL Properties
  // !!! on PostgreSQL, the server configuration property "maxPreparedConnections"
  // must be set to a value > 0
  ds.setXaDataSourceClassName("org.postgresql.xa.PGXADataSource");
  props.setProperty("user", "jppf");
  props.setProperty("password", "jppf");
  props.setProperty("databaseName", "jppf_samples");
  props.setProperty("serverName", "localhost");
  props.setProperty("portNumber", "5432");
  // MySQL Properties
  ds.setXaDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlXADataSource");
  props.setProperty("user", "jppf");
  props.setProperty("password", "jppf");
  props.setProperty("serverName", "localhost");
  props.setProperty("port", "3306");
  props.setProperty("databaseName", "jppf_samples");
  props.setProperty("pinGlobalTxToPhysicalConnection", "true");
  */
  // H2 Properties
  ds.setXaDataSourceClassName("org.h2.jdbcx.JdbcDataSource");
  props.setProperty("user", "jppf");
  props.setProperty("password", "jppf");
  props.setProperty("URL", "jdbc:h2:tcp://localhost:9092/./jppf_samples;SCHEMA=PUBLIC");

  // common properties
  ds.setTestQuery("select count(id) from task_result");
  ds.setUniqueResourceName("jppf_samples_ds");
  ds.setPoolSize(10);
  return ds;
}
 
Example 8
Source Project: mybatis.flying   Source File: DataSourceConfig.java    License: 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 9
Source Project: mybatis.flying   Source File: DataSourceConfig.java    License: 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 10
Source Project: hsweb-framework   Source File: AtomikosDataSourceConfig.java    License: 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 11
Source Project: shardingsphere   Source File: DataSourceUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Build data source.
 *
 * @param dataSourceClass data source
 * @param databaseType database type
 * @param databaseName database name
 * @return data source
 */
public static DataSource build(final Class<? extends DataSource> dataSourceClass, final DatabaseType databaseType, final String databaseName) {
    if (HikariDataSource.class == dataSourceClass) {
        return createHikariDataSource(databaseType, databaseName);
    } else if (AtomikosDataSourceBean.class == dataSourceClass) {
        return createAtomikosDataSourceBean(databaseType, createHikariDataSource(databaseType, databaseName), databaseName);
    }
    
    throw new UnsupportedOperationException(dataSourceClass.getClass().getName());
}
 
Example 12
@Test
public void assertGetAtomikosConnection() throws SQLException, RollbackException, SystemException {
    DataSource dataSource = DataSourceUtils.build(AtomikosDataSourceBean.class, DatabaseTypes.getActualDatabaseType("H2"), "ds1");
    XATransactionDataSource transactionDataSource = new XATransactionDataSource(DatabaseTypes.getActualDatabaseType("H2"), "ds1", dataSource, xaTransactionManager);
    try (Connection ignored = transactionDataSource.getConnection()) {
        verify(xaTransactionManager, times(0)).getTransactionManager();
    }
}
 
Example 13
@Test
public void assertCloseAtomikosDataSourceBean() {
    DataSource dataSource = DataSourceUtils.build(AtomikosDataSourceBean.class, DatabaseTypes.getActualDatabaseType("H2"), "ds11");
    XATransactionDataSource transactionDataSource = new XATransactionDataSource(DatabaseTypes.getActualDatabaseType("H2"), "ds11", dataSource, xaTransactionManager);
    transactionDataSource.close();
    verify(xaTransactionManager, times(0)).removeRecoveryResource(anyString(), any(XADataSource.class));
   
}
 
Example 14
private Collection<ResourceDataSource> createResourceDataSources(final DatabaseType databaseType) {
    List<ResourceDataSource> result = new LinkedList<>();
    result.add(new ResourceDataSource("ds1", DataSourceUtils.build(HikariDataSource.class, databaseType, "demo_ds_1")));
    result.add(new ResourceDataSource("ds2", DataSourceUtils.build(HikariDataSource.class, databaseType, "demo_ds_2")));
    result.add(new ResourceDataSource("ds3", DataSourceUtils.build(AtomikosDataSourceBean.class, databaseType, "demo_ds_3")));
    return result;
}
 
Example 15
@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 16
Source Project: tutorials   Source File: OrderConfig.java    License: 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 17
Source Project: tutorials   Source File: InventoryConfig.java    License: 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 18
Source Project: tutorials   Source File: Config.java    License: 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 19
Source Project: tutorials   Source File: Config.java    License: 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 20
Source Project: sbp   Source File: LibraryPlugin.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void releaseResource() {
    AtomikosDataSourceBean dataSource = (AtomikosDataSourceBean)
            getApplicationContext().getBean("dataSource");
    dataSource.close();
}
 
Example 21
@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 22
Source Project: shardingsphere   Source File: DataSourceUtils.java    License: 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;
}