KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > query > constraint > SubQueryConstraintImpl


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.constraint;
25
26 import org.objectweb.jalisto.se.api.Session;
27 import org.objectweb.jalisto.se.api.internal.SessionInternal;
28 import org.objectweb.jalisto.se.api.query.FielComparator;
29 import org.objectweb.jalisto.se.api.query.Query;
30 import org.objectweb.jalisto.se.api.query.Constraint;
31 import org.objectweb.jalisto.se.query.exception.QueryEngineException;
32 import org.objectweb.jalisto.se.query.execution.ExecutionTree;
33 import org.objectweb.jalisto.se.query.parameter.SubQuery;
34 import org.objectweb.jalisto.se.query.result.QueryResultWrapper;
35
36 import java.util.ArrayList JavaDoc;
37
38 public class SubQueryConstraintImpl extends ConstraintImpl {
39     public SubQueryConstraintImpl(SubQuery subQuery, String JavaDoc className, ArrayList JavaDoc subFieldNames) {
40         this.className = className;
41         this.subQuery = subQuery;
42         this.fieldNames = new String JavaDoc[subFieldNames.size()];
43         for (int i = 0; i < fieldNames.length; i++) {
44             fieldNames[i] = (String JavaDoc) subFieldNames.get(i);
45         }
46     }
47
48     public Object JavaDoc getObject() {
49         return subQuery;
50     }
51
52     public Query getQuery() {
53         return subQuery.getQuery();
54     }
55
56     public ExecutionTree getTree() {
57         return subQuery.getTree(null);
58     }
59
60     public String JavaDoc getFieldName() {
61         return fieldNames[0];
62     }
63
64     public String JavaDoc[] getFieldNames() {
65         return fieldNames;
66     }
67
68     public Constraint contains() {
69         throw new QueryEngineException("cannot do this operation on a subQuery");
70     }
71
72     public Constraint equal() {
73         throw new QueryEngineException("cannot do this operation on a subQuery");
74     }
75
76     public Constraint greater() {
77         throw new QueryEngineException("cannot do this operation on a subQuery");
78     }
79
80     public Constraint identity() {
81         throw new QueryEngineException("cannot do this operation on a subQuery");
82     }
83
84     public Constraint like() {
85         throw new QueryEngineException("cannot do this operation on a subQuery");
86     }
87
88     public Constraint not() {
89         not = !not;
90         return this;
91     }
92
93     public Constraint smaller() {
94         throw new QueryEngineException("cannot do this operation on a subQuery");
95     }
96
97     public boolean execute(Session session, FielComparator comparator, Object JavaDoc candidate) {
98         return subQuery.getTree(null).resolveOnOneElement(
99                 (SessionInternal) session,
100                 (QueryResultWrapper) candidate);
101     }
102
103     public String JavaDoc getClassName() {
104         return className;
105     }
106
107     public String JavaDoc toString() {
108         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
109         sb.append("SubQueryConstraint");
110         return sb.toString();
111     }
112
113     private SubQuery subQuery;
114     private String JavaDoc className;
115     private String JavaDoc[] fieldNames;
116     private boolean not = false;
117 }
118
Popular Tags