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
00026 package org.openmobileis.synchro.journal;
00027
00028 import org.odbms.ObjectSet;
00029 import org.odbms.Query;
00030 import org.openmobileis.common.util.exception.ServiceException;
00031 import org.openmobileis.common.util.log.LogManager;
00032 import org.openmobileis.common.util.PropertiesManager;
00033 import org.openmobileis.common.util.collection.Array;
00034 import org.openmobileis.database.DatabaseException;
00035 import org.openmobileis.database.fastobjectdb.FODBCollectionDescriptor;
00036 import org.openmobileis.database.fastobjectdb.FODBIndexDescriptor;
00037 import org.openmobileis.database.fastobjectdb.FODBStringIndexDescriptor;
00038 import org.openmobileis.database.fastobjectdb.FastObjectDB;
00039 import org.openmobileis.database.fastobjectdb.FastObjectDBManager;
00040 import org.openmobileis.database.fastobjectdb.db.query.soda.FODBSodaObjectSet;
00041 import org.openmobileis.synchro.openmsp.client.db.ActionDB;
00042
00051 public class JournalQueryManager {
00052
00053 public JournalQueryManager() {
00054 }
00055
00056
00057
00058 public void createJournalTable() throws ServiceException, DatabaseException {
00059 String dbPath = PropertiesManager.getManager().getProperty("fastobjectdb.database.path");
00060 if (dbPath == null) {
00061 LogManager.traceError(0, "JournalQueryManager FPDB ERROR : FODB path property is not set. Can't create db");
00062 }
00063 try {
00064 FastObjectDB db = FastObjectDBManager.getCurrentFODB();
00065 if (!db.isCollectionExist("OMJournalEntry")) {
00066 FODBCollectionDescriptor descriptor = new FODBCollectionDescriptor("OMJournalEntry", JournalEntry.class);
00067 descriptor.setSynchronize(false);
00068 db.createCollection(descriptor);
00069 FODBStringIndexDescriptor IDDescriptor = new FODBStringIndexDescriptor("ID", FODBIndexDescriptor.UNIQUE, "getEntryID()", 12, 60);
00070 db.addIndex("OMJournalEntry", IDDescriptor);
00071 FODBStringIndexDescriptor serviceNameDescriptor = new FODBStringIndexDescriptor("ServiceName", FODBIndexDescriptor.MULTIPLE, "getServiceName()", 12, 50, 10);
00072 db.addIndex("OMJournalEntry", serviceNameDescriptor);
00073 }
00074 } catch (Throwable ex) {
00075 LogManager.traceError(0, "Client Factory FPDB ERROR : Unknown error during creation");
00076 LogManager.traceError(0, ex);
00077 }
00078 }
00079
00080
00081
00082 public void createOrUpdate(JournalEntry entry) throws DatabaseException {
00083 try {
00084 Query q = FastObjectDBManager.getCurrentFODB().query();
00085 q.constrain(JournalEntry.class);
00086 Query subq = q.descend("getEntryID()");
00087 subq.constrain(entry.getEntryID()).equal();
00088 ObjectSet set = q.execute();
00089 if (set.hasNext()) {
00090 FastObjectDBManager.getCurrentFODB().replace("OMJournalEntry", entry);
00091 } else {
00092 FastObjectDBManager.getCurrentFODB().add("OMJournalEntry", entry);
00093 }
00094 } catch (Throwable ex) {
00095 throw new DatabaseException(ex);
00096 }
00097 }
00098
00099
00100
00101
00102
00103 public void deleteAllEntryForService(String serviceName) throws ServiceException, DatabaseException {
00104 try {
00105 Array entryList = this.getAllEntryForService(serviceName);
00106 for (int i = 0; i < entryList.size(); i++) {
00107 JournalEntry entry = (JournalEntry) entryList.get(i);
00108 FastObjectDBManager.getCurrentFODB().delete("OMJournalEntry", entry);
00109 }
00110 } catch (Throwable ex) {
00111 throw new DatabaseException(ex);
00112 }
00113 }
00114
00115
00116
00117
00118
00119 public Array getAllEntryForService(String serviceName) throws ServiceException, DatabaseException {
00120 try {
00121 Query q = FastObjectDBManager.getCurrentFODB().query();
00122 q.constrain(JournalEntry.class);
00123 Query subq = q.descend("getServiceName()");
00124 subq.constrain(serviceName).equal();
00125 ObjectSet set = q.execute();
00126 return ((FODBSodaObjectSet)set).getArrayFromSet();
00127 } catch (Throwable ex) {
00128 throw new DatabaseException(ex);
00129 }
00130 }
00131 }