00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.openmobileis.database.fastobjectdb.db.test;
00026
00027 import org.odbms.ObjectSet;
00028 import org.odbms.Query;
00029 import org.openmobileis.common.user.UserNotFoundException;
00030 import org.openmobileis.common.util.collection.Array;
00031 import org.openmobileis.common.util.exception.ServiceException;
00032 import org.openmobileis.database.fastobjectdb.FastObjectDB;
00033 import org.openmobileis.database.fastobjectdb.FastObjectDBManager;
00034 import org.openmobileis.database.fastobjectdb.db.query.soda.FODBSodaObjectSet;
00035 import org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget;
00036 import org.openmobileis.synchro.algo.replication.AlwaysUpdateServerSynchroConflicResolver;
00037 import org.openmobileis.synchro.algo.replication.DefaultSynchroAtomicObject;
00038 import org.openmobileis.synchro.algo.replication.SynchroAtomicObject;
00039 import org.openmobileis.synchro.algo.replication.SynchroConflicResolver;
00040 import org.openmobileis.synchro.openmsp.OpenMSPException;
00041 import org.openmobileis.synchro.security.auth.Credential;
00042
00050 public final class TestFODBSyncTarget implements FODBSyncTarget {
00051 private AlwaysUpdateServerSynchroConflicResolver conflicResolver;
00052
00056 public TestFODBSyncTarget() {
00057 super();
00058 conflicResolver = new AlwaysUpdateServerSynchroConflicResolver();
00059 }
00060
00061
00062
00063
00064 public String getCollectionName() {
00065 return "CLIENT";
00066 }
00067
00068
00069
00070
00071 public Object getCollectionObjectWithId(String id) throws OpenMSPException {
00072 try {
00073 Query q = FastObjectDBManager.getCurrentFODB().query();
00074 q.constrain("SERVER");
00075 Query q2 = q.descend("getKey()");
00076 q2.constrain(id).equal();
00077 ObjectSet set = q.execute();
00078 if (set.hasNext()) {
00079 return (TestData) set.next();
00080 }
00081 return null;
00082 } catch (Throwable ex) {
00083 throw new OpenMSPException(ex);
00084 }
00085 }
00086
00087 public Array getAllCollectionObject() throws OpenMSPException {
00088 try {
00089 Query q = FastObjectDBManager.getCurrentFODB().query();
00090 q.constrain("SERVER");
00091 q.descend("getKey()");
00092 ObjectSet set = q.execute();
00093 return ((FODBSodaObjectSet)set).getArrayFromSet();
00094 } catch (Throwable ex) {
00095 throw new OpenMSPException(ex);
00096 }
00097 }
00098
00099
00100
00101
00102
00103 public void updateCollectionObject(Object obj) throws OpenMSPException {
00104 try {
00105 TestData test = (TestData)obj;
00106 Object dbobj = this.getCollectionObjectWithId(test.getKey());
00107 if (dbobj == null) {
00108 FastObjectDBManager.getCurrentFODB().add("SERVER", test);
00109 } else {
00110 FastObjectDBManager.getCurrentFODB().replace("SERVER", test);
00111 }
00112 } catch (Throwable ex) {
00113 throw new OpenMSPException(ex);
00114 }
00115 }
00116
00117
00118
00119
00120 public void deleteCollectionObject(String id) throws OpenMSPException {
00121 try {
00122 FastObjectDBManager.getCurrentFODB().deleteWithId("SERVER", id);
00123 } catch (Throwable ex) {
00124 throw new OpenMSPException(ex);
00125 }
00126 }
00127
00128
00129
00130
00131 public SynchroConflicResolver getConflicResolver() {
00132 return conflicResolver;
00133 }
00134
00135
00136
00137
00138 public SynchroAtomicObject[] getAllModifiedAtomicObjectSince(long syncnumber) throws OpenMSPException {
00139
00140 SynchroAtomicObject[] ret = new SynchroAtomicObject[0];
00141 if (syncnumber == 0) {
00142 ret = new SynchroAtomicObject[1];
00143 ret[0] = new DefaultSynchroAtomicObject("FIRSTS", "");
00144 ret[0].setModificationType(SynchroAtomicObject.ADD);
00145 }else if (syncnumber == 1) {
00146 TestData data = new TestData("FIRSTS");
00147 data.setToModify("1S");
00148 try {
00149 FastObjectDBManager.getCurrentFODB().replace("SERVER", data);
00150 } catch (Throwable ex) {
00151 throw new OpenMSPException(ex);
00152 }
00153 ret = new SynchroAtomicObject[1];
00154 ret[0] = new DefaultSynchroAtomicObject("FIRSTS", "");
00155 ret[0].setModificationType(SynchroAtomicObject.REPLACE);
00156 }else if (syncnumber == 2) {
00157 try {
00158 FastObjectDBManager.getCurrentFODB().deleteWithId("SERVER", "FIRSTS");
00159 } catch (Throwable ex) {
00160 throw new OpenMSPException(ex);
00161 }
00162 ret = new SynchroAtomicObject[1];
00163 ret[0] = new DefaultSynchroAtomicObject("FIRSTS", "");
00164 ret[0].setModificationType(SynchroAtomicObject.DELETE);
00165 }else if (syncnumber == 3) {
00166 TestData data = new TestData("THIRD");
00167 data.setToModify("0S");
00168 try {
00169 FastObjectDBManager.getCurrentFODB().add("SERVER", data);
00170 } catch (Throwable ex) {
00171 throw new OpenMSPException(ex);
00172 }
00173 data = new TestData("FOURTH");
00174 data.setToModify("0S");
00175 try {
00176 FastObjectDBManager.getCurrentFODB().add("SERVER", data);
00177 } catch (Throwable ex) {
00178 throw new OpenMSPException(ex);
00179 }
00180 ret = new SynchroAtomicObject[2];
00181 ret[0] = new DefaultSynchroAtomicObject("THIRD", "");
00182 ret[0].setModificationType(SynchroAtomicObject.ADD);
00183 ret[1] = new DefaultSynchroAtomicObject("FOURTH", "");
00184 ret[1].setModificationType(SynchroAtomicObject.ADD);
00185 }
00186 syncnumber++;
00187 return ret;
00188 }
00189
00190
00191
00192
00193 public int getUpdateMaxNbRow() {
00194 return 1;
00195 }
00196
00197
00198
00199
00200 public void updateSynchroDB(FastObjectDB db) throws OpenMSPException {
00201 }
00202
00203
00204
00205
00206 public void connect(Credential cred) throws UserNotFoundException, ServiceException {
00207 }
00208
00209
00210
00211
00212 public void disconnect() {
00213 }
00214
00215 }