KickJava   Java API By Example, From Geeks To Geeks.

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


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 STChar implements STClass1{
28     
29     final static String JavaDoc DESCENDANT = "i_char";
30     
31     public static transient SodaTest st;
32     
33     public char i_char;
34     
35     public STChar(){
36     }
37     
38     private STChar(char a_char){
39         i_char = a_char;
40     }
41     
42     public Object JavaDoc[] store() {
43         return new Object JavaDoc[]{
44             new STChar((char)0),
45             new STChar((char)1),
46             new STChar((char)99),
47             new STChar((char)909)
48         };
49     }
50     
51     public void testEquals(){
52         Query q = st.query();
53         q.constrain(new STChar((char)0));
54         
55         // Primitive default values are ignored, so we need an
56
// additional constraint:
57
q.descend(DESCENDANT).constrain(new Character JavaDoc((char)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 Character JavaDoc((char)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 STChar((char)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 STChar((char)1));
80         q.descend(DESCENDANT).constraints().smaller();
81         st.expectOne(q, store()[0]);
82     }
83     
84     public void testIdentity(){
85         Query q = st.query();
86         Constraint c = q.constrain(new STChar((char)1));
87         ObjectSet set = q.execute();
88         STChar identityConstraint = (STChar)set.next();
89         identityConstraint.i_char = 9999;
90         q = st.query();
91         q.constrain(identityConstraint).identity();
92         identityConstraint.i_char = 1;
93         st.expectOne(q,store()[1]);
94     }
95     
96     public void testNotIdentity(){
97         Query q = st.query();
98         Constraint c = q.constrain(new STChar((char)1));
99         ObjectSet set = q.execute();
100         STChar identityConstraint = (STChar)set.next();
101         identityConstraint.i_char = 9080;
102         q = st.query();
103         q.constrain(identityConstraint).identity().not();
104         identityConstraint.i_char = 1;
105         Object JavaDoc[] r = store();
106         st.expect(q, new Object JavaDoc[] {r[0], r[2], r[3]});
107     }
108     
109     public void testConstraints(){
110         Query q = st.query();
111         q.constrain(new STChar((char)1));
112         q.constrain(new STChar((char)0));
113         Constraints cs = q.constraints();
114         Constraint[] csa = cs.toArray();
115         if(csa.length != 2){
116             st.error("Constraints not returned");
117         }
118     }
119     
120 }
121
122
Popular Tags