use of com.actiontech.dble.route.parser.druid.RouteCalculateUnit in project dble by actiontech.
the class RouterUtil method routeFromParser.
public static RouteResultset routeFromParser(DruidParser druidParser, SchemaConfig schema, RouteResultset rrs, SQLStatement statement, String originSql, LayerCachePool cachePool, ServerSchemaStatVisitor visitor, ServerConnection sc) throws SQLException {
schema = druidParser.parser(schema, rrs, statement, originSql, cachePool, visitor, sc);
if (rrs.isFinishedExecute()) {
return null;
}
if (rrs.isFinishedRoute()) {
return rrs;
}
/**
* no name table or others
*/
DruidShardingParseInfo ctx = druidParser.getCtx();
if ((ctx.getTables() == null || ctx.getTables().size() == 0) && (ctx.getTableAliasMap() == null || ctx.getTableAliasMap().isEmpty())) {
if (schema == null) {
schema = DbleServer.getInstance().getConfig().getSchemas().get(SchemaUtil.getRandomDb());
}
return RouterUtil.routeToSingleNode(rrs, schema.getRandomDataNode());
}
/* multi-tables*/
if (druidParser.getCtx().getRouteCalculateUnits().size() == 0) {
RouteCalculateUnit routeCalculateUnit = new RouteCalculateUnit();
druidParser.getCtx().addRouteCalculateUnit(routeCalculateUnit);
}
SortedSet<RouteResultsetNode> nodeSet = new TreeSet<>();
for (RouteCalculateUnit unit : druidParser.getCtx().getRouteCalculateUnits()) {
RouteResultset rrsTmp = RouterUtil.tryRouteForTables(schema, druidParser.getCtx(), unit, rrs, isSelect(statement), cachePool);
if (rrsTmp != null && rrsTmp.getNodes() != null) {
Collections.addAll(nodeSet, rrsTmp.getNodes());
if (rrsTmp.isGlobalTable()) {
break;
}
}
}
RouteResultsetNode[] nodes = new RouteResultsetNode[nodeSet.size()];
int i = 0;
for (RouteResultsetNode aNodeSet : nodeSet) {
nodes[i] = aNodeSet;
i++;
}
rrs.setNodes(nodes);
return rrs;
}
Aggregations