KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > query > execution > SubQueryExecutionLeaf


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

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 JavaDoc;
38 import java.util.Collection JavaDoc;
39 import java.util.Iterator JavaDoc;
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     // not an index => "Or branch" i.e. not resolvable branch
51
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     /**
69      * ***************************** RESOLVE ******************************************
70      */

71
72     public boolean resolveOnElement(Session session, QueryResultWrapper wrapper) {
73         Object JavaDoc value = wrapper.getValue()[navigationInfos.getIndex()];
74         ArrayList JavaDoc candidates = new ArrayList JavaDoc();
75         if (Collection JavaDoc.class.isAssignableFrom(value.getClass())) {
76             Iterator JavaDoc it = ((Collection JavaDoc) value).iterator();
77             while (it.hasNext()) {
78                 LogicalOid floid = (LogicalOid) it.next();
79                 Object JavaDoc[] array = session.readObjectByOid(floid);
80                 candidates.add(new QueryResultWrapper(floid, array));
81             }
82         } else {
83             Object JavaDoc[] 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 JavaDoc toString() {
102         return "Eleaf:" + subQueryConstraint.toString();
103     }
104
105     private SubQueryConstraintImpl subQueryConstraint;
106     private NavigationInfo navigationInfos;
107 }
108
Popular Tags