private boolean hasHiddenField(Path path) { for (int i = 0; i < path.numSegments(); i++) { if (path.head(i).equals(DocTranslator.HIDDEN_SUB_PATH.toString())) { return true; } } return false; }
private Path toRelative(Path field, Path context) { Path abs = context.isEmpty() ? field : new Path(context, field); if (relativeTo.matchingPrefix(abs)) { return abs.suffix(-relativeTo.numSegments()); } else { throw new IllegalArgumentException("Cannot write " + abs + " relative to " + relativeTo); } } }
public Name(Path p) { int n=p.numSegments(); for(int i=0;i<n;i++) { String s=p.head(i); parts.add(new Part(s,p.isIndex(i))); } }
private Path removeContext(Path context, Path p, Path original) { if (context.isEmpty()) { return p; } else if (context.matchingPrefix(p)) { return p.suffix(-context.numSegments()); } else { return original; } } }
/** * Check if this path is a matching prefix of the pattern, that is: - path * matches pattern, or - path matches a prefix of the pattern */ public boolean matchingPrefix(Path pattern) { int n = pattern.numSegments(); if (n > numSegments()) { return matches(pattern.prefix(numSegments())); } else if (n == numSegments()) { return matches(pattern); } return false; }
/** * Remove the context prefix from the field. If the field is under an array elemMatch, and if the field * shares the same prefix as the array field, remove that prefix. This is only useful if the field * and the array are in the same entity */ private Path removeContext(CompositeMetadata fieldEntity,Path fieldName) { if(contextField!=null&&fieldEntity==contextField.getFieldEntity()) { Path prefix=new Path(contextField.getEntityRelativeFieldName(),Path.ANYPATH); if(fieldName.numSegments()>=prefix.numSegments()) { Path fieldPrefix=fieldName.prefix(prefix.numSegments()); // Also include the * if(fieldPrefix.equals(prefix)) { // Remove fieldPrefix Path relativeFieldName=fieldName.suffix(-prefix.numSegments()); if(relativeFieldName.isEmpty()) relativeFieldName=new Path(Path.THIS); return relativeFieldName; } } } return fieldName; }
public ChildSlot(CompositeMetadata root, ResolvedReferenceField reference) { Path erfn = root.getEntityRelativeFieldName(reference); if (erfn.numSegments() == 1) { localContainerName = Path.EMPTY; referenceFieldName = erfn.head(0); slotFieldName = new Path(referenceFieldName); } else { localContainerName = erfn.prefix(-1); referenceFieldName = erfn.tail(0); slotFieldName = erfn; } this.reference = reference; }
private Path translateIndexPath(Path p) { MutablePath newPath = new MutablePath(); int n = p.numSegments(); for (int i = 0; i < n; i++) { String x = p.head(i); if (!x.equals(Path.ANY)) { if (p.isIndex(i)) { throw Error.get(MongoCrudConstants.ERR_INVALID_INDEX_FIELD, p.toString()); } newPath.push(x); } } return newPath.immutableCopy(); }
private int findLastAnyIndex(Path p) { for (int i = p.numSegments() - 1; i >= 0; i--) { if (p.head(i).equals(Path.ANY)) { return i; } } return -1; }
private void convertObjectFieldToBson(JsonNode node, JsonNodeCursor cursor, BasicDBObject ret, Path path, EntityMetadata md,ResultMetadata rmd) { if (node != null) { if (node instanceof ObjectNode) { if (cursor.firstChild()) { ret.append(path.tail(0), objectToBson(cursor, md,rmd)); cursor.parent(); } } else if (node instanceof NullNode) { ret.append(path.tail(0), null); } else { throw Error.get(ERR_INVALID_FIELD, path.toString()); } } }
/** * Returns the @mongoHidden at the root level of the document. Adds one if necessary. */ public static DBObject getHidden(DBObject doc,boolean addIfNotFound) { DBObject hidden=(DBObject)doc.get(DocTranslator.HIDDEN_SUB_PATH.toString()); if(hidden==null&&addIfNotFound) { doc.put(DocTranslator.HIDDEN_SUB_PATH.toString(),hidden=new BasicDBObject()); } return hidden; }
/** * If a path includes array indexes, change the indexes into ANY */ private static Path toMask(Path p) { int n = p.numSegments(); MutablePath mp = null; for (int i = 0; i < n; i++) { if (p.isIndex(i)) { if (mp == null) { mp = p.mutableCopy(); } mp.set(i, Path.ANY); } } return mp == null ? p : mp.immutableCopy(); }
/** * Get a reference to the path's hidden sub-field. * * This does not guarantee the sub-path exists. * * @param path * @return */ public static Path getHiddenForField(Path path) { if (path.getLast().equals(Path.ANY)) { return path.prefix(-2).mutableCopy().push(HIDDEN_SUB_PATH).push(path.suffix(2)); } return path.prefix(-1).mutableCopy().push(HIDDEN_SUB_PATH).push(path.getLast()); }
@Override protected Projection.Inclusion projectArray(Path p, QueryEvaluationContext ctx) { LOGGER.debug("Evaluating array query projection for {}", p); Path contextRoot = ctx.getPath(); QueryEvaluationContext nestedContext = ctx.getNestedContext(contextRoot.isEmpty() ? p : p.suffix(-contextRoot.numSegments())); if (query.evaluate(nestedContext)) { LOGGER.debug("query evaluates to true"); return isIncluded() ? Projection.Inclusion.explicit_inclusion : Projection.Inclusion.explicit_exclusion; } return isIncluded() ? Projection.Inclusion.explicit_exclusion : Projection.Inclusion.explicit_inclusion; } }
public String toString() { if (context.numSegments() > 0) { return query.toString() + "@" + context.toString(); } else { return query.toString(); } } }
@Override public String translateFieldName(Path path){ String attributeName = fieldsToAttributes.get(path); if(attributeName != null){ return attributeName; } Path last = path.suffix(1); attributeName = fieldsToAttributes.get(last); if(attributeName != null){ return attributeName; } return last.toString(); }
/** * Get a reference to the hidden path's actual field. * * This does not guarantee the sub-path exists. * * @param path * @return */ public static Path getFieldForHidden(Path hiddenPath) { return hiddenPath.prefix(-2).mutableCopy().push(hiddenPath.getLast()); }
private static boolean isFieldQueried(Path field, Path qField, Path context) { LOGGER.debug("Checking if field {} is included in qfield={} with context={}", field, qField, context); Path absField = context.isEmpty() ? qField : new Path(context, qField); if (field.matchingPrefix(absField)) { LOGGER.debug("Field {} is queried", absField); return true; } else { LOGGER.debug("Field {} is not queried", absField); return false; } }
public CompositeMetadata(EntityInfo info, CompositeSchema schema, Path path, CompositeMetadata parent) { super(info, schema); this.entityPath = path; this.parent = parent; }