001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.test.legacy.soda.classes.untypedhierarchy;
022:
023: import com.db4o.query.*;
024: import com.db4o.test.legacy.soda.*;
025:
026: /** RUH: RoundTrip Untyped Hierarchy */
027: public class STRUH1 implements STClass {
028:
029: public static transient SodaTest st;
030:
031: Object h2;
032: String foo1;
033:
034: public STRUH1() {
035: }
036:
037: public STRUH1(STRUH2 a2) {
038: h2 = a2;
039: }
040:
041: public STRUH1(String str) {
042: foo1 = str;
043: }
044:
045: public STRUH1(STRUH2 a2, String str) {
046: h2 = a2;
047: foo1 = str;
048: }
049:
050: public Object[] store() {
051:
052: STRUH1[] objects = { new STRUH1(), new STRUH1("str1"),
053: new STRUH1(new STRUH2()),
054: new STRUH1(new STRUH2("str2")),
055: new STRUH1(new STRUH2(new STRUH3("str3"))),
056: new STRUH1(new STRUH2(new STRUH3("str3"), "str2")) };
057: for (int i = 0; i < objects.length; i++) {
058: objects[i].adjustParents();
059:
060: }
061: return objects;
062: }
063:
064: /** this is the special part of this test: circular references */
065: void adjustParents() {
066: if (h2 != null) {
067: STRUH2 th2 = (STRUH2) h2;
068:
069: th2.parent = this ;
070: if (th2.h3 != null) {
071: STRUH3 th3 = (STRUH3) th2.h3;
072: th3.parent = th2;
073: th3.grandParent = this ;
074: }
075: }
076: }
077:
078: public void testStrNull() {
079: Query q = st.query();
080: q.constrain(new STRUH1());
081: q.descend("foo1").constrain(null);
082: Object[] r = store();
083: st.expect(q, new Object[] { r[0], r[2], r[3], r[4], r[5] });
084: }
085:
086: public void testBothNull() {
087: Query q = st.query();
088: q.constrain(new STRUH1());
089: q.descend("foo1").constrain(null);
090: q.descend("h2").constrain(null);
091: st.expectOne(q, store()[0]);
092: }
093:
094: public void testDescendantNotNull() {
095: Query q = st.query();
096: Object[] r = store();
097: q.constrain(new STRUH1());
098: q.descend("h2").constrain(null).not();
099: st.expect(q, new Object[] { r[2], r[3], r[4], r[5] });
100: }
101:
102: public void testDescendantDescendantNotNull() {
103: Query q = st.query();
104: Object[] r = store();
105: q.constrain(new STRUH1());
106: q.descend("h2").descend("h3").constrain(null).not();
107: st.expect(q, new Object[] { r[4], r[5] });
108: }
109:
110: public void testDescendantExists() {
111: Query q = st.query();
112: Object[] r = store();
113: q.constrain(r[2]);
114: st.expect(q, new Object[] { r[2], r[3], r[4], r[5] });
115: }
116:
117: public void testDescendantValue() {
118: Query q = st.query();
119: Object[] r = store();
120: q.constrain(r[3]);
121: st.expect(q, new Object[] { r[3], r[5] });
122: }
123:
124: public void testDescendantDescendantExists() {
125: Query q = st.query();
126: Object[] r = store();
127: q.constrain(new STRUH1(new STRUH2(new STRUH3())));
128: st.expect(q, new Object[] { r[4], r[5] });
129: }
130:
131: public void testDescendantDescendantValue() {
132: Query q = st.query();
133: Object[] r = store();
134: q.constrain(new STRUH1(new STRUH2(new STRUH3("str3"))));
135: st.expect(q, new Object[] { r[4], r[5] });
136: }
137:
138: public void testDescendantDescendantStringPath() {
139: Query q = st.query();
140: Object[] r = store();
141: q.constrain(new STRUH1());
142: q.descend("h2").descend("h3").descend("foo3").constrain("str3");
143: st.expect(q, new Object[] { r[4], r[5] });
144: }
145:
146: public void testSequentialAddition() {
147: Query q = st.query();
148: Object[] r = store();
149: q.constrain(new STRUH1());
150: Query cur = q.descend("h2");
151: cur.constrain(new STRUH2());
152: cur.descend("foo2").constrain("str2");
153: cur = cur.descend("h3");
154: cur.constrain(new STRUH3());
155: cur.descend("foo3").constrain("str3");
156: st.expectOne(q, store()[5]);
157: }
158:
159: public void testTwoLevelOr() {
160: Query q = st.query();
161: Object[] r = store();
162: q.constrain(new STRUH1("str1"));
163: q.descend("foo1").constraints().or(
164: q.descend("h2").descend("h3").descend("foo3")
165: .constrain("str3"));
166: st.expect(q, new Object[] { r[1], r[4], r[5] });
167: }
168:
169: public void testThreeLevelOr() {
170: Query q = st.query();
171: Object[] r = store();
172: q.constrain(new STRUH1("str1"));
173: q.descend("foo1").constraints().or(
174: q.descend("h2").descend("foo2").constrain("str2")).or(
175: q.descend("h2").descend("h3").descend("foo3")
176: .constrain("str3"));
177: st.expect(q, new Object[] { r[1], r[3], r[4], r[5] });
178: }
179: }
|