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: import com.db4o.test.legacy.soda.classes.typedhierarchy.*;
026:
027: /** UH: Untyped Hierarchy */
028: public class STUH1 implements STClass {
029:
030: public static transient SodaTest st;
031:
032: Object h2;
033: Object foo1;
034:
035: public STUH1() {
036: }
037:
038: public STUH1(STUH2 a2) {
039: h2 = a2;
040: }
041:
042: public STUH1(String str) {
043: foo1 = str;
044: }
045:
046: public STUH1(STUH2 a2, String str) {
047: h2 = a2;
048: foo1 = str;
049: }
050:
051: public Object[] store() {
052: return new Object[] { new STUH1(), new STUH1("str1"),
053: new STUH1(new STUH2()), new STUH1(new STUH2("str2")),
054: new STUH1(new STUH2(new STUH3("str3"))),
055: new STUH1(new STUH2(new STUH3("str3"), "str2")), };
056: }
057:
058: public void testStrNull() {
059: Query q = st.query();
060: q.constrain(new STUH1());
061: q.descend("foo1").constrain(null);
062: Object[] r = store();
063: st.expect(q, new Object[] { r[0], r[2], r[3], r[4], r[5] });
064: }
065:
066: public void testBothNull() {
067: Query q = st.query();
068: q.constrain(new STUH1());
069: q.descend("foo1").constrain(null);
070: q.descend("h2").constrain(null);
071: st.expectOne(q, store()[0]);
072: }
073:
074: public void testDescendantNotNull() {
075: Query q = st.query();
076: Object[] r = store();
077: q.constrain(new STUH1());
078: q.descend("h2").constrain(null).not();
079: st.expect(q, new Object[] { r[2], r[3], r[4], r[5] });
080: }
081:
082: public void testDescendantDescendantNotNull() {
083: Query q = st.query();
084: Object[] r = store();
085: q.constrain(new STUH1());
086: q.descend("h2").descend("h3").constrain(null).not();
087: st.expect(q, new Object[] { r[4], r[5] });
088: }
089:
090: public void testDescendantExists() {
091: Query q = st.query();
092: Object[] r = store();
093: q.constrain(r[2]);
094: st.expect(q, new Object[] { r[2], r[3], r[4], r[5] });
095: }
096:
097: public void testDescendantValue() {
098: Query q = st.query();
099: Object[] r = store();
100: q.constrain(r[3]);
101: st.expect(q, new Object[] { r[3], r[5] });
102: }
103:
104: public void testDescendantDescendantExists() {
105: Query q = st.query();
106: Object[] r = store();
107: q.constrain(new STUH1(new STUH2(new STUH3())));
108: st.expect(q, new Object[] { r[4], r[5] });
109: }
110:
111: public void testDescendantDescendantValue() {
112: Query q = st.query();
113: Object[] r = store();
114: q.constrain(new STUH1(new STUH2(new STUH3("str3"))));
115: st.expect(q, new Object[] { r[4], r[5] });
116: }
117:
118: public void testDescendantDescendantStringPath() {
119: Query q = st.query();
120: Object[] r = store();
121: q.constrain(new STUH1());
122: q.descend("h2").descend("h3").descend("foo3").constrain("str3");
123: st.expect(q, new Object[] { r[4], r[5] });
124: }
125:
126: public void testSequentialAddition() {
127: Query q = st.query();
128: q.constrain(new STUH1());
129: Object[] r = store();
130: Query cur = q.descend("h2");
131: cur.constrain(new STUH2());
132: cur.descend("foo2").constrain("str2");
133: cur = cur.descend("h3");
134: cur.constrain(new STUH3());
135: cur.descend("foo3").constrain("str3");
136: st.expectOne(q, store()[5]);
137: }
138:
139: public void testTwoLevelOr() {
140: Query q = st.query();
141: Object[] r = store();
142: q.constrain(new STUH1("str1"));
143: q.descend("foo1").constraints().or(
144: q.descend("h2").descend("h3").descend("foo3")
145: .constrain("str3"));
146: st.expect(q, new Object[] { r[1], r[4], r[5] });
147: }
148:
149: public void testThreeLevelOr() {
150: Query q = st.query();
151: Object[] r = store();
152: q.constrain(new STUH1("str1"));
153: q.descend("foo1").constraints().or(
154: q.descend("h2").descend("foo2").constrain("str2")).or(
155: q.descend("h2").descend("h3").descend("foo3")
156: .constrain("str3"));
157:
158: st.expect(q, new Object[] { r[1], r[3], r[4], r[5] });
159: }
160:
161: public void testNonExistentDescendant() {
162: Query q = st.query();
163: STUH1 constraint = new STUH1();
164: constraint.foo1 = new STETH2();
165: q.constrain(constraint);
166: st.expectNone(q);
167: }
168:
169: }
|