KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > replication > old > ReplicateDb4oList


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 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.replication.old;
22
23 import java.util.*;
24
25 import com.db4o.*;
26 import com.db4o.ext.*;
27 import com.db4o.query.*;
28 import com.db4o.replication.*;
29 import com.db4o.test.*;
30
31
32 public class ReplicateDb4oList {
33     
34     List list;
35     
36     public void configure() {
37         Db4o.configure().generateUUIDs(Integer.MAX_VALUE);
38         Db4o.configure().generateVersionNumbers(Integer.MAX_VALUE);
39     }
40     
41     public void storeOne() {
42         
43         list = Test.objectContainer().collections().newLinkedList();
44         list.add(new RDLElement("store1"));
45         list.add(new RDLElement("store2"));
46     }
47     
48     public void testOne(){
49
50         Test.deleteAll(Test.replica());
51         
52         replicate(false);
53         
54         ObjectContainer oc = Test.replica();
55         Query q = oc.query();
56         q.constrain(ReplicateDb4oList.class);
57         ObjectSet objectSet = q.execute();
58         Test.ensure(objectSet.size() == 1);
59         ReplicateDb4oList rdl = (ReplicateDb4oList)objectSet.next();
60         RDLElement elem = (RDLElement)rdl.list.get(0);
61         Test.ensure(elem.name.equals("store1"));
62         elem = (RDLElement)rdl.list.get(1);
63         Test.ensure(elem.name.equals("store2"));
64         
65         // Test.reOpen();
66

67         list.add(new RDLElement("afterReplication"));
68         elem = (RDLElement)list.get(0);
69         elem.name = "replicated";
70         Test.store(elem);
71         
72         // storing this to make sure it is dirty
73
Test.store(this);
74         
75         replicate(true);
76         
77         oc = Test.replica();
78         q = oc.query();
79         q.constrain(ReplicateDb4oList.class);
80         objectSet = q.execute();
81         Test.ensure(objectSet.size() == 1);
82         rdl = (ReplicateDb4oList)objectSet.next();
83         elem = (RDLElement)rdl.list.get(0);
84         Test.ensure(elem.name.equals("replicated"));
85         elem = (RDLElement)rdl.list.get(1);
86         Test.ensure(elem.name.equals("store2"));
87         elem = (RDLElement)rdl.list.get(2);
88         Test.ensure(elem.name.equals("afterReplication"));
89     }
90     
91     private void replicate(boolean modifiedOnly) {
92         ExtObjectContainer peerA = Test.objectContainer().ext();
93         ObjectContainer peerB = Test.replica();
94         
95         ReplicationProcess replication = peerA.replicationBegin(peerB, new ReplicationConflictHandler() {
96             public Object JavaDoc resolveConflict(ReplicationProcess replicationProcess, Object JavaDoc a, Object JavaDoc b) {
97                 return null;
98             }
99         });
100         Query q = peerA.query();
101         q.constrain(ReplicateDb4oList.class);
102         if (modifiedOnly) {
103             replication.whereModified(q);
104         }
105         ObjectSet objectSet = q.execute();
106         while (objectSet.hasNext()) {
107             ReplicateDb4oList rdl = (ReplicateDb4oList)objectSet.next();
108             replication.replicate(rdl);
109             // replication.replicate(rdl.list);
110
}
111         replication.commit();
112     }
113
114     
115     public static class RDLElement{
116         
117         private String JavaDoc name;
118         
119         public RDLElement(String JavaDoc name){
120             this.name = name;
121         }
122     }
123 }
124
Popular Tags