Search in sources :

Example 1 with BindingTableRule

use of io.shardingjdbc.core.rule.BindingTableRule in project sharding-jdbc by shardingjdbc.

the class SQLRewriteEngine method getTableTokens.

private Map<String, String> getTableTokens(final CartesianTableReference cartesianTableReference) {
    Map<String, String> result = new HashMap<>();
    for (TableUnit each : cartesianTableReference.getTableUnits()) {
        String logicTableName = each.getLogicTableName().toLowerCase();
        result.put(logicTableName, each.getActualTableName());
        Optional<BindingTableRule> bindingTableRule = shardingRule.findBindingTableRule(logicTableName);
        if (bindingTableRule.isPresent()) {
            result.putAll(getBindingTableTokens(each, bindingTableRule.get()));
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) BindingTableRule(io.shardingjdbc.core.rule.BindingTableRule) TableUnit(io.shardingjdbc.core.routing.type.TableUnit)

Example 2 with BindingTableRule

use of io.shardingjdbc.core.rule.BindingTableRule in project sharding-jdbc by shardingjdbc.

the class OrchestrationShardingNamespaceTest method assertMultiBindingTableRulesDatasource.

@Test
public void assertMultiBindingTableRulesDatasource() {
    ShardingRule shardingRule = getShardingRule("multiBindingTableRulesDatasource");
    assertThat(shardingRule.getBindingTableRules().size(), is(2));
    Iterator<BindingTableRule> bindingTableRules = shardingRule.getBindingTableRules().iterator();
    BindingTableRule orderRule = bindingTableRules.next();
    assertThat(orderRule.getBindingActualTable("dbtbl_0", "t_order", "t_order_item"), is("t_order"));
    assertThat(orderRule.getBindingActualTable("dbtbl_1", "t_order", "t_order_item"), is("t_order"));
    BindingTableRule userRule = bindingTableRules.next();
    assertThat(userRule.getBindingActualTable("dbtbl_0", "t_user", "t_user_detail"), is("t_user"));
    assertThat(userRule.getBindingActualTable("dbtbl_1", "t_user", "t_user_detail"), is("t_user"));
}
Also used : BindingTableRule(io.shardingjdbc.core.rule.BindingTableRule) ShardingRule(io.shardingjdbc.core.rule.ShardingRule) Test(org.junit.Test)

Example 3 with BindingTableRule

use of io.shardingjdbc.core.rule.BindingTableRule in project sharding-jdbc by shardingjdbc.

the class OrchestrationShardingNamespaceTest method assertBindingTableRuleDatasource.

@Test
public void assertBindingTableRuleDatasource() {
    ShardingRule shardingRule = getShardingRule("bindingTableRuleDatasource");
    assertThat(shardingRule.getBindingTableRules().size(), is(1));
    BindingTableRule bindingTableRule = shardingRule.getBindingTableRules().iterator().next();
    assertThat(bindingTableRule.getBindingActualTable("dbtbl_0", "t_order", "t_order_item"), is("t_order"));
    assertThat(bindingTableRule.getBindingActualTable("dbtbl_1", "t_order", "t_order_item"), is("t_order"));
}
Also used : BindingTableRule(io.shardingjdbc.core.rule.BindingTableRule) ShardingRule(io.shardingjdbc.core.rule.ShardingRule) Test(org.junit.Test)

Example 4 with BindingTableRule

use of io.shardingjdbc.core.rule.BindingTableRule in project sharding-jdbc by shardingjdbc.

the class ShardingNamespaceTest method assertMultiBindingTableRulesDatasource.

@Test
public void assertMultiBindingTableRulesDatasource() {
    ShardingRule shardingRule = getShardingRule("multiBindingTableRulesDatasource");
    assertThat(shardingRule.getBindingTableRules().size(), is(2));
    Iterator<BindingTableRule> bindingTableRules = shardingRule.getBindingTableRules().iterator();
    BindingTableRule orderRule = bindingTableRules.next();
    assertThat(orderRule.getBindingActualTable("dbtbl_0", "t_order", "t_order_item"), is("t_order"));
    assertThat(orderRule.getBindingActualTable("dbtbl_1", "t_order", "t_order_item"), is("t_order"));
    BindingTableRule userRule = bindingTableRules.next();
    assertThat(userRule.getBindingActualTable("dbtbl_0", "t_user", "t_user_detail"), is("t_user"));
    assertThat(userRule.getBindingActualTable("dbtbl_1", "t_user", "t_user_detail"), is("t_user"));
}
Also used : BindingTableRule(io.shardingjdbc.core.rule.BindingTableRule) ShardingRule(io.shardingjdbc.core.rule.ShardingRule) Test(org.junit.Test)

Example 5 with BindingTableRule

use of io.shardingjdbc.core.rule.BindingTableRule in project sharding-jdbc by shardingjdbc.

the class ShardingNamespaceTest method assertBindingTableRuleDatasource.

@Test
public void assertBindingTableRuleDatasource() {
    ShardingRule shardingRule = getShardingRule("bindingTableRuleDatasource");
    assertThat(shardingRule.getBindingTableRules().size(), is(1));
    BindingTableRule bindingTableRule = shardingRule.getBindingTableRules().iterator().next();
    assertThat(bindingTableRule.getBindingActualTable("dbtbl_0", "t_order", "t_order_item"), is("t_order"));
    assertThat(bindingTableRule.getBindingActualTable("dbtbl_1", "t_order", "t_order_item"), is("t_order"));
}
Also used : BindingTableRule(io.shardingjdbc.core.rule.BindingTableRule) ShardingRule(io.shardingjdbc.core.rule.ShardingRule) Test(org.junit.Test)

Aggregations

BindingTableRule (io.shardingjdbc.core.rule.BindingTableRule)5 ShardingRule (io.shardingjdbc.core.rule.ShardingRule)4 Test (org.junit.Test)4 TableUnit (io.shardingjdbc.core.routing.type.TableUnit)1 HashMap (java.util.HashMap)1