@Override protected QueryExpression itrArrayMatchExpression(ArrayMatchExpression q, Path context) { // No need to rewrite elemMatch using relative context, because that is already interpreted relative to the array return new ArrayMatchExpression(toRelative(q.getArray(), context), q.getElemMatch()); }
private DBObject translateArrayElemMatch(FieldTreeNode context, ArrayMatchExpression expr) { FieldTreeNode arrayNode = resolve(context, expr.getArray()); if (arrayNode instanceof ArrayField) { ArrayElement el = ((ArrayField) arrayNode).getElement(); if (el instanceof ObjectArrayElement) { return new BasicDBObject(translatePath(expr.getArray()), new BasicDBObject("$elemMatch", translate(el, expr.getElemMatch()))); } } throw Error.get(ERR_INVALID_FIELD, expr.toString()); }
@Override protected T itrArrayMatchExpression(ArrayMatchExpression q, Path context) { QueryFieldInfo oldArray=enclosingArray; enclosingArray=findFieldInfo(q.getArray(),q); T ret=processArrayMatchExpression(q.getElemMatch(), new Path(new Path(context, q.getArray()), Path.ANYPATH)); enclosingArray=oldArray; return ret; } }
@Override protected QueryExpression itrArrayMatchExpression(ArrayMatchExpression q, Path context) { fieldInfo.add(resolveField(q.getArray(), context, q, false)); return super.itrArrayMatchExpression(q, context); }
@Override protected ItrState itrArrayMatchExpression(ArrayMatchExpression q, Path context) { return iterate(q.getElemMatch(),context); }
/** * Parses an array match expression from the given json object */ public static ArrayMatchExpression fromJson(ObjectNode node) { JsonNode x = node.get("array"); if (x != null) { Path field = new Path(x.asText()); x = node.get("elemMatch"); if (x != null) { return new ArrayMatchExpression(field, QueryExpression.fromJson(x)); } } throw Error.get(QueryConstants.ERR_INVALID_ARRAY_COMPARISON_EXPRESSION, node.toString()); } }
/** * Parses an array contains or array match expression from the given object * node */ public static ArrayComparisonExpression fromJson(ObjectNode node) { JsonNode x = node.get("contains"); if (x != null) { return ArrayContainsExpression.fromJson(node); } else { x = node.get("elemMatch"); if (x != null) { return ArrayMatchExpression.fromJson(node); } } throw Error.get(QueryConstants.ERR_INVALID_ARRAY_COMPARISON_EXPRESSION, node.toString()); } }
private static boolean isFieldQueried(Path field, ArrayMatchExpression q, Path context) { LOGGER.debug("Checking if field {} is queried by array expression {}", field, q); if (isFieldQueried(field, q.getArray(), context)) { return true; } else { return q.getElemMatch().isRequired(field, new Path(new Path(context, q.getArray()), Path.ANYPATH)); } } }
@Override protected QueryExpression itrArrayMatchExpression(ArrayMatchExpression q, Path context) { fieldInfo.add(resolveField(q.getArray(), context, q, false)); return super.itrArrayMatchExpression(q, context); }
@Override protected ItrState itrArrayMatchExpression(ArrayMatchExpression q, Path context) { return iterate(q.getElemMatch(),context); }
/** * Parses an array match expression from the given json object */ public static ArrayMatchExpression fromJson(ObjectNode node) { JsonNode x = node.get("array"); if (x != null) { Path field = new Path(x.asText()); x = node.get("elemMatch"); if (x != null) { return new ArrayMatchExpression(field, QueryExpression.fromJson(x)); } } throw Error.get(QueryConstants.ERR_INVALID_ARRAY_COMPARISON_EXPRESSION, node.toString()); } }
/** * Parses an array contains or array match expression from the given object * node */ public static ArrayComparisonExpression fromJson(ObjectNode node) { JsonNode x = node.get("contains"); if (x != null) { return ArrayContainsExpression.fromJson(node); } else { x = node.get("elemMatch"); if (x != null) { return ArrayMatchExpression.fromJson(node); } } throw Error.get(QueryConstants.ERR_INVALID_ARRAY_COMPARISON_EXPRESSION, node.toString()); } }
@Override protected QueryExpression itrArrayMatchExpression(ArrayMatchExpression q, Path context) { // No need to rewrite elemMatch using relative context, because that is already interpreted relative to the array return new ArrayMatchExpression(toRelative(q.getArray(), context), q.getElemMatch()); }
private static boolean isFieldQueried(Path field, ArrayMatchExpression q, Path context) { LOGGER.debug("Checking if field {} is queried by array expression {}", field, q); if (isFieldQueried(field, q.getArray(), context)) { return true; } else { return q.getElemMatch().isRequired(field, new Path(new Path(context, q.getArray()), Path.ANYPATH)); } } }
private DBObject translateArrayElemMatch(FieldTreeNode context, EntityMetadata md, ArrayMatchExpression expr, EntityMetadata emd, MutablePath fullPath) { FieldInfo finfo=resolveFieldForQuery(context,fullPath.immutableCopy(),expr.getArray()); if (finfo.fieldMd instanceof ArrayField) { ArrayElement el = ((ArrayField) finfo.fieldMd).getElement(); if (el instanceof ObjectArrayElement) { fullPath.push(finfo.field).push(Path.ANYPATH); BasicDBObject obj = new BasicDBObject(translatePath(finfo.field), new BasicDBObject("$elemMatch", translate(el, expr.getElemMatch(), emd, fullPath))); fullPath.pop().pop(); return obj; } else { throw new NeedsJS(); } } throw Error.get(ERR_INVALID_FIELD, expr.toString()); }
private Path normalize(ArrayMatchExpression ae, Path field) { Path p = new Path(new Path(ae.getArray(), Path.ANYPATH), field); return p.normalize(); } }
@Override public QueryExpression rewrite(QueryExpression q) { ArrayMatchExpression ae = dyncast(ArrayMatchExpression.class, q); QueryExpression newq = q; if (ae != null) { QueryExpression nestedq = ae.getElemMatch(); ValueComparisonExpression vce; FieldComparisonExpression fce; NaryValueRelationalExpression nvre; NaryFieldRelationalExpression nfre; if ((vce = dyncast(ValueComparisonExpression.class, nestedq)) != null) { newq = new ValueComparisonExpression(normalize(ae, vce.getField()), vce.getOp(), vce.getRvalue()); } else if ((fce = dyncast(FieldComparisonExpression.class, nestedq)) != null) { newq = new FieldComparisonExpression(normalize(ae, fce.getField()), fce.getOp(), normalize(ae, fce.getRfield())); } } return newq; }
@Override protected QueryExpression itrArrayMatchExpression(ArrayMatchExpression q, Path context) { Path p = rewrite(context, q.getArray()); if (!p.equals(q.getArray())) { return new ArrayMatchExpression(p, q.getElemMatch()); } else { return q; } }
@Override protected T itrArrayMatchExpression(ArrayMatchExpression q, Path context) { QueryFieldInfo oldArray=enclosingArray; enclosingArray=findFieldInfo(q.getArray(),q); T ret=processArrayMatchExpression(q.getElemMatch(), new Path(new Path(context, q.getArray()), Path.ANYPATH)); enclosingArray=oldArray; return ret; } }
private Path normalize(ArrayMatchExpression ae, Path field) { Path p = new Path(new Path(ae.getArray(), Path.ANYPATH), field); return p.normalize(); } }