1 24 package org.objectweb.jalisto.se.query.execution; 25 26 import org.objectweb.jalisto.se.api.Session; 27 import org.objectweb.jalisto.se.api.MetaRepository; 28 import org.objectweb.jalisto.se.api.query.IndexManager; 29 import org.objectweb.jalisto.se.query.constraint.BinaryBooleanOperatorConstraint; 30 import org.objectweb.jalisto.se.query.result.QueryResultWrapper; 31 import org.objectweb.jalisto.se.query.result.WrapperSet; 32 33 import java.util.List ; 34 35 public class ExecutionNode extends ExecutionElement { 36 37 public ExecutionNode(ExecutionTree tree, ExecutionElement father, 38 BinaryBooleanOperatorConstraint binaryConstraint, int depth) { 39 super(tree, father, depth); 40 this.andOp = binaryConstraint.isAndOperator(); 41 } 42 43 public void setLeft(ExecutionElement left) { 44 this.left = left; 45 } 46 47 public void setRight(ExecutionElement right) { 48 this.right = right; 49 } 50 51 public boolean onlyOneToResolve() { 52 if (left.isResolved()) { 53 return !right.isResolved(); 54 } 55 return right.isResolved(); 56 } 57 58 public boolean isAndNode() { 59 return andOp; 60 } 61 62 public boolean isInOrBranch(IndexManager indexManager) { 63 return ((!andOp) && (left.isInOrBranch(indexManager) || right.isInOrBranch(indexManager))); 64 } 65 66 public void cleanSubExecutionTree() { 67 super.cleanSubExecutionTree(); 68 left.cleanSubExecutionTree(); 69 right.cleanSubExecutionTree(); 70 } 71 72 public void cleanAll() { 73 super.cleanAll(); 74 left.cleanAll(); 75 right.cleanAll(); 76 } 77 78 public void defineMeta(MetaRepository repository) { 79 left.defineMeta(repository); 80 right.defineMeta(repository); 81 } 82 83 86 87 public ExecutionNode resolveBack() { 88 if (isResolved()) { 89 return getFather(); 90 } 91 92 if (left.isResolved() && right.isResolved()) { 93 WrapperSet setLeft = left.getResolvedValues(); 94 WrapperSet setRight = right.getResolvedValues(); 95 if (andOp) { 96 doIntersection(resolvedValues, setLeft, setRight); 97 tree.getToResolveAndNodes().remove(this); 98 } else { 99 resolvedValues.addAll(setLeft); 100 resolvedValues.addAll(setRight); 101 } 102 isResolved = true; 103 if (andOp) { 104 tree.getToResolveAndNodes().remove(this); 105 } 106 return getFather(); 107 } 108 109 return null; 110 } 111 112 public void resolveBeforeAndNodeNearRoot(Session session, WrapperSet candidates, List toResolve) { 113 ExecutionElement resolved; 115 ExecutionElement unresolved; 116 if (left.isResolved()) { 117 resolved = left; 118 unresolved = right; 119 } else { 120 resolved = right; 121 unresolved = left; 122 } 123 124 if (candidates != null) { 125 unresolved.resolveBeforeAndNodeNearRoot( 126 session, 127 doIntersection(new WrapperSet(), candidates, resolved.getResolvedValues()), 128 toResolve); 129 } else { 130 unresolved.resolveBeforeAndNodeNearRoot(session, resolved.getResolvedValues(), toResolve); 131 } 132 133 toResolve.remove(this); 134 } 135 136 public boolean resolveOnElement(Session session, QueryResultWrapper wrapper) { 137 if (andOp) { 138 return left.resolveOnElement(session, wrapper) && right.resolveOnElement(session, wrapper); 139 } else { 140 return left.resolveOnElement(session, wrapper) || right.resolveOnElement(session, wrapper); 141 } 142 } 143 144 public WrapperSet resolveWithCandidates(Session session, WrapperSet candidates) { 145 if (isResolved()) { 146 return doIntersection(new WrapperSet(), candidates, resolvedValues); 147 } 148 149 ExecutionElement resolved; 151 ExecutionElement unresolved; 152 if (left.isResolved()) { 153 resolved = left; 154 unresolved = right; 155 } else { 156 resolved = right; 157 unresolved = left; 158 } 159 160 WrapperSet wSet = doIntersection(new WrapperSet(), candidates, resolved.getResolvedValues()); 161 resolvedValues = unresolved.resolveWithCandidates(session, wSet); 162 isResolved = true; 163 164 if (andOp) { 165 tree.getToResolveAndNodes().remove(this); } 167 168 return resolvedValues; 169 } 170 171 public String toString() { 172 if (andOp) { 173 return "Enode&&"; 174 } else { 175 return "Enode||"; 176 } 177 } 178 179 180 private boolean andOp; 181 private ExecutionElement left; 182 private ExecutionElement right; 183 184 } 185 | Popular Tags |