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:
027: /**
028: * @exclude
029: */
030: public class QConEvaluation extends QCon {
031:
032: private transient Object i_evaluation;
033:
034: public byte[] i_marshalledEvaluation;
035:
036: public int i_marshalledID;
037:
038: public QConEvaluation() {
039: // C/S only
040: }
041:
042: public QConEvaluation(Transaction a_trans, Object a_evaluation) {
043: super (a_trans);
044: i_evaluation = a_evaluation;
045: }
046:
047: void evaluateEvaluationsExec(QCandidates a_candidates,
048: boolean rereadObject) {
049: if (rereadObject) {
050: a_candidates.traverse(new Visitor4() {
051: public void visit(Object a_object) {
052: ((QCandidate) a_object).useField(null);
053: }
054: });
055: }
056: a_candidates.filter(this );
057: }
058:
059: void marshall() {
060: super .marshall();
061: if (Deploy.csharp) {
062: marshallUsingDb4oFormat();
063: } else {
064: try {
065: i_marshalledEvaluation = Platform4
066: .serialize(i_evaluation);
067: } catch (Exception e) {
068: marshallUsingDb4oFormat();
069: }
070: }
071: }
072:
073: private void marshallUsingDb4oFormat() {
074: SerializedGraph serialized = Serializer.marshall(container(),
075: i_evaluation);
076: i_marshalledEvaluation = serialized._bytes;
077: i_marshalledID = serialized._id;
078: }
079:
080: void unmarshall(Transaction a_trans) {
081: if (i_trans == null) {
082: super .unmarshall(a_trans);
083: if (Deploy.csharp) {
084: i_evaluation = Serializer.unmarshall(container(),
085: i_marshalledEvaluation, i_marshalledID);
086: } else {
087: if (i_marshalledID > 0) {
088: i_evaluation = Serializer.unmarshall(container(),
089: i_marshalledEvaluation, i_marshalledID);
090: } else {
091: i_evaluation = Platform4
092: .deserialize(i_marshalledEvaluation);
093: }
094: }
095: }
096: }
097:
098: public void visit(Object obj) {
099: QCandidate candidate = (QCandidate) obj;
100:
101: // force activation outside the try block
102: // so any activation errors bubble up
103: forceActivation(candidate);
104:
105: try {
106: Platform4.evaluationEvaluate(i_evaluation, candidate);
107: } catch (Exception e) {
108: candidate.include(false);
109: // TODO: implement Exception callback for the user coder
110: // at least for test cases
111: }
112: if (!candidate._include) {
113: doNotInclude(candidate.getRoot());
114: }
115: }
116:
117: private void forceActivation(QCandidate candidate) {
118: candidate.getObject();
119: }
120:
121: boolean supportsIndex() {
122: return false;
123: }
124: }
|