1 24 package org.objectweb.jalisto.se.query.execution; 25 26 import org.objectweb.jalisto.se.api.ClassDescription; 27 import org.objectweb.jalisto.se.impl.LogicalOid; 28 import org.objectweb.jalisto.se.api.Session; 29 import org.objectweb.jalisto.se.api.MetaRepository; 30 import org.objectweb.jalisto.se.api.query.IndexManager; 31 import org.objectweb.jalisto.se.api.internal.SessionInternal; 32 import org.objectweb.jalisto.se.query.NavigationInfo; 33 import org.objectweb.jalisto.se.query.constraint.SubQueryConstraintImpl; 34 import org.objectweb.jalisto.se.query.result.QueryResultWrapper; 35 import org.objectweb.jalisto.se.query.result.WrapperSet; 36 37 import java.util.ArrayList ; 38 import java.util.Collection ; 39 import java.util.Iterator ; 40 41 public class SubQueryExecutionLeaf extends ExecutionElement { 42 43 public SubQueryExecutionLeaf(ExecutionTree tree, ExecutionElement father, 44 SubQueryConstraintImpl subQueryConstraint, int depth) { 45 super(tree, father, depth); 46 this.subQueryConstraint = subQueryConstraint; 47 setToLeaf(0); 48 } 49 50 public boolean isInOrBranch(IndexManager indexManager) { 52 return false; 53 } 54 55 public boolean isResolved() { 56 return false; 57 } 58 59 public WrapperSet getResolvedValues() { 60 return new WrapperSet(); 61 } 62 63 public void defineMeta(MetaRepository repository) { 64 ClassDescription meta = repository.getMetaData(subQueryConstraint.getClassName()); 65 navigationInfos = new NavigationInfo(meta, subQueryConstraint.getFieldNames()); 66 } 67 68 71 72 public boolean resolveOnElement(Session session, QueryResultWrapper wrapper) { 73 Object value = wrapper.getValue()[navigationInfos.getIndex()]; 74 ArrayList candidates = new ArrayList (); 75 if (Collection .class.isAssignableFrom(value.getClass())) { 76 Iterator it = ((Collection ) value).iterator(); 77 while (it.hasNext()) { 78 LogicalOid floid = (LogicalOid) it.next(); 79 Object [] array = session.readObjectByOid(floid); 80 candidates.add(new QueryResultWrapper(floid, array)); 81 } 82 } else { 83 Object [] array = session.readObjectByOid(value); 84 candidates.add(new QueryResultWrapper((LogicalOid) value, array)); 85 } 86 for (int i = 0; i < candidates.size(); i++) { 87 boolean result = subQueryConstraint.getTree().resolveOnOneElement( 88 (SessionInternal) session, 89 (QueryResultWrapper) candidates.get(i)); 90 if (result) { 91 return true; 92 } 93 } 94 return false; 95 } 96 97 public WrapperSet resolveWithCandidates(Session session, WrapperSet candidates) { 98 return new WrapperSet(); 99 } 100 101 public String toString() { 102 return "Eleaf:" + subQueryConstraint.toString(); 103 } 104 105 private SubQueryConstraintImpl subQueryConstraint; 106 private NavigationInfo navigationInfos; 107 } 108 | Popular Tags |