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.db4ounit.common.assorted;
22:
23: import com.db4o.ObjectSet;
24: import com.db4o.config.Configuration;
25: import com.db4o.ext.ExtObjectContainer;
26: import com.db4o.query.Query;
27:
28: import db4ounit.Assert;
29: import db4ounit.extensions.Db4oClientServerTestCase;
30:
31: public class RollbackUpdateCascadeTestCase extends
32: Db4oClientServerTestCase {
33:
34: public static void main(String[] args) {
35: new RollbackUpdateCascadeTestCase().runClientServer();
36: }
37:
38: protected void configure(Configuration config) {
39: config.objectClass(Atom.class).cascadeOnUpdate(true);
40: config.objectClass(Atom.class).cascadeOnDelete(true);
41: }
42:
43: protected void store() {
44: Atom atom = new Atom("root");
45: atom.child = new Atom("child");
46: atom.child.child = new Atom("child.child");
47: store(atom);
48: }
49:
50: public void test() {
51: ExtObjectContainer oc1 = openNewClient();
52: ExtObjectContainer oc2 = openNewClient();
53: ExtObjectContainer oc3 = openNewClient();
54: try {
55: Query query1 = oc1.query();
56: query1.descend("name").constrain("root");
57: ObjectSet os1 = query1.execute();
58: Assert.areEqual(1, os1.size());
59: Atom o1 = (Atom) os1.next();
60: o1.child.child.name = "o1";
61: oc1.set(o1);
62:
63: Query query2 = oc2.query();
64: query2.descend("name").constrain("root");
65: ObjectSet os2 = query2.execute();
66: Assert.areEqual(1, os2.size());
67: Atom o2 = (Atom) os2.next();
68: Assert.areEqual("child.child", o2.child.child.name);
69:
70: oc1.rollback();
71: oc2.purge(o2);
72: os2 = query2.execute();
73: Assert.areEqual(1, os2.size());
74: o2 = (Atom) os2.next();
75: Assert.areEqual("child.child", o2.child.child.name);
76:
77: oc1.set(o1);
78: oc1.commit();
79:
80: os2 = query2.execute();
81: Assert.areEqual(1, os2.size());
82: o2 = (Atom) os2.next();
83: oc2.refresh(o2, Integer.MAX_VALUE);
84: Assert.areEqual("o1", o2.child.child.name);
85:
86: Query query3 = oc3.query();
87: query3.descend("name").constrain("root");
88: ObjectSet os3 = query1.execute();
89: Assert.areEqual(1, os3.size());
90: Atom o3 = (Atom) os3.next();
91: Assert.areEqual("o1", o3.child.child.name);
92:
93: } finally {
94: oc1.close();
95: oc2.close();
96: oc3.close();
97: }
98: }
99: }
|