use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class UpdateStatementParserTest method parseWithoutCondition.
@Test
public void parseWithoutCondition() {
ShardingRule shardingRule = createShardingRule();
SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "UPDATE TABLE_XXX SET field1=field1+1", shardingRule);
DMLStatement updateStatement = (DMLStatement) statementParser.parse();
assertThat(updateStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX"));
}
use of io.shardingjdbc.core.rule.ShardingRule 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();
}
use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class MasterSlaveNamespaceTest method getShardingRule.
private ShardingRule getShardingRule(final String shardingDataSourceName) {
ShardingDataSource shardingDataSource = this.applicationContext.getBean(shardingDataSourceName, ShardingDataSource.class);
Object shardingContext = FieldValueUtil.getFieldValue(shardingDataSource, "shardingContext", true);
return (ShardingRule) FieldValueUtil.getFieldValue(shardingContext, "shardingRule");
}
use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class MasterSlaveNamespaceTest method assertDefaultShardingDataSource.
@Test
public void assertDefaultShardingDataSource() {
Map<String, DataSource> dataSourceMap = getDataSourceMap("defaultShardingDataSource");
assertNotNull(dataSourceMap.get("randomMasterSlaveDataSource"));
assertNotNull(dataSourceMap.get("refMasterSlaveDataSource"));
ShardingRule shardingRule = getShardingRule("defaultShardingDataSource");
assertThat(shardingRule.getDefaultDataSourceName(), is("randomMasterSlaveDataSource"));
assertThat(shardingRule.getTableRules().size(), is(1));
assertThat(shardingRule.getTableRules().iterator().next().getLogicTable(), is("t_order"));
}
use of io.shardingjdbc.core.rule.ShardingRule in project sharding-jdbc by shardingjdbc.
the class ShardingNamespaceTest method assertMultiTableRulesDataSource.
@Test
public void assertMultiTableRulesDataSource() {
ShardingRule shardingRule = getShardingRule("multiTableRulesDataSource");
assertThat(shardingRule.getTableRules().size(), is(2));
Iterator<TableRule> tableRules = shardingRule.getTableRules().iterator();
assertThat(tableRules.next().getLogicTable(), is("t_order"));
assertThat(tableRules.next().getLogicTable(), is("t_order_item"));
}
Aggregations