001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.test;
022:
023: import com.db4o.*;
024: import com.db4o.ext.*;
025: import com.db4o.query.*;
026:
027: public class Refresh extends AllTests {
028:
029: public String name;
030:
031: public Refresh child;
032:
033: public Refresh() {
034:
035: }
036:
037: public Refresh(String name, Refresh child) {
038: this .name = name;
039: this .child = child;
040: }
041:
042: public void store() {
043: Refresh r3 = new Refresh("o3", null);
044: Refresh r2 = new Refresh("o2", r3);
045: Refresh r1 = new Refresh("o1", r2);
046: Test.store(r1);
047: }
048:
049: public void test() {
050: ExtObjectContainer oc1 = Test.objectContainer();
051: Refresh r11 = getRoot(oc1);
052: r11.name = "cc";
053: oc1.refresh(r11, 0);
054: Test.ensure(r11.name.equals("cc"));
055: oc1.refresh(r11, 1);
056: Test.ensure(r11.name.equals("o1"));
057: r11.child.name = "cc";
058: oc1.refresh(r11, 1);
059: Test.ensure(r11.child.name.equals("cc"));
060: oc1.refresh(r11, 2);
061: Test.ensure(r11.child.name.equals("o2"));
062:
063: if (Test.isClientServer()) {
064: ExtObjectContainer oc2 = null;
065: try {
066: oc2 = Db4o.openClient(SERVER_HOSTNAME, SERVER_PORT,
067: DB4O_USER, DB4O_PASSWORD).ext();
068: } catch (Exception e) {
069: e.printStackTrace();
070: return;
071: }
072:
073: Refresh r12 = getRoot(oc2);
074: Refresh r32 = r12.child.child;
075:
076: r11.child.name = "n2";
077: r11.child.child.name = "n3";
078: r11.child.child.child = new Refresh("n4", null);
079: oc1.set(r11.child.child);
080: oc1.set(r11.child);
081: oc1.set(r11);
082:
083: oc2.refresh(r12, Integer.MAX_VALUE);
084: Test.ensure(r12.child.name.equals("o2"));
085:
086: Test.commitSync(oc1, oc2);
087:
088: oc2.refresh(r12, Integer.MAX_VALUE);
089: Test.ensure(r12.child.name.equals("n2"));
090: Test.ensure(r12.child.child.name.equals("n3"));
091: Test.ensure(r12.child.child.child.name.equals("n4"));
092:
093: r11.child.child.child = null;
094: oc1.set(r11.child.child);
095: Test.commitSync(oc1, oc2);
096:
097: oc2.refresh(r12, Integer.MAX_VALUE);
098: Test.ensure(r12.child.child.child == null);
099:
100: r11.child.child = new Refresh("nn2", null);
101: oc1.set(r11.child);
102: Test.commitSync(oc1, oc2);
103:
104: oc2.refresh(r12, Integer.MAX_VALUE);
105: Test.ensure(r12.child.child != r32);
106: Test.ensure(r12.child.child.name.equals("nn2"));
107:
108: oc2.close();
109: }
110:
111: }
112:
113: private void commitAndWait(ObjectContainer client1,
114: ObjectContainer client2) {
115: }
116:
117: private Refresh getRoot(ObjectContainer oc) {
118: Query q = oc.query();
119: q.constrain(Refresh.class);
120: q.descend("name").constrain("o1");
121: ObjectSet objectSet = q.execute();
122: return (Refresh) objectSet.next();
123: }
124:
125: }
|