use of io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource in project sharding-jdbc by shardingjdbc.
the class ShardingDatabaseOnlyWithHintForSelectTest method assertSelectBetweenWithSingleTable.
@Test
public void assertSelectBetweenWithSingleTable() throws SQLException, DatabaseUnitException {
String sql = SQLPlaceholderUtil.replacePreparedStatement(DatabaseTestSQL.SELECT_BETWEEN_WITH_SINGLE_TABLE_SQL);
for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
assertDataSet("integrate/dataset/sharding/db/expect/select/SelectBetweenWithSingleTable.xml", new HintShardingValueHelper(Lists.newArrayList(10, 12), ShardingOperator.BETWEEN, Lists.newArrayList(1001, 1200), ShardingOperator.BETWEEN), each.getValue().getConnection(), sql, each.getKey(), 10, 12, 1001, 1200);
assertDataSet("integrate/dataset/Empty.xml", new HintShardingValueHelper(Lists.newArrayList(10, 12), ShardingOperator.BETWEEN, Lists.newArrayList(1309, 1408), ShardingOperator.BETWEEN), each.getValue().getConnection(), sql, each.getKey(), 10, 12, 1309, 1408);
}
}
use of io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource in project sharding-jdbc by shardingjdbc.
the class ShardingDatabaseOnlyWithHintForSelectTest method assertSelectEqualsWithSingleTable.
@Test
public void assertSelectEqualsWithSingleTable() throws SQLException, DatabaseUnitException {
String sql = SQLPlaceholderUtil.replacePreparedStatement(DatabaseTestSQL.SELECT_EQUALS_WITH_SINGLE_TABLE_SQL);
for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
assertDataSet("integrate/dataset/sharding/db/expect/select/SelectEqualsWithSingleTable_0.xml", new HintShardingValueHelper(10, 1000), each.getValue().getConnection(), sql, each.getKey(), 10, 1000);
assertDataSet("integrate/dataset/sharding/db/expect/select/SelectEqualsWithSingleTable_1.xml", new HintShardingValueHelper(12, 1201), each.getValue().getConnection(), sql, each.getKey(), 12, 1201);
assertDataSet("integrate/dataset/Empty.xml", new HintShardingValueHelper(12, 1000), each.getValue().getConnection(), sql, each.getKey(), 12, 1000);
}
}
use of io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource in project sharding-jdbc by shardingjdbc.
the class ShardingDatabaseOnlyWithHintForSelectTest method assertSelectInWithSingleTable.
@Test
public void assertSelectInWithSingleTable() throws SQLException, DatabaseUnitException {
String sql = SQLPlaceholderUtil.replacePreparedStatement(DatabaseTestSQL.SELECT_IN_WITH_SINGLE_TABLE_SQL);
for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
assertDataSet("integrate/dataset/sharding/db/expect/select/SelectInWithSingleTable_0.xml", new HintShardingValueHelper(Lists.newArrayList(10, 12, 15), ShardingOperator.IN, Lists.newArrayList(1000, 1201), ShardingOperator.IN), each.getValue().getConnection(), sql, each.getKey(), 10, 12, 15, 1000, 1201);
assertDataSet("integrate/dataset/sharding/db/expect/select/SelectInWithSingleTable_1.xml", new HintShardingValueHelper(Lists.newArrayList(10, 12, 15), ShardingOperator.IN, Lists.newArrayList(1000, 1101), ShardingOperator.IN), each.getValue().getConnection(), sql, each.getKey(), 10, 12, 15, 1000, 1101);
assertDataSet("integrate/dataset/Empty.xml", new HintShardingValueHelper(Lists.newArrayList(10, 12, 15), ShardingOperator.IN, Lists.newArrayList(1309, 1408), ShardingOperator.IN), each.getValue().getConnection(), sql, each.getKey(), 10, 12, 15, 1309, 1408);
}
}
use of io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource in project sharding-jdbc by shardingjdbc.
the class AbstractShardingDatabaseOnlyTest method getDataSources.
@Override
protected Map<DatabaseType, ShardingDataSource> getDataSources() throws SQLException {
if (!getShardingDataSources().isEmpty()) {
return getShardingDataSources();
}
Map<DatabaseType, Map<String, DataSource>> dataSourceMap = createDataSourceMap();
for (Map.Entry<DatabaseType, Map<String, DataSource>> each : dataSourceMap.entrySet()) {
final ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
TableRuleConfiguration orderTableRuleConfig = new TableRuleConfiguration();
orderTableRuleConfig.setLogicTable("t_order");
orderTableRuleConfig.setLogicIndex("t_order_index");
orderTableRuleConfig.setKeyGeneratorColumnName("order_id");
orderTableRuleConfig.setKeyGenerator(new IncrementKeyGenerator());
shardingRuleConfig.getTableRuleConfigs().add(orderTableRuleConfig);
TableRuleConfiguration orderItemTableRuleConfig = new TableRuleConfiguration();
orderItemTableRuleConfig.setLogicTable("t_order_item");
TableRuleConfiguration logTableRuleConfig = new TableRuleConfiguration();
logTableRuleConfig.setLogicIndex("t_log_index");
logTableRuleConfig.setLogicTable("t_log");
TableRuleConfiguration tempLogTableRuleConfig = new TableRuleConfiguration();
tempLogTableRuleConfig.setLogicTable("t_temp_log");
shardingRuleConfig.getTableRuleConfigs().add(logTableRuleConfig);
shardingRuleConfig.getTableRuleConfigs().add(tempLogTableRuleConfig);
shardingRuleConfig.getTableRuleConfigs().add(orderItemTableRuleConfig);
shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new ComplexShardingStrategyConfiguration("user_id", new ComplexKeysModuloDatabaseShardingAlgorithm()));
shardingRuleConfig.setDefaultTableShardingStrategyConfig(new NoneShardingStrategyConfiguration());
getShardingDataSources().put(each.getKey(), new ShardingDataSource(each.getValue(), new ShardingRule(shardingRuleConfig, each.getValue().keySet())));
}
return getShardingDataSources();
}
use of io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource in project sharding-jdbc by shardingjdbc.
the class AbstractSoftTransactionIntegrationTest method prepareEnv.
private void prepareEnv() throws SQLException {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
tableRuleConfig.setLogicTable("transaction_test");
shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
Map<String, DataSource> dataSourceMap = createDataSourceMap();
ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, dataSourceMap.keySet());
shardingDataSource = new ShardingDataSource(dataSourceMap, shardingRule);
createTable(shardingDataSource);
transactionDataSource = createTransactionLogDataSource();
}
Aggregations