Search in sources :

Example 6 with DruidXADataSource

use of com.alibaba.druid.pool.xa.DruidXADataSource in project seata by seata.

the class XAModeTest2 method createNewDruidXADataSource.

private DruidXADataSource createNewDruidXADataSource() throws Throwable {
    DruidXADataSource druidDataSource = new DruidXADataSource();
    initDruidDataSource(druidDataSource);
    return druidDataSource;
}
Also used : DruidXADataSource(com.alibaba.druid.pool.xa.DruidXADataSource)

Example 7 with DruidXADataSource

use of com.alibaba.druid.pool.xa.DruidXADataSource in project Mycat2 by MyCATApache.

the class SeataXADatasourceProvider method createDataSource.

@Override
public JdbcDataSource createDataSource(DatasourceConfig config) {
    String username = config.getUser();
    String password = config.getPassword();
    String url = Objects.requireNonNull(config.getUrl());
    String dbType = config.getDbType();
    int maxRetryCount = config.getMaxRetryCount();
    List<String> initSQLs = config.getInitSqls();
    int maxCon = config.getMaxCon();
    int minCon = config.getMinCon();
    DruidXADataSource datasource = new DruidXADataSource();
    datasource.setPassword(password);
    datasource.setUsername(username);
    datasource.setUrl(url);
    datasource.setMaxWait(TimeUnit.SECONDS.toMillis(60));
    datasource.setMaxActive(maxCon);
    datasource.setMinIdle(minCon);
    datasource.setKeepAlive(true);
    datasource.setTestOnReturn(true);
    datasource.setTestOnBorrow(true);
    datasource.setValidationQuery("select 'x'");
    datasource.setTestWhileIdle(true);
    if (maxRetryCount > 0) {
        datasource.setConnectionErrorRetryAttempts(maxRetryCount);
    }
    if (dbType != null) {
        datasource.setDbType(dbType);
    }
    if (initSQLs != null) {
        datasource.setConnectionInitSqls(initSQLs);
    }
    return new JdbcDataSource(config, new DataSourceProxyXA(datasource));
}
Also used : DataSourceProxyXA(io.seata.rm.datasource.xa.DataSourceProxyXA) JdbcDataSource(io.mycat.datasource.jdbc.datasource.JdbcDataSource) DruidXADataSource(com.alibaba.druid.pool.xa.DruidXADataSource)

Example 8 with DruidXADataSource

use of com.alibaba.druid.pool.xa.DruidXADataSource in project mybatis.flying by limeng32.

the class DataSourceConfig method xaDataSource2.

public XADataSource xaDataSource2() {
    DruidXADataSource xaDataSource = new DruidXADataSource();
    xaDataSource.setUrl("jdbc:h2:mem:testdb2;MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MV_STORE=FALSE;MVCC=FALSE;FILE_LOCK=NO");
    xaDataSource.setUsername("sa1");
    xaDataSource.setPassword("null");
    return xaDataSource;
}
Also used : DruidXADataSource(com.alibaba.druid.pool.xa.DruidXADataSource)

Example 9 with DruidXADataSource

use of com.alibaba.druid.pool.xa.DruidXADataSource in project druid by alibaba.

the class H2XATest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    dataSource = new DruidXADataSource();
    dataSource.setMinIdle(1);
    dataSource.setUrl("jdbc:h2:mem:test;");
    dataSource.setTestOnBorrow(false);
    JdbcUtils.execute(dataSource, "CREATE TABLE user (id INT, name VARCHAR(40))");
}
Also used : DruidXADataSource(com.alibaba.druid.pool.xa.DruidXADataSource)

Example 10 with DruidXADataSource

use of com.alibaba.druid.pool.xa.DruidXADataSource in project citrus by Yiuman.

the class DynamicDataSourceAutoConfiguration method buildDruidXaDataSource.

/**
 * 根据配置构建XA数据源
 *
 * @param resourceName 资源名,用于定义XA唯一资源
 * @param properties   数据源配置
 * @return XA数据源
 */
public DataSource buildDruidXaDataSource(String resourceName, DataSourceProperties properties) {
    DruidXADataSource druidDataSource = new DruidXADataSource();
    druidDataSource.setUrl(properties.getUrl());
    druidDataSource.setUsername(properties.getUsername());
    druidDataSource.setPassword(properties.getPassword());
    druidDataSource.setDriverClassName(properties.getDriverClassName());
    AtomikosDataSourceBean atomikosDataSourceBean = new AtomikosDataSourceBean();
    atomikosDataSourceBean.setXaDataSource(druidDataSource);
    atomikosDataSourceBean.setUniqueResourceName(String.format("%s$$%s", resourceName, UUID.randomUUID().toString().substring(0, 15)));
    return atomikosDataSourceBean;
}
Also used : AtomikosDataSourceBean(org.springframework.boot.jta.atomikos.AtomikosDataSourceBean) DruidXADataSource(com.alibaba.druid.pool.xa.DruidXADataSource)

Aggregations

DruidXADataSource (com.alibaba.druid.pool.xa.DruidXADataSource)11 AtomikosDataSourceBean (org.springframework.boot.jta.atomikos.AtomikosDataSourceBean)3 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)2 Bean (org.springframework.context.annotation.Bean)2 JdbcDataSource (io.mycat.datasource.jdbc.datasource.JdbcDataSource)1 DataSourceProxyXA (io.seata.rm.datasource.xa.DataSourceProxyXA)1 XAXid (io.seata.rm.datasource.xa.XAXid)1 XAConnection (javax.sql.XAConnection)1 XAResource (javax.transaction.xa.XAResource)1 Xid (javax.transaction.xa.Xid)1 Disabled (org.junit.jupiter.api.Disabled)1 Test (org.junit.jupiter.api.Test)1 Primary (org.springframework.context.annotation.Primary)1