KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.db4o.*;
24 import com.db4o.config.*;
25 import com.db4o.ext.*;
26 import com.db4o.foundation.*;
27
28
29 public class TraverseIndexedFieldValues {
30     
31     private static final int COUNT = 30;
32     
33     public Atom _atom;
34     
35     public String JavaDoc _string;
36     
37     public int _int;
38     
39     
40     public TraverseIndexedFieldValues(){
41         
42     }
43     
44     public TraverseIndexedFieldValues(Atom atom, String JavaDoc str, int anint){
45         _atom = atom;
46         _string = str;
47         _int = anint;
48     }
49     
50     public void configure(){
51         ObjectClass objectClass = Db4o.configure().objectClass(getClass());
52         objectClass.objectField("_atom").indexed(true);
53         objectClass.objectField("_string").indexed(true);
54         objectClass.objectField("_int").indexed(true);
55     }
56     
57     public void store(){
58         for (int i = 0; i < COUNT; i++) {
59             String JavaDoc str = "" + i;
60             Test.store(new TraverseIndexedFieldValues(new Atom(str), str, i));
61         }
62     }
63     
64     public void test(){
65         final ExtObjectContainer oc = Test.objectContainer();
66         StoredClass sc = oc.storedClass(this);
67         
68         StoredField atomField = sc.storedField("_atom", null);
69         StoredField stringField = sc.storedField("_string", null);
70         StoredField intField = sc.storedField("_int", null);
71         
72         final Collection4 fieldValues = new Collection4();
73         
74         atomField.traverseValues(new Visitor4() {
75             public void visit(Object JavaDoc obj) {
76                 oc.activate(obj, 1);
77                 Test.ensure(! fieldValues.contains(obj));
78                 Test.ensure(obj instanceof Atom);
79                 fieldValues.add(obj);
80             }
81         });
82         
83         Test.ensure(fieldValues.size() == COUNT);
84         
85         
86         fieldValues.clear();
87         
88         stringField.traverseValues(new Visitor4() {
89             public void visit(Object JavaDoc obj) {
90                 Test.ensure(! fieldValues.contains(obj));
91                 Test.ensure(obj instanceof String JavaDoc);
92                 fieldValues.add(obj);
93             }
94         });
95         
96         
97         Test.ensure(fieldValues.size() == COUNT);
98         
99         fieldValues.clear();
100         
101         intField.traverseValues(new Visitor4() {
102             public void visit(Object JavaDoc obj) {
103                 Test.ensure(! fieldValues.contains(obj));
104                 Test.ensure(obj instanceof Integer JavaDoc);
105                 fieldValues.add(obj);
106             }
107         });
108         
109         Test.ensure(fieldValues.size() == COUNT);
110     }
111     
112     
113
114 }
115
Popular Tags