/** * Builds a projector using the given projection and entity metadata */ public static Projector getInstance(Projection projection, EntityMetadata md) { return getInstance(projection, Path.EMPTY, md.getFieldTreeRoot()); }
private JsonDoc project(JsonDoc doc, Projector p) { if (doc == null) { return null; } else { return p.project(doc, factory); } } }
@Override public Boolean project(Path p, QueryEvaluationContext ctx) { nestedProjector = null; decidingProjector=null; ListIterator<Projector> itemsItr=items.listIterator(items.size()); while (itemsItr.hasPrevious()) { Projector projector = itemsItr.previous(); Boolean projectionResult = projector.project(p, ctx); if (projectionResult != null) { nestedProjector = projector.getNestedProjector(); decidingProjector = projector.getDecidingProjector(); return projectionResult; } } return null; } }
/** * Evaluate the list of projections backwards, so the first projection that * decides about the inclusion of the field is the last projection specified * in the list. */ @Override public Projection.Inclusion project(Path p, QueryEvaluationContext ctx) { nestedProjector = null; ListIterator<Projector> itemsItr = items.listIterator(items.size()); while (itemsItr.hasPrevious()) { Projector projector = itemsItr.previous(); Projection.Inclusion projectionResult = projector.project(p, ctx); if (projectionResult != Projection.Inclusion.undecided) { nestedProjector = projector.getNestedProjector(); return projectionResult; } } return Projection.Inclusion.undecided; } }
private static ArrayProjector findArrayProjectorForField(Projector p, Path field) { if (p instanceof ListProjector) { List<Projector> items = ((ListProjector) p).getItems(); ListIterator<Projector> itemsItr = items.listIterator(items.size()); while (itemsItr.hasPrevious()) { Projector projector = itemsItr.previous(); ArrayProjector x = findArrayProjectorForField(projector, field); if (x != null) { return x; } } } else if (p instanceof ArrayProjector) { if (field.matches(((ArrayProjector) p).getArrayFieldPattern())) { return (ArrayProjector) p; } return findArrayProjectorForField(p.getNestedProjector(), field); } return null; } }
projector = Projector.getInstance(combinedProjection, md); } else { projector = null; inputDoc.setResultMetadata(jsonDoc.rmd); if (projector != null) { inputDoc.setOutputDocument(projector.project(jsonDoc.doc, ctx.getFactory().getNodeFactory())); } else { inputDoc.setOutputDocument(new JsonDoc(new ObjectNode(ctx.getFactory().getNodeFactory())));
Projection.Inclusion result = project(fieldPath, ctx); LOGGER.debug("Projecting '{}' in context '{}': {}", fieldPath, contextPath, result); if (result == Projection.Inclusion.undecided) { JsonNode newNode; if (cursor.firstChild()) { newNode = (getNestedProjector() == null ? this : getNestedProjector()). project(factory, contextPath, cursor, ctx, fieldNode instanceof ArrayNode); cursor.parent(); } else { newNode = sort(factory, this, (ArrayNode) newNode, fieldPath); LOGGER.debug("Projecting object field {}", cursor.getCurrentPath()); if (cursor.firstChild()) { newNode = (getNestedProjector() == null ? this : getNestedProjector()). project(factory, contextPath, cursor, ctx, false); cursor.parent(); LOGGER.debug("Child object:{}", newNode); LOGGER.debug("Projecting array field {}", cursor.getCurrentPath()); if (cursor.firstChild()) { newNode = (getNestedProjector() == null ? this : getNestedProjector()). project(factory, contextPath, cursor, ctx, true); cursor.parent(); LOGGER.debug("Child object:{}", newNode); newNode = sort(factory, this, (ArrayNode) newNode, fieldPath);
if (fieldMd != null) { LOGGER.debug("Projecting {} in context {}", contextRelativePath, contextPath); Boolean result = projector.project(fieldPath, ctx); if (result != null) { if (result) { LOGGER.debug("Projection includes {} md={}", fieldPath,fieldMd); if (fieldMd instanceof ObjectField) { projectObjectField(fieldNode, ret, fieldPath, cursor, projector, mdContext, contextPath, factory, ctx); } else if (fieldMd instanceof SimpleField) { projectSimpleField(fieldNode, ret, fieldPath); } else if(fieldMd instanceof ResolvedReferenceField) { if(projector.exactMatch()) { projectArrayField(projector,factory,fieldMd,ret,fieldPath,fieldNode,cursor,ctx); } else { LOGGER.debug("Projection excludes {} because it crosses entity boundary with no explicit projection", fieldPath); projectArrayField(projector, factory, fieldMd, ret, fieldPath, fieldNode, cursor, ctx);
Path elemPath = cursor.getCurrentPath(); LOGGER.debug("Project array element {} context {}", elemPath, contextPath); Boolean result = projector.project(elemPath, ctx); if (result != null) { if (result) { Projector nestedProjector = projector.getNestedProjector(); if (nestedProjector == null) { nestedProjector = projector; if (cursor.firstChild()) { JsonNode ret = projectObject(nestedProjector, factory, mdContext, elemPath, cursor, ctx); cursor.parent(); return ret;
Projector deciding=projector.getDecidingProjector(); ArrayNode newNode = factory.arrayNode(); if (cursor.firstChild()) { do { JsonNode node = projectArrayElement(projector, factory, ((ArrayField) fieldMd).getElement(),
private static ArrayNode sort(JsonNodeFactory factory, Projector projector, ArrayNode node, Path nodePath) { ArrayProjector p = findArrayProjectorForField(projector, nodePath); if (p != null && p.getSort() != null) { LOGGER.debug("Sorting array elements using {}", p.getSort()); return p.sortArray(node, factory); } return node; }
@Override public boolean exactMatch() { for(Projector p:items) if(p.exactMatch()) return true; return false; }
@Override public Boolean project(Path p, QueryEvaluationContext ctx) { decidingProjector=null; lastMatch = false; if (p.matchingPrefix(arrayFieldPattern)) { decidingProjector=this; return include ? Boolean.TRUE : Boolean.FALSE; } // Is this field pointing to an element of the array // It is so if 'p' has one more element than 'arrayFieldPattern', and // if it is a matching descendant if (p.numSegments() == arrayFieldPattern.numSegments() + 1 && p.matchingDescendant(arrayFieldPattern)) { Boolean ret=projectArray(p, ctx); if(ret!=null&&nestedProjector!=null) { decidingProjector=nestedProjector.getDecidingProjector(); } return ret; } return null; }
projector = Projector.getInstance(combinedProjection, md); } else { projector = null; JsonDoc jsonDoc = translator.toJson(dbObject); LOGGER.debug("Translated doc: {}", jsonDoc); inputDoc.setOutputDocument(projector.project(jsonDoc, ctx.getFactory().getNodeFactory())); } else { inputDoc.setOutputDocument(new JsonDoc(new ObjectNode(ctx.getFactory().getNodeFactory())));
Projection.Inclusion result = project(fieldPath, ctx); LOGGER.debug("Projecting '{}' in context '{}': {}", fieldPath, contextPath, result); if (result == Projection.Inclusion.undecided) { JsonNode newNode; if (cursor.firstChild()) { newNode = (getNestedProjector() == null ? this : getNestedProjector()). project(factory, contextPath, cursor, ctx, fieldNode instanceof ArrayNode); cursor.parent(); } else { newNode = sort(factory, this, (ArrayNode) newNode, fieldPath); LOGGER.debug("Projecting object field {}", cursor.getCurrentPath()); if (cursor.firstChild()) { newNode = (getNestedProjector() == null ? this : getNestedProjector()). project(factory, contextPath, cursor, ctx, false); cursor.parent(); LOGGER.debug("Child object:{}", newNode); LOGGER.debug("Projecting array field {}", cursor.getCurrentPath()); if (cursor.firstChild()) { newNode = (getNestedProjector() == null ? this : getNestedProjector()). project(factory, contextPath, cursor, ctx, true); cursor.parent(); LOGGER.debug("Child object:{}", newNode); newNode = sort(factory, this, (ArrayNode) newNode, fieldPath);
/** * Evaluate the list of projections backwards, so the first projection that * decides about the inclusion of the field is the last projection specified * in the list. */ @Override public Projection.Inclusion project(Path p, QueryEvaluationContext ctx) { nestedProjector = null; ListIterator<Projector> itemsItr = items.listIterator(items.size()); while (itemsItr.hasPrevious()) { Projector projector = itemsItr.previous(); Projection.Inclusion projectionResult = projector.project(p, ctx); if (projectionResult != Projection.Inclusion.undecided) { nestedProjector = projector.getNestedProjector(); return projectionResult; } } return Projection.Inclusion.undecided; } }
private static ArrayProjector findArrayProjectorForField(Projector p, Path field) { if (p instanceof ListProjector) { List<Projector> items = ((ListProjector) p).getItems(); ListIterator<Projector> itemsItr = items.listIterator(items.size()); while (itemsItr.hasPrevious()) { Projector projector = itemsItr.previous(); ArrayProjector x = findArrayProjectorForField(projector, field); if (x != null) { return x; } } } else if (p instanceof ArrayProjector) { if (field.matches(((ArrayProjector) p).getArrayFieldPattern())) { return (ArrayProjector) p; } return findArrayProjectorForField(p.getNestedProjector(), field); } return null; } }
private static ArrayNode sort(JsonNodeFactory factory, Projector projector, ArrayNode node, Path nodePath) { ArrayProjector p = findArrayProjectorForField(projector, nodePath); if (p != null && p.getSort() != null) { LOGGER.debug("Sorting array elements using {}", p.getSort()); return p.sortArray(node, factory); } return node; }
public Project(ExecutionBlock block, Source<ResultDocument> source, Projection projection) { super(block); this.source = source; this.projection = projection; this.p = Projector.getInstance(projection, block.getMetadata()); }
response.setSize(finder.find(ctx, coll, mongoQuery, mongoProjection, mongoSort, from, to)); Projector projector = Projector.getInstance(Projection.add(projection, roleEval.getExcludedFields(FieldAccessRoleEvaluator.Operation.find)), md); for (DocCtx document : ctx.getDocuments()) { document.setOutputDocument(projector.project(document, ctx.getFactory().getNodeFactory()));