FODBHistoryManager.java

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  *  Modifications :
00025  *  Creation P.Delrieu
00026  * 
00027  */
00028 
00029 package org.openmobileis.modules.common.history;
00030 
00031 import org.odbms.ObjectSet;
00032 import org.odbms.Query;
00033 import org.openmobileis.common.util.PropertiesManager;
00034 import org.openmobileis.common.util.collection.Array;
00035 import org.openmobileis.common.util.exception.DatabaseException;
00036 import org.openmobileis.common.util.log.LogManager;
00037 import org.openmobileis.common.util.log.LogServices;
00038 import org.openmobileis.database.fastobjectdb.FODBCollectionDescriptor;
00039 import org.openmobileis.database.fastobjectdb.FODBIndexDescriptor;
00040 import org.openmobileis.database.fastobjectdb.FODBStringIndexDescriptor;
00041 import org.openmobileis.database.fastobjectdb.FastObjectDB;
00042 import org.openmobileis.database.fastobjectdb.FastObjectDBManager;
00043 
00044 
00045 
00046 
00059 public class FODBHistoryManager implements HistoryManager{
00060 
00061   private String histoName;
00062   private int sizeTab;
00063  
00064   
00065   public FODBHistoryManager (String name, int maxsize){
00066     super();
00067                 histoName = name;
00068                 sizeTab = maxsize;
00069                 
00070     String dbPath = PropertiesManager.getManager().getProperty("fastobjectdb.database.path");
00071                 if (dbPath == null)     {
00072                         LogManager.traceError(0, "History Factory FODB ERROR : FODB path property is not set. Can't create db");
00073                 }
00074                 try     {
00075                         FastObjectDB db = FastObjectDBManager.getCurrentFODB();
00076                         if (!db.isCollectionExist("FWKHISTORY")) {
00077               FODBCollectionDescriptor coldesc = new FODBCollectionDescriptor("FWKHISTORY", HistoryData.class);
00078               coldesc.setSynchronize(false);
00079                                 db.createCollection(coldesc);
00080                                 FODBStringIndexDescriptor IDMDescriptor = new FODBStringIndexDescriptor("Service", FODBIndexDescriptor.UNIQUE, "getService()", 12, 20);
00081                                 db.addIndex("FWKHISTORY", IDMDescriptor);
00082                         }
00083                         
00084                 }catch (Throwable ex){
00085                   
00086                   LogManager.traceError(0, "History Factory FODB ERROR : Unknown error during creation");
00087                         LogManager.traceError(0, ex);
00088                 }
00089                 
00090   }
00091 
00092   
00093         private void setUIds(HistoryData hd) {
00094          
00095           try{
00096       Query q = FastObjectDBManager.getCurrentFODB().query();
00097       q.constrain(HistoryData.class);
00098       Query subq = q.descend("getService()");
00099       subq.constrain(histoName).equal();
00100       ObjectSet set  = q.execute();
00101             
00102             if(set.hasNext()){
00103               FastObjectDBManager.getCurrentFODB().replace("FWKHISTORY",hd);
00104             }
00105             else{
00106               
00107               FastObjectDBManager.getCurrentFODB().add("FWKHISTORY",hd);
00108             }
00109             
00110           }
00111           catch(Throwable ex){
00112           
00113             LogManager.traceError(0, "History Factory FODB ERROR : Unknown error during creation");
00114                         LogManager.traceError(0, ex);
00115           }
00116           
00117         }
00118   
00119         private HistoryData getUIds() {
00120         
00121             try {
00122               Query q = FastObjectDBManager.getCurrentFODB().query();
00123               q.constrain(HistoryData.class);
00124               Query subq = q.descend("getService()");
00125               subq.constrain(histoName).equal();
00126               ObjectSet set  = q.execute();
00127               
00128               if(!set.hasNext()){
00129                 HistoryData Hd = new HistoryData(this.histoName,this.sizeTab);
00130                 return Hd;
00131               } else    {
00132                 
00133                 HistoryData Hd = (HistoryData)set.next();
00134                       return Hd;  
00135               }    
00136           
00137             } 
00138             catch (DatabaseException ex) {
00139               LogManager.traceError(LogServices.WEBSERVICE, ex);
00140               return null;
00141             }
00142             
00143         }
00144 
00145         public void addUID (String uid){
00146         
00147           HistoryData hd = this.getUIds();
00148           
00149             hd.addId(uid);
00150             setUIds(hd);
00151         }
00152          
00153         
00154         public void removeUID (String uid){
00155           
00156         }
00157 
00158         public Array getAll(){
00159           
00160           HistoryData Hd = this.getUIds();
00161           String[] uidsTemps = Hd.getIds();       
00162                 Array results = new Array(5);
00163                 for (int i=uidsTemps.length -1; i >= 0; i--) {
00164                         if (uidsTemps[i] != null) {
00165                                 results.add(uidsTemps[i]);
00166                         }
00167                 }
00168                 return results;
00169         }
00170 
00171         public String getHistoryName(){
00172           
00173           return this.histoName;
00174         }
00175 
00176 
00177 }

Generated on Mon Dec 4 11:03:26 2006 for OpenMobileIS by  doxygen 1.5.1-p1