Search in sources :

Example 81 with DataSource

use of javax.sql.DataSource in project mybatis-3 by mybatis.

the class BlobInputStreamTypeHandlerTest method setupSqlSessionFactory.

@BeforeClass
public static void setupSqlSessionFactory() throws Exception {
    DataSource dataSource = BaseDataTest.createUnpooledDataSource("org/apache/ibatis/type/jdbc.properties");
    BaseDataTest.runScript(dataSource, "org/apache/ibatis/type/BlobInputStreamTypeHandlerTest.sql");
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("Production", transactionFactory, dataSource);
    Configuration configuration = new Configuration(environment);
    configuration.addMapper(Mapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) Environment(org.apache.ibatis.mapping.Environment) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) DataSource(javax.sql.DataSource) BeforeClass(org.junit.BeforeClass)

Example 82 with DataSource

use of javax.sql.DataSource in project mybatis-3 by mybatis.

the class ClobReaderTypeHandlerTest method setupSqlSessionFactory.

@BeforeClass
public static void setupSqlSessionFactory() throws Exception {
    DataSource dataSource = BaseDataTest.createUnpooledDataSource("org/apache/ibatis/type/jdbc.properties");
    BaseDataTest.runScript(dataSource, "org/apache/ibatis/type/ClobReaderTypeHandlerTest.sql");
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("Production", transactionFactory, dataSource);
    Configuration configuration = new Configuration(environment);
    configuration.addMapper(Mapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) Environment(org.apache.ibatis.mapping.Environment) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) DataSource(javax.sql.DataSource) BeforeClass(org.junit.BeforeClass)

Example 83 with DataSource

use of javax.sql.DataSource in project sharding-jdbc by dangdangdotcom.

the class ShardingDataSourceFactoryTest method createShardingRule.

private ShardingRule createShardingRule() throws SQLException {
    DataSource dataSource = mock(DataSource.class);
    Connection connection = mock(Connection.class);
    DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
    when(dataSource.getConnection()).thenReturn(connection);
    when(connection.getMetaData()).thenReturn(databaseMetaData);
    when(databaseMetaData.getDatabaseProductName()).thenReturn("H2");
    Map<String, DataSource> dataSourceMap = new HashMap<>(1);
    dataSourceMap.put("ds", dataSource);
    DataSourceRule dataSourceRule = new DataSourceRule(dataSourceMap);
    TableRule tableRule = TableRule.builder("logicTable").actualTables(Arrays.asList("table_0", "table_1", "table_2")).dataSourceRule(dataSourceRule).build();
    return ShardingRule.builder().dataSourceRule(dataSourceRule).tableRules(Collections.singletonList(tableRule)).build();
}
Also used : TableRule(com.dangdang.ddframe.rdb.sharding.api.rule.TableRule) HashMap(java.util.HashMap) DataSourceRule(com.dangdang.ddframe.rdb.sharding.api.rule.DataSourceRule) Connection(java.sql.Connection) DatabaseMetaData(java.sql.DatabaseMetaData) DataSource(javax.sql.DataSource)

Example 84 with DataSource

use of javax.sql.DataSource in project sharding-jdbc by dangdangdotcom.

the class AbstractShardingMasterSlaveDBUnitTest method getShardingDataSource.

