KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > legacy > soda > classes > untypedhierarchy > STUH1


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.classes.untypedhierarchy;
22
23 import com.db4o.query.*;
24 import com.db4o.test.legacy.soda.*;
25 import com.db4o.test.legacy.soda.classes.typedhierarchy.*;
26
27
28 /** UH: Untyped Hierarchy */
29 public class STUH1 implements STClass {
30
31     public static transient SodaTest st;
32     
33     Object JavaDoc h2;
34     Object JavaDoc foo1;
35
36     public STUH1() {
37     }
38
39     public STUH1(STUH2 a2) {
40         h2 = a2;
41     }
42
43     public STUH1(String JavaDoc str) {
44         foo1 = str;
45     }
46
47     public STUH1(STUH2 a2, String JavaDoc str) {
48         h2 = a2;
49         foo1 = str;
50     }
51
52     public Object JavaDoc[] store() {
53         return new Object JavaDoc[] {
54             new STUH1(),
55             new STUH1("str1"),
56             new STUH1(new STUH2()),
57             new STUH1(new STUH2("str2")),
58             new STUH1(new STUH2(new STUH3("str3"))),
59             new STUH1(new STUH2(new STUH3("str3"), "str2")),
60             };
61     }
62
63     public void testStrNull() {
64         Query q = st.query();
65         q.constrain(new STUH1());
66         q.descend("foo1").constrain(null);
67         Object JavaDoc[] r = store();
68         st.expect(q, new Object JavaDoc[] { r[0], r[2], r[3], r[4], r[5] });
69     }
70
71     public void testBothNull() {
72         Query q = st.query();
73         q.constrain(new STUH1());
74         q.descend("foo1").constrain(null);
75         q.descend("h2").constrain(null);
76         st.expectOne(q, store()[0]);
77     }
78
79     public void testDescendantNotNull() {
80         Query q = st.query();
81         Object JavaDoc[] r = store();
82         q.constrain(new STUH1());
83         q.descend("h2").constrain(null).not();
84         st.expect(q, new Object JavaDoc[] { r[2], r[3], r[4], r[5] });
85     }
86
87     public void testDescendantDescendantNotNull() {
88         Query q = st.query();
89         Object JavaDoc[] r = store();
90         q.constrain(new STUH1());
91         q.descend("h2").descend("h3").constrain(null).not();
92         st.expect(q, new Object JavaDoc[] { r[4], r[5] });
93     }
94
95     public void testDescendantExists() {
96         Query q = st.query();
97         Object JavaDoc[] r = store();
98         q.constrain(r[2]);
99         st.expect(q, new Object JavaDoc[] { r[2], r[3], r[4], r[5] });
100     }
101
102     public void testDescendantValue() {
103         Query q = st.query();
104         Object JavaDoc[] r = store();
105         q.constrain(r[3]);
106         st.expect(q, new Object JavaDoc[] { r[3], r[5] });
107     }
108
109     public void testDescendantDescendantExists() {
110         Query q = st.query();
111         Object JavaDoc[] r = store();
112         q.constrain(new STUH1(new STUH2(new STUH3())));
113         st.expect(q, new Object JavaDoc[] { r[4], r[5] });
114     }
115
116     public void testDescendantDescendantValue() {
117         Query q = st.query();
118         Object JavaDoc[] r = store();
119         q.constrain(new STUH1(new STUH2(new STUH3("str3"))));
120         st.expect(q, new Object JavaDoc[] { r[4], r[5] });
121     }
122
123     public void testDescendantDescendantStringPath() {
124         Query q = st.query();
125         Object JavaDoc[] r = store();
126         q.constrain(new STUH1());
127         q.descend("h2").descend("h3").descend("foo3").constrain("str3");
128         st.expect(q, new Object JavaDoc[] { r[4], r[5] });
129     }
130
131     public void testSequentialAddition() {
132         Query q = st.query();
133         q.constrain(new STUH1());
134         Object JavaDoc[] r = store();
135         Query cur = q.descend("h2");
136         cur.constrain(new STUH2());
137         cur.descend("foo2").constrain("str2");
138         cur = cur.descend("h3");
139         cur.constrain(new STUH3());
140         cur.descend("foo3").constrain("str3");
141         st.expectOne(q, store()[5]);
142     }
143
144     public void testTwoLevelOr() {
145         Query q = st.query();
146         Object JavaDoc[] r = store();
147         q.constrain(new STUH1("str1"));
148         q.descend("foo1").constraints().or(
149             q.descend("h2").descend("h3").descend("foo3").constrain("str3"));
150         st.expect(q, new Object JavaDoc[] { r[1], r[4], r[5] });
151     }
152
153     public void testThreeLevelOr() {
154         Query q = st.query();
155         Object JavaDoc[] r = store();
156         q.constrain(new STUH1("str1"));
157         q.descend("foo1").constraints().or(
158             q.descend("h2").descend("foo2").constrain("str2")).or(
159             q.descend("h2").descend("h3").descend("foo3").constrain("str3"));
160
161         st.expect(q, new Object JavaDoc[] { r[1], r[3], r[4], r[5] });
162     }
163
164     public void testNonExistentDescendant() {
165         Query q = st.query();
166         STUH1 constraint = new STUH1();
167         constraint.foo1 = new STETH2();
168         q.constrain(constraint);
169         st.expectNone(q);
170     }
171
172 }
173
Popular Tags