@Override protected QueryExpression itrNaryValueRelationalExpression(NaryValueRelationalExpression q, Path context) { return new NaryValueRelationalExpression(toRelative(q.getField(), context), q.getOp(), q.getValues()); }
private DBObject translateNaryValueRelationalExpression(FieldTreeNode context, NaryValueRelationalExpression expr) { Type t = resolve(context, expr.getField()).getType(); if (t.supportsEq()) { List<Object> values = translateValueList(t, expr.getValues()); return new BasicDBObject(translatePath(expr.getField()), new BasicDBObject(NARY_RELATIONAL_OPERATOR_MAP.get(expr.getOp()), values)); } else { throw Error.get(ERR_INVALID_FIELD, expr.toString()); } }
/** * Returns a json representation of this query */ @Override public JsonNode toJson() { ArrayNode arr = getFactory().arrayNode(); for (Value x : values) { arr.add(x.toJson()); } return getFactory().objectNode().put("field", getField().toString()). put("op", getOp().toString()). set("values", arr); }
public NaryValueRelationalExpressionEvaluator(NaryValueRelationalExpression expr, FieldTreeNode context) { field = expr.getField(); fieldMd = context.resolve(field); if (fieldMd == null) { throw new EvaluationError(expr, CrudConstants.ERR_FIELD_NOT_THERE + field); } operator = expr.getOp(); values = new HashSet<>(); for (Value x : expr.getValues()) { values.add(fieldMd.getType().cast(x.getValue())); } LOGGER.debug("ctor {} {} {}", expr.getField(), operator, values); }
@Override protected QueryExpression itrNaryValueRelationalExpression(NaryValueRelationalExpression q, Path context) { fieldInfo.add(resolveField(q.getField(), context, q, true)); return q; }
@Override protected T itrNaryValueRelationalExpression(NaryValueRelationalExpression q, Path context) { if(q.getOp()==NaryRelationalOperator._in) { return processInExpression(q); } else { return null; } }
/** * Parses an n-ary relational expression from the given json object */ public static NaryValueRelationalExpression fromJson(ObjectNode node) { if (node.size() == 3) { JsonNode x = node.get("op"); if (x != null) { NaryRelationalOperator op = NaryRelationalOperator.fromString(x.asText()); if (op != null) { x = node.get("field"); if (x != null) { Path field = new Path(x.asText()); x = node.get("values"); if (x instanceof ArrayNode) { ArrayList<Value> values = new ArrayList<>(((ArrayNode) x).size()); for (Iterator<JsonNode> itr = ((ArrayNode) x).elements(); itr.hasNext();) { values.add(Value.fromJson(itr.next())); } return new NaryValueRelationalExpression(field, op, values); } } } } } throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString()); } }
/** * Parses an n-ary relational expression from the given json object */ public static NaryRelationalExpression fromJson(ObjectNode node) { if (node.size() == 3) { if (node.get("rfield") != null) { return NaryFieldRelationalExpression.fromJson(node); } else if (node.get("values") != null) { return NaryValueRelationalExpression.fromJson(node); } } throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString()); } }
public NaryValueRelationalExpressionEvaluator(NaryValueRelationalExpression expr, FieldTreeNode context) { field = expr.getField(); fieldMd = context.resolve(field); if (fieldMd == null) { throw new EvaluationError(expr, CrudConstants.ERR_FIELD_NOT_THERE + field); } operator = expr.getOp(); values = new HashSet<>(); for (Value x : expr.getValues()) { values.add(fieldMd.getType().cast(x.getValue())); } LOGGER.debug("ctor {} {} {}", expr.getField(), operator, values); }
@Override protected QueryExpression itrNaryValueRelationalExpression(NaryValueRelationalExpression q, Path context) { fieldInfo.add(resolveField(q.getField(), context, q, true)); return q; }
@Override protected T itrNaryValueRelationalExpression(NaryValueRelationalExpression q, Path context) { if(q.getOp()==NaryRelationalOperator._in) { return processInExpression(q); } else { return null; } }
/** * Parses an n-ary relational expression from the given json object */ public static NaryValueRelationalExpression fromJson(ObjectNode node) { if (node.size() == 3) { JsonNode x = node.get("op"); if (x != null) { NaryRelationalOperator op = NaryRelationalOperator.fromString(x.asText()); if (op != null) { x = node.get("field"); if (x != null) { Path field = new Path(x.asText()); x = node.get("values"); if (x instanceof ArrayNode) { ArrayList<Value> values = new ArrayList<>(((ArrayNode) x).size()); for (Iterator<JsonNode> itr = ((ArrayNode) x).elements(); itr.hasNext();) { values.add(Value.fromJson(itr.next())); } return new NaryValueRelationalExpression(field, op, values); } } } } } throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString()); } }
/** * Parses an n-ary relational expression from the given json object */ public static NaryRelationalExpression fromJson(ObjectNode node) { if (node.size() == 3) { if (node.get("rfield") != null) { return NaryFieldRelationalExpression.fromJson(node); } else if (node.get("values") != null) { return NaryValueRelationalExpression.fromJson(node); } } throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString()); } }
@Override protected QueryExpression itrNaryValueRelationalExpression(NaryValueRelationalExpression q, Path context) { return new NaryValueRelationalExpression(toRelative(q.getField(), context), q.getOp(), q.getValues()); }
FieldTreeNode fieldMd=ctx.contextNode.resolve(query.getField()); String globalArr=declareValueArray(ctx,fieldMd,query.getValues()); Block block=new Block(ctx.topLevel.newGlobal(ctx,query.getOp()==NaryRelationalOperator._in?"false":"true")); String loopVar=ctx.newName("i"); ForLoop forLoop=new ForLoop(loopVar,globalArr); Name fieldName=ctx.varName(new Name(query.getField())); block.add(IfStatement.ifDefined(fieldName,forLoop)); if(fieldMd.getType() instanceof DateType) { if(query.getOp()==NaryRelationalOperator._in) { forLoop.add(new IfStatement(new SimpleExpression("this.%s.valueOf()==this.%s[%s].valueOf()",fieldName,globalArr,loopVar), new SimpleStatement("%s=true",block.resultVar), if(query.getOp()==NaryRelationalOperator._in) { forLoop.add(new IfStatement(new SimpleExpression("this.%s==%s[%s]",fieldName,globalArr,loopVar), new SimpleStatement("%s=true",block.resultVar),
private DBObject translateNaryValueRelationalExpression(FieldTreeNode context, EntityMetadata md, NaryValueRelationalExpression expr,MutablePath fullPath) { FieldInfo finfo=resolveFieldForQuery(context,fullPath.immutableCopy(),expr.getField()); Type t = finfo.fieldMd.getType(); if (t.supportsEq()) { List<Object> values = translateValueList(t, expr.getValues(),finfo.field.equals(ID_PATH)); return new BasicDBObject(translatePath(finfo.field), new BasicDBObject(NARY_RELATIONAL_OPERATOR_MAP.get(expr.getOp()), values)); } else { throw Error.get(ERR_INVALID_FIELD, expr.toString()); } }