From 440b331591c8e29af7b2be1bf902b1ca21b7d351 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Tue, 19 Sep 2017 15:21:08 +0800 Subject: [PATCH] fix #382 --- .../rdb/sharding/api/rule/ShardingRule.java | 15 +++++++++++++++ .../sharding/routing/router/ParsingSQLRouter.java | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/rule/ShardingRule.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/rule/ShardingRule.java index 6b9c57c7e6bb0..d5109af926d76 100644 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/rule/ShardingRule.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/rule/ShardingRule.java @@ -181,6 +181,21 @@ public boolean isAllBindingTables(final Collection logicTables) { return !bindingTables.isEmpty() && bindingTables.containsAll(logicTables); } + /** + * Adjust logic tables is all belong to default data source. + * + * @param logicTables names of logic tables + * @return logic tables is all belong to default data source + */ + public boolean isAllInDefaultDataSource(final Collection logicTables) { + for (String each : logicTables) { + if (tryFindTableRule(each).isPresent()) { + return false; + } + } + return true; + } + /** * Filter all binding tables. * diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/routing/router/ParsingSQLRouter.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/routing/router/ParsingSQLRouter.java index 6be7e69c7b355..d72d981f1656c 100644 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/routing/router/ParsingSQLRouter.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/routing/router/ParsingSQLRouter.java @@ -108,7 +108,7 @@ public SQLRouteResult route(final String logicSQL, final List parameters private RoutingResult route(final List parameters, final SQLStatement sqlStatement) { Collection tableNames = sqlStatement.getTables().getTableNames(); RoutingEngine routingEngine; - if (1 == tableNames.size() || shardingRule.isAllBindingTables(tableNames)) { + if (1 == tableNames.size() || shardingRule.isAllBindingTables(tableNames) || shardingRule.isAllInDefaultDataSource(tableNames)) { routingEngine = new SimpleRoutingEngine(shardingRule, parameters, tableNames.iterator().next(), sqlStatement); } else { // TODO config for cartesian set