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.untyped;
022:
023: import com.db4o.*;
024: import com.db4o.query.*;
025: import com.db4o.test.legacy.soda.*;
026:
027: public class STCharWU implements STClass {
028:
029: final static String DESCENDANT = "i_char";
030:
031: public static transient SodaTest st;
032:
033: Object i_char;
034:
035: public STCharWU() {
036: }
037:
038: private STCharWU(char a_char) {
039: i_char = new Character(a_char);
040: }
041:
042: public Object[] store() {
043: return new Object[] { new STCharWU((char) 0),
044: new STCharWU((char) 1), new STCharWU((char) 99),
045: new STCharWU((char) 909) };
046: }
047:
048: public void testEquals() {
049: Query q = st.query();
050: q.constrain(new STCharWU((char) 0));
051:
052: // Primitive default values are ignored, so we need an
053: // additional constraint:
054: q.descend(DESCENDANT).constrain(new Character((char) 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 STCharWU((char) 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 STCharWU((char) 1));
077: q.descend(DESCENDANT).constraints().smaller();
078: st.expectOne(q, store()[0]);
079: }
080:
081: public void testIdentity() {
082: Query q = st.query();
083: Constraint c = q.constrain(new STCharWU((char) 1));
084: ObjectSet set = q.execute();
085: STCharWU identityConstraint = (STCharWU) set.next();
086: identityConstraint.i_char = new Character((char) 9999);
087: q = st.query();
088: q.constrain(identityConstraint).identity();
089: identityConstraint.i_char = new Character((char) 1);
090: st.expectOne(q, store()[1]);
091: }
092:
093: public void testNotIdentity() {
094: Query q = st.query();
095: Constraint c = q.constrain(new STCharWU((char) 1));
096: ObjectSet set = q.execute();
097: STCharWU identityConstraint = (STCharWU) set.next();
098: identityConstraint.i_char = new Character((char) 9080);
099: q = st.query();
100: q.constrain(identityConstraint).identity().not();
101: identityConstraint.i_char = new Character((char) 1);
102: Object[] r = store();
103: st.expect(q, new Object[] { r[0], r[2], r[3] });
104: }
105:
106: public void testConstraints() {
107: Query q = st.query();
108: q.constrain(new STCharWU((char) 1));
109: q.constrain(new STCharWU((char) 0));
110: Constraints cs = q.constraints();
111: Constraint[] csa = cs.toArray();
112: if (csa.length != 2) {
113: st.error("Constraints not returned");
114: }
115: }
116:
117: public void testEvaluation() {
118: Query q = st.query();
119: q.constrain(new STCharWU());
120: q.constrain(new Evaluation() {
121: public void evaluate(Candidate candidate) {
122: STCharWU sts = (STCharWU) candidate.getObject();
123: candidate
124: .include((((Character) sts.i_char).charValue() + 2) > 100);
125: }
126: });
127: Object[] r = store();
128: st.expect(q, new Object[] { r[2], r[3] });
129: }
130:
131: }
|