KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > QConEvaluation


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
25 /**
26  * @exclude
27  */

28 public class QConEvaluation extends QCon {
29
30     private transient Object JavaDoc i_evaluation;
31
32     public byte[] i_marshalledEvaluation;
33
34     public int i_marshalledID;
35
36     public QConEvaluation() {
37         // C/S only
38
}
39
40     QConEvaluation(Transaction a_trans, Object JavaDoc a_evaluation) {
41         super(a_trans);
42         i_evaluation = a_evaluation;
43     }
44
45     void evaluateEvaluationsExec(QCandidates a_candidates, boolean rereadObject) {
46         if (rereadObject) {
47             a_candidates.traverse(new Visitor4() {
48                 public void visit(Object JavaDoc a_object) {
49                     ((QCandidate) a_object).useField(null);
50                 }
51             });
52         }
53         a_candidates.filter(this);
54     }
55
56     void marshall() {
57         super.marshall();
58         int[] id = {0};
59         if(Deploy.csharp){
60             i_marshalledEvaluation = i_trans.stream().marshall(Platform4.wrapEvaluation(i_evaluation), id);
61         }else{
62             try{
63                 // try serialisation. If it fails, store as db4o.
64
i_marshalledEvaluation = Platform4.serialize(i_evaluation);
65             }catch (Exception JavaDoc e){
66                 i_marshalledEvaluation = i_trans.stream().marshall(i_evaluation, id);
67             }
68             
69         }
70         i_marshalledID = id[0];
71     }
72
73     void unmarshall(Transaction a_trans) {
74         if (i_trans == null) {
75             super.unmarshall(a_trans);
76             if(Deploy.csharp){
77                 i_evaluation = i_trans.stream().unmarshall(i_marshalledEvaluation, i_marshalledID);
78             }else{
79                 if(i_marshalledID > 0){
80                     i_evaluation = i_trans.stream().unmarshall(i_marshalledEvaluation, i_marshalledID);
81                 }else{
82                     i_evaluation = Platform4.deserialize(i_marshalledEvaluation);
83                 }
84             }
85         }
86     }
87
88     public void visit(Object JavaDoc obj) {
89         QCandidate candidate = (QCandidate) obj;
90         try {
91             Platform4.evaluationEvaluate(i_evaluation, candidate);
92             if (!candidate._include) {
93                 doNotInclude(candidate.getRoot());
94             }
95         } catch (Exception JavaDoc e) {
96             candidate.include(false);
97             doNotInclude(candidate.getRoot());
98             // TODO: implement Exception callback for the user coder
99
// at least for test cases
100
}
101     }
102
103     boolean supportsIndex() {
104         return false;
105     }
106 }
107
Popular Tags