Skip to content

Commit

Permalink
use InstanceDatabaseBroadcastRoutingEngine for dcl.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristaZero committed Jul 13, 2018
1 parent 016d17c commit 24592b6
Showing 1 changed file with 5 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.shardingsphere.core.routing.type.RoutingResult;
import io.shardingsphere.core.routing.type.TableUnit;
import io.shardingsphere.core.routing.type.broadcast.DatabaseBroadcastRoutingEngine;
import io.shardingsphere.core.routing.type.broadcast.InstanceDatabaseBroadcastRoutingEngine;
import io.shardingsphere.core.routing.type.broadcast.TableBroadcastRoutingEngine;
import io.shardingsphere.core.routing.type.complex.ComplexRoutingEngine;
import io.shardingsphere.core.routing.type.ignore.IgnoreRoutingEngine;
Expand Down Expand Up @@ -118,8 +119,10 @@ private RoutingResult route(final List<Object> parameters, final SQLStatement sq
routingEngine = new IgnoreRoutingEngine();
} else if (sqlStatement instanceof DDLStatement || (sqlStatement instanceof DCLStatement && ((DCLStatement) sqlStatement).isGrantForSingleTable())) {
routingEngine = new TableBroadcastRoutingEngine(shardingRule, sqlStatement);
} else if (sqlStatement instanceof ShowDatabasesStatement || sqlStatement instanceof ShowTablesStatement || sqlStatement instanceof DCLStatement) {
} else if (sqlStatement instanceof ShowDatabasesStatement || sqlStatement instanceof ShowTablesStatement) {
routingEngine = new DatabaseBroadcastRoutingEngine(shardingRule);
} else if (sqlStatement instanceof DCLStatement) {
routingEngine = new InstanceDatabaseBroadcastRoutingEngine(shardingRule, shardingDataSourceMetaData);
} else if (shardingConditions.isAlwaysFalse()) {
routingEngine = new UnicastRoutingEngine(shardingRule, tableNames);
} else if (sqlStatement instanceof DALStatement) {
Expand All @@ -134,25 +137,7 @@ private RoutingResult route(final List<Object> parameters, final SQLStatement sq
// TODO config for cartesian set
routingEngine = new ComplexRoutingEngine(shardingRule, parameters, tableNames, shardingConditions);
}
return getRoutingResult(routingEngine, sqlStatement);
}

private RoutingResult getRoutingResult(final RoutingEngine routingEngine, final SQLStatement sqlStatement) {
RoutingResult result = routingEngine.route();
if (routingEngine instanceof DatabaseBroadcastRoutingEngine && sqlStatement instanceof DCLStatement) {
removeRedundantTableUnits(result);
}
return result;
}

private void removeRedundantTableUnits(final RoutingResult routingResult) {
Collection<TableUnit> toRemoved = new LinkedList<>();
for (TableUnit each : routingResult.getTableUnits().getTableUnits()) {
if (!shardingDataSourceMetaData.getAllInstanceDataSourceNames().contains(each.getDataSourceName())) {
toRemoved.add(each);
}
}
routingResult.getTableUnits().getTableUnits().removeAll(toRemoved);
return routingEngine.route();
}

private GeneratedKey getGenerateKey(final ShardingRule shardingRule, final InsertStatement insertStatement, final List<Object> parameters) {
Expand Down

0 comments on commit 24592b6

Please sign in to comment.