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 CascadeToHashMap { 29 30 HashMap hm; 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 CascadeToHashMap cth = new CascadeToHashMap(); 41 cth.hm = new HashMap(); 42 cth.hm.put("key1", new Atom("stored1")); 43 cth.hm.put("key2", new Atom(new Atom("storedChild1"), "stored2")); 44 Test.store(cth); 45 } 46 47 public void test() { 48 49 Test.forEach(this, new Visitor4() { 50 public void visit(Object obj) { 51 CascadeToHashMap cth = (CascadeToHashMap) obj; 52 cth.hm.put("key1", new Atom("updated1")); 53 Atom atom = (Atom)cth.hm.get("key2"); 54 atom.name = "updated2"; 55 Test.store(cth); 56 } 57 }); 58 Test.reOpen(); 59 60 Test.forEach(this, new Visitor4() { 61 public void visit(Object obj) { 62 CascadeToHashMap cth = (CascadeToHashMap) obj; 63 Atom atom = (Atom)cth.hm.get("key1"); 64 Test.ensure(atom.name.equals("updated1")); 65 atom = (Atom)cth.hm.get("key2"); 66 Test.ensure(atom.name.equals("updated2")); 67 } 68 }); 69 70 72 Test.reOpen(); 73 Test.deleteAllInstances(this); 74 Test.ensureOccurrences(new Atom(), 1); 75 } 76 } 77 | Popular Tags |