KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > legacy > soda > wrapper > typed > STShortWT


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.test.legacy.soda.wrapper.typed;
22
23 import com.db4o.*;
24 import com.db4o.query.*;
25 import com.db4o.test.legacy.soda.*;
26
27 public class STShortWT implements STClass{
28     
29     final static String JavaDoc DESCENDANT = "i_short";
30     
31     public static transient SodaTest st;
32     
33     Short JavaDoc i_short;
34     
35     
36     public STShortWT(){
37     }
38     
39     private STShortWT(short a_short){
40         i_short = new Short JavaDoc(a_short);
41     }
42     
43     public Object JavaDoc[] store() {
44         return new Object JavaDoc[]{
45             new STShortWT((short)0),
46             new STShortWT((short)1),
47             new STShortWT((short)99),
48             new STShortWT((short)909)
49         };
50     }
51     
52     public void testEquals(){
53         Query q = st.query();
54         q.constrain(new STShortWT((short)0));
55         
56         // Primitive default values are ignored, so we need an
57
// additional constraint:
58
q.descend(DESCENDANT).constrain(new Short JavaDoc((short)0));
59         st.expectOne(q, store()[0]);
60     }
61     
62     public void testNotEquals(){
63         Query q = st.query();
64         Object JavaDoc[] r = store();
65         Constraint c = q.constrain(r[0]);
66         q.descend(DESCENDANT).constraints().not();
67         st.expect(q, new Object JavaDoc[] {r[1], r[2], r[3]});
68     }
69     
70     public void testGreater(){
71         Query q = st.query();
72         Constraint c = q.constrain(new STShortWT((short)9));
73         q.descend(DESCENDANT).constraints().greater();
74         Object JavaDoc[] r = store();
75         st.expect(q, new Object JavaDoc[] {r[2], r[3]});
76     }
77     
78     public void testSmaller(){
79         Query q = st.query();
80         Constraint c = q.constrain(new STShortWT((short)1));
81         q.descend(DESCENDANT).constraints().smaller();
82         st.expectOne(q, store()[0]);
83     }
84     
85     public void testContains(){
86         Query q = st.query();
87         Constraint c = q.constrain(new STShortWT((short)9));
88         q.descend(DESCENDANT).constraints().contains();
89         Object JavaDoc[] r = store();
90         st.expect(q, new Object JavaDoc[] {r[2], r[3]});
91     }
92     
93     public void testNotContains(){
94         Query q = st.query();
95         Constraint c = q.constrain(new STShortWT((short)0));
96         q.descend(DESCENDANT).constraints().contains().not();
97         Object JavaDoc[] r = store();
98         st.expect(q, new Object JavaDoc[] {r[1], r[2]});
99     }
100     
101     public void testLike(){
102         Query q = st.query();
103         Constraint c = q.constrain(new STShortWT((short)90));
104         q.descend(DESCENDANT).constraints().like();
105         st.expectOne(q, store()[3]);
106         q = st.query();
107         c = q.constrain(new STShortWT((short)10));
108         q.descend(DESCENDANT).constraints().like();
109         st.expectNone(q);
110     }
111     
112     public void testNotLike(){
113         Query q = st.query();
114         Constraint c = q.constrain(new STShortWT((short)1));
115         q.descend(DESCENDANT).constraints().like().not();
116         Object JavaDoc[] r = store();
117         st.expect(q, new Object JavaDoc[] {r[0], r[2], r[3]});
118     }
119     
120     public void testIdentity(){
121         Query q = st.query();
122         Constraint c = q.constrain(new STShortWT((short)1));
123         ObjectSet set = q.execute();
124         STShortWT identityConstraint = (STShortWT)set.next();
125         identityConstraint.i_short = new Short JavaDoc((short)9999);
126         q = st.query();
127         q.constrain(identityConstraint).identity();
128         identityConstraint.i_short = new Short JavaDoc((short)1);
129         st.expectOne(q,store()[1]);
130     }
131     
132     public void testNotIdentity(){
133         Query q = st.query();
134         Constraint c = q.constrain(new STShortWT((short)1));
135         ObjectSet set = q.execute();
136         STShortWT identityConstraint = (STShortWT)set.next();
137         identityConstraint.i_short = new Short JavaDoc((short)9080);
138         q = st.query();
139         q.constrain(identityConstraint).identity().not();
140         identityConstraint.i_short = new Short JavaDoc((short)1);
141         Object JavaDoc[] r = store();
142         st.expect(q, new Object JavaDoc[] {r[0], r[2], r[3]});
143     }
144     
145     public void testConstraints(){
146         Query q = st.query();
147         q.constrain(new STShortWT((short)1));
148         q.constrain(new STShortWT((short)0));
149         Constraints cs = q.constraints();
150         Constraint[] csa = cs.toArray();
151         if(csa.length != 2){
152             st.error("Constraints not returned");
153         }
154     }
155     
156     public void testEvaluation(){
157         Query q = st.query();
158         q.constrain(new STShortWT());
159         q.constrain(new Evaluation() {
160             public void evaluate(Candidate candidate) {
161                 STShortWT sts = (STShortWT)candidate.getObject();
162                 candidate.include((sts.i_short.shortValue() + 2) > 100);
163             }
164         });
165         Object JavaDoc[] r = store();
166         st.expect(q, new Object JavaDoc[] {r[2], r[3]});
167     }
168     
169 }
170
171
Popular Tags