KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > legacy > soda > experiments > STIdentityEvaluation


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.test.legacy.soda.experiments;
22
23 import com.db4o.*;
24 import com.db4o.query.*;
25 import com.db4o.test.legacy.soda.*;
26
27 public class STIdentityEvaluation implements STClass1{
28     
29     public static transient SodaTest st;
30     
31     public Object JavaDoc[] store() {
32         
33         Helper helperA = new Helper("aaa");
34         
35         return new Object JavaDoc[] {
36             new STIdentityEvaluation(null),
37             new STIdentityEvaluation(helperA),
38             new STIdentityEvaluation(helperA),
39             new STIdentityEvaluation(helperA),
40             new STIdentityEvaluation(new HelperDerivate("bbb")),
41             new STIdentityEvaluation(new Helper("dod"))
42             };
43     }
44     
45     public Helper helper;
46     
47     public STIdentityEvaluation(){
48     }
49     
50     public STIdentityEvaluation(Helper h){
51         this.helper = h;
52     }
53     
54     public void test(){
55         Query q = st.query();
56         Object JavaDoc[] r = store();
57         q.constrain(new Helper("aaa"));
58         ObjectSet os = q.execute();
59         Helper helperA = (Helper)os.next();
60         q = st.query();
61         q.constrain(STIdentityEvaluation.class);
62         q.descend("helper").constrain(helperA).identity();
63         q.constrain(new Evaluation() {
64             public void evaluate(Candidate candidate) {
65                 candidate.include(true);
66             }
67         });
68         st.expect(q,new Object JavaDoc[]{r[1], r[2], r[3]});
69     }
70     
71     public void testMemberClassConstraint(){
72         Query q = st.query();
73         Object JavaDoc[] r = store();
74         q.constrain(STIdentityEvaluation.class);
75         q.descend("helper").constrain(HelperDerivate.class);
76         st.expect(q,new Object JavaDoc[]{r[4]});
77     }
78     
79     public static class Helper{
80         
81         public String JavaDoc hString;
82         
83         public Helper(){
84         }
85         
86         public Helper(String JavaDoc str){
87             hString = str;
88         }
89     }
90     
91     public static class HelperDerivate extends Helper{
92         public HelperDerivate(){
93         }
94         
95         public HelperDerivate(String JavaDoc str){
96             super(str);
97         }
98         
99     }
100     
101 }
102
Popular Tags