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