use of com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource in project sharding-jdbc by dangdangdotcom.
the class ShardingTablesOnlyForStatementWithDMLTest method assertUpdate.
@Test
public void assertUpdate() throws SQLException, DatabaseUnitException {
ShardingDataSource shardingDataSource = getShardingDataSource();
String sql = "UPDATE `t_order` SET `status` = '%s' WHERE `order_id` = %s AND `user_id` = %s";
for (int i = 10; i < 12; i++) {
for (int j = 0; j < 10; j++) {
try (Connection connection = shardingDataSource.getConnection();
Statement stmt = connection.createStatement()) {
assertThat(stmt.executeUpdate(String.format(sql, "updated", i * 100 + j, i)), is(1));
}
}
}
assertDataSet("update", "updated");
}
use of com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource in project sharding-jdbc by dangdangdotcom.
the class ShardingTablesOnlyForStatementWithDMLTest method assertDelete.
@Test
public void assertDelete() throws SQLException, DatabaseUnitException {
ShardingDataSource shardingDataSource = getShardingDataSource();
String sql = "DELETE `t_order` WHERE `order_id` = %s AND `user_id` = %s AND `status` = '%s'";
for (int i = 10; i < 12; i++) {
for (int j = 0; j < 10; j++) {
try (Connection connection = shardingDataSource.getConnection();
Statement stmt = connection.createStatement()) {
assertThat(stmt.executeUpdate(String.format(sql, i * 100 + j, i, "init")), is(1));
}
}
}
assertDataSet("delete", "init");
}
use of com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource in project sharding-jdbc by dangdangdotcom.
the class AbstractSoftTransactionIntegrationTest method prepareEnv.
private void prepareEnv() throws SQLException {
DataSourceRule dataSourceRule = new DataSourceRule(createDataSourceMap());
TableRule tableRule = TableRule.builder("transaction_test").dataSourceRule(dataSourceRule).build();
ShardingRule shardingRule = ShardingRule.builder().dataSourceRule(dataSourceRule).tableRules(Lists.newArrayList(tableRule)).build();
shardingDataSource = new ShardingDataSource(shardingRule);
createTable(shardingDataSource);
transactionDataSource = createTransactionLogDataSource();
}
use of com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource in project sharding-jdbc by dangdangdotcom.
the class AbstractRoutingDatabaseOnlyTest method initDataSource.
protected ShardingDataSource initDataSource() {
DataSourceRule dataSourceRule = new DataSourceRule(createDataSourceMap("dataSource_%s"));
ShardingRule shardingRule = ShardingRule.builder().dataSourceRule(dataSourceRule).databaseShardingStrategy(new DatabaseShardingStrategy(new NoneKeyModuloDatabaseShardingAlgorithm())).build();
return new ShardingDataSource(shardingRule);
}
use of com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource in project sharding-jdbc by dangdangdotcom.
the class AbstractShardingDataBasesOnlyHintDBUnitTest method initDataSource.
ShardingDataSource initDataSource() {
DataSourceRule dataSourceRule = new DataSourceRule(createDataSourceMap("dataSource_%s"));
TableRule orderTableRule = TableRule.builder("t_order").dataSourceRule(dataSourceRule).build();
TableRule orderItemTableRule = TableRule.builder("t_order_item").dataSourceRule(dataSourceRule).build();
ShardingRule shardingRule = ShardingRule.builder().dataSourceRule(dataSourceRule).tableRules(Lists.newArrayList(orderTableRule, orderItemTableRule)).bindingTableRules(Collections.singletonList(new BindingTableRule(Arrays.asList(orderTableRule, orderItemTableRule)))).databaseShardingStrategy(new DatabaseShardingStrategy(Collections.singletonList("user_id"), new MultipleKeysModuloDatabaseShardingAlgorithm())).tableShardingStrategy(new TableShardingStrategy(Collections.singletonList("order_id"), new NoneTableShardingAlgorithm())).build();
return new ShardingDataSource(shardingRule);
}
Aggregations