Search in sources :

Example 1 with MysqlXADataSource

use of com.mysql.cj.jdbc.MysqlXADataSource in project springBoot_2017 by showkawa.

the class DataSourceConfig02 method kawa02DataSource.

/* @Bean
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource druid(){
        return new DruidDataSource();
    }*/
/**
 * 配置数据源
 * @return
 */
/*@Bean(name="kawa02DataSource")
    @ConfigurationProperties(prefix = "spring.datasource.kawa02")
    public DataSource kawa02DataSource(){

        return DataSourceBuilder.create().build();
    }*/
@Bean(name = "kawa02DataSource")
public DataSource kawa02DataSource(DbConfig02 dbConfig) throws SQLException {
    MysqlXADataSource mysqlXaDataSource = new MysqlXADataSource();
    mysqlXaDataSource.setUrl(dbConfig.getJdbcUrl());
    mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
    mysqlXaDataSource.setPassword(dbConfig.getPassword());
    mysqlXaDataSource.setUser(dbConfig.getUsername());
    mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
    // 将本地事务注册到Atomikos全局事务中
    AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
    xaDataSource.setXaDataSource(mysqlXaDataSource);
    xaDataSource.setUniqueResourceName("kawa02DataSource");
    xaDataSource.setMinPoolSize(dbConfig.getMinPoolSize());
    xaDataSource.setMaxPoolSize(dbConfig.getMaxPoolSize());
    xaDataSource.setMaxLifetime(dbConfig.getMaxLifetime());
    xaDataSource.setBorrowConnectionTimeout(dbConfig.getBorrowConnectionTimeout());
    xaDataSource.setLoginTimeout(dbConfig.getLoginTimeout());
    xaDataSource.setMaintenanceInterval(dbConfig.getMaintenanceInterval());
    xaDataSource.setMaxIdleTime(dbConfig.getMaxIdleTime());
    xaDataSource.setTestQuery(dbConfig.getTestQuery());
    return xaDataSource;
}
Also used : MysqlXADataSource(com.mysql.cj.jdbc.MysqlXADataSource) AtomikosDataSourceBean(com.atomikos.jdbc.AtomikosDataSourceBean) AtomikosDataSourceBean(com.atomikos.jdbc.AtomikosDataSourceBean) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with MysqlXADataSource

use of com.mysql.cj.jdbc.MysqlXADataSource in project narayana by jbosstm.

the class PerformanceTestCommitMarkableResource method testXAResource.

