public void addToUnionList(Set<ConstraintImpl> target) { // conditions of type // @a = 1 and (@x = 1 or @y = 2) // are automatically converted to // (@a = 1 and @x = 1) union (@a = 1 and @y = 2) AndImpl and = pullOrRight(); ConstraintImpl last = and.getLastConstraint(); if (last instanceof OrImpl) { OrImpl or = (OrImpl) last; // same as above, but with the added "and" for(ConstraintImpl c : or.getConstraints()) { ArrayList<ConstraintImpl> list = and.getFirstConstraints(); list.add(c); new AndImpl(list).addToUnionList(target); } return; } target.add(this); }
public AndImpl pullOrRight() { if (getLastConstraint() instanceof OrImpl) { return this; } ArrayList<ConstraintImpl> andList = getAllAndConditions(); for (int i = 0; i < andList.size() - 1; i++) { ConstraintImpl c = andList.get(i); if (c instanceof OrImpl) { ArrayList<ConstraintImpl> list = new ArrayList<ConstraintImpl>(); list.addAll(andList); list.remove(i); list.add(c); return new AndImpl(list); } } return this; }
/** * Calls accept on each of the attached constraints of the AND node. */ @Override public boolean visit(AndImpl node) { for (ConstraintImpl constraint : node.getConstraints()) { constraint.accept(this); } return true; }
public AndImpl and(ConstraintImpl constraint1, ConstraintImpl constraint2) { return new AndImpl(constraint1, constraint2); }
@Override public String getPlan(NodeState rootState) { StringBuilder buff = new StringBuilder(); buff.append(toString()); buff.append(" /* "); QueryIndex index = getIndex(); if (index != null) { if (index instanceof AdvancedQueryIndex) { AdvancedQueryIndex adv = (AdvancedQueryIndex) index; IndexPlan p = plan.getIndexPlan(); buff.append(adv.getPlanDescription(p, rootState)); } else { buff.append(index.getPlan(createFilter(true), rootState)); } } else { buff.append("no-index"); } if (!selectorConstraints.isEmpty()) { buff.append(" where ").append(new AndImpl(selectorConstraints).toString()); } buff.append(" */"); return buff.toString(); }
result.add(new AndImpl(c, right)); addToUnionList(set); if (set.size() == 1) {
@Override public boolean visit(AndImpl node) { node.setQuery(query); return super.visit(node); }
private ArrayList<ConstraintImpl> getAllAndConditions() { ArrayList<ConstraintImpl> list = new ArrayList<ConstraintImpl>(); for(ConstraintImpl c : constraints) { if (c instanceof AndImpl) { list.addAll(((AndImpl) c).getAllAndConditions()); } else { list.add(c); } } return list; }
@Override public String toString() { if (constraints.size() == 1) { return constraints.iterator().next().toString(); } else { StringBuilder builder = new StringBuilder(); for (ConstraintImpl constraint : constraints) { if (builder.length() > 0) { builder.append(" and "); } builder.append(protect(constraint)); } return builder.toString(); } }
public AndImpl and(ConstraintImpl constraint1, ConstraintImpl constraint2) { return new AndImpl(constraint1, constraint2); }
@Override public String getPlan(NodeState rootState) { StringBuilder buff = new StringBuilder(); buff.append(toString()); buff.append(" /* "); QueryIndex index = getIndex(); if (index != null) { if (index instanceof AdvancedQueryIndex) { AdvancedQueryIndex adv = (AdvancedQueryIndex) index; IndexPlan p = plan.getIndexPlan(); buff.append(adv.getPlanDescription(p, rootState)); } else { buff.append(index.getPlan(createFilter(true), rootState)); } } else { buff.append("no-index"); } if (!selectorConstraints.isEmpty()) { buff.append(" where ").append(new AndImpl(selectorConstraints).toString()); } buff.append(" */"); return buff.toString(); }
result.add(new AndImpl(c, right)); addToUnionList(set); if (set.size() == 1) {
@Override public boolean visit(AndImpl node) { node.setQuery(query); return super.visit(node); }
private ArrayList<ConstraintImpl> getAllAndConditions() { ArrayList<ConstraintImpl> list = new ArrayList<ConstraintImpl>(); for(ConstraintImpl c : constraints) { if (c instanceof AndImpl) { list.addAll(((AndImpl) c).getAllAndConditions()); } else { list.add(c); } } return list; }
@Override public String toString() { if (constraints.size() == 1) { return constraints.iterator().next().toString(); } else { StringBuilder builder = new StringBuilder(); for (ConstraintImpl constraint : constraints) { if (builder.length() > 0) { builder.append(" and "); } builder.append(protect(constraint)); } return builder.toString(); } }
public void addToUnionList(Set<ConstraintImpl> target) { // conditions of type // @a = 1 and (@x = 1 or @y = 2) // are automatically converted to // (@a = 1 and @x = 1) union (@a = 1 and @y = 2) AndImpl and = pullOrRight(); ConstraintImpl last = and.getLastConstraint(); if (last instanceof OrImpl) { OrImpl or = (OrImpl) last; // same as above, but with the added "and" for(ConstraintImpl c : or.getConstraints()) { ArrayList<ConstraintImpl> list = and.getFirstConstraints(); list.add(c); new AndImpl(list).addToUnionList(target); } return; } target.add(this); }
public AndImpl pullOrRight() { if (getLastConstraint() instanceof OrImpl) { return this; } ArrayList<ConstraintImpl> andList = getAllAndConditions(); for (int i = 0; i < andList.size() - 1; i++) { ConstraintImpl c = andList.get(i); if (c instanceof OrImpl) { ArrayList<ConstraintImpl> list = new ArrayList<ConstraintImpl>(); list.addAll(andList); list.remove(i); list.add(c); return new AndImpl(list); } } return this; }
public AndImpl and(ConstraintImpl constraint1, ConstraintImpl constraint2) { return new AndImpl(constraint1, constraint2); }