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