KickJava   Java API By Example, From Geeks To Geeks.

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


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 STByte implements STClass1{
28     
29     final static String JavaDoc DESCENDANT = "i_byte";
30     
31     public static transient SodaTest st;
32     
33     public byte i_byte;
34     
35     
36     public STByte(){
37     }
38     
39     private STByte(byte a_byte){
40         i_byte = a_byte;
41     }
42     
43     public Object JavaDoc[] store() {
44         return new Object JavaDoc[]{
45             new STByte((byte)0),
46             new STByte((byte)1),
47             new STByte((byte)99),
48             new STByte((byte)113)
49         };
50     }
51     
52     public void testEquals(){
53         Query q = st.query();
54         q.constrain(new STByte((byte)0));
55         
56         // Primitive default values are ignored, so we need an
57
// additional constraint:
58
q.descend(DESCENDANT).constrain(new Byte JavaDoc((byte)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).constrain(new Byte JavaDoc((byte)0)).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 STByte((byte)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 STByte((byte)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 STByte((byte)9));
88         q.descend(DESCENDANT).constraints().contains();
89         Object JavaDoc[] r = store();
90         st.expect(q, new Object JavaDoc[] {r[2]});
91     }
92     
93     public void testNotContains(){
94         Query q = st.query();
95         Constraint c = q.constrain(new STByte((byte)0));
96         q.descend(DESCENDANT).constrain(new Byte JavaDoc((byte)0)).contains().not();
97         Object JavaDoc[] r = store();
98         st.expect(q, new Object JavaDoc[] {r[1], r[2], r[3]});
99     }
100     
101     public void testLike(){
102         Query q = st.query();
103         Constraint c = q.constrain(new STByte((byte)11));
104         q.descend(DESCENDANT).constraints().like();
105         st.expectOne(q, new STByte((byte)113));
106         q = st.query();
107         c = q.constrain(new STByte((byte)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 STByte((byte)1));
115         q.descend(DESCENDANT).constraints().like().not();
116         Object JavaDoc[] r = store();
117         st.expect(q, new Object JavaDoc[] {r[0], r[2]});
118     }
119     
120     public void testIdentity(){
121         Query q = st.query();
122         Constraint c = q.constrain(new STByte((byte)1));
123         ObjectSet set = q.execute();
124         STByte identityConstraint = (STByte)set.next();
125         identityConstraint.i_byte = 102;
126         q = st.query();
127         q.constrain(identityConstraint).identity();
128         identityConstraint.i_byte = 1;
129         st.expectOne(q,store()[1]);
130     }
131     
132     public void testNotIdentity(){
133         Query q = st.query();
134         Constraint c = q.constrain(new STByte((byte)1));
135         ObjectSet set = q.execute();
136         STByte identityConstraint = (STByte)set.next();
137         identityConstraint.i_byte = 102;
138         q = st.query();
139         q.constrain(identityConstraint).identity().not();
140         identityConstraint.i_byte = 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 STByte((byte)1));
148         q.constrain(new STByte((byte)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 }
157
158
Popular Tags