use of com.wplatform.ddal.result.SearchRow in project jdbc-shards by wplatform.
the class RoutingHandlerImpl method doRoute.
@Override
public RoutingResult doRoute(TableMate table, Session session, List<IndexCondition> indexConditions) {
TableRouter tr = table.getTableRouter();
if (tr == null) {
return fixedRoutingResult(table.getShards());
} else {
Map<String, List<Value>> routingArgs = New.hashMap();
List<RuleColumn> ruleCols = tr.getRuleColumns();
SearchRow start = null, end = null;
for (IndexCondition condition : indexConditions) {
Column column = condition.getColumn();
String colName = column.getName();
RuleColumn matched = null;
for (RuleColumn ruleColumn : ruleCols) {
if (colName.equalsIgnoreCase(ruleColumn.getName())) {
matched = ruleColumn;
}
}
if (matched == null) {
continue;
}
List<Value> values = routingArgs.get(matched.getName());
if (values == null) {
values = New.arrayList();
routingArgs.put(matched.getName(), values);
}
if (condition.getCompareType() == Comparison.IN_LIST) {
Value[] inList = condition.getCurrentValueList(session);
for (Value value : inList) {
values.add(value);
}
} else if (condition.getCompareType() == Comparison.IN_QUERY) {
ResultInterface result = condition.getCurrentResult();
while (result.next()) {
Value v = result.currentRow()[0];
if (v != ValueNull.INSTANCE) {
v = column.convert(v);
values.add(v);
}
}
} else {
int columnId = column.getColumnId();
Value v = condition.getCurrentValue(session);
boolean isStart = condition.isStart();
boolean isEnd = condition.isEnd();
if (isStart) {
start = getSearchRow(table, session, start, columnId, v, true);
}
if (isEnd) {
end = getSearchRow(table, session, end, columnId, v, false);
}
}
}
exportRangeArg(table, start, end, routingArgs);
RoutingResult rr = trc.calculate(tr, routingArgs);
return rr;
}
}
Aggregations