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.deepOR;
022:
023: import java.util.*;
024:
025: import com.db4o.query.*;
026: import com.db4o.test.legacy.soda.*;
027:
028: public class STOrContains implements STClass {
029:
030: public static transient SodaTest st;
031:
032: SodaTest pm;
033:
034: String name;
035: ArrayList al1;
036: ArrayList al2;
037:
038: public STOrContains() {
039: }
040:
041: public STOrContains(String name, Object[] l1, Object[] l2) {
042: this .name = name;
043: al1 = new ArrayList();
044: if (l1 != null) {
045: for (int i = 0; i < l1.length; i++) {
046: al1.add(l1[i]);
047: }
048: }
049: al2 = new ArrayList();
050: if (l2 != null) {
051: for (int i = 0; i < l2.length; i++) {
052: al2.add(l2[i]);
053: }
054: }
055:
056: }
057:
058: public Object[] store() {
059: return new Object[] {
060: new STOrContains("one", new Object[] {
061: new Named("Marcus"), new Named("8"),
062: new Named("Woohaa") }, new Object[] {
063: new Named("one"), new Named("two"),
064: new Named("three") }),
065: new STOrContains("two", new Object[] {
066: new Named("one"), new Named("two"),
067: new Named("three") }, new Object[] {
068: new Named("Marcus"), new Named("8"),
069: new Named("Woohaa") }),
070: new STOrContains("three", new Object[] {
071: new Named("is"), new Named("this"),
072: new Named("true") }, new Object[] {
073: new Named("no"), new Named("ho"),
074: new Named("wo") }) };
075: }
076:
077: public void testNoneFound() {
078: Query q = st.query();
079: q.constrain(STOrContains.class);
080: Query name1 = q.descend("al1").descend("name");
081: Query name2 = q.descend("al2").descend("name");
082: name1.constrain("hugolo").or(name2.constrain("hugoli"));
083: Object[] r = store();
084: st.expectNone(q);
085: }
086:
087: public void testOneFound() {
088: Query q = st.query();
089: q.constrain(STOrContains.class);
090: Query name1 = q.descend("al1").descend("name");
091: Query name2 = q.descend("al2").descend("name");
092: name1.constrain("Woohaa").or(name2.constrain("Woohaa"));
093: Object[] r = store();
094: st.expect(q, new Object[] { r[0], r[1] });
095: }
096:
097: public void testBothFound() {
098: Query q = st.query();
099: q.constrain(STOrContains.class);
100: Query name1 = q.descend("al1").descend("name");
101: Query name2 = q.descend("al2").descend("name");
102: name1.constrain("Marcus").or(name2.constrain("three"));
103: Object[] r = store();
104: st.expect(q, new Object[] { r[0] });
105: }
106:
107: public void testMoreOr1() {
108: Query q = st.query();
109: q.constrain(STOrContains.class);
110: Query name1 = q.descend("al1").descend("name");
111: Query name2 = q.descend("al2").descend("name");
112: name1.constrain("Marcus").or(name2.constrain("three")).or(
113: q.descend("name").constrain("three"));
114: Object[] r = store();
115: st.expect(q, new Object[] { r[0], r[2] });
116: }
117:
118: public void testMoreOr2() {
119: Query q = st.query();
120: q.constrain(STOrContains.class);
121: Query name1 = q.descend("al1").descend("name");
122: Query name2 = q.descend("al2").descend("name");
123: name1.constrain("Marcus").or(name2.constrain("wo")).or(
124: q.descend("name").constrain("three"));
125: Object[] r = store();
126: st.expect(q, new Object[] { r[0], r[2] });
127: }
128:
129: public static class Named {
130: String name;
131:
132: public Named() {
133: }
134:
135: public Named(String name) {
136: this.name = name;
137: }
138: }
139:
140: }
|