protected final ShardingDataSource getShardingDataSource() {
    if (null != shardingDataSource && !isShutdown) {
        return shardingDataSource;
    }
    isShutdown = false;
    Map<String, DataSource> masterSlaveDataSourceMap = createDataSourceMap("dataSource_%s");
    MasterSlaveDataSource masterSlaveDs0 = new MasterSlaveDataSource("ms_0", masterSlaveDataSourceMap.get("dataSource_master_0"), Collections.singletonList(masterSlaveDataSourceMap.get("dataSource_slave_0")));
    MasterSlaveDataSource masterSlaveDs1 = new MasterSlaveDataSource("ms_1", masterSlaveDataSourceMap.get("dataSource_master_1"), Collections.singletonList(masterSlaveDataSourceMap.get("dataSource_slave_1")));
    MasterSlaveDataSource masterSlaveDs2 = new MasterSlaveDataSource("ms_2", masterSlaveDataSourceMap.get("dataSource_master_2"), Collections.singletonList(masterSlaveDataSourceMap.get("dataSource_slave_2")));
    MasterSlaveDataSource masterSlaveDs3 = new MasterSlaveDataSource("ms_3", masterSlaveDataSourceMap.get("dataSource_master_3"), Collections.singletonList(masterSlaveDataSourceMap.get("dataSource_slave_3")));
    MasterSlaveDataSource masterSlaveDs4 = new MasterSlaveDataSource("ms_4", masterSlaveDataSourceMap.get("dataSource_master_4"), Collections.singletonList(masterSlaveDataSourceMap.get("dataSource_slave_4")));
    MasterSlaveDataSource masterSlaveDs5 = new MasterSlaveDataSource("ms_5", masterSlaveDataSourceMap.get("dataSource_master_5"), Collections.singletonList(masterSlaveDataSourceMap.get("dataSource_slave_5")));
    MasterSlaveDataSource masterSlaveDs6 = new MasterSlaveDataSource("ms_6", masterSlaveDataSourceMap.get("dataSource_master_6"), Collections.singletonList(masterSlaveDataSourceMap.get("dataSource_slave_6")));
    MasterSlaveDataSource masterSlaveDs7 = new MasterSlaveDataSource("ms_7", masterSlaveDataSourceMap.get("dataSource_master_7"), Collections.singletonList(masterSlaveDataSourceMap.get("dataSource_slave_7")));
    MasterSlaveDataSource masterSlaveDs8 = new MasterSlaveDataSource("ms_8", masterSlaveDataSourceMap.get("dataSource_master_8"), Collections.singletonList(masterSlaveDataSourceMap.get("dataSource_slave_8")));
    MasterSlaveDataSource masterSlaveDs9 = new MasterSlaveDataSource("ms_9", masterSlaveDataSourceMap.get("dataSource_master_9"), Collections.singletonList(masterSlaveDataSourceMap.get("dataSource_slave_9")));
    Map<String, DataSource> dataSourceMap = new HashMap<>(10);
    dataSourceMap.put("ms_0", masterSlaveDs0);
    dataSourceMap.put("ms_1", masterSlaveDs1);
    dataSourceMap.put("ms_2", masterSlaveDs2);
    dataSourceMap.put("ms_3", masterSlaveDs3);
    dataSourceMap.put("ms_4", masterSlaveDs4);
    dataSourceMap.put("ms_5", masterSlaveDs5);
    dataSourceMap.put("ms_6", masterSlaveDs6);
    dataSourceMap.put("ms_7", masterSlaveDs7);
    dataSourceMap.put("ms_8", masterSlaveDs8);
    dataSourceMap.put("ms_9", masterSlaveDs9);
    DataSourceRule dataSourceRule = new DataSourceRule(dataSourceMap);
    TableRule orderTableRule = TableRule.builder("t_order").actualTables(Arrays.asList("t_order_0", "t_order_1", "t_order_2", "t_order_3", "t_order_4", "t_order_5", "t_order_6", "t_order_7", "t_order_8", "t_order_9")).dataSourceRule(dataSourceRule).build();
    TableRule orderItemTableRule = TableRule.builder("t_order_item").actualTables(Arrays.asList("t_order_item_0", "t_order_item_1", "t_order_item_2", "t_order_item_3", "t_order_item_4", "t_order_item_5", "t_order_item_6", "t_order_item_7", "t_order_item_8", "t_order_item_9")).dataSourceRule(dataSourceRule).build();
    TableRule configRule = TableRule.builder("t_config").dataSourceRule(dataSourceRule).build();
    ShardingRule shardingRule = ShardingRule.builder().dataSourceRule(dataSourceRule).tableRules(Arrays.asList(orderTableRule, orderItemTableRule, configRule)).bindingTableRules(Collections.singletonList(new BindingTableRule(Arrays.asList(orderTableRule, orderItemTableRule)))).databaseShardingStrategy(new DatabaseShardingStrategy("user_id", new SingleKeyModuloDatabaseShardingAlgorithm())).tableShardingStrategy(new TableShardingStrategy("order_id", new SingleKeyModuloTableShardingAlgorithm())).build();
    shardingDataSource = new ShardingDataSource(shardingRule);
    return shardingDataSource;
}
Also used : TableRule(com.dangdang.ddframe.rdb.sharding.api.rule.TableRule) BindingTableRule(com.dangdang.ddframe.rdb.sharding.api.rule.BindingTableRule) DatabaseShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingStrategy) HashMap(java.util.HashMap) ShardingDataSource(com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource) DataSourceRule(com.dangdang.ddframe.rdb.sharding.api.rule.DataSourceRule) MasterSlaveDataSource(com.dangdang.ddframe.rdb.sharding.jdbc.MasterSlaveDataSource) BindingTableRule(com.dangdang.ddframe.rdb.sharding.api.rule.BindingTableRule) TableShardingStrategy(com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy) SingleKeyModuloTableShardingAlgorithm(com.dangdang.ddframe.rdb.integrate.fixture.SingleKeyModuloTableShardingAlgorithm) MasterSlaveDataSource(com.dangdang.ddframe.rdb.sharding.jdbc.MasterSlaveDataSource) ShardingDataSource(com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource) DataSource(javax.sql.DataSource) ShardingRule(com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule) SingleKeyModuloDatabaseShardingAlgorithm(com.dangdang.ddframe.rdb.integrate.fixture.SingleKeyModuloDatabaseShardingAlgorithm)

