/** * @param tableRouter * @param positions * @throws RuleEvaluateException */ private void checkReturnValue(ShardedTableRule tableRouter, Integer... positions) throws RuleEvaluateException { ObjectNode[] partition = tableRouter.getObjectNodes(); String ptrName = tableRouter.getPartitioner().getClass().getName(); if (positions == null) { String msg = String.format("The %s returned a illegal value null.", ptrName); throw new RuleEvaluateException(msg); } for (Integer position : positions) { if (position == null) { String msg = String.format("The %s returned a illegal value null.", ptrName); throw new RuleEvaluateException(msg); } if (position < 0 || position >= partition.length) { String msg = String.format("The %s returned a illegal value %d, it's out of table nodes bounds.", ptrName, position); throw new RuleEvaluateException(msg); } } }
private long getTime(Value value) { int type; type = value.getType(); switch (type) { case Value.DATE: case Value.TIME: case Value.TIMESTAMP: ValueTimestamp v = (ValueTimestamp) value.convertTo(Value.TIMESTAMP); return v.getTimestamp().getTime(); default: throw new RuleEvaluateException("Invalid type for " + getClass().getName()); } } }
/** * @param value */ protected boolean checkNull(Value value) { if (isNull(value)) { if (getDefaultNodeIndex() == -1) { throw new RuleEvaluateException( "No default node defined when no rule column value from SQL"); } return true; } else { return false; } }
return position; default: throw new RuleEvaluateException("Invalid type for " + getClass().getName());
@Override public RoutingResult calculate(ShardedTableRule tableRouter, List<RoutingArgument> arguments) { ObjectNode[] partition = tableRouter.getObjectNodes(); Object partitioner = tableRouter.getPartitioner(); boolean typeof = partitioner instanceof MultColumnPartitioner; if (!typeof) { String name = partitioner.getClass().getName(); throw new RuleEvaluateException("Algorithm " + name + " can't supported multiple rule column."); } MultColumnPartitioner cp = (MultColumnPartitioner) partitioner; Integer[] position = cp.partition(arguments); checkReturnValue(tableRouter, position); List<ObjectNode> selected = New.arrayList(); for (Integer integer : position) { ObjectNode tableNode = partition[integer]; selected.add(tableNode); } return RoutingResult.fixedResult(selected); }
return partitionUtil.partition(hash); default: throw new RuleEvaluateException("Invalid type for " + getClass().getName());
throw new RuleEvaluateException("Type is not consistent"); break; default: throw new RuleEvaluateException("Invalid type for " + getClass().getName());
@Override public Integer[] partition(List<RoutingArgument> args) { if (args.size() != 2) { throw new RuleEvaluateException("impossibility");
if (!typeof) { String name = tableRouter.getPartitioner().getClass().getName(); throw new RuleEvaluateException("Algorithm " + name + " not type of " + Partitioner.class.getName());