KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > legacy > soda > wrapper > typed > STCharWT


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.wrapper.typed;
22
23 import com.db4o.*;
24 import com.db4o.query.*;
25 import com.db4o.test.legacy.soda.*;
26
27 public class STCharWT implements STClass{
28     
29     final static String JavaDoc DESCENDANT = "i_char";
30     
31     public static transient SodaTest st;
32     
33     Character JavaDoc i_char;
34     
35     
36     public STCharWT(){
37     }
38     
39     private STCharWT(char a_char){
40         i_char = new Character JavaDoc(a_char);
41     }
42     
43     public Object JavaDoc[] store() {
44         return new Object JavaDoc[]{
45             new STCharWT((char)0),
46             new STCharWT((char)1),
47             new STCharWT((char)99),
48             new STCharWT((char)909)
49         };
50     }
51     
52     public void testEquals(){
53         Query q = st.query();
54         q.constrain(new STCharWT((char)0));
55         
56         // Primitive default values are ignored, so we need an
57
// additional constraint:
58
q.descend(DESCENDANT).constrain(new Character JavaDoc((char)0));
59         st.expectOne(q, store()[0]);
60     }
61     
62     public void testNotEquals(){
63         Query q = st.query();
64         Object JavaDoc[] r = store();
65         Constraint c = q.constrain(r[0]);
66         q.descend(DESCENDANT).constraints().not();
67         st.expect(q, new Object JavaDoc[] {r[1], r[2], r[3]});
68     }
69     
70     public void testGreater(){
71         Query q = st.query();
72         Constraint c = q.constrain(new STCharWT((char)9));
73         q.descend(DESCENDANT).constraints().greater();
74         Object JavaDoc[] r = store();
75         st.expect(q, new Object JavaDoc[] {r[2], r[3]});
76     }
77     
78     public void testSmaller(){
79         Query q = st.query();
80         Constraint c = q.constrain(new STCharWT((char)1));
81         q.descend(DESCENDANT).constraints().smaller();
82         st.expectOne(q, store()[0]);
83     }
84     
85     public void testIdentity(){
86         Query q = st.query();
87         Constraint c = q.constrain(new STCharWT((char)1));
88         ObjectSet set = q.execute();
89         STCharWT identityConstraint = (STCharWT)set.next();
90         identityConstraint.i_char = new Character JavaDoc((char)9999);
91         q = st.query();
92         q.constrain(identityConstraint).identity();
93         identityConstraint.i_char = new Character JavaDoc((char)1);
94         st.expectOne(q,store()[1]);
95     }
96     
97     public void testNotIdentity(){
98         Query q = st.query();
99         Constraint c = q.constrain(new STCharWT((char)1));
100         ObjectSet set = q.execute();
101         STCharWT identityConstraint = (STCharWT)set.next();
102         identityConstraint.i_char = new Character JavaDoc((char)9080);
103         q = st.query();
104         q.constrain(identityConstraint).identity().not();
105         identityConstraint.i_char = new Character JavaDoc((char)1);
106         Object JavaDoc[] r = store();
107         st.expect(q, new Object JavaDoc[] {r[0], r[2], r[3]});
108     }
109     
110     public void testConstraints(){
111         Query q = st.query();
112         q.constrain(new STCharWT((char)1));
113         q.constrain(new STCharWT((char)0));
114         Constraints cs = q.constraints();
115         Constraint[] csa = cs.toArray();
116         if(csa.length != 2){
117             st.error("Constraints not returned");
118         }
119     }
120     
121     public void testEvaluation(){
122         Query q = st.query();
123         q.constrain(new STCharWT());
124         q.constrain(new Evaluation() {
125             public void evaluate(Candidate candidate) {
126                 STCharWT sts = (STCharWT)candidate.getObject();
127                 candidate.include((sts.i_char.charValue() + 2) > 100);
128             }
129         });
130         Object JavaDoc[] r = store();
131         st.expect(q, new Object JavaDoc[] {r[2], r[3]});
132     }
133     
134 }
135
136
Popular Tags