FODBImportQueryManager.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.synchro.client;
00026 
00027 import org.openmobileis.common.util.exception.DatabaseException;
00028 import org.openmobileis.database.fastobjectdb.FastObjectDBManager;
00029 import org.openmobileis.synchro.openmsp.client.db.ObjectDBImportQueryManager;
00030 
00038 public final class FODBImportQueryManager extends ObjectDBImportQueryManager {
00039   private SynchroFODBReturnListener synchroListener;
00040   private String collectionName;
00044   public FODBImportQueryManager(String collectionName) {
00045     super();
00046     this.collectionName = collectionName;
00047   }
00048   
00049   public void registerSynchroListener(SynchroFODBReturnListener listener) {
00050     this.synchroListener = listener;
00051   }
00052 
00053   /* (non-Javadoc)
00054    * @see org.openmobileis.synchro.openmsp.client.db.ObjectDBImportQueryManager#addObject(java.lang.String, java.lang.Object)
00055    */
00056   public void addObject(String uid, Object object) throws DatabaseException {
00057     try {
00058       if (this.synchroListener !=null)  {
00059         Object newOne = this.synchroListener.notifyBeginDBUpdate(object);
00060         if (newOne != null) {
00061           object = newOne;
00062         }
00063       }
00064       SynchroFastObjectDB db = (SynchroFastObjectDB)FastObjectDBManager.getCurrentFODB();
00065       boolean exist = db.isObjectInCollection(collectionName, object);
00066       if (exist)  {
00067         db.replaceFODB(collectionName, object);
00068       } else  {
00069         db.addFODB(collectionName, object);
00070       }
00071     } catch (Throwable ex)  {
00072       throw new DatabaseException(ex);
00073     }
00074   }
00075 
00076   /* (non-Javadoc)
00077    * @see org.openmobileis.synchro.openmsp.client.db.ObjectDBImportQueryManager#replaceObject(java.lang.String, java.lang.Object)
00078    */
00079   public void replaceObject(String uid, Object object) throws DatabaseException {
00080     this.addObject(uid, object);
00081 
00082   }
00083 
00084   /* (non-Javadoc)
00085    * @see org.openmobileis.synchro.openmsp.client.db.ObjectDBImportQueryManager#deleteObject(java.lang.String)
00086    */
00087   public void deleteObject(String uid) throws DatabaseException {
00088     try {
00089       SynchroFastObjectDB db = (SynchroFastObjectDB)FastObjectDBManager.getCurrentFODB();
00090       db.deleteWithIdFODB(collectionName, uid);
00091       if (this.synchroListener !=null) this.synchroListener.notifyDBDelete(uid);
00092     } catch (Throwable ex)  {
00093       throw new DatabaseException(ex);
00094     }
00095   }
00096 
00097   /* (non-Javadoc)
00098    * @see org.openmobileis.synchro.openmsp.client.db.ObjectDBImportQueryManager#beginImport()
00099    */
00100   protected void beginImport() throws DatabaseException {
00101 
00102   }
00103 
00104   /* (non-Javadoc)
00105    * @see org.openmobileis.synchro.openmsp.client.db.ObjectDBImportQueryManager#endImport()
00106    */
00107   protected void endImport() throws DatabaseException {
00108     // TODO Auto-generated method stub
00109 
00110   }
00111 
00112   public SynchroFODBReturnListener getSynchroReturnListener() {
00113     return synchroListener;
00114   }
00115 }

Generated on Mon Dec 4 11:03:26 2006 for OpenMobileIS by  doxygen 1.5.1-p1