Example 85 with DataSource

use of javax.sql.DataSource in project sharding-jdbc by dangdangdotcom.

the class TransactionLogStorageFactoryTest method assertCreateRdbTransactionLogStorageFactory.

@Test
public void assertCreateRdbTransactionLogStorageFactory() {
    DataSource dataSource = mock(DataSource.class);
    TransactionLogDataSource transactionLogDataSource = new RdbTransactionLogDataSource(dataSource);
    assertThat(TransactionLogStorageFactory.createTransactionLogStorage(transactionLogDataSource), instanceOf(TransactionLogStorage.class));
}
Also used : RdbTransactionLogDataSource(com.dangdang.ddframe.rdb.transaction.soft.datasource.impl.RdbTransactionLogDataSource) MemoryTransactionLogDataSource(com.dangdang.ddframe.rdb.transaction.soft.datasource.impl.MemoryTransactionLogDataSource) TransactionLogDataSource(com.dangdang.ddframe.rdb.transaction.soft.datasource.TransactionLogDataSource) RdbTransactionLogDataSource(com.dangdang.ddframe.rdb.transaction.soft.datasource.impl.RdbTransactionLogDataSource) MemoryTransactionLogDataSource(com.dangdang.ddframe.rdb.transaction.soft.datasource.impl.MemoryTransactionLogDataSource) DataSource(javax.sql.DataSource) TransactionLogDataSource(com.dangdang.ddframe.rdb.transaction.soft.datasource.TransactionLogDataSource) RdbTransactionLogDataSource(com.dangdang.ddframe.rdb.transaction.soft.datasource.impl.RdbTransactionLogDataSource) Test(org.junit.Test)

Aggregations

DataSource (javax.sql.DataSource)603 Connection (java.sql.Connection)211 Test (org.junit.Test)207 SQLException (java.sql.SQLException)124 Context (javax.naming.Context)73 InitialContext (javax.naming.InitialContext)64 NamingException (javax.naming.NamingException)62 ResultSet (java.sql.ResultSet)60 Statement (java.sql.Statement)59 HashMap (java.util.HashMap)40 EJBException (javax.ejb.EJBException)40 PreparedStatement (java.sql.PreparedStatement)38 Properties (java.util.Properties)37 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)35 IOException (java.io.IOException)32 RemoteException (java.rmi.RemoteException)32 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)31 UserTransaction (javax.transaction.UserTransaction)30 ArrayList (java.util.ArrayList)26 Map (java.util.Map)21