KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > legacy > soda > joins > typed > STOrT


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.joins.typed;
22
23 import com.db4o.query.*;
24 import com.db4o.test.legacy.soda.*;
25
26 public class STOrT implements STClass {
27
28     public static transient SodaTest st;
29     
30     int orInt;
31     String JavaDoc orString;
32
33     public STOrT() {
34     }
35
36     private STOrT(int a_int, String JavaDoc a_string) {
37         orInt = a_int;
38         orString = a_string;
39     }
40
41     public String JavaDoc toString() {
42         return "STOr: int:" + orInt + " str:" + orString;
43     }
44
45     public Object JavaDoc[] store() {
46         return new Object JavaDoc[] {
47             new STOrT(0, "hi"),
48             new STOrT(5, null),
49             new STOrT(1000, "joho"),
50             new STOrT(30000, "osoo"),
51             new STOrT(Integer.MAX_VALUE - 1, null),
52             };
53     }
54     
55     public void testSmallerGreater() {
56         Query q = st.query();
57         q.constrain(new STOrT());
58         Query sub = q.descend("orInt");
59         sub.constrain(new Integer JavaDoc(30000)).greater().or(
60             sub.constrain(new Integer JavaDoc(5)).smaller());
61         Object JavaDoc[] r = store();
62         st.expect(q, new Object JavaDoc[] { r[0], r[4] });
63     }
64
65     public void testGreaterGreater() {
66         Query q = st.query();
67         q.constrain(new STOrT());
68         Query sub = q.descend("orInt");
69         sub.constrain(new Integer JavaDoc(30000)).greater().or(
70             sub.constrain(new Integer JavaDoc(5)).greater());
71         Object JavaDoc[] r = store();
72         st.expect(q, new Object JavaDoc[] { r[2], r[3], r[4] });
73     }
74
75     public void testGreaterEquals() {
76         Query q = st.query();
77         q.constrain(new STOrT());
78         Query sub = q.descend("orInt");
79         sub.constrain(new Integer JavaDoc(1000)).greater().or(
80             sub.constrain(new Integer JavaDoc(0)));
81         Object JavaDoc[] r = store();
82         st.expect(q, new Object JavaDoc[] { r[0], r[3], r[4] });
83     }
84
85     public void testEqualsNull() {
86         Query q = st.query();
87         q.constrain(new STOrT(1000, null));
88         q.descend("orInt").constraints().or(
89             q.descend("orString").constrain(null));
90         Object JavaDoc[] r = store();
91         st.expect(q, new Object JavaDoc[] { r[1], r[2], r[4] });
92     }
93
94
95     public void testAndOrAnd() {
96         Query q = st.query();
97         q.constrain(new STOrT(0, null));
98         (
99             q.descend("orInt").constrain(new Integer JavaDoc(5)).and(
100             q.descend("orString").constrain(null))
101         ).or(
102             q.descend("orInt").constrain(new Integer JavaDoc(1000)).and(
103             q.descend("orString").constrain("joho"))
104         );
105         Object JavaDoc[] r = store();
106         st.expect(q, new Object JavaDoc[] { r[1], r[2]});
107     }
108     
109     public void testOrAndOr() {
110         Query q = st.query();
111         q.constrain(new STOrT(0, null));
112         (
113             q.descend("orInt").constrain(new Integer JavaDoc(5)).or(
114             q.descend("orString").constrain(null))
115         ).and(
116             q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
117             q.descend("orString").constrain("joho"))
118         );
119         st.expectOne(q, store()[4]);
120     }
121     
122     public void testOrOrAnd() {
123         Query q = st.query();
124         q.constrain(new STOrT(0, null));
125         (
126             q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
127             q.descend("orString").constrain("joho"))
128         ).or(
129             q.descend("orInt").constrain(new Integer JavaDoc(5)).and(
130             q.descend("orString").constrain(null))
131         );
132         Object JavaDoc[] r = store();
133         st.expect(q, new Object JavaDoc[] { r[1], r[2], r[4]});
134     }
135     
136     public void testMultiOrAnd(){
137         Query q = st.query();
138         q.constrain(new STOrT(0, null));
139         (
140             (
141                 q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
142                 q.descend("orString").constrain("joho"))
143             ).or(
144                 q.descend("orInt").constrain(new Integer JavaDoc(5)).and(
145                 q.descend("orString").constrain("joho"))
146             )
147         ).or(
148             (
149                 q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
150                 q.descend("orString").constrain(null))
151             ).and(
152                 q.descend("orInt").constrain(new Integer JavaDoc(5)).or(
153                 q.descend("orString").constrain(null))
154             )
155         );
156         Object JavaDoc[] r = store();
157         st.expect(q, new Object JavaDoc[] {r[1], r[2], r[4]});
158     }
159     
160     public void testNotSmallerGreater() {
161         Query q = st.query();
162         q.constrain(new STOrT());
163         Query sub = q.descend("orInt");
164         (sub.constrain(new Integer JavaDoc(30000)).greater().or(
165             sub.constrain(new Integer JavaDoc(5)).smaller())).not();
166         Object JavaDoc[] r = store();
167         st.expect(q, new Object JavaDoc[] { r[1], r[2], r[3] });
168     }
169
170     public void testNotGreaterGreater() {
171         Query q = st.query();
172         q.constrain(new STOrT());
173         Query sub = q.descend("orInt");
174         (sub.constrain(new Integer JavaDoc(30000)).greater().or(
175             sub.constrain(new Integer JavaDoc(5)).greater())).not();
176         Object JavaDoc[] r = store();
177         st.expect(q, new Object JavaDoc[] { r[0], r[1]});
178     }
179
180     public void testNotGreaterEquals() {
181         Query q = st.query();
182         q.constrain(new STOrT());
183         Query sub = q.descend("orInt");
184         (sub.constrain(new Integer JavaDoc(1000)).greater().or(
185             sub.constrain(new Integer JavaDoc(0)))).not();
186         Object JavaDoc[] r = store();
187         st.expect(q, new Object JavaDoc[] { r[1], r[2]});
188     }
189
190     public void testNotEqualsNull() {
191         Query q = st.query();
192         q.constrain(new STOrT(1000, null));
193         (q.descend("orInt").constraints().or(
194             q.descend("orString").constrain(null))).not();
195         Object JavaDoc[] r = store();
196         st.expect(q, new Object JavaDoc[] { r[0], r[3]});
197     }
198
199     public void testNotAndOrAnd() {
200         Query q = st.query();
201         q.constrain(new STOrT(0, null));
202         (
203             q.descend("orInt").constrain(new Integer JavaDoc(5)).and(
204             q.descend("orString").constrain(null))
205         ).or(
206             q.descend("orInt").constrain(new Integer JavaDoc(1000)).and(
207             q.descend("orString").constrain("joho"))
208         ).not();
209         Object JavaDoc[] r = store();
210         st.expect(q, new Object JavaDoc[] { r[0], r[3], r[4]});
211     }
212     
213     public void testNotOrAndOr() {
214         Query q = st.query();
215         q.constrain(new STOrT(0, null));
216         (
217             q.descend("orInt").constrain(new Integer JavaDoc(5)).or(
218             q.descend("orString").constrain(null))
219         ).and(
220             q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
221             q.descend("orString").constrain("joho"))
222         ).not();
223         Object JavaDoc[] r = store();
224         st.expect(q, new Object JavaDoc[] { r[0], r[1], r[2], r[3]});
225     }
226     
227     public void testNotOrOrAnd() {
228         Query q = st.query();
229         q.constrain(new STOrT(0, null));
230         (
231             q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
232             q.descend("orString").constrain("joho"))
233         ).or(
234             q.descend("orInt").constrain(new Integer JavaDoc(5)).and(
235             q.descend("orString").constrain(null))
236         ).not();
237         Object JavaDoc[] r = store();
238         st.expect(q, new Object JavaDoc[] { r[0], r[3]});
239     }
240     
241     public void testNotMultiOrAnd(){
242         Query q = st.query();
243         q.constrain(new STOrT(0, null));
244         (
245             (
246                 q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
247                 q.descend("orString").constrain("joho"))
248             ).or(
249                 q.descend("orInt").constrain(new Integer JavaDoc(5)).and(
250                 q.descend("orString").constrain("joho"))
251             )
252         ).or(
253             (
254                 q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
255                 q.descend("orString").constrain(null))
256             ).and(
257                 q.descend("orInt").constrain(new Integer JavaDoc(5)).or(
258                 q.descend("orString").constrain(null))
259             )
260         ).not();
261         Object JavaDoc[] r = store();
262         st.expect(q, new Object JavaDoc[] {r[0], r[3]});
263     }
264     
265     public void testOrNotAndOr() {
266         Query q = st.query();
267         q.constrain(new STOrT(0, null));
268         (
269             q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).or(
270             q.descend("orString").constrain("joho"))
271         ).not().and(
272             q.descend("orInt").constrain(new Integer JavaDoc(5)).or(
273             q.descend("orString").constrain(null))
274         );
275         Object JavaDoc[] r = store();
276         st.expect(q, new Object JavaDoc[] { r[1]});
277     }
278     
279     public void testAndNotAndAnd() {
280         Query q = st.query();
281         q.constrain(new STOrT(0, null));
282         (
283             q.descend("orInt").constrain(new Integer JavaDoc(Integer.MAX_VALUE - 1)).and(
284             q.descend("orString").constrain(null))
285         ).not().and(
286             q.descend("orInt").constrain(new Integer JavaDoc(5)).or(
287             q.descend("orString").constrain("osoo"))
288         );
289         Object JavaDoc[] r = store();
290         st.expect(q, new Object JavaDoc[] { r[1], r[3]});
291     }
292     
293 }
294
Popular Tags