001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.internal.query.processor;
022:
023: import com.db4o.*;
024: import com.db4o.foundation.*;
025: import com.db4o.internal.*;
026: import com.db4o.query.*;
027: import com.db4o.reflect.*;
028:
029: /**
030: *
031: * Class constraint on queries
032: *
033: * @exclude
034: */
035: public class QConClass extends QConObject {
036:
037: private transient ReflectClass _claxx;
038: public String _className;
039: public boolean i_equal;
040:
041: public QConClass() {
042: // C/S
043: }
044:
045: QConClass(Transaction a_trans, QCon a_parent, QField a_field,
046: ReflectClass claxx) {
047: super (a_trans, a_parent, a_field, null);
048: if (claxx != null) {
049: i_yapClass = a_trans.container()
050: .produceClassMetadata(claxx);
051: if (claxx
052: .equals(a_trans.container()._handlers.ICLASS_OBJECT)) {
053: i_yapClass = (ClassMetadata) i_yapClass.typeHandler();
054: }
055: }
056: _claxx = claxx;
057: }
058:
059: QConClass(Transaction trans, ReflectClass claxx) {
060: this (trans, null, null, claxx);
061: }
062:
063: public boolean canBeIndexLeaf() {
064: return false;
065: }
066:
067: boolean evaluate(QCandidate a_candidate) {
068: boolean res = true;
069: ReflectClass claxx = a_candidate.classReflector();
070: if (claxx == null) {
071: res = false;
072: } else {
073: res = i_equal ? _claxx.equals(claxx) : _claxx
074: .isAssignableFrom(claxx);
075: }
076: return i_evaluator.not(res);
077: }
078:
079: void evaluateSelf() {
080:
081: // optimization for simple class queries:
082: // No instantiation of objects, if not necessary.
083: // Does not handle the special comparison of the
084: // Compare interface.
085: //
086: // TODO: consider another strategy for not reevaluating when result set was loaded from
087: // the class index
088: // if(i_evaluator.isDefault()){
089: // if(! hasOrdering() && ! hasJoins()){
090: // if(i_yapClass != null && i_candidates.i_yapClass != null){
091: // if(i_yapClass.getHigherHierarchy(i_candidates.i_yapClass) == i_yapClass){
092: // return;
093: // }
094: // }
095: // }
096: // }
097: i_candidates.filter(this );
098: }
099:
100: public Constraint equal() {
101: synchronized (streamLock()) {
102: i_equal = true;
103: return this ;
104: }
105: }
106:
107: boolean isNullConstraint() {
108: return false;
109: }
110:
111: String logObject() {
112: if (Debug.queries) {
113: if (_claxx != null) {
114: return _claxx.toString();
115: }
116: }
117: return "";
118: }
119:
120: void marshall() {
121: super .marshall();
122: if (_claxx != null) {
123: _className = _claxx.getName();
124: }
125: }
126:
127: public String toString() {
128: if (!Debug4.prettyToStrings) {
129: return super .toString();
130: }
131: String str = "QConClass ";
132: if (_claxx != null) {
133: str += _claxx.toString() + " ";
134: }
135: return str + super .toString();
136: }
137:
138: void unmarshall(Transaction a_trans) {
139: if (i_trans == null) {
140: super.unmarshall(a_trans);
141: if (_className != null) {
142: _claxx = a_trans.reflector().forName(_className);
143: }
144: }
145: }
146:
147: }
|