Search in sources :

Example 1 with SearchRow

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;
    }
}
Also used : ResultInterface(com.wplatform.ddal.result.ResultInterface) Column(com.wplatform.ddal.dbobject.table.Column) Value(com.wplatform.ddal.value.Value) List(java.util.List) IndexCondition(com.wplatform.ddal.dbobject.index.IndexCondition) SearchRow(com.wplatform.ddal.result.SearchRow)

Aggregations

IndexCondition (com.wplatform.ddal.dbobject.index.IndexCondition)1 Column (com.wplatform.ddal.dbobject.table.Column)1 ResultInterface (com.wplatform.ddal.result.ResultInterface)1 SearchRow (com.wplatform.ddal.result.SearchRow)1 Value (com.wplatform.ddal.value.Value)1 List (java.util.List)1