Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

TestFODBSyncTarget.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
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.SynchroAtomicObject;
00038 import org.openmobileis.synchro.algo.replication.SynchroConflicResolver;
00039 import org.openmobileis.synchro.algo.replication.utils.DefaultSynchroAtomicObject;
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   /* (non-Javadoc)
00062    * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget#getCollectionName()
00063    */
00064   public String getCollectionName() {
00065      return "CLIENT";
00066   }
00067 
00068   /* (non-Javadoc)
00069    * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget#getCollectionObjectWithId(java.lang.String)
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   /* (non-Javadoc)
00101    * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget#updateCollectionObject(java.lang.Object)
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   /* (non-Javadoc)
00118    * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget#deleteCollectionObject(java.lang.String)
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   /* (non-Javadoc)
00129    * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget#getConflicResolver()
00130    */
00131   public SynchroConflicResolver getConflicResolver() {
00132     return conflicResolver;
00133   }
00134 
00135   /* (non-Javadoc)
00136    * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget#getAllModifiedAtomicObjectForServiceSince(long)
00137    */
00138   public SynchroAtomicObject[] getAllModifiedAtomicObjectSince(long syncnumber) throws OpenMSPException {
00139 //    Object obj = this.getCollectionObjectWithId("FIRSTS");
00140     try {
00141     SynchroAtomicObject[] ret = new SynchroAtomicObject[0];
00142     if (syncnumber == 0)  {  // add
00143       ret = new SynchroAtomicObject[1];
00144       ret[0] = new DefaultSynchroAtomicObject("FIRSTS", "");
00145       ret[0].setModificationType(SynchroAtomicObject.ADD);
00146     }else if (syncnumber == 1)  {  //replace
00147       TestData data = new TestData("FIRSTS");
00148       data.setToModify("1S");
00149       try {
00150         FastObjectDBManager.getCurrentFODB().replace("SERVER", data);
00151       } catch (Throwable ex)  {
00152         throw new OpenMSPException(ex);
00153       }
00154       ret = new SynchroAtomicObject[1];
00155       ret[0] = new DefaultSynchroAtomicObject("FIRSTS", "");
00156       ret[0].setModificationType(SynchroAtomicObject.REPLACE);
00157     }else if (syncnumber == 2)  { //delete
00158       try {
00159         FastObjectDBManager.getCurrentFODB().deleteWithId("SERVER", "FIRSTS");
00160       } catch (Throwable ex)  {
00161         throw new OpenMSPException(ex);
00162       }
00163       ret = new SynchroAtomicObject[1];
00164       ret[0] = new DefaultSynchroAtomicObject("FIRSTS", "");
00165       ret[0].setModificationType(SynchroAtomicObject.DELETE);
00166     }else if (syncnumber == 3)  { //complete
00167       TestData data = new TestData("THIRD");
00168       data.setToModify("0S");
00169       try {
00170         FastObjectDBManager.getCurrentFODB().add("SERVER", data);
00171       } catch (Throwable ex)  {
00172         throw new OpenMSPException(ex);
00173       }
00174       data = new TestData("FOURTH");
00175       data.setToModify("0S");
00176       try {
00177         FastObjectDBManager.getCurrentFODB().add("SERVER", data);
00178       } catch (Throwable ex)  {
00179         throw new OpenMSPException(ex);
00180       }
00181       ret = new SynchroAtomicObject[2];
00182       ret[0] = new DefaultSynchroAtomicObject("THIRD", "");
00183       ret[0].setModificationType(SynchroAtomicObject.ADD);
00184       ret[1] = new DefaultSynchroAtomicObject("FOURTH", "");
00185       ret[1].setModificationType(SynchroAtomicObject.ADD);
00186     }
00187     syncnumber++;
00188     return ret;
00189     } catch (Throwable ex)  {
00190       throw new OpenMSPException(ex);
00191     }
00192   }
00193 
00194   /* (non-Javadoc)
00195    * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget#getUpdateMaxNbRow()
00196    */
00197   public int getUpdateMaxNbRow() {
00198     return 1;
00199   }
00200 
00201   /* (non-Javadoc)
00202    * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget#updateSynchroDB(org.openmobileis.database.fastobjectdb.FastObjectDB)
00203    */
00204   public void updateSynchroDB(FastObjectDB db) throws OpenMSPException {
00205   }
00206 
00207   /* (non-Javadoc)
00208    * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget#connect(org.openmobileis.synchro.security.auth.Credential)
00209    */
00210   public void connect(Credential cred) throws UserNotFoundException, ServiceException {
00211   }
00212 
00213   /* (non-Javadoc)
00214    * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget#disconnect()
00215    */
00216   public void disconnect() {
00217   }
00218 
00219 }

Generated on Mon Jul 10 10:29:33 2006 for OpenMobileIS by  doxygen 1.4.4