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