@Override public boolean update(JsonDoc doc, FieldTreeNode contextMd, Path contextPath) { return doc.modify(contextPath, null, false) != null; } }
@Override public boolean update(JsonDoc doc, FieldTreeNode contextMd, Path contextPath) { return doc.modify(contextPath, null, false) != null; } }
@Override public boolean update(JsonDoc doc, FieldTreeNode contextMd, Path contextPath) { return doc.modify(contextPath, null, false) != null; } }
/** * Modifies an existing node value * * @param p Path to modify * @param newValue new value to set. If null, path is removed from the doc. * @param createPath If true, creates all intermediate nodes if they don't * exist * * @return Old value */ public JsonNode modify(Path p, JsonNode newValue, boolean createPath) { return modify(docRoot, p, newValue, createPath); }
/** * Modifies an existing node value * * @param p Path to modify * @param newValue new value to set. If null, path is removed from the doc. * @param createPath If true, creates all intermediate nodes if they don't * exist * * @return Old value */ public JsonNode modify(Path p, JsonNode newValue, boolean createPath) { return modify(docRoot, p, newValue, createPath); }
private static ArrayNode ensureDestNodeExists(ResultDocument doc,ArrayNode destNode,Path fieldName) { if (destNode == null) { destNode = JsonNodeFactory.instance.arrayNode(); doc.getDoc().modify(fieldName, destNode, true); } return destNode; }
private static ArrayNode ensureDestNodeExists(ResultDocument doc,ArrayNode destNode,Path fieldName) { if (destNode == null) { destNode = JsonNodeFactory.instance.arrayNode(); doc.getDoc().modify(fieldName, destNode, true); } return destNode; }
private JsonNode setOrAdd(JsonDoc doc, Path contextPath, FieldData df, JsonNode newValueNode, Object newValue, Type newValueType) { JsonNode oldValueNode = null; Path fieldPath = new Path(contextPath, df.field); if (op == UpdateOperator._set) { LOGGER.debug("set fieldPath={}, newValue={}", fieldPath, newValueNode); oldValueNode = doc.modify(fieldPath, newValueNode, true); } else if (op == UpdateOperator._add) { oldValueNode = doc.get(fieldPath); if (newValueNode != null && oldValueNode != null) { newValueNode = df.fieldType.toJson(factory, Arith.add(df.fieldType.fromJson(oldValueNode), newValue, Arith.promote(df.fieldType, newValueType))); doc.modify(fieldPath, newValueNode, false); } } return oldValueNode; }
private JsonNode setOrAdd(JsonDoc doc, Path contextPath, FieldData df, JsonNode newValueNode, Object newValue, Type newValueType) { JsonNode oldValueNode = null; Path fieldPath = new Path(contextPath, df.field); if (op == UpdateOperator._set) { LOGGER.debug("set fieldPath={}, newValue={}",fieldPath,newValueNode); oldValueNode = doc.modify(fieldPath, newValueNode, true); } else if (op == UpdateOperator._add) { oldValueNode = doc.get(fieldPath); if (newValueNode != null && oldValueNode != null) { newValueNode = df.fieldType.toJson(factory, Arith.add(df.fieldType.fromJson(oldValueNode), newValue, Arith.promote(df.fieldType, newValueType))); doc.modify(fieldPath, newValueNode, false); } } return oldValueNode; }
private JsonNode setOrAdd(JsonDoc doc, Path contextPath, FieldData df, JsonNode newValueNode, Object newValue, Type newValueType) { JsonNode oldValueNode = null; Path fieldPath = new Path(contextPath, df.field); if (op == UpdateOperator._set) { LOGGER.debug("set fieldPath={}, newValue={}", fieldPath, newValueNode); oldValueNode = doc.modify(fieldPath, newValueNode, true); } else if (op == UpdateOperator._add) { oldValueNode = doc.get(fieldPath); if (newValueNode != null && oldValueNode != null) { newValueNode = df.fieldType.toJson(factory, Arith.add(df.fieldType.fromJson(oldValueNode), newValue, Arith.promote(df.fieldType, newValueType))); doc.modify(fieldPath, newValueNode, false); } } return oldValueNode; }
private void updatePredefinedFields(OperationContext ctx,CRUDController controller, String entity) { for (JsonDoc doc : ctx.getDocuments()) { PredefinedFields.updateArraySizes(factory.getNodeFactory(), doc); JsonNode node = doc.get(OBJECT_TYPE_PATH); if (node == null) { doc.modify(OBJECT_TYPE_PATH, factory.getNodeFactory().textNode(entity), false); } else if (!node.asText().equals(entity)) { throw Error.get(CrudConstants.ERR_INVALID_ENTITY, node.asText()); } controller.updatePredefinedFields(ctx,doc); } } }
@Override public boolean update(JsonDoc doc, FieldTreeNode contextMd, Path contextPath) { boolean ret = false; MutablePath p = new MutablePath(); for (AbsPath x : fields) { Path fld = new Path(contextPath, x.field); LOGGER.debug("Removing {}", fld); if (doc.modify(fld, null, false) != null) { ret = true; if (x.absArrayField != null) { // This is an array p.set(x.absArrayField); p.rewriteIndexes(fld); ArrayNode node = (ArrayNode) doc.get(p); p.setLast(p.getLast() + "#"); doc.modify(p, factory.numberNode(node.size()), false); } } } return ret; } }
@Override public boolean update(JsonDoc doc, FieldTreeNode contextMd, Path contextPath) { boolean ret = false; MutablePath p = new MutablePath(); for (AbsPath x : fields) { Path fld = new Path(contextPath, x.field); LOGGER.debug("Removing {}", fld); if (doc.modify(fld, null, false) != null) { ret = true; if (x.absArrayField != null) { // This is an array p.set(x.absArrayField); p.rewriteIndexes(fld); ArrayNode node = (ArrayNode) doc.get(p); p.setLast(p.getLast() + "#"); doc.modify(p, factory.numberNode(node.size()), false); } } } return ret; } }
@Override public boolean update(JsonDoc doc, FieldTreeNode contextMd, Path contextPath) { boolean ret = false; MutablePath p = new MutablePath(); for (AbsPath x : fields) { Path fld = new Path(contextPath, x.field); LOGGER.debug("Removing {}", fld); if (doc.modify(fld, null, false) != null) { ret = true; if (x.absArrayField != null) { // This is an array p.set(x.absArrayField); p.rewriteIndexes(fld); ArrayNode node = (ArrayNode) doc.get(p); p.setLast(p.getLast() + "#"); doc.modify(p, factory.numberNode(node.size()), false); } } } return ret; } }
/** * Insert the child documents into a slot of this document * * @param parentDoc The parent document * @param childDocs A list of child docs * @param dest The destination field name to insert the result set */ public void insertChildDocs(ChildSlot slot, Stream<ResultDocument> childDocs) { ObjectNode containerField; if (slot.getLocalContainerName().isEmpty()) { containerField = (ObjectNode) doc.getRoot(); } else { containerField = (ObjectNode) doc.get(slot.getLocalContainerName()); if (containerField == null) { doc.modify(slot.getLocalContainerName(), containerField = JsonNodeFactory.instance.objectNode(), true); } } ArrayNode arrayField = (ArrayNode) containerField.get(slot.getReferenceFieldName()); if (arrayField == null) { containerField.set(slot.getReferenceFieldName(), arrayField = JsonNodeFactory.instance.arrayNode()); } for (Iterator<ResultDocument> docItr = childDocs.iterator(); docItr.hasNext();) { arrayField.add(docItr.next().doc.getRoot()); } }
private void updatePredefinedFields(OperationContext ctx, CRUDController controller, String entity) { ctx.measure.begin("updatePredefinedFields"); for (JsonDoc doc : ctx.getInputDocuments()) { PredefinedFields.updateArraySizes(ctx.getTopLevelEntityMetadata(), factory.getNodeFactory(), doc); JsonNode node = doc.get(OBJECT_TYPE_PATH); if (node == null) { doc.modify(OBJECT_TYPE_PATH, factory.getNodeFactory().textNode(entity), false); } else if (!node.asText().equals(entity)) { throw Error.get(CrudConstants.ERR_INVALID_ENTITY, node.asText()); } controller.updatePredefinedFields(ctx, doc); } ctx.measure.end("updatePredefinedFields"); }
private void updatePredefinedFields(OperationContext ctx, CRUDController controller, String entity) { ctx.measure.begin("updatePredefinedFields"); for (JsonDoc doc : ctx.getInputDocuments()) { PredefinedFields.updateArraySizes(ctx.getTopLevelEntityMetadata(), factory.getNodeFactory(), doc); JsonNode node = doc.get(OBJECT_TYPE_PATH); if (node == null) { doc.modify(OBJECT_TYPE_PATH, factory.getNodeFactory().textNode(entity), false); } else if (!node.asText().equals(entity)) { throw Error.get(CrudConstants.ERR_INVALID_ENTITY, node.asText()); } controller.updatePredefinedFields(ctx, doc); } ctx.measure.end("updatePredefinedFields"); }
@Override public void updatePredefinedFields(CRUDOperationContext ctx, JsonDoc doc) { // If it is a save operation, we rely on _id being passed by client, so we don't auto-generate that // If not, it needs to be auto-generated if (ctx.getCRUDOperation() != CRUDOperation.SAVE) { JsonNode idNode = doc.get(DocTranslator.ID_PATH); if (idNode == null || idNode instanceof NullNode) { doc.modify(DocTranslator.ID_PATH, ctx.getFactory().getNodeFactory().textNode(ObjectId.get().toString()), false); } } }
@Override public void updatePredefinedFields(CRUDOperationContext ctx, JsonDoc doc) { // If it is a save operation, we rely on _id being passed by client, so we don't auto-generate that // If not, it needs to be auto-generated if(ctx.getCRUDOperation()!=CRUDOperation.SAVE) { JsonNode idNode = doc.get(Translator.ID_PATH); if (idNode == null || idNode instanceof NullNode) { doc.modify(Translator.ID_PATH, ctx.getFactory().getNodeFactory().textNode(ObjectId.get().toString()), false); } } }
private void retrieveFragments(QueryPlanDoc doc, QueryPlanNodeExecutor exec) { // We only process child nodes. QueryPlanNode[] destinations=exec.getNode().getDestinations(); for(QueryPlanNode childNode:destinations) { QueryPlanNodeExecutor childExecutor=childNode.getProperty(QueryPlanNodeExecutor.class); CompositeMetadata childMd=childNode.getMetadata(); Path insertInto=childMd.getEntityPath(); JsonNode insertionNode=doc.getDoc().get(insertInto); if(insertionNode==null) doc.getDoc().modify(insertInto,insertionNode=factory.getNodeFactory().arrayNode(),true); List<QueryPlanDoc> children=doc.getChildren(childNode); if(children!=null) { for(QueryPlanDoc childDoc:children) { ((ArrayNode)insertionNode).add(childDoc.getDoc().getRoot()); retrieveFragments(doc,childExecutor); } } } }