KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > NullWrapperQueries


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;
22
23 import java.util.*;
24
25 import com.db4o.*;
26 import com.db4o.inside.marshall.*;
27 import com.db4o.query.*;
28
29
30 /**
31  *
32  */

33 public class NullWrapperQueries {
34     
35     public Boolean JavaDoc m1;
36 // Byte m2; Byte will not work, since we always use 0 for null.
37
public Boolean JavaDoc m2;
38     public Character JavaDoc m3;
39     public Date m4;
40     public Double JavaDoc m5;
41     public Float JavaDoc m6;
42     public Integer JavaDoc m7;
43     public Long JavaDoc m8;
44     public Short JavaDoc m9;
45     public String JavaDoc m10;
46     
47     public void configure(){
48         for (int i = 1; i < 11; i++) {
49             String JavaDoc desc = "m" + i;
50             Db4o.configure().objectClass(this).objectField(desc).indexed(true);
51         }
52     }
53     
54     public void store(){
55         Test.deleteAllInstances(this);
56         NullWrapperQueries nwq = new NullWrapperQueries();
57         nwq.fill1();
58         Test.store(nwq);
59         nwq = new NullWrapperQueries();
60         nwq.fill0();
61         Test.store(nwq);
62         nwq = new NullWrapperQueries();
63         nwq.fill0();
64         Test.store(nwq);
65         nwq = new NullWrapperQueries();
66         nwq.fill1();
67         Test.store(nwq);
68         nwq = new NullWrapperQueries();
69         Test.store(nwq);
70         nwq = new NullWrapperQueries();
71         Test.store(nwq);
72     }
73     
74     public void test(){
75         for (int i = 1; i < 11; i++) {
76             Query q = Test.query();
77             q.constrain(NullWrapperQueries.class);
78             String JavaDoc desc = "m" + i;
79             q.descend(desc).constrain(null);
80             Test.ensureEquals(2,q.execute().size());
81         }
82     }
83     
84     private void fill0(){
85         m1 = new Boolean JavaDoc(false);
86         // m2 = new Byte((byte)0);
87
m2 = new Boolean JavaDoc(false);
88
89         m3 = new Character JavaDoc((char)0);
90         m4 = new Date(0);
91         m5 = new Double JavaDoc(0);
92         m6 = new Float JavaDoc(0);
93         m7 = new Integer JavaDoc(0);
94         m8 = new Long JavaDoc(0);
95         m9 = new Short JavaDoc((short)0);
96         m10 = "";
97     }
98     
99     private void fill1(){
100         m1 = new Boolean JavaDoc(true);
101         // m2 = new Byte((byte)1);
102
m2 = new Boolean JavaDoc(true);
103         m3 = new Character JavaDoc((char)1);
104         m4 = new Date(1);
105         m5 = new Double JavaDoc(1);
106         m6 = new Float JavaDoc(1);
107         m7 = new Integer JavaDoc(1);
108         m8 = new Long JavaDoc(1);
109         m9 = new Short JavaDoc((short)1);
110         m10 = "1";
111     }
112     
113     
114     
115     
116     
117     
118     
119     
120     
121     
122     
123
124 }
125
Popular Tags