| 1 21 package com.db4o.test; 22 23 import com.db4o.*; 24 import com.db4o.query.*; 25 26 29 public class IndexedByIdentity { 30 31 public Atom atom; 32 33 static final int COUNT = 10; 34 35 public void configure(){ 36 Db4o.configure().objectClass(this).objectField("atom").indexed(true); 37 } 38 39 public void store(){ 40 for (int i = 0; i < COUNT; i++) { 41 IndexedByIdentity ibi = new IndexedByIdentity(); 42 ibi.atom = new Atom("ibi" + i); 43 Test.store(ibi); 44 } 45 } 46 47 public void test(){ 48 readAndUpdate("ibi"); 49 readAndUpdate("updated"); 50 51 } 52 53 private void readAndUpdate(String atomName){ 54 for (int i = 0; i < COUNT; i++) { 55 Query q = Test.query(); 56 q.constrain(Atom.class); 57 q.descend("name").constrain(atomName + i); 58 ObjectSet objectSet = q.execute(); 59 Atom child = (Atom)objectSet.next(); 60 q = Test.query(); 62 q.constrain(IndexedByIdentity.class); 63 q.descend("atom").constrain(child).identity(); 64 objectSet = q.execute(); 65 Test.ensure(objectSet.size() == 1); 66 IndexedByIdentity ibi = (IndexedByIdentity)objectSet.next(); 67 Test.ensure(ibi.atom == child); 68 ibi.atom = new Atom("updated" + i); 69 Test.store(ibi); 70 } 71 72 73 } 74 75 76 77 78 } 79 | Popular Tags |