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.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
00054
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.getManager().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
00077
00078
00079 public void replaceObject(String uid, Object object) throws DatabaseException {
00080 this.addObject(uid, object);
00081
00082 }
00083
00084
00085
00086
00087 public void deleteObject(String uid) throws DatabaseException {
00088 try {
00089 SynchroFastObjectDB db = (SynchroFastObjectDB)FastObjectDBManager.getManager().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
00098
00099
00100 protected void beginImport() throws DatabaseException {
00101
00102 }
00103
00104
00105
00106
00107 protected void endImport() throws DatabaseException {
00108
00109
00110 }
00111
00112 public SynchroFODBReturnListener getSynchroReturnListener() {
00113 return synchroListener;
00114 }
00115 }