@Override public QueryExpression rewrite(QueryExpression q) { NaryLogicalExpression le=dyncast(NaryLogicalExpression.class,q); if(le!=null) if(le.getQueries().size()==1) return le.getQueries().get(0); return q; } }
@Override public QueryExpression rewrite(QueryExpression q) { NaryLogicalExpression le = dyncast(NaryLogicalExpression.class, q); if (le != null) { if (le.getQueries().size() == 1) { return le.getQueries().get(0); } } return q; } }
@Override public QueryExpression rewrite(QueryExpression q) { NaryLogicalExpression le = dyncast(NaryLogicalExpression.class, q); if (le != null) { if (le.getQueries().size() == 1) { return le.getQueries().get(0); } } return q; } }
private static boolean isFieldQueried(Path field, NaryLogicalExpression q, Path context) { for (QueryExpression x : q.getQueries()) { if (x.isRequired(field, context)) { return true; } } return false; }
private static boolean isFieldQueried(Path field, NaryLogicalExpression q, Path context) { for (QueryExpression x : q.getQueries()) { if (x.isRequired(field, context)) { return true; } } return false; }
private DBObject translateNaryLogicalExpression(FieldTreeNode context, EntityMetadata md, NaryLogicalExpression expr, EntityMetadata emd, MutablePath fullPath) { List<QueryExpression> queries = expr.getQueries(); List<DBObject> list = new ArrayList<>(queries.size()); for (QueryExpression query : queries) { list.add(translate(context, query, emd, fullPath)); } return new BasicDBObject(NARY_LOGICAL_OPERATOR_MAP.get(expr.getOp()), list); }
public NaryLogicalExpressionEvaluator(NaryLogicalExpression expr, FieldTreeNode context) { List<QueryExpression> queries = expr.getQueries(); evaluators = new ArrayList<>(queries.size()); for (QueryExpression q : queries) { evaluators.add(QueryEvaluator.getInstance(q, context)); } operator = expr.getOp(); }
private DBObject translateNaryLogicalExpression(FieldTreeNode context, NaryLogicalExpression expr) { List<QueryExpression> queries = expr.getQueries(); List<DBObject> list = new ArrayList<>(queries.size()); for (QueryExpression query : queries) { list.add(translate(context, query)); } return new BasicDBObject(NARY_LOGICAL_OPERATOR_MAP.get(expr.getOp()), list); }
public NaryLogicalExpressionEvaluator(NaryLogicalExpression expr, FieldTreeNode context) { List<QueryExpression> queries = expr.getQueries(); evaluators = new ArrayList<>(queries.size()); for (QueryExpression q : queries) { evaluators.add(QueryEvaluator.getInstance(q, context)); } operator = expr.getOp(); }
public NaryLogicalExpressionEvaluator(NaryLogicalExpression expr, FieldTreeNode context) { List<QueryExpression> queries = expr.getQueries(); evaluators = new ArrayList<>(queries.size()); for (QueryExpression q : queries) { evaluators.add(QueryEvaluator.getInstance(q, context)); } operator = expr.getOp(); }
@Override public QueryExpression rewrite(QueryExpression q) { UnaryLogicalExpression le=dyncast(UnaryLogicalExpression.class,q); if(le!=null&&le.getOp()==UnaryLogicalOperator._not) { NaryLogicalExpression oreq=dyncast(NaryLogicalExpression.class,le.getQuery()); if(oreq!=null&&oreq.getOp()==NaryLogicalOperator._or) { List<QueryExpression> newList=new ArrayList<>(oreq.getQueries().size()); for(QueryExpression x:oreq.getQueries()) newList.add(new UnaryLogicalExpression(UnaryLogicalOperator._not,x)); return new NaryLogicalExpression(NaryLogicalOperator._and,newList); } } return q; } }
@Override public QueryExpression rewrite(QueryExpression q) { UnaryLogicalExpression le = dyncast(UnaryLogicalExpression.class, q); if (le != null && le.getOp() == UnaryLogicalOperator._not) { NaryLogicalExpression oreq = dyncast(NaryLogicalExpression.class, le.getQuery()); if (oreq != null && oreq.getOp() == NaryLogicalOperator._or) { List<QueryExpression> newList = new ArrayList<>(oreq.getQueries().size()); for (QueryExpression x : oreq.getQueries()) { newList.add(new UnaryLogicalExpression(UnaryLogicalOperator._not, x)); } return new NaryLogicalExpression(NaryLogicalOperator._and, newList); } } return q; } }
@Override public QueryExpression rewrite(QueryExpression q) { UnaryLogicalExpression le = dyncast(UnaryLogicalExpression.class, q); if (le != null && le.getOp() == UnaryLogicalOperator._not) { NaryLogicalExpression oreq = dyncast(NaryLogicalExpression.class, le.getQuery()); if (oreq != null && oreq.getOp() == NaryLogicalOperator._or) { List<QueryExpression> newList = new ArrayList<>(oreq.getQueries().size()); for (QueryExpression x : oreq.getQueries()) { newList.add(new UnaryLogicalExpression(UnaryLogicalOperator._not, x)); } return new NaryLogicalExpression(NaryLogicalOperator._and, newList); } } return q; } }
/** * Appends objectType:X to the query */ public static QueryExpression appendObjectType(QueryExpression q,String entityName) { QueryExpression ot=new ValueComparisonExpression(DocTranslator.OBJECT_TYPE,BinaryComparisonOperator._eq,new Value(entityName)); if(q==null) { return ot; } if(q instanceof NaryLogicalExpression && ((NaryLogicalExpression)q).getOp()==NaryLogicalOperator._and) { List<QueryExpression> l=new ArrayList<>(((NaryLogicalExpression)q).getQueries()); l.add(ot); return new NaryLogicalExpression(NaryLogicalOperator._and,l); } else { return new NaryLogicalExpression(NaryLogicalOperator._and,q,ot); } }
/** * <pre> * var r0=false; * { * q1; * q2;... * } * r0=r1&&r2&&... * return r0; * </pre> */ private Block translateNaryLogicalExpression(Context ctx,NaryLogicalExpression query) { Block block=new Block(ctx.topLevel.newGlobalBoolean(ctx)); List<String> vars=new ArrayList(); for(QueryExpression x:query.getQueries()) { Block nested=translateQuery(ctx,x); vars.add(nested.resultVar); block.add(nested); } String op=query.getOp()==NaryLogicalOperator._and?"&&":"||"; block.add(new SimpleStatement("%s=%s",block.resultVar,String.join(op,vars))); return block; }
@Override public QueryExpression rewrite(QueryExpression q) { NaryLogicalExpression le=dyncast(NaryLogicalExpression.class,q); if(le!=null) { if(le.getOp()==NaryLogicalOperator._and) { CopyOnWriteIterator<QueryExpression> itr=new CopyOnWriteIterator<>(le.getQueries()); while(itr.hasNext()) { QueryExpression x=itr.next(); NaryLogicalExpression nested=dyncast(NaryLogicalExpression.class,x); if(nested!=null&&nested.getOp()==NaryLogicalOperator._and) { // Remove this element, and add all its queries to the parent query itr.remove(); itr.getCopiedList().addAll(nested.getQueries()); } } if(itr.isCopied()) return new NaryLogicalExpression(NaryLogicalOperator._and,itr.getCopiedList()); } } return q; } }
@Override public QueryExpression rewrite(QueryExpression q) { NaryLogicalExpression le = dyncast(NaryLogicalExpression.class, q); if (le != null) { if (le.getOp() == NaryLogicalOperator._and) { CopyOnWriteIterator<QueryExpression> itr = new CopyOnWriteIterator<>(le.getQueries()); while (itr.hasNext()) { QueryExpression x = itr.next(); NaryLogicalExpression nested = dyncast(NaryLogicalExpression.class, x); if (nested != null && nested.getOp() == NaryLogicalOperator._and) { // Remove this element, and add all its queries to the parent query itr.remove(); itr.getCopiedList().addAll(nested.getQueries()); } } if (itr.isCopied()) { return new NaryLogicalExpression(NaryLogicalOperator._and, itr.getCopiedList()); } } } return q; } }
@Override public QueryExpression rewrite(QueryExpression q) { NaryLogicalExpression le = dyncast(NaryLogicalExpression.class, q); if (le != null) { if (le.getOp() == NaryLogicalOperator._and) { CopyOnWriteIterator<QueryExpression> itr = new CopyOnWriteIterator<>(le.getQueries()); while (itr.hasNext()) { QueryExpression x = itr.next(); NaryLogicalExpression nested = dyncast(NaryLogicalExpression.class, x); if (nested != null && nested.getOp() == NaryLogicalOperator._and) { // Remove this element, and add all its queries to the parent query itr.remove(); itr.getCopiedList().addAll(nested.getQueries()); } } if (itr.isCopied()) { return new NaryLogicalExpression(NaryLogicalOperator._and, itr.getCopiedList()); } } } return q; } }
/** * Default behavior is to recursively iterate the nested quereies. If nested * processing returns objects different from the original nested queries, * this method creates a new n-ary logical expression using the new query * expressions and returns that. */ protected QueryExpression itrNaryLogicalExpression(NaryLogicalExpression q, Path context) { CopyOnWriteIterator<QueryExpression> itr = new CopyOnWriteIterator<>(q.getQueries()); while (itr.hasNext()) { QueryExpression nestedq = itr.next(); QueryExpression newq = iterate(nestedq, context); if (newq != nestedq) { itr.set(newq); } } if (itr.isCopied()) { return new NaryLogicalExpression(q.getOp(), itr.getCopiedList()); } else { return q; } }
/** * Default behavior is to recursively iterate the nested quereies. If nested * processing returns objects different from the original nested queries, * this method creates a new n-ary logical expression using the new query * expressions and returns that. */ protected QueryExpression itrNaryLogicalExpression(NaryLogicalExpression q, Path context) { CopyOnWriteIterator<QueryExpression> itr = new CopyOnWriteIterator<>(q.getQueries()); while (itr.hasNext()) { QueryExpression nestedq = itr.next(); QueryExpression newq = iterate(nestedq, context); if (newq != nestedq) { itr.set(newq); } } if (itr.isCopied()) { return new NaryLogicalExpression(q.getOp(), itr.getCopiedList()); } else { return q; } }