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