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: /** ETH: Extends Typed Hierarchy */
027: public class STETH1 implements STClass {
028:
029: public static transient SodaTest st;
030:
031: String foo1;
032:
033: public STETH1() {
034: }
035:
036: public STETH1(String str) {
037: foo1 = str;
038: }
039:
040: public Object[] store() {
041: return new Object[] { new STETH1(), new STETH1("str1"),
042: new STETH2(), new STETH2("str1", "str2"), new STETH3(),
043: new STETH3("str1a", "str2", "str3"),
044: new STETH3("str1a", "str2a", null), new STETH4(),
045: new STETH4("str1a", "str2", "str4"),
046: new STETH4("str1b", "str2a", "str4") };
047: }
048:
049: public void testStrNull() {
050: Query q = st.query();
051: q.constrain(new STETH1());
052: q.descend("foo1").constrain(null);
053: Object[] r = store();
054: st.expect(q, new Object[] { r[0], r[2], r[4], r[7] });
055: }
056:
057: public void testTwoNull() {
058: Query q = st.query();
059: q.constrain(new STETH1());
060: q.descend("foo1").constrain(null);
061: q.descend("foo3").constrain(null);
062: Object[] r = store();
063: st.expect(q, new Object[] { r[0], r[2], r[4], r[7] });
064: }
065:
066: public void testClass() {
067: Query q = st.query();
068: q.constrain(STETH2.class);
069: Object[] r = store();
070: st.expect(q, new Object[] { r[2], r[3], r[4], r[5], r[6], r[7],
071: r[8], r[9] });
072: }
073:
074: public void testOrClass() {
075: Query q = st.query();
076: q.constrain(STETH3.class).or(q.constrain(STETH4.class));
077: Object[] r = store();
078: st.expect(q,
079: new Object[] { r[4], r[5], r[6], r[7], r[8], r[9] });
080: }
081:
082: public void testAndClass() {
083: Query q = st.query();
084: q.constrain(STETH1.class);
085: q.constrain(STETH4.class);
086: Object[] r = store();
087: st.expect(q, new Object[] { r[7], r[8], r[9] });
088: }
089:
090: public void testParalellDescendantPaths() {
091: Query q = st.query();
092: q.constrain(STETH3.class).or(q.constrain(STETH4.class));
093: q.descend("foo3").constrain("str3").or(
094: q.descend("foo4").constrain("str4"));
095: Object[] r = store();
096: st.expect(q, new Object[] { r[5], r[8], r[9] });
097: }
098:
099: public void testOrObjects() {
100: Query q = st.query();
101: Object[] r = store();
102: q.constrain(r[3]).or(q.constrain(r[5]));
103: st.expect(q, new Object[] { r[3], r[5] });
104: }
105:
106: }
|