1 21 package com.db4o.db4ounit.common.querying; 22 23 import com.db4o.*; 24 import com.db4o.config.*; 25 import com.db4o.foundation.*; 26 27 import db4ounit.*; 28 import db4ounit.extensions.*; 29 30 public class CascadeToArray extends AbstractDb4oTestCase { 31 32 public static class Atom { 33 34 public Atom child; 35 36 public String name; 37 38 public Atom() { 39 } 40 41 public Atom(Atom child) { 42 this.child = child; 43 } 44 45 public Atom(String name) { 46 this.name = name; 47 } 48 49 public Atom(Atom child, String name) { 50 this(child); 51 this.name = name; 52 } 53 } 54 55 public Object [] objects; 56 57 protected void configure(Configuration conf) { 58 conf.objectClass(this).cascadeOnUpdate(true); 59 conf.objectClass(this).cascadeOnDelete(true); 60 } 61 62 protected void store() { 63 CascadeToArray cta = new CascadeToArray(); 64 cta.objects = new Object [] { new Atom("stored1"), 65 new Atom(new Atom("storedChild1"), "stored2") }; 66 db().set(cta); 67 } 68 69 public void test() throws Exception { 70 foreach(getClass(), new Visitor4() { 71 public void visit(Object obj) { 72 CascadeToArray cta = (CascadeToArray) obj; 73 for (int i = 0; i < cta.objects.length; i++) { 74 Atom atom = (Atom) cta.objects[i]; 75 atom.name = "updated"; 76 if (atom.child != null) { 77 atom.child.name = "updated"; 79 } 80 } 81 db().set(cta); 82 } 83 }); 84 85 reopen(); 86 87 foreach(getClass(), new Visitor4() { 88 public void visit(Object obj) { 89 CascadeToArray cta = (CascadeToArray) obj; 90 for (int i = 0; i < cta.objects.length; i++) { 91 Atom atom = (Atom) cta.objects[i]; 92 Assert.areEqual("updated", atom.name); 93 if (atom.child != null) { 94 Assert.areNotEqual("updated", atom.child.name); 95 } 96 } 97 } 98 }); 99 100 db().commit(); 102 reopen(); 103 104 ObjectSet os = newQuery(getClass()).execute(); 105 while (os.hasNext()) 106 db().delete(os.next()); 107 108 Assert.areEqual(1, countOccurences(Atom.class)); 109 } 110 } 111 | Popular Tags |