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.set;
22:
23: import com.db4o.ext.*;
24:
25: import db4ounit.*;
26: import db4ounit.extensions.*;
27:
28: public class DeepSetClientServerTestCase extends
29: Db4oClientServerTestCase {
30:
31: public static void main(String[] args) {
32: new DeepSetClientServerTestCase().runAll();
33: }
34:
35: public static class Item {
36: public Item child;
37: public String name;
38: }
39:
40: protected void store() {
41: Item item = new Item();
42: item.name = "1";
43: item.child = new Item();
44: item.child.name = "2";
45: item.child.child = new Item();
46: item.child.child.name = "3";
47: store(item);
48: }
49:
50: public void test() throws Exception {
51: ExtObjectContainer oc1 = openNewClient();
52: ExtObjectContainer oc2 = openNewClient();
53: ExtObjectContainer oc3 = openNewClient();
54: Item example = new Item();
55: example.name = "1";
56: try {
57: Item item1 = (Item) oc1.get(example).next();
58: Assert.areEqual("1", item1.name);
59: Assert.areEqual("2", item1.child.name);
60: Assert.areEqual("3", item1.child.child.name);
61:
62: Item item2 = (Item) oc2.get(example).next();
63: Assert.areEqual("1", item2.name);
64: Assert.areEqual("2", item2.child.name);
65: Assert.areEqual("3", item2.child.child.name);
66:
67: item1.child.name = "12";
68: item1.child.child.name = "13";
69: oc1.set(item1, 2);
70: oc1.commit();
71:
72: // check result
73: Item item = (Item) oc1.get(example).next();
74: Assert.areEqual("1", item.name);
75: Assert.areEqual("12", item.child.name);
76: Assert.areEqual("13", item.child.child.name);
77:
78: item = (Item) oc2.get(example).next();
79: oc2.refresh(item, 3);
80: Assert.areEqual("1", item.name);
81: Assert.areEqual("12", item.child.name);
82: Assert.areEqual("3", item.child.child.name);
83:
84: item = (Item) oc3.get(example).next();
85: Assert.areEqual("1", item.name);
86: Assert.areEqual("12", item.child.name);
87: Assert.areEqual("3", item.child.child.name);
88: } finally {
89: oc1.close();
90: oc2.close();
91: oc3.close();
92: }
93: }
94:
95: }
|