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.replication.old;
022:
023: import java.util.*;
024:
025: import com.db4o.*;
026: import com.db4o.ext.*;
027: import com.db4o.query.*;
028: import com.db4o.replication.*;
029: import com.db4o.test.*;
030:
031: public class ReplicateDb4oList {
032:
033: List list;
034:
035: public void configure() {
036: Db4o.configure().generateUUIDs(Integer.MAX_VALUE);
037: Db4o.configure().generateVersionNumbers(Integer.MAX_VALUE);
038: }
039:
040: public void storeOne() {
041:
042: list = Test.objectContainer().collections().newLinkedList();
043: list.add(new RDLElement("store1"));
044: list.add(new RDLElement("store2"));
045: }
046:
047: public void testOne() {
048:
049: Test.deleteAll(Test.replica());
050:
051: replicate(false);
052:
053: ObjectContainer oc = Test.replica();
054: Query q = oc.query();
055: q.constrain(ReplicateDb4oList.class);
056: ObjectSet objectSet = q.execute();
057: Test.ensure(objectSet.size() == 1);
058: ReplicateDb4oList rdl = (ReplicateDb4oList) objectSet.next();
059: RDLElement elem = (RDLElement) rdl.list.get(0);
060: Test.ensure(elem.name.equals("store1"));
061: elem = (RDLElement) rdl.list.get(1);
062: Test.ensure(elem.name.equals("store2"));
063:
064: // Test.reOpen();
065:
066: list.add(new RDLElement("afterReplication"));
067: elem = (RDLElement) list.get(0);
068: elem.name = "replicated";
069: Test.store(elem);
070:
071: // storing this to make sure it is dirty
072: Test.store(this );
073:
074: replicate(true);
075:
076: oc = Test.replica();
077: q = oc.query();
078: q.constrain(ReplicateDb4oList.class);
079: objectSet = q.execute();
080: Test.ensure(objectSet.size() == 1);
081: rdl = (ReplicateDb4oList) objectSet.next();
082: elem = (RDLElement) rdl.list.get(0);
083: Test.ensure(elem.name.equals("replicated"));
084: elem = (RDLElement) rdl.list.get(1);
085: Test.ensure(elem.name.equals("store2"));
086: elem = (RDLElement) rdl.list.get(2);
087: Test.ensure(elem.name.equals("afterReplication"));
088: }
089:
090: private void replicate(boolean modifiedOnly) {
091: ExtObjectContainer peerA = Test.objectContainer().ext();
092: ObjectContainer peerB = Test.replica();
093:
094: ReplicationProcess replication = peerA.replicationBegin(peerB,
095: new ReplicationConflictHandler() {
096: public Object resolveConflict(
097: ReplicationProcess replicationProcess,
098: Object a, Object b) {
099: return null;
100: }
101: });
102: Query q = peerA.query();
103: q.constrain(ReplicateDb4oList.class);
104: if (modifiedOnly) {
105: replication.whereModified(q);
106: }
107: ObjectSet objectSet = q.execute();
108: while (objectSet.hasNext()) {
109: ReplicateDb4oList rdl = (ReplicateDb4oList) objectSet
110: .next();
111: replication.replicate(rdl);
112: // replication.replicate(rdl.list);
113: }
114: replication.commit();
115: }
116:
117: public static class RDLElement {
118:
119: private String name;
120:
121: public RDLElement(String name) {
122: this.name = name;
123: }
124: }
125: }
|