1 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 _string; 36 37 public int _int; 38 39 40 public TraverseIndexedFieldValues(){ 41 42 } 43 44 public TraverseIndexedFieldValues(Atom atom, String 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 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 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 obj) { 90 Test.ensure(! fieldValues.contains(obj)); 91 Test.ensure(obj instanceof String ); 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 obj) { 103 Test.ensure(! fieldValues.contains(obj)); 104 Test.ensure(obj instanceof Integer ); 105 fieldValues.add(obj); 106 } 107 }); 108 109 Test.ensure(fieldValues.size() == COUNT); 110 } 111 112 113 114 } 115 | Popular Tags |