1 21 package com.db4o.test; 22 23 import java.util.*; 24 25 import com.db4o.ext.*; 26 27 28 public class TransientClone { 29 30 List list; 31 Hashtable ht; 32 String str; 33 int myInt; 34 Molecule[] molecules; 35 36 public void storeOne(){ 37 list = new ArrayList(); 38 list.add(new Atom("listAtom")); 39 list.add(this); 40 ht = new Hashtable(); 41 ht.put("htc", new Molecule("htAtom")); 42 ht.put("recurse", this); 43 str = "str"; 44 myInt = 100; 45 molecules = new Molecule[3]; 46 for (int i = 0; i < molecules.length; i++) { 47 molecules[i] = new Molecule("arr" + i); 48 molecules[i].child = new Atom("arr" + i); 49 molecules[i].child.child = new Atom("arrc" + i); 50 } 51 } 52 53 public void testOne(){ 54 ExtObjectContainer oc = Test.objectContainer(); 55 oc.activate(this, Integer.MAX_VALUE); 56 TransientClone originalValues = cmp(this, false); 57 oc.deactivate(this, Integer.MAX_VALUE); 58 TransientClone modified = cmp(originalValues, false); 59 oc.activate(this, Integer.MAX_VALUE); 60 modified.str = "changed"; 61 modified.molecules[0].name = "changed"; 62 str = "changed"; 63 molecules[0].name = "changed"; 64 oc.set(molecules[0]); 65 oc.set(this); 66 cmp(originalValues, true); 67 cmp(modified, false); 68 oc.commit(); 69 cmp(modified, true); 70 } 71 72 private TransientClone cmp(TransientClone to, boolean committed){ 73 ExtObjectContainer oc = Test.objectContainer(); 74 TransientClone tc = (TransientClone)oc.peekPersisted(this, Integer.MAX_VALUE, committed); 75 Test.ensure(tc != to); 76 Test.ensure(tc.list != to); 77 Test.ensure(tc.list.size() == to.list.size()); 78 Iterator i = tc.list.iterator(); 79 Iterator j = to.list.iterator(); 80 Atom tca = (Atom)i.next(); 81 Atom tct = (Atom)j.next(); 82 Test.ensure(tca != tct); 83 Test.ensure(tca.name.equals(tct.name)); 84 Test.ensure(i.next() == tc); 85 Test.ensure(j.next() == to); 86 Test.ensure(tc.ht != to.ht); 87 Molecule tcm = (Molecule)tc.ht.get("htc"); 88 Molecule tom = (Molecule)to.ht.get("htc"); 89 Test.ensure(tcm != tom); 90 Test.ensure(tcm.name.equals(tom.name)); 91 Test.ensure(tc.ht.get("recurse") == tc); 92 Test.ensure(to.ht.get("recurse") == to); 93 Test.ensure(tc.str.equals(to.str)); 94 Test.ensure(tc.myInt == to.myInt); 95 Test.ensure(tc.molecules.length == to.molecules.length); 96 Test.ensure(tc.molecules.length == to.molecules.length); 97 tcm = tc.molecules[0]; 98 tom = to.molecules[0]; 99 Test.ensure(tcm != tom); 100 Test.ensure(tcm.name.equals(tom.name)); 101 Test.ensure(tcm.child != tom.child); 102 Test.ensure(tcm.child.name.equals(tom.child.name)); 103 return tc; 104 } 105 } 106 | Popular Tags |