Search in sources :

Example 6 with DataNode

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

the class StandardRoutingEngine method route.

@Override
public RoutingResult route() {
    TableRule tableRule = shardingRule.getTableRule(logicTableName);
    List<ShardingValue> databaseShardingValues = getDatabaseShardingValues(tableRule);
    List<ShardingValue> tableShardingValues = getTableShardingValues(tableRule);
    Collection<String> routedDataSources = routeDataSources(tableRule, databaseShardingValues);
    Collection<DataNode> routedDataNodes = new LinkedList<>();
    for (String each : routedDataSources) {
        routedDataNodes.addAll(routeTables(tableRule, each, tableShardingValues));
    }
    return generateRoutingResult(routedDataNodes);
}
Also used : TableRule(io.shardingjdbc.core.rule.TableRule) DataNode(io.shardingjdbc.core.rule.DataNode) ShardingValue(io.shardingjdbc.core.api.algorithm.sharding.ShardingValue) LinkedList(java.util.LinkedList)

Example 7 with DataNode

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

the class ShardingNamespaceTest method assertDefaultActualDataNodes.

@Test
public void assertDefaultActualDataNodes() {
    ShardingDataSource multiTableRulesDataSource = this.applicationContext.getBean("multiTableRulesDataSource", ShardingDataSource.class);
    Object shardingContext = FieldValueUtil.getFieldValue(multiTableRulesDataSource, "shardingContext", true);
    ShardingRule shardingRule = (ShardingRule) FieldValueUtil.getFieldValue(shardingContext, "shardingRule");
    assertThat(shardingRule.getTableRules().size(), is(2));
    Iterator<TableRule> tableRules = shardingRule.getTableRules().iterator();
    TableRule orderRule = tableRules.next();
    assertThat(orderRule.getActualDataNodes().size(), is(2));
    assertTrue(orderRule.getActualDataNodes().contains(new DataNode("dbtbl_0", "t_order")));
    assertTrue(orderRule.getActualDataNodes().contains(new DataNode("dbtbl_1", "t_order")));
    TableRule orderItemRule = tableRules.next();
    assertThat(orderItemRule.getActualDataNodes().size(), is(2));
    assertTrue(orderItemRule.getActualDataNodes().contains(new DataNode("dbtbl_0", "t_order_item")));
    assertTrue(orderItemRule.getActualDataNodes().contains(new DataNode("dbtbl_1", "t_order_item")));
}
Also used : BindingTableRule(io.shardingjdbc.core.rule.BindingTableRule) TableRule(io.shardingjdbc.core.rule.TableRule) ShardingDataSource(io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource) SpringShardingDataSource(io.shardingjdbc.spring.datasource.SpringShardingDataSource) DataNode(io.shardingjdbc.core.rule.DataNode) ShardingRule(io.shardingjdbc.core.rule.ShardingRule) Test(org.junit.Test)

Aggregations

DataNode (io.shardingjdbc.core.rule.DataNode)7 TableRule (io.shardingjdbc.core.rule.TableRule)6 BindingTableRule (io.shardingjdbc.core.rule.BindingTableRule)4 ShardingRule (io.shardingjdbc.core.rule.ShardingRule)4 Test (org.junit.Test)4 LinkedList (java.util.LinkedList)3 InlineShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.InlineShardingStrategyConfiguration)2 StandardShardingStrategyConfiguration (io.shardingjdbc.core.api.config.strategy.StandardShardingStrategyConfiguration)2 ShardingDataSource (io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource)2 ShardingValue (io.shardingjdbc.core.api.algorithm.sharding.ShardingValue)1 TableUnit (io.shardingjdbc.core.routing.type.TableUnit)1 SpringShardingDataSource (io.shardingjdbc.spring.datasource.SpringShardingDataSource)1