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 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 }