1 21 package com.db4o.test; 22 23 import java.util.*; 24 25 import com.db4o.*; 26 import com.db4o.foundation.*; 27 28 public class CascadeToHashtable { 29 30 public Hashtable ht; 31 32 public void configure() { 33 Db4o.configure().objectClass(this).cascadeOnUpdate(true); 34 Db4o.configure().objectClass(this).cascadeOnDelete(true); 35 } 36 37 public void store() { 38 Test.deleteAllInstances(this); 39 Test.deleteAllInstances(new Atom()); 40 CascadeToHashtable cth = new CascadeToHashtable(); 41 cth.ht = new Hashtable(); 42 cth.ht.put("key1", new Atom("stored1")); 43 cth.ht.put("key2", new Atom(new Atom("storedChild1"), "stored2")); 44 Test.store(cth); 45 } 46 47 public void test() { 48 Test.forEach(this, new Visitor4() { 49 public void visit(Object obj) { 50 CascadeToHashtable cth = (CascadeToHashtable) obj; 51 cth.ht.put("key1", new Atom("updated1")); 52 Atom atom = (Atom)cth.ht.get("key2"); 53 atom.name = "updated2"; 54 Test.store(cth); 55 } 56 }); 57 Test.reOpen(); 58 59 Test.forEach(this, new Visitor4() { 60 public void visit(Object obj) { 61 CascadeToHashtable cth = (CascadeToHashtable) obj; 62 Atom atom = (Atom)cth.ht.get("key1"); 63 Test.ensure(atom.name.equals("updated1")); 64 atom = (Atom)cth.ht.get("key2"); 65 Test.ensure(atom.name.equals("updated2")); 66 } 67 }); 68 69 71 Test.reOpen(); 72 Test.deleteAllInstances(this); 73 Test.ensureOccurrences(new Atom(), 1); 74 } 75 } 76 | Popular Tags |