KickJava   Java API By Example, From Geeks To Geeks.

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


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 STIntegerWT implements STClass{
28     
29     public static transient SodaTest st;
30     
31     Integer JavaDoc i_int;
32     
33     public STIntegerWT(){
34     }
35     
36     private STIntegerWT(int a_int){
37         i_int = new Integer JavaDoc(a_int);
38     }
39     
40     public Object JavaDoc[] store() {
41         return new Object JavaDoc[]{
42             new STIntegerWT(0),
43             new STIntegerWT(1),
44             new STIntegerWT(99),
45             new STIntegerWT(909)
46         };
47     }
48     
49     public void testEquals(){
50         Query q = st.query();
51         q.constrain(new STIntegerWT(0));
52         
53         // Primitive default values are ignored, so we need an
54
// additional constraint:
55
q.descend("i_int").constrain(new Integer JavaDoc(0));
56         st.expectOne(q, store()[0]);
57     }
58     
59     public void testNotEquals(){
60         Query q = st.query();
61         Object JavaDoc[] r = store();
62         Constraint c = q.constrain(new STIntegerWT());
63         q.descend("i_int").constrain(new Integer JavaDoc(0)).not();
64         st.expect(q, new Object JavaDoc[] {r[1], r[2], r[3]});
65     }
66     
67     public void testGreater(){
68         Query q = st.query();
69         Constraint c = q.constrain(new STIntegerWT(9));
70         q.descend("i_int").constraints().greater();
71         Object JavaDoc[] r = store();
72         st.expect(q, new Object JavaDoc[] {r[2], r[3]});
73     }
74     
75     public void testSmaller(){
76         Query q = st.query();
77         Constraint c = q.constrain(new STIntegerWT(1));
78         q.descend("i_int").constraints().smaller();
79         st.expectOne(q, store()[0]);
80     }
81     
82     public void testContains(){
83         Query q = st.query();
84         Constraint c = q.constrain(new STIntegerWT(9));
85         q.descend("i_int").constraints().contains();
86         Object JavaDoc[] r = store();
87         st.expect(q, new Object JavaDoc[] {r[2], r[3]});
88     }
89     
90     public void testNotContains(){
91         Query q = st.query();
92         Constraint c = q.constrain(new STIntegerWT());
93         q.descend("i_int").constrain(new Integer JavaDoc(0)).contains().not();
94         Object JavaDoc[] r = store();
95         st.expect(q, new Object JavaDoc[] {r[1], r[2]});
96     }
97     
98     public void testLike(){
99         Query q = st.query();
100         Constraint c = q.constrain(new STIntegerWT(90));
101         q.descend("i_int").constraints().like();
102         st.expectOne(q, new STIntegerWT(909));
103         q = st.query();
104         c = q.constrain(new STIntegerWT(10));
105         q.descend("i_int").constraints().like();
106         st.expectNone(q);
107     }
108     
109     public void testNotLike(){
110         Query q = st.query();
111         Constraint c = q.constrain(new STIntegerWT(1));
112         q.descend("i_int").constraints().like().not();
113         Object JavaDoc[] r = store();
114         st.expect(q, new Object JavaDoc[] {r[0], r[2], r[3]});
115     }
116     
117     public void testIdentity(){
118         Query q = st.query();
119         Constraint c = q.constrain(new STIntegerWT(1));
120         ObjectSet set = q.execute();
121         STIntegerWT identityConstraint = (STIntegerWT)set.next();
122         identityConstraint.i_int = new Integer JavaDoc(9999);
123         q = st.query();
124         q.constrain(identityConstraint).identity();
125         identityConstraint.i_int = new Integer JavaDoc(1);
126         st.expectOne(q,store()[1]);
127     }
128     
129     public void testNotIdentity(){
130         Query q = st.query();
131         Constraint c = q.constrain(new STIntegerWT(1));
132         ObjectSet set = q.execute();
133         STIntegerWT identityConstraint = (STIntegerWT)set.next();
134         identityConstraint.i_int = new Integer JavaDoc(9080);
135         q = st.query();
136         q.constrain(identityConstraint).identity().not();
137         identityConstraint.i_int = new Integer JavaDoc(1);
138         Object JavaDoc[] r = store();
139         st.expect(q, new Object JavaDoc[] {r[0], r[2], r[3]});
140     }
141     
142     public void testConstraints(){
143         Query q = st.query();
144         q.constrain(new STIntegerWT(1));
145         q.constrain(new STIntegerWT(0));
146         Constraints cs = q.constraints();
147         Constraint[] csa = cs.toArray();
148         if(csa.length != 2){
149             st.error("Constraints not returned");
150         }
151     }
152     
153     public void testEvaluation(){
154         Query q = st.query();
155         q.constrain(new STIntegerWT());
156         q.constrain(new Evaluation() {
157             public void evaluate(Candidate candidate) {
158                 STIntegerWT sti = (STIntegerWT)candidate.getObject();
159                 candidate.include((sti.i_int.intValue() + 2) > 100);
160             }
161         });
162         Object JavaDoc[] r = store();
163         st.expect(q, new Object JavaDoc[] {r[2], r[3]});
164     }
165     
166 }
167
168
Popular Tags