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 } finally { 00074 if (this.synchroListener != null) { 00075 try { 00076 this.synchroListener.notifyFODBObjectSynchroDone(uid); 00077 } catch (Throwable ex) { 00078 throw new DatabaseException(ex); 00079 } 00080 } 00081 00082 } 00083 } 00084 00085 /* (non-Javadoc) 00086 * @see org.openmobileis.synchro.openmsp.client.db.ObjectDBImportQueryManager#replaceObject(java.lang.String, java.lang.Object) 00087 */ 00088 public void replaceObject(String uid, Object object) throws DatabaseException { 00089 this.addObject(uid, object); 00090 00091 } 00092 00093 /* (non-Javadoc) 00094 * @see org.openmobileis.synchro.openmsp.client.db.ObjectDBImportQueryManager#deleteObject(java.lang.String) 00095 */ 00096 public void deleteObject(String uid) throws DatabaseException { 00097 try { 00098 SynchroFastObjectDB db = (SynchroFastObjectDB)FastObjectDBManager.getCurrentFODB(); 00099 db.deleteWithIdFODB(collectionName, uid); 00100 if (this.synchroListener !=null) this.synchroListener.notifyDBDelete(uid); 00101 } catch (Throwable ex) { 00102 throw new DatabaseException(ex); 00103 } 00104 } 00105 00106 /* (non-Javadoc) 00107 * @see org.openmobileis.synchro.openmsp.client.db.ObjectDBImportQueryManager#beginImport() 00108 */ 00109 protected void beginImport() throws DatabaseException { 00110 00111 } 00112 00113 /* (non-Javadoc) 00114 * @see org.openmobileis.synchro.openmsp.client.db.ObjectDBImportQueryManager#endImport() 00115 */ 00116 protected void endImport() throws DatabaseException { 00117 // TODO Auto-generated method stub 00118 00119 } 00120 00121 public SynchroFODBReturnListener getSynchroReturnListener() { 00122 return synchroListener; 00123 } 00124 }