// @org.junit.Ignore
@Test
public void testXAResource() throws Exception {
    System.out.println("testXAResource: " + new Date());
    XADataSource dataSource = null;
    if (dbType.equals("oracle")) {
        Class clazz = Class.forName("oracle.jdbc.xa.client.OracleXADataSource");
        dataSource = (XADataSource) clazz.newInstance();
        clazz.getMethod("setDriverType", new Class[] { String.class }).invoke(dataSource, new Object[] { "thin" });
        clazz.getMethod("setServerName", new Class[] { String.class }).invoke(dataSource, new Object[] { "tywin.eng.hst.ams2.redhat.com" });
        clazz.getMethod("setNetworkProtocol", new Class[] { String.class }).invoke(dataSource, new Object[] { "tcp" });
        clazz.getMethod("setDatabaseName", new Class[] { String.class }).invoke(dataSource, new Object[] { "orcl" });
        clazz.getMethod("setUser", new Class[] { String.class }).invoke(dataSource, new Object[] { "dtf11" });
        clazz.getMethod("setPassword", new Class[] { String.class }).invoke(dataSource, new Object[] { "dtf11" });
        clazz.getMethod("setPortNumber", new Class[] { int.class }).invoke(dataSource, new Object[] { 1521 });
    } else if (dbType.equals("sybase")) {
        Class clazz = Class.forName("com.sybase.jdbc3.jdbc.SybXADataSource");
        dataSource = (XADataSource) clazz.newInstance();
        clazz.getMethod("setServerName", new Class[] { String.class }).invoke(dataSource, new Object[] { "192.168.1.5" });
        clazz.getMethod("setDatabaseName", new Class[] { String.class }).invoke(dataSource, new Object[] { "LOCALHOST" });
        clazz.getMethod("setUser", new Class[] { String.class }).invoke(dataSource, new Object[] { "sa" });
        clazz.getMethod("setPassword", new Class[] { String.class }).invoke(dataSource, new Object[] { "sybase" });
        clazz.getMethod("setPortNumber", new Class[] { int.class }).invoke(dataSource, new Object[] { 5000 });
    } else if (dbType.equals("h2")) {
        dataSource = new org.h2.jdbcx.JdbcDataSource();
        ((JdbcDataSource) dataSource).setURL("jdbc:h2:mem:JBTMDB2;MVCC=TRUE;DB_CLOSE_DELAY=-1");
    } else if (dbType.equals("postgres")) {
        dataSource = new PGXADataSource();
        ((PGXADataSource) dataSource).setPortNumber(5432);
        ((PGXADataSource) dataSource).setUser("dtf11");
        ((PGXADataSource) dataSource).setPassword("dtf11");
        ((PGXADataSource) dataSource).setServerName("tywin.eng.hst.ams2.redhat.com");
        ((PGXADataSource) dataSource).setDatabaseName("jbossts");
    } else if (dbType.equals("mysql")) {
        dataSource = new MysqlXADataSource();
        ((MysqlXADataSource) dataSource).setServerName("tywin.eng.hst.ams2.redhat.com");
        ((MysqlXADataSource) dataSource).setPortNumber(3306);
        ((MysqlXADataSource) dataSource).setDatabaseName("jbossts");
        ((MysqlXADataSource) dataSource).setUser("dtf11");
        ((MysqlXADataSource) dataSource).setPassword("dtf11");
    } else if (dbType.equals("db2")) {
        Class clazz = Class.forName("com.ibm.db2.jcc.DB2XADataSource");
        dataSource = (XADataSource) clazz.newInstance();
        clazz.getMethod("setServerName", new Class[] { String.class }).invoke(dataSource, new Object[] { "tywin.eng.hst.ams2.redhat.com" });
        clazz.getMethod("setDatabaseName", new Class[] { String.class }).invoke(dataSource, new Object[] { "BTDB1" });
        clazz.getMethod("setUser", new Class[] { String.class }).invoke(dataSource, new Object[] { "db2" });
        clazz.getMethod("setPassword", new Class[] { String.class }).invoke(dataSource, new Object[] { "db2" });
        clazz.getMethod("setDriverType", new Class[] { int.class }).invoke(dataSource, new Object[] { 4 });
        clazz.getMethod("setPortNumber", new Class[] { int.class }).invoke(dataSource, new Object[] { 50001 });
    } else if (dbType.equals("sqlserver")) {
        Class clazz = Class.forName("com.microsoft.sqlserver.jdbc.SQLServerXADataSource");
        dataSource = (XADataSource) clazz.newInstance();
        clazz.getMethod("setServerName", new Class[] { String.class }).invoke(dataSource, new Object[] { "dev30.mw.lab.eng.bos.redhat.com" });
        clazz.getMethod("setDatabaseName", new Class[] { String.class }).invoke(dataSource, new Object[] { "crashrec" });
        clazz.getMethod("setUser", new Class[] { String.class }).invoke(dataSource, new Object[] { "crashrec" });
        clazz.getMethod("setPassword", new Class[] { String.class }).invoke(dataSource, new Object[] { "crashrec" });
        clazz.getMethod("setSendStringParametersAsUnicode", new Class[] { Boolean.class }).invoke(dataSource, new Object[] { false });
        clazz.getMethod("setPortNumber", new Class[] { int.class }).invoke(dataSource, new Object[] { 3918 });
    }
    Utils.createTables(dataSource);
    doTest(new Handler(dataSource), "_testXAResource_" + dbType);
}
Also used : XADataSource(javax.sql.XADataSource) MysqlXADataSource(com.mysql.cj.jdbc.MysqlXADataSource) PGXADataSource(org.postgresql.xa.PGXADataSource) MysqlXADataSource(com.mysql.cj.jdbc.MysqlXADataSource) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Date(java.util.Date) PGXADataSource(org.postgresql.xa.PGXADataSource) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Test(org.junit.Test)

Example 3 with MysqlXADataSource

use of com.mysql.cj.jdbc.MysqlXADataSource in project Mycat2 by MyCATApache.

the class SeataMySQLXADatasourceProvider 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();
    MysqlXADataSource datasource = new MysqlXADataSource();
    datasource.setPassword(password);
    datasource.setUser(username);
    datasource.setUrl(url);
    return new JdbcDataSource(config, new DataSourceProxyXA(datasource));
}
Also used : DataSourceProxyXA(io.seata.rm.datasource.xa.DataSourceProxyXA) MysqlXADataSource(com.mysql.cj.jdbc.MysqlXADataSource) JdbcDataSource(io.mycat.datasource.jdbc.datasource.JdbcDataSource)

Example 4 with MysqlXADataSource

use of com.mysql.cj.jdbc.MysqlXADataSource in project springBoot_2017 by showkawa.

the class DataSourceConfig method kawaDataSource.

/* @Bean
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource druid(){
        return new DruidDataSource();
    }*/
/**
 * 配置数据源
 * @return
 */
/*@Bean(name="kawaDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.kawa")
    public DataSource kawaDataSource(){
        return DataSourceBuilder.create().build();
    }*/
@Bean(name = "kawaDataSource")
public DataSource kawaDataSource(DbConfig dbConfig) throws SQLException {
    MysqlXADataSource mysqlXaDataSource = new MysqlXADataSource();
    mysqlXaDataSource.setUrl(dbConfig.getJdbcUrl());
    mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
    mysqlXaDataSource.setPassword(dbConfig.getPassword());
    mysqlXaDataSource.setUser(dbConfig.getUsername());
    mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
    // 将本地事务注册到Atomikos全局事务中
    AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
    xaDataSource.setXaDataSource(mysqlXaDataSource);
    xaDataSource.setUniqueResourceName("kawaDataSource");
    xaDataSource.setMinPoolSize(dbConfig.getMinPoolSize());
    xaDataSource.setMaxPoolSize(dbConfig.getMaxPoolSize());
    xaDataSource.setMaxLifetime(dbConfig.getMaxLifetime());
    xaDataSource.setBorrowConnectionTimeout(dbConfig.getBorrowConnectionTimeout());
    xaDataSource.setLoginTimeout(dbConfig.getLoginTimeout());
    xaDataSource.setMaintenanceInterval(dbConfig.getMaintenanceInterval());
    xaDataSource.setMaxIdleTime(dbConfig.getMaxIdleTime());
    xaDataSource.setTestQuery(dbConfig.getTestQuery());
    return xaDataSource;
}
Also used : MysqlXADataSource(com.mysql.cj.jdbc.MysqlXADataSource) AtomikosDataSourceBean(com.atomikos.jdbc.AtomikosDataSourceBean) AtomikosDataSourceBean(com.atomikos.jdbc.AtomikosDataSourceBean) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

MysqlXADataSource (com.mysql.cj.jdbc.MysqlXADataSource)4 AtomikosDataSourceBean (com.atomikos.jdbc.AtomikosDataSourceBean)2 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 Date (java.util.Date)1 XADataSource (javax.sql.XADataSource)1 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)1 Test (org.junit.Test)1 PGXADataSource (org.postgresql.xa.PGXADataSource)1