KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > QConClass


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o;
22
23 import com.db4o.foundation.*;
24 import com.db4o.query.*;
25 import com.db4o.reflect.*;
26
27 /**
28  *
29  * Class constraint on queries
30  *
31  * @exclude
32  */

33 public class QConClass extends QConObject{
34     
35     private transient ReflectClass _claxx;
36     public String JavaDoc _className;
37     public boolean i_equal;
38     
39     public QConClass(){
40         // C/S
41
}
42     
43     QConClass(Transaction a_trans, QCon a_parent, QField a_field, ReflectClass claxx){
44         super(a_trans, a_parent, a_field, null);
45         if(claxx != null){
46             i_yapClass = a_trans.stream().produceYapClass(claxx);
47             if(claxx.equals(a_trans.stream().i_handlers.ICLASS_OBJECT)){
48                 i_yapClass = (YapClass)((YapClassPrimitive)i_yapClass).i_handler;
49             }
50         }
51         _claxx = claxx;
52     }
53     
54     public boolean canBeIndexLeaf(){
55         return false;
56     }
57     
58     boolean evaluate(QCandidate a_candidate){
59         boolean res = true;
60         ReflectClass claxx = a_candidate.classReflector();
61         if(claxx == null){
62             res = false;
63         }else{
64             res = i_equal ? _claxx.equals(claxx) : _claxx.isAssignableFrom(claxx);
65         }
66         return i_evaluator.not(res);
67     }
68     
69     void evaluateSelf() {
70         
71         // optimization for simple class queries:
72
// No instantiation of objects, if not necessary.
73
// Does not handle the special comparison of the
74
// Compare interface.
75
//
76
if(i_evaluator.isDefault()){
77             if(i_orderID == 0 && ! hasJoins()){
78                 if(i_yapClass != null && i_candidates.i_yapClass != null){
79                     if(i_yapClass.getHigherHierarchy(i_candidates.i_yapClass) == i_yapClass){
80                         return;
81                     }
82                 }
83             }
84         }
85         i_candidates.filter(this);
86     }
87     
88     public Constraint equal (){
89         synchronized(streamLock()){
90             i_equal = true;
91             return this;
92         }
93     }
94     
95     boolean isNullConstraint() {
96         return false;
97     }
98     
99     String JavaDoc logObject() {
100         if (Debug.queries) {
101             if(_claxx != null){
102                 return _claxx.toString();
103             }
104         }
105         return "";
106     }
107     
108     void marshall() {
109         super.marshall();
110         if(_claxx!=null) {
111             _className = _claxx.getName();
112         }
113     }
114     
115     public String JavaDoc toString(){
116         if(! Debug4.prettyToStrings){
117             return super.toString();
118         }
119         String JavaDoc str = "QConClass ";
120         if(_claxx != null){
121             str += _claxx.toString() + " ";
122         }
123         return str + super.toString();
124     }
125     
126     void unmarshall(Transaction a_trans) {
127         if (i_trans == null) {
128             super.unmarshall(a_trans);
129             if(_className!=null) {
130                 _claxx = a_trans.reflector().forName(_className);
131             }
132         }
133     }
134     
135 }
136
137
Popular Tags