Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

JournalQueryManager.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
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 
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   * check if the sync table exists. IF it does not exist, create it
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   * Add a Service journal entry in the database
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 { //add
00092         FastObjectDBManager.getCurrentFODB().add("OMJournalEntry", entry);
00093       }
00094     } catch (Throwable ex) {
00095       throw new DatabaseException(ex);
00096     }
00097   }
00098 
00099   /*
00100   * Delete all entries for a service
00101   * parameters SERVICE_NAME
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   * get all entries for service
00117   * parameters SERVICE_NAME
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 }

Generated on Wed Dec 14 21:05:34 2005 for OpenMobileIS by  doxygen 1.4.4