KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > legacy > soda > classes > simple > STShort


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