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.Index; 31 import org.objectweb.jalisto.se.api.query.IndexManager; 32 import org.objectweb.jalisto.se.query.exception.QueryEngineException; 33 import org.objectweb.jalisto.se.query.NavigationInfo; 34 import org.objectweb.jalisto.se.query.constraint.ValueConstraintImpl; 35 import org.objectweb.jalisto.se.query.result.QueryResultWrapper; 36 import org.objectweb.jalisto.se.query.result.WrapperSet; 37 38 import java.util.Iterator ; 39 40 public class ValueExecutionLeaf extends ExecutionElement { 41 42 public ValueExecutionLeaf(ExecutionTree tree, ExecutionElement father, 43 ValueConstraintImpl valueConstraint, int depth) { 44 super(tree, father, depth); 45 this.valueConstraint = valueConstraint; 46 setToLeaf(0); 47 } 48 49 public boolean isInOrBranch(IndexManager indexManager) { 51 return (navigationInfos.getIndexIfa() == null); 52 } 53 54 public boolean isResolved() { 55 return (super.isResolved() || valueConstraint.isResolved()); 56 } 57 58 public WrapperSet getResolvedValues() { 59 if (resolvedValues.isEmpty() && valueConstraint.isResolved()) { 60 return valueConstraint.getResolvedValues(); 61 } 62 return resolvedValues; 63 } 64 65 public void cleanAll() { 66 super.cleanAll(); 67 valueConstraint.clean(); 68 } 69 70 public void defineMeta(MetaRepository repository) { 71 ClassDescription meta = repository.getMetaData(valueConstraint.getClassName()); 72 navigationInfos = new NavigationInfo(meta, valueConstraint.getFieldNames()); 73 } 74 75 79 80 public void resolveLeafOnIndex(Session session, IndexManager indexManager) { 82 if (!navigationInfos.isIndexDefined()) { 83 return; 84 } 85 if (!valueConstraint.isResolved()) { 86 WrapperSet result = valueConstraint.getResolvedValues(); Index indexOnValues = navigationInfos.getIndex(indexManager); 88 Iterator keys = indexOnValues.keySet().iterator(); 89 while (keys.hasNext()) { 90 Object value = keys.next(); 91 if (valueConstraint.execute(session, navigationInfos.getComparator(), value)) { 92 Iterator oids = indexOnValues.get(value).iterator(); 93 while (oids.hasNext()) { 94 LogicalOid oid = (LogicalOid) oids.next(); 95 result.addToUnread(new QueryResultWrapper(oid, null)); 96 } 97 } 98 } 99 valueConstraint.setResolved(true); 100 } 101 } 102 103 public boolean resolveOnElement(Session session, QueryResultWrapper wrapper) { 104 Object value = wrapper.getValue()[navigationInfos.getIndex()]; 105 return valueConstraint.execute(session, navigationInfos.getComparator(), value); 106 } 107 108 public WrapperSet resolveWithCandidates(Session session, WrapperSet candidates) { 110 if (valueConstraint.isResolved()) { 111 throw new QueryEngineException("resolveWithCandidates on a resolved leaf"); 112 } 113 candidates.readAll(session, tree.getReadedValues()); 114 Iterator wrappers = candidates.iterator(); 115 while (wrappers.hasNext()) { 116 QueryResultWrapper wrapper = (QueryResultWrapper) wrappers.next(); 117 if (resolveOnElement(session, wrapper)) { 118 resolvedValues.addToRead(wrapper); 119 } 120 } 121 return resolvedValues; 122 } 123 124 public String toString() { 125 return "Eleaf:" + valueConstraint.toString(); 126 } 127 128 private ValueConstraintImpl valueConstraint; 129 private NavigationInfo navigationInfos; 130 } 131 | Popular Tags |