/** * Creates an rvalue expression that is a constant value */ public RValueExpression(Value value) { if (value == null || value.getValue() == null) { this.value = null; this.path = null; this.type = RValueType._null; } else { this.value = value; this.path = null; this.type = RValueType._value; } }
private Object getValue(FieldTreeNode fieldMd, JsonNode valueNode) { if (fieldMd instanceof ArrayField) { Type t = ((ArrayField) fieldMd).getElement().getType(); if (valueNode instanceof ArrayNode) { List<Value> list = new ArrayList<>(); for (Iterator<JsonNode> itr = ((ArrayNode) valueNode).elements(); itr.hasNext();) { list.add(new Value(t.fromJson(itr.next()))); } return list; } else { return new ArrayList<Value>(); } } else { return new Value(fieldMd.getType().fromJson(valueNode)); } }
/** * Parses an rvalue from a json node. */ public static RValueExpression fromJson(JsonNode node) { if (node instanceof ObjectNode) { if (node.size() == 1) { JsonNode path = node.get("$valueof"); if (path != null && path.isValueNode()) { return new RValueExpression(new Path(path.asText())); } else { return new RValueExpression(new Value(node)); } } else { return new RValueExpression(new Value(node)); } } if (node instanceof ArrayNode) { return new RValueExpression(new Value(node)); } else if (node.isValueNode()) { if (node.asText().equals("$null")) { return NULL; } else { return new RValueExpression(Value.fromJson(node)); } } throw Error.get(QueryConstants.ERR_INVALID_RVALUE_EXPRESSION, node.toString()); }
if(x.equals(vce.getRvalue())) { found=true; break;
/** * Returns the json representation of the query */ @Override public JsonNode toJson() { return getFactory().objectNode().put("field", field.toString()). put("op", op.toString()). set("rvalue", rvalue.toJson()); } }
/** * Parses an ArrayContainsExpression from a JSON object node. */ public static ArrayContainsExpression fromJson(ObjectNode node) { JsonNode x = node.get("array"); if (x != null) { Path field = new Path(x.asText()); x = node.get("contains"); if (x != null) { ContainsOperator op = ContainsOperator.fromString(x.asText()); if (op != null) { 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 ArrayContainsExpression(field, op, values); } } } } throw Error.get(QueryConstants.ERR_INVALID_ARRAY_COMPARISON_EXPRESSION, node.toString()); } }
/** * Creates the appropriate json node based on the type of the value */ @Override public JsonNode toJson() { if (value instanceof Number) { if (value instanceof BigDecimal) { return getFactory().numberNode((BigDecimal) value); } else if (value instanceof BigInteger) { return getFactory().numberNode((BigInteger) value); } else if (value instanceof Double) { return getFactory().numberNode((Double) value); } else if (value instanceof Float) { return getFactory().numberNode((Float) value); } else if (value instanceof Long) { return getFactory().numberNode((Long) value); } else { return getFactory().numberNode(((Number) value).intValue()); } } else if (value instanceof Boolean) { return getFactory().booleanNode((Boolean) value); } else if (value == null) { return getFactory().nullNode(); } else if (value instanceof JsonNode) { return (JsonNode) value; } else { return getFactory().textNode(value.toString()); } }
if (x.equals(vce.getRvalue())) { found = true; break;
/** * Returns the json representation of the query */ @Override public JsonNode toJson() { return getFactory().objectNode().put("field", field.toString()). put("op", op.toString()). set("rvalue", rvalue.toJson()); } }
/** * Parses an ArrayContainsExpression from a JSON object node. */ public static ArrayContainsExpression fromJson(ObjectNode node) { JsonNode x = node.get("array"); if (x != null) { Path field = new Path(x.asText()); x = node.get("contains"); if (x != null) { ContainsOperator op = ContainsOperator.fromString(x.asText()); if (op != null) { 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 ArrayContainsExpression(field, op, values); } } } } throw Error.get(QueryConstants.ERR_INVALID_ARRAY_COMPARISON_EXPRESSION, node.toString()); } }
/** * Creates the appropriate json node based on the type of the value */ @Override public JsonNode toJson() { if (value instanceof Number) { if (value instanceof BigDecimal) { return getFactory().numberNode((BigDecimal) value); } else if (value instanceof BigInteger) { return getFactory().numberNode((BigInteger) value); } else if (value instanceof Double) { return getFactory().numberNode((Double) value); } else if (value instanceof Float) { return getFactory().numberNode((Float) value); } else if (value instanceof Long) { return getFactory().numberNode((Long) value); } else { return getFactory().numberNode(((Number) value).intValue()); } } else if (value instanceof Boolean) { return getFactory().booleanNode((Boolean) value); } else if (value == null) { return getFactory().nullNode(); } else if (value instanceof JsonNode) { return (JsonNode) value; } else { return getFactory().textNode(value.toString()); } }
/** * Creates an rvalue expression that is a constant value */ public RValueExpression(Value value) { if (value == null || value.getValue() == null) { this.value = null; this.path = null; this.type = RValueType._null; } else { this.value = value; this.path = null; this.type = RValueType._value; } }
private Object getValue(FieldTreeNode fieldMd, JsonNode valueNode) { if (fieldMd instanceof ArrayField) { Type t = ((ArrayField) fieldMd).getElement().getType(); if (valueNode instanceof ArrayNode) { List<Value> list = new ArrayList<>(); for (Iterator<JsonNode> itr = ((ArrayNode) valueNode).elements(); itr.hasNext();) { list.add(new Value(t.fromJson(itr.next()))); } return list; } else { return new ArrayList<Value>(); } } else { return new Value(fieldMd.getType().fromJson(valueNode)); } }
/** * Parses an rvalue from a json node. */ public static RValueExpression fromJson(JsonNode node) { if (node instanceof ObjectNode) { if (node.size() == 1) { JsonNode path = node.get("$valueof"); if (path != null && path.isValueNode()) { return new RValueExpression(new Path(path.asText())); } else { return new RValueExpression(new Value(node)); } } else { return new RValueExpression(new Value(node)); } } if (node instanceof ArrayNode) { return new RValueExpression(new Value(node)); } else if (node.isValueNode()) { if (node.asText().equals("$null")) { return NULL; } else { return new RValueExpression(Value.fromJson(node)); } } throw Error.get(QueryConstants.ERR_INVALID_RVALUE_EXPRESSION, node.toString()); }
if (x.equals(vce.getRvalue())) { found = true; break;
/** * Returns a json representation of the query */ @Override public JsonNode toJson() { ArrayNode arr = getFactory().arrayNode(); for (Value x : values) { arr.add(x.toJson()); } return getFactory().objectNode(). put("array", array.toString()). put("contains", op.toString()). set("values", arr); }
/** * 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()); } }
/** * <pre> * { $or : [ {field:value1},{field:value2},...] } * </pre> */ private DBObject translateArrayContainsAny(Type t, Path array, List<Value> values) { List<BasicDBObject> l = new ArrayList<>(values.size()); for (Value x : values) { l.add(new BasicDBObject(translatePath(array), x == null ? null : x.getValue() == null ? null : t.cast(x.getValue()))); } return new BasicDBObject("$or", l); }
/** * 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); } }
/** * Returns a json representation of the query */ @Override public JsonNode toJson() { ArrayNode arr = getFactory().arrayNode(); for (Value x : values) { arr.add(x.toJson()); } return getFactory().objectNode(). put("array", array.toString()). put("contains", op.toString()). set("values", arr); }