1 24 package org.objectweb.jalisto.se.query.execution; 25 26 import org.objectweb.jalisto.se.api.MetaRepository; 27 import org.objectweb.jalisto.se.api.Session; 28 import org.objectweb.jalisto.se.api.query.IndexManager; 29 import org.objectweb.jalisto.se.query.result.QueryResultWrapper; 30 import org.objectweb.jalisto.se.query.result.WrapperSet; 31 32 import java.util.Iterator ; 33 import java.util.List ; 34 import java.util.Set ; 35 36 public class ExecutionElement implements Comparable { 37 38 public ExecutionElement(ExecutionTree tree, ExecutionElement father, int depth) { 39 this.tree = tree; 40 this.resolvedValues = new WrapperSet(); 41 this.isResolved = false; 42 this.father = (ExecutionNode) father; 43 this.depth = depth; 44 this.toLeaf = -1; 45 } 46 47 public void setToLeaf(int toLeaf) { 48 if (this.toLeaf < toLeaf) { 49 this.toLeaf = toLeaf; 50 if (father != null) { 51 father.setToLeaf(toLeaf + 1); 52 } 53 } 54 } 55 56 public boolean onlyOneToResolve() { 57 return false; 58 } 59 60 public boolean isAndNode() { 61 return false; 62 } 63 64 public boolean isInOrBranch(IndexManager indexManager) { 65 return true; 66 } 67 68 public ExecutionNode getFather() { 69 return father; 70 } 71 72 public boolean isResolved() { 73 return isResolved; 74 } 75 76 public void setResolved(boolean resolved) { 77 isResolved = resolved; 78 } 79 80 public WrapperSet getResolvedValues() { 81 return resolvedValues; 82 } 83 84 public int getToLeaf() { 85 return toLeaf; 86 } 87 88 public int getDepth() { 89 return depth; 90 } 91 92 public void cleanSubExecutionTree() { 94 resolvedValues.clear(); 95 isResolved = false; 96 } 97 98 public void cleanAll() { 99 resolvedValues.clear(); 100 isResolved = false; 101 } 102 103 public void defineMeta(MetaRepository repository) { 104 } 105 106 public int compareTo(Object o) { 107 ExecutionElement candidate = (ExecutionElement) o; 108 if (this.toLeaf < candidate.toLeaf) { 109 return -1; 110 } else if (candidate.toLeaf == this.toLeaf) { 111 return 0; 112 } else { 113 return 1; 114 } 115 } 116 117 122 123 public ExecutionNode resolveBack() { 126 if (isResolved()) { 127 return father; 128 } 129 return null; 130 } 131 132 public void resolveBeforeAndNodeNearRoot(Session session, WrapperSet candidates, List toResolve) { 134 resolveWithCandidates(session, candidates); 135 toResolve.remove(this); 136 } 137 138 public WrapperSet resolveWithCandidates(Session session, WrapperSet candidates) { 140 return new WrapperSet(); 141 } 142 143 public boolean resolveOnElement(Session session, QueryResultWrapper wrapper) { 145 return false; 146 } 147 148 public void resolveLeafOnIndex(Session session, IndexManager indexManager) { 150 } 151 152 156 157 public WrapperSet doIntersection(WrapperSet in, WrapperSet s1, WrapperSet s2) { 159 if (s1.isEmpty()) { 160 in.addAll(s2); 161 return in; 162 } 163 if (s2.isEmpty()) { 164 in.addAll(s1); 165 return in; 166 } 167 Iterator i = s1.iterator(); 168 while (i.hasNext()) { 169 QueryResultWrapper w = (QueryResultWrapper) i.next(); 170 QueryResultWrapper w2 = s2.get(w.getLogicalOid()); 171 if (w2 != null) { 172 if (w.isReaded()) { 173 in.addToRead(w); 174 } else { 175 in.add(w2); 176 } 177 } 178 } 179 return in; 180 } 181 182 public WrapperSet doIntersection(WrapperSet s1, WrapperSet s2) { 184 if (s1.isEmpty()) { 185 s1.addAll(s2); 186 return s1; 187 } 188 if (s2.isEmpty()) { 189 return s1; 190 } 191 Iterator i = s1.iterator(); 192 while (i.hasNext()) { 193 QueryResultWrapper w = (QueryResultWrapper) i.next(); 194 QueryResultWrapper w2 = s2.get(w.getLogicalOid()); 195 if (w2 != null) { 196 if ((!w.isReaded()) && w2.isReaded()) { 197 s1.remove(w); 198 s1.addToRead(w2); 199 } 200 } 201 } 202 return s1; 203 } 204 205 public Set readValues(Session session, Set set) { 206 Iterator wrappers = set.iterator(); 207 session.currentTransaction().begin(); 208 while (wrappers.hasNext()) { 209 QueryResultWrapper wrapper = (QueryResultWrapper) wrappers.next(); 210 if (wrapper.getValue() == null) { 211 wrapper.setValue(session.readObjectByOid(wrapper.getLogicalOid())); 212 } 213 } 214 session.currentTransaction().commit(); 215 return set; 216 } 217 218 219 private ExecutionNode father; 220 private int depth; 221 private int toLeaf; 222 protected WrapperSet resolvedValues; 223 protected boolean isResolved; 224 protected ExecutionTree tree; 225 } 226 | Popular Tags |