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-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
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.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   /* (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     SynchroAtomicObject[] ret = new SynchroAtomicObject[0];
00141     if (syncnumber == 0)  {  // add
00142       ret = new SynchroAtomicObject[1];
00143       ret[0] = new DefaultSynchroAtomicObject("FIRSTS", "");
00144       ret[0].setModificationType(SynchroAtomicObject.ADD);
00145     }else if (syncnumber == 1)  {  //replace
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)  { //delete
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)  { //complete
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   /* (non-Javadoc)
00191    * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget#getUpdateMaxNbRow()
00192    */
00193   public int getUpdateMaxNbRow() {
00194     return 1;
00195   }
00196 
00197   /* (non-Javadoc)
00198    * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget#updateSynchroDB(org.openmobileis.database.fastobjectdb.FastObjectDB)
00199    */
00200   public void updateSynchroDB(FastObjectDB db) throws OpenMSPException {
00201   }
00202 
00203   /* (non-Javadoc)
00204    * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget#connect(org.openmobileis.synchro.security.auth.Credential)
00205    */
00206   public void connect(Credential cred) throws UserNotFoundException, ServiceException {
00207   }
00208 
00209   /* (non-Javadoc)
00210    * @see org.openmobileis.database.fastobjectdb.synchro.server.FODBSyncTarget#disconnect()
00211    */
00212   public void disconnect() {
00213   }
00214 
00215 }

Generated on Wed Dec 14 21:05:35 2005 for OpenMobileIS by  doxygen 1.4.4