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.joins.typed;
022:
023: import com.db4o.query.*;
024: import com.db4o.test.legacy.soda.*;
025:
026: public class STOrT implements STClass {
027:
028: public static transient SodaTest st;
029:
030: int orInt;
031: String orString;
032:
033: public STOrT() {
034: }
035:
036: private STOrT(int a_int, String a_string) {
037: orInt = a_int;
038: orString = a_string;
039: }
040:
041: public String toString() {
042: return "STOr: int:" + orInt + " str:" + orString;
043: }
044:
045: public Object[] store() {
046: return new Object[] { new STOrT(0, "hi"), new STOrT(5, null),
047: new STOrT(1000, "joho"), new STOrT(30000, "osoo"),
048: new STOrT(Integer.MAX_VALUE - 1, null), };
049: }
050:
051: public void testSmallerGreater() {
052: Query q = st.query();
053: q.constrain(new STOrT());
054: Query sub = q.descend("orInt");
055: sub.constrain(new Integer(30000)).greater().or(
056: sub.constrain(new Integer(5)).smaller());
057: Object[] r = store();
058: st.expect(q, new Object[] { r[0], r[4] });
059: }
060:
061: public void testGreaterGreater() {
062: Query q = st.query();
063: q.constrain(new STOrT());
064: Query sub = q.descend("orInt");
065: sub.constrain(new Integer(30000)).greater().or(
066: sub.constrain(new Integer(5)).greater());
067: Object[] r = store();
068: st.expect(q, new Object[] { r[2], r[3], r[4] });
069: }
070:
071: public void testGreaterEquals() {
072: Query q = st.query();
073: q.constrain(new STOrT());
074: Query sub = q.descend("orInt");
075: sub.constrain(new Integer(1000)).greater().or(
076: sub.constrain(new Integer(0)));
077: Object[] r = store();
078: st.expect(q, new Object[] { r[0], r[3], r[4] });
079: }
080:
081: public void testEqualsNull() {
082: Query q = st.query();
083: q.constrain(new STOrT(1000, null));
084: q.descend("orInt").constraints().or(
085: q.descend("orString").constrain(null));
086: Object[] r = store();
087: st.expect(q, new Object[] { r[1], r[2], r[4] });
088: }
089:
090: public void testAndOrAnd() {
091: Query q = st.query();
092: q.constrain(new STOrT(0, null));
093: (q.descend("orInt").constrain(new Integer(5)).and(q.descend(
094: "orString").constrain(null))).or(q.descend("orInt")
095: .constrain(new Integer(1000)).and(
096: q.descend("orString").constrain("joho")));
097: Object[] r = store();
098: st.expect(q, new Object[] { r[1], r[2] });
099: }
100:
101: public void testOrAndOr() {
102: Query q = st.query();
103: q.constrain(new STOrT(0, null));
104: (q.descend("orInt").constrain(new Integer(5)).or(q.descend(
105: "orString").constrain(null))).and(q.descend("orInt")
106: .constrain(new Integer(Integer.MAX_VALUE - 1)).or(
107: q.descend("orString").constrain("joho")));
108: st.expectOne(q, store()[4]);
109: }
110:
111: public void testOrOrAnd() {
112: Query q = st.query();
113: q.constrain(new STOrT(0, null));
114: (q.descend("orInt").constrain(
115: new Integer(Integer.MAX_VALUE - 1)).or(q.descend(
116: "orString").constrain("joho"))).or(q.descend("orInt")
117: .constrain(new Integer(5)).and(
118: q.descend("orString").constrain(null)));
119: Object[] r = store();
120: st.expect(q, new Object[] { r[1], r[2], r[4] });
121: }
122:
123: public void testMultiOrAnd() {
124: Query q = st.query();
125: q.constrain(new STOrT(0, null));
126: ((q.descend("orInt").constrain(
127: new Integer(Integer.MAX_VALUE - 1)).or(q.descend(
128: "orString").constrain("joho"))).or(q.descend("orInt")
129: .constrain(new Integer(5)).and(
130: q.descend("orString").constrain("joho"))))
131: .or((q.descend("orInt").constrain(
132: new Integer(Integer.MAX_VALUE - 1)).or(q
133: .descend("orString").constrain(null))).and(q
134: .descend("orInt").constrain(new Integer(5)).or(
135: q.descend("orString").constrain(null))));
136: Object[] r = store();
137: st.expect(q, new Object[] { r[1], r[2], r[4] });
138: }
139:
140: public void testNotSmallerGreater() {
141: Query q = st.query();
142: q.constrain(new STOrT());
143: Query sub = q.descend("orInt");
144: (sub.constrain(new Integer(30000)).greater().or(sub.constrain(
145: new Integer(5)).smaller())).not();
146: Object[] r = store();
147: st.expect(q, new Object[] { r[1], r[2], r[3] });
148: }
149:
150: public void testNotGreaterGreater() {
151: Query q = st.query();
152: q.constrain(new STOrT());
153: Query sub = q.descend("orInt");
154: (sub.constrain(new Integer(30000)).greater().or(sub.constrain(
155: new Integer(5)).greater())).not();
156: Object[] r = store();
157: st.expect(q, new Object[] { r[0], r[1] });
158: }
159:
160: public void testNotGreaterEquals() {
161: Query q = st.query();
162: q.constrain(new STOrT());
163: Query sub = q.descend("orInt");
164: (sub.constrain(new Integer(1000)).greater().or(sub
165: .constrain(new Integer(0)))).not();
166: Object[] r = store();
167: st.expect(q, new Object[] { r[1], r[2] });
168: }
169:
170: public void testNotEqualsNull() {
171: Query q = st.query();
172: q.constrain(new STOrT(1000, null));
173: (q.descend("orInt").constraints().or(q.descend("orString")
174: .constrain(null))).not();
175: Object[] r = store();
176: st.expect(q, new Object[] { r[0], r[3] });
177: }
178:
179: public void testNotAndOrAnd() {
180: Query q = st.query();
181: q.constrain(new STOrT(0, null));
182: (q.descend("orInt").constrain(new Integer(5)).and(q.descend(
183: "orString").constrain(null))).or(
184: q.descend("orInt").constrain(new Integer(1000)).and(
185: q.descend("orString").constrain("joho"))).not();
186: Object[] r = store();
187: st.expect(q, new Object[] { r[0], r[3], r[4] });
188: }
189:
190: public void testNotOrAndOr() {
191: Query q = st.query();
192: q.constrain(new STOrT(0, null));
193: (q.descend("orInt").constrain(new Integer(5)).or(q.descend(
194: "orString").constrain(null))).and(
195: q.descend("orInt").constrain(
196: new Integer(Integer.MAX_VALUE - 1)).or(
197: q.descend("orString").constrain("joho"))).not();
198: Object[] r = store();
199: st.expect(q, new Object[] { r[0], r[1], r[2], r[3] });
200: }
201:
202: public void testNotOrOrAnd() {
203: Query q = st.query();
204: q.constrain(new STOrT(0, null));
205: (q.descend("orInt").constrain(
206: new Integer(Integer.MAX_VALUE - 1)).or(q.descend(
207: "orString").constrain("joho"))).or(
208: q.descend("orInt").constrain(new Integer(5)).and(
209: q.descend("orString").constrain(null))).not();
210: Object[] r = store();
211: st.expect(q, new Object[] { r[0], r[3] });
212: }
213:
214: public void testNotMultiOrAnd() {
215: Query q = st.query();
216: q.constrain(new STOrT(0, null));
217: ((q.descend("orInt").constrain(
218: new Integer(Integer.MAX_VALUE - 1)).or(q.descend(
219: "orString").constrain("joho"))).or(q.descend("orInt")
220: .constrain(new Integer(5)).and(
221: q.descend("orString").constrain("joho"))))
222: .or(
223: (q.descend("orInt").constrain(
224: new Integer(Integer.MAX_VALUE - 1))
225: .or(q.descend("orString").constrain(
226: null))).and(q.descend("orInt")
227: .constrain(new Integer(5)).or(
228: q.descend("orString")
229: .constrain(null))))
230: .not();
231: Object[] r = store();
232: st.expect(q, new Object[] { r[0], r[3] });
233: }
234:
235: public void testOrNotAndOr() {
236: Query q = st.query();
237: q.constrain(new STOrT(0, null));
238: (q.descend("orInt").constrain(
239: new Integer(Integer.MAX_VALUE - 1)).or(q.descend(
240: "orString").constrain("joho"))).not().and(
241: q.descend("orInt").constrain(new Integer(5)).or(
242: q.descend("orString").constrain(null)));
243: Object[] r = store();
244: st.expect(q, new Object[] { r[1] });
245: }
246:
247: public void testAndNotAndAnd() {
248: Query q = st.query();
249: q.constrain(new STOrT(0, null));
250: (q.descend("orInt").constrain(
251: new Integer(Integer.MAX_VALUE - 1)).and(q.descend(
252: "orString").constrain(null))).not().and(
253: q.descend("orInt").constrain(new Integer(5)).or(
254: q.descend("orString").constrain("osoo")));
255: Object[] r = store();
256: st.expect(q, new Object[] { r[1], r[3] });
257: }
258:
259: }
|