@Override public Sort parseSort(JsonNode object) { return object == null ? null : Sort.fromJson(object); }
@Override public void putSort(JsonNode object,String name,Sort s) { if(s!=null) ((ObjectNode)object).put(name,s.toJson()); } }
/** * Returns if the field is referenced in a sort key * * @param field The field */ public boolean isRequired(Path field) { return isRequired(field, Path.EMPTY); }
@Override public void putSort(JsonNode object, String name, Sort s) { if (s != null) { ((ObjectNode) object).set(name, s.toJson()); } } }
@Override public Sort getSort(JsonNode object, String name) { JsonNode node = object.get(name); return node == null ? null : Sort.fromJson(node); }
/** * Returns if the field is referenced in a sort key * * @param field The field */ public boolean isRequired(Path field) { return isRequired(field, Path.EMPTY); }
@Override public void putSort(JsonNode object, String name, Sort s) { if (s != null) { ((ObjectNode) object).set(name, s.toJson()); } } }
@Override public Sort getSort(JsonNode object, String name) { JsonNode node = object.get(name); return node == null ? null : Sort.fromJson(node); }
/** * Returns if the field is referenced in a sort key * * @param field The field * @param ctx The nested context */ public boolean isRequired(Path field, Path ctx) { if (this instanceof SortKey) { return isRequired(field, (SortKey) this, ctx); } else if (this instanceof CompositeSortKey) { return isRequired(field, (CompositeSortKey) this, ctx); } return false; }
@Override public void putSort(Object object, String name, Sort s) { if (s != null) { ((BSONObject) object).put(name, s.toJson().toString()); } }
@Override public Sort parseSort(BSONObject object) { return object == null ? null : Sort.fromJson(toJson(object)); }
/** * Returns if the field is referenced in a sort key * * @param field The field * @param ctx The nested context */ public boolean isRequired(Path field, Path ctx) { if (this instanceof SortKey) { return isRequired(field, (SortKey) this, ctx); } else if (this instanceof CompositeSortKey) { return isRequired(field, (CompositeSortKey) this, ctx); } return false; }
@Override public void putSort(BSONObject object, String name, Sort s) { if (s != null) { object.put(name, s.toJson().toString()); } }
@Override public Sort getSort(Object object, String name) { String x = (String) ((BSONObject) object).get(name); return x == null ? null : Sort.fromJson(toJson(x)); }
private static boolean isRequired(Path field, CompositeSortKey sort, Path ctx) { for (SortKey key : sort.getKeys()) { if (isRequired(field, key, ctx)) { return true; } } return false; }
@Override public JsonNode toJson() { ObjectNode o = JsonNodeFactory.instance.objectNode(); o.set("sort", sort.toJson()); o.set("source", source.getStep().toJson()); return o; }
@Override public Sort getSort(BSONObject object, String name) { String x = (String) object.get(name); return x == null ? null : Sort.fromJson(toJson(x)); }
private static boolean isRequired(Path field, CompositeSortKey sort, Path ctx) { for (SortKey key : sort.getKeys()) { if (isRequired(field, key, ctx)) { return true; } } return false; }
@Override public JsonNode explain(ExecutionContext ctx) { ObjectNode o = JsonNodeFactory.instance.objectNode(); o.set("sort", sort.toJson()); o.set("source", source.getStep().explain(ctx)); return o; } }
/** * Parses a find request from a json object. Unrecognized elements are * ignored. */ public void fromJson(ObjectNode node) { JsonNode x = node.get("query"); if (x != null) { query = QueryExpression.fromJson(x); } x = node.get("projection"); if (x != null) { projection = Projection.fromJson(x); } x = node.get("sort"); if (x != null) { sort = Sort.fromJson(x); } x = node.get("range"); if (x instanceof ArrayNode && ((ArrayNode) x).size() == 2) { from = ((ArrayNode) x).get(0).asLong(); to = ((ArrayNode) x).get(1).asLong(); } }