FastObjectDBManager.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  */
00025 package org.openmobileis.database.fastobjectdb;
00026 
00027 import java.util.Hashtable;
00028 
00029 import org.openmobileis.common.context.ApplicationContextManager;
00030 import org.openmobileis.common.util.PropertiesManager;
00031 import org.openmobileis.common.util.exception.DatabaseException;
00032 import org.openmobileis.common.util.log.LogManager;
00033 import org.openmobileis.database.fastobjectdb.db.FODBCollection;
00034 import org.openmobileis.database.fastobjectdb.db.crypto.FODBCypher;
00035 
00036 
00046 public class FastObjectDBManager implements FastObjectDBManagerService{
00047         protected static Hashtable cypherList;
00048 
00049         protected FastObjectDB db;
00050         protected boolean fodbStarted = false;
00051         protected static FastObjectDBManager manager;
00052 
00053         protected FastObjectDBManager() {
00054 
00055         }
00056 
00057   public final static void registerManager(FastObjectDBManager newManager) {
00058         if (manager == null) {
00059                 manager = newManager;
00060                         ApplicationContextManager.getManager().addManager(manager);
00061         } else  {
00062                 LogManager.traceDebug(0, "SessionContextManager registerManager already done no use");
00063         }
00064   }
00065 
00066   public final static FastObjectDBManager getManager()  {
00067     if (manager == null)  {
00068       manager = new FastObjectDBManager();
00069       ApplicationContextManager.getManager().addManager(manager);
00070         }
00071           return manager;
00072   }
00073 
00080         public FastObjectDB getCurrentFODB() throws DatabaseException   {
00081                 if (db == null) {
00082                         String dbPath = PropertiesManager.getManager().getProperty("fastobjectdb.database.path");
00083                         String dbname = PropertiesManager.getManager().getProperty("fastobjectdb.database.name");
00084                         if ((dbPath == null) || (dbname == null))       {
00085                                 throw new DatabaseException("FODB ERROR : FODB path or name property is not set. Can't create db");
00086                         }
00087                         synchronized(FastObjectDBManager.class) {
00088                                 if (db==null)   {
00089                                         try     {
00090                                                 db = FastObjectDB.open(dbPath, dbname);
00091                                                 ApplicationContextManager.getManager().addManager(db);
00092                                                 fodbStarted = true;
00093                                         } catch (Throwable ex)  {
00094                                                 throw new DatabaseException(ex);
00095                                         }
00096                                 }
00097                         }
00098                 }
00099                 return db;
00100         }
00101 
00102 
00103         public boolean isFodbStarted() {
00104                 return fodbStarted;
00105         }
00106 
00110         public void flushDB() throws DatabaseException{
00111             if (db != null)     {
00112                 FODBCollection[] colList = db.getDatabaseCollectionArray();
00113                 cypherList = new Hashtable();
00114                 for (int i=0; i<colList.length; i++)    {
00115                     FODBCypher cypher = colList[i].getCollectionCypher();
00116                     if (cypher != null) {
00117                         cypherList.put(colList[i].getName(), cypher);
00118                     }
00119                 }
00120             }
00121             db=null;
00122             FastObjectDBManager.getManager().getCurrentFODB();
00123         }
00124 
00125 }

Generated on Tue May 22 23:01:09 2007 for OpenMobileIS by  doxygen 1.5.1-p1