01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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",
44: new Atom(new Atom("storedChild1"), "stored2"));
45: Test.store(cth);
46: }
47:
48: public void test() {
49: Test.forEach(this , new Visitor4() {
50: public void visit(Object obj) {
51: CascadeToHashtable cth = (CascadeToHashtable) obj;
52: cth.ht.put("key1", new Atom("updated1"));
53: Atom atom = (Atom) cth.ht.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: CascadeToHashtable cth = (CascadeToHashtable) obj;
63: Atom atom = (Atom) cth.ht.get("key1");
64: Test.ensure(atom.name.equals("updated1"));
65: atom = (Atom) cth.ht.get("key2");
66: Test.ensure(atom.name.equals("updated2"));
67: }
68: });
69:
70: // Cascade-On-Delete Test: We only want one atom to remain.
71:
72: Test.reOpen();
73: Test.deleteAllInstances(this );
74: Test.ensureOccurrences(new Atom(), 1);
75: }
76: }
|