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.simple;
022:
023: import com.db4o.*;
024: import com.db4o.query.*;
025: import com.db4o.test.legacy.soda.*;
026:
027: public class STInteger implements STClass1 {
028:
029: public static transient SodaTest st;
030:
031: public int i_int;
032:
033: public STInteger() {
034: }
035:
036: private STInteger(int a_int) {
037: i_int = a_int;
038: }
039:
040: public Object[] store() {
041: return new Object[] { new STInteger(0), new STInteger(1),
042: new STInteger(99), new STInteger(909) };
043: }
044:
045: public void testEquals() {
046: Query q = st.query();
047: q.constrain(new STInteger(0));
048:
049: // Primitive default values are ignored, so we need an
050: // additional constraint:
051: q.descend("i_int").constrain(new Integer(0));
052: st.expectOne(q, store()[0]);
053: }
054:
055: public void testNotEquals() {
056: Query q = st.query();
057: Object[] r = store();
058: Constraint c = q.constrain(r[0]);
059: q.descend("i_int").constrain(new Integer(0)).not();
060: st.expect(q, new Object[] { r[1], r[2], r[3] });
061: }
062:
063: public void testGreater() {
064: Query q = st.query();
065: Constraint c = q.constrain(new STInteger(9));
066: q.descend("i_int").constraints().greater();
067: Object[] r = store();
068: st.expect(q, new Object[] { r[2], r[3] });
069: }
070:
071: public void testSmaller() {
072: Query q = st.query();
073: Constraint c = q.constrain(new STInteger(1));
074: q.descend("i_int").constraints().smaller();
075: st.expectOne(q, store()[0]);
076: }
077:
078: public void testContains() {
079: Query q = st.query();
080: Constraint c = q.constrain(new STInteger(9));
081: q.descend("i_int").constraints().contains();
082: Object[] r = store();
083: st.expect(q, new Object[] { r[2], r[3] });
084: }
085:
086: public void testNotContains() {
087: Query q = st.query();
088: Constraint c = q.constrain(new STInteger(0));
089: q.descend("i_int").constrain(new Integer(0)).contains().not();
090: Object[] r = store();
091: st.expect(q, new Object[] { r[1], r[2] });
092: }
093:
094: public void testLike() {
095: Query q = st.query();
096: Constraint c = q.constrain(new STInteger(90));
097: q.descend("i_int").constraints().like();
098: st.expectOne(q, new STInteger(909));
099: q = st.query();
100: c = q.constrain(new STInteger(10));
101: q.descend("i_int").constraints().like();
102: st.expectNone(q);
103: }
104:
105: public void testNotLike() {
106: Query q = st.query();
107: Constraint c = q.constrain(new STInteger(1));
108: q.descend("i_int").constraints().like().not();
109: Object[] r = store();
110: st.expect(q, new Object[] { r[0], r[2], r[3] });
111: }
112:
113: public void testIdentity() {
114: Query q = st.query();
115: Constraint c = q.constrain(new STInteger(1));
116: ObjectSet set = q.execute();
117: STInteger identityConstraint = (STInteger) set.next();
118: identityConstraint.i_int = 9999;
119: q = st.query();
120: q.constrain(identityConstraint).identity();
121: identityConstraint.i_int = 1;
122: st.expectOne(q, store()[1]);
123: }
124:
125: public void testNotIdentity() {
126: Query q = st.query();
127: Constraint c = q.constrain(new STInteger(1));
128: ObjectSet set = q.execute();
129: STInteger identityConstraint = (STInteger) set.next();
130: identityConstraint.i_int = 9080;
131: q = st.query();
132: q.constrain(identityConstraint).identity().not();
133: identityConstraint.i_int = 1;
134: Object[] r = store();
135: st.expect(q, new Object[] { r[0], r[2], r[3] });
136: }
137:
138: public void testConstraints() {
139: Query q = st.query();
140: q.constrain(new STInteger(1));
141: q.constrain(new STInteger(0));
142: Constraints cs = q.constraints();
143: Constraint[] csa = cs.toArray();
144: if (csa.length != 2) {
145: st.error("Constraints not returned");
146: }
147: }
148:
149: }
|