KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > legacy > soda > deepOR > STOrContains


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.deepOR;
22
23 import java.util.*;
24
25 import com.db4o.query.*;
26 import com.db4o.test.legacy.soda.*;
27
28 public class STOrContains implements STClass {
29
30     public static transient SodaTest st;
31     
32     SodaTest pm;
33     
34     String JavaDoc name;
35     ArrayList al1;
36     ArrayList al2;
37     
38     public STOrContains() {
39     }
40     
41     public STOrContains(String JavaDoc name, Object JavaDoc[] l1, Object JavaDoc[] l2) {
42         this.name = name;
43         al1 = new ArrayList();
44         if(l1 != null){
45             for (int i = 0; i < l1.length; i++) {
46                 al1.add(l1[i]);
47             }
48         }
49         al2 = new ArrayList();
50         if(l2 != null){
51             for (int i = 0; i < l2.length; i++) {
52                 al2.add(l2[i]);
53             }
54         }
55         
56     }
57
58     public Object JavaDoc[] store() {
59         return new Object JavaDoc[] {
60             new STOrContains("one", new Object JavaDoc[] {
61                 new Named("Marcus"),
62                 new Named("8"),
63                 new Named("Woohaa")
64             }, new Object JavaDoc[] {
65                 new Named("one"),
66                 new Named("two"),
67                 new Named("three")
68             }),
69             new STOrContains("two", new Object JavaDoc[] {
70                 new Named("one"),
71                 new Named("two"),
72                 new Named("three")
73             }, new Object JavaDoc[] {
74                 new Named("Marcus"),
75                 new Named("8"),
76                 new Named("Woohaa")
77             }),
78             new STOrContains("three", new Object JavaDoc[] {
79                 new Named("is"),
80                 new Named("this"),
81                 new Named("true")
82             }, new Object JavaDoc[] {
83                 new Named("no"),
84                 new Named("ho"),
85                 new Named("wo")
86             })
87             };
88     }
89
90     public void testNoneFound() {
91         Query q = st.query();
92         q.constrain(STOrContains.class);
93         Query name1 = q.descend("al1").descend("name");
94         Query name2 = q.descend("al2").descend("name");
95         name1.constrain("hugolo").or(name2.constrain("hugoli"));
96         Object JavaDoc[] r = store();
97         st.expectNone(q);
98     }
99     
100     public void testOneFound() {
101         Query q = st.query();
102         q.constrain(STOrContains.class);
103         Query name1 = q.descend("al1").descend("name");
104         Query name2 = q.descend("al2").descend("name");
105         name1.constrain("Woohaa").or(name2.constrain("Woohaa"));
106         Object JavaDoc[] r = store();
107         st.expect(q, new Object JavaDoc[] { r[0], r[1] });
108     }
109     
110     public void testBothFound() {
111         Query q = st.query();
112         q.constrain(STOrContains.class);
113         Query name1 = q.descend("al1").descend("name");
114         Query name2 = q.descend("al2").descend("name");
115         name1.constrain("Marcus").or(name2.constrain("three"));
116         Object JavaDoc[] r = store();
117         st.expect(q, new Object JavaDoc[] { r[0]});
118     }
119     
120     
121     public void testMoreOr1(){
122         Query q = st.query();
123         q.constrain(STOrContains.class);
124         Query name1 = q.descend("al1").descend("name");
125         Query name2 = q.descend("al2").descend("name");
126         name1.constrain("Marcus")
127         .or(name2.constrain("three"))
128         .or(q.descend("name").constrain("three"));
129         Object JavaDoc[] r = store();
130         st.expect(q, new Object JavaDoc[] { r[0], r[2]});
131     }
132     
133     public void testMoreOr2(){
134         Query q = st.query();
135         q.constrain(STOrContains.class);
136         Query name1 = q.descend("al1").descend("name");
137         Query name2 = q.descend("al2").descend("name");
138         name1.constrain("Marcus")
139         .or(name2.constrain("wo"))
140         .or(q.descend("name").constrain("three"));
141         Object JavaDoc[] r = store();
142         st.expect(q, new Object JavaDoc[] { r[0], r[2]});
143     }
144     
145     public static class Named{
146         String JavaDoc name;
147         
148         public Named(){
149         }
150         
151         public Named(String JavaDoc name){
152             this.name = name;
153         }
154     }
155
156 }
157
158
159
Popular Tags