@Override protected QueryExpression itrValueComparisonExpression(ValueComparisonExpression q, Path context) { return new ValueComparisonExpression(toRelative(q.getField(), context), q.getOp(), q.getRvalue()); }
private DBObject translateValueComparisonExpression(FieldTreeNode context, ValueComparisonExpression expr) { Type t = resolve(context, expr.getField()).getType(); Object value=expr.getRvalue().getValue(); if (expr.getOp() == BinaryComparisonOperator._eq || expr.getOp() == BinaryComparisonOperator._neq) { if (!t.supportsEq()&&value!=null) { throw Error.get(ERR_INVALID_COMPARISON, expr.toString()); } } else { if (!t.supportsOrdering()) { throw Error.get(ERR_INVALID_COMPARISON, expr.toString()); } } Object valueObject = filterBigNumbers(t.cast(value)); if (expr.getField().equals(ID_PATH)) { valueObject = createIdFrom(valueObject); } if (expr.getOp() == BinaryComparisonOperator._eq) { return new BasicDBObject(translatePath(expr.getField()), valueObject); } else { return new BasicDBObject(translatePath(expr.getField()), new BasicDBObject(BINARY_COMPARISON_OPERATOR_MAP.get(expr.getOp()), valueObject)); } }
/** * Constructs evaluator for {field op value} style comparison * * @param expr The expression * @param md Entity metadata */ public ValueComparisonEvaluator(ValueComparisonExpression expr, FieldTreeNode context) { this.field = expr.getField(); fieldMd = context.resolve(field); if (fieldMd == null) { throw new EvaluationError(expr, CrudConstants.ERR_FIELD_NOT_THERE + field); } operator = expr.getOp(); rvalue = expr.getRvalue(); LOGGER.debug("ctor {} {}", field, operator); }
/** * Parses a field comparison or value comparison expression from the given * json object */ public static BinaryRelationalExpression fromJson(ObjectNode node) { if (node.size() == 3) { JsonNode x = node.get("op"); if (x != null) { BinaryComparisonOperator op = BinaryComparisonOperator.fromString(x.asText()); if (op != null) { x = node.get("field"); if (x != null) { Path field = new Path(x.asText()); x = node.get("rfield"); if (x != null) { return new FieldComparisonExpression(field, op, new Path(x.asText())); } else { x = node.get("rvalue"); if (x != null) { return new ValueComparisonExpression(field, op, Value.fromJson(x)); } } } } } } throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString()); } }
@Override protected LookupSpec processOrQueries(List<QueryExpression> list,Path context) { // Here, we're sure that all queries in the list refer to the same field, and there is only one // SimpleKeySpec for the whole list // Thus, we build a multiValuelookupSpec List<Object> values=new ArrayList<>(list.size()); QueryExpression firstq=null; Path firstPath=null; boolean first=true; for(QueryExpression q:list) { if(first) firstq=q; if(q instanceof ValueComparisonExpression) { if(first) firstPath=((ValueComparisonExpression)q).getField(); values.add( ((ValueComparisonExpression)q).getRvalue().getValue() ); } else if(q instanceof NaryValueRelationalExpression) { if(first) firstPath=((NaryValueRelationalExpression)q).getField(); for(Value v: ((NaryValueRelationalExpression)q).getValues()) { values.add(v.getValue()); } } first=false; } return new MultiValueLookupSpec(simpleKeySpec(findFieldInfo(firstPath,firstq)),values); }
QueryFieldInfo fld=null; if(query instanceof ValueComparisonExpression && ((ValueComparisonExpression)query).getOp()==BinaryComparisonOperator._eq) { fld=findFieldInfo( ((ValueComparisonExpression)query).getField(), query); } else if(query instanceof NaryValueRelationalExpression && ((NaryValueRelationalExpression)query).getOp()==NaryRelationalOperator._in) {
@Override protected QueryExpression itrValueComparisonExpression(ValueComparisonExpression q, Path context) { fieldInfo.add(resolveField(q.getField(), context, q, true)); return q; }
@Override protected T itrValueComparisonExpression(ValueComparisonExpression q, Path context) { if(q.getOp()==BinaryComparisonOperator._neq) { return null; } else { return processValueComparisonExpression(q); } }
/** * Constructs evaluator for {field op value} style comparison * * @param expr The expression * @param md Entity metadata */ public ValueComparisonEvaluator(ValueComparisonExpression expr, FieldTreeNode context) { this.field = expr.getField(); fieldMd = context.resolve(field); if (fieldMd == null) { throw new EvaluationError(expr, CrudConstants.ERR_FIELD_NOT_THERE + field); } operator = expr.getOp(); rvalue = expr.getRvalue(); LOGGER.debug("ctor {} {}", field, operator); }
/** * Parses a field comparison or value comparison expression from the given * json object */ public static BinaryRelationalExpression fromJson(ObjectNode node) { if (node.size() == 3) { JsonNode x = node.get("op"); if (x != null) { BinaryComparisonOperator op = BinaryComparisonOperator.fromString(x.asText()); if (op != null) { x = node.get("field"); if (x != null) { Path field = new Path(x.asText()); x = node.get("rfield"); if (x != null) { return new FieldComparisonExpression(field, op, new Path(x.asText())); } else { x = node.get("rvalue"); if (x != null) { return new ValueComparisonExpression(field, op, Value.fromJson(x)); } } } } } } throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString()); } }
@Override protected LookupSpec processOrQueries(List<QueryExpression> list,Path context) { // Here, we're sure that all queries in the list refer to the same field, and there is only one // SimpleKeySpec for the whole list // Thus, we build a multiValuelookupSpec List<Object> values=new ArrayList<>(list.size()); QueryExpression firstq=null; Path firstPath=null; boolean first=true; for(QueryExpression q:list) { if(first) firstq=q; if(q instanceof ValueComparisonExpression) { if(first) firstPath=((ValueComparisonExpression)q).getField(); values.add( ((ValueComparisonExpression)q).getRvalue().getValue() ); } else if(q instanceof NaryValueRelationalExpression) { if(first) firstPath=((NaryValueRelationalExpression)q).getField(); for(Value v: ((NaryValueRelationalExpression)q).getValues()) { values.add(v.getValue()); } } first=false; } return new MultiValueLookupSpec(simpleKeySpec(findFieldInfo(firstPath,firstq)),values); }
QueryFieldInfo fld=null; if(query instanceof ValueComparisonExpression && ((ValueComparisonExpression)query).getOp()==BinaryComparisonOperator._eq) { fld=findFieldInfo( ((ValueComparisonExpression)query).getField(), query); } else if(query instanceof NaryValueRelationalExpression && ((NaryValueRelationalExpression)query).getOp()==NaryRelationalOperator._in) {
@Override protected QueryExpression itrValueComparisonExpression(ValueComparisonExpression q, Path context) { fieldInfo.add(resolveField(q.getField(), context, q, true)); return q; }
@Override protected T itrValueComparisonExpression(ValueComparisonExpression q, Path context) { if(q.getOp()==BinaryComparisonOperator._neq) { return null; } else { return processValueComparisonExpression(q); } }
@Override protected QueryExpression itrValueComparisonExpression(ValueComparisonExpression q, Path context) { return new ValueComparisonExpression(toRelative(q.getField(), context), q.getOp(), q.getRvalue()); }
/** * Constructs evaluator for {field op value} style comparison * * @param expr The expression * @param md Entity metadata */ public ValueComparisonEvaluator(ValueComparisonExpression expr, FieldTreeNode context) { this.field = expr.getField(); fieldMd = context.resolve(field); if (fieldMd == null) { throw new EvaluationError(expr, CrudConstants.ERR_FIELD_NOT_THERE + field); } operator = expr.getOp(); rvalue = expr.getRvalue(); LOGGER.debug("ctor {} {}", field, operator); }
private DBObject translateValueComparisonExpression(FieldTreeNode context, EntityMetadata md, ValueComparisonExpression expr,MutablePath fullPath) { FieldInfo finfo=resolveFieldForQuery(context,fullPath.immutableCopy(),expr.getField()); Type t = finfo.fieldMd.getType(); Object value = expr.getRvalue().getValue(); if (expr.getOp() == BinaryComparisonOperator._eq || expr.getOp() == BinaryComparisonOperator._neq) { if (!t.supportsEq() && value != null) { throw Error.get(ERR_INVALID_COMPARISON, expr.toString()); } } else if (!t.supportsOrdering()) { throw Error.get(ERR_INVALID_COMPARISON, expr.toString()); } Object valueObject = DocTranslator.filterBigNumbers(t.cast(value)); if (finfo.field.equals(ID_PATH)) { valueObject = DocTranslator.createIdFrom(valueObject); } if (expr.getOp() == BinaryComparisonOperator._eq) { return new BasicDBObject(translatePath(finfo.field), valueObject); } else { return new BasicDBObject(translatePath(finfo.field), new BasicDBObject(BINARY_COMPARISON_OPERATOR_MAP.get(expr.getOp()), valueObject)); } }
/** * Appends objectType:X to the query */ public static QueryExpression appendObjectType(QueryExpression q,String entityName) { QueryExpression ot=new ValueComparisonExpression(DocTranslator.OBJECT_TYPE,BinaryComparisonOperator._eq,new Value(entityName)); if(q==null) { return ot; } if(q instanceof NaryLogicalExpression && ((NaryLogicalExpression)q).getOp()==NaryLogicalOperator._and) { List<QueryExpression> l=new ArrayList<>(((NaryLogicalExpression)q).getQueries()); l.add(ot); return new NaryLogicalExpression(NaryLogicalOperator._and,l); } else { return new NaryLogicalExpression(NaryLogicalOperator._and,q,ot); } }
private static boolean isFieldQueried(Path field, ValueComparisonExpression q, Path context) { LOGGER.debug("Checking if field {} is queried by value comparison {}", field, q); return isFieldQueried(field, q.getField(), context); }
@Override protected QueryExpression itrValueComparisonExpression(ValueComparisonExpression q, Path context) { Path p = rewrite(context, q.getField()); if (!p.equals(q.getField())) { return new ValueComparisonExpression(p, q.getOp(), q.getRvalue()); } else { return q; } }