LeadsFactory.java

00001 
00025 package org.openmobileis.examples.mycrm.data.fodb;
00026 
00027 import org.odbms.ObjectSet;
00028 import org.odbms.Query;
00029 import org.openmobileis.common.context.ApplicationContextManager;
00030 import org.openmobileis.common.util.collection.Array;
00031 import org.openmobileis.common.util.exception.DatabaseException;
00032 import org.openmobileis.common.util.log.LogManager;
00033 import org.openmobileis.database.fastobjectdb.FODBCollectionDescriptor;
00034 import org.openmobileis.database.fastobjectdb.FODBIndexDescriptor;
00035 import org.openmobileis.database.fastobjectdb.FODBStringIndexDescriptor;
00036 import org.openmobileis.database.fastobjectdb.FastObjectDB;
00037 import org.openmobileis.database.fastobjectdb.FastObjectDBManager;
00038 import org.openmobileis.database.fastobjectdb.db.query.soda.FODBSodaObjectSet;
00039 import org.openmobileis.database.fastobjectdb.synchro.client.SynchroFastObjectDB;
00040 import org.openmobileis.examples.mycrm.data.Leads;
00041 
00042 public final class LeadsFactory {
00043 
00044   private static LeadsFactory manager;
00045 
00046   private LeadsFactory() {
00047     super();
00048     this.initDB();
00049   }
00050 
00051   public static LeadsFactory getManager() {
00052     if (manager == null) {
00053       synchronized (LeadsFactory.class) {
00054         if (manager == null) {
00055           manager = new LeadsFactory();
00056           //register the manager to avoid class garbage.
00057           ApplicationContextManager.getManager().addManager(manager);
00058         }
00059       }
00060     }
00061     return manager;
00062   }
00063 
00064   private void initDB() {
00065     try {
00066       FastObjectDB db = FastObjectDBManager.getCurrentFODB();
00067       // test if the collection has already been created.
00068       //if not create it. Created collection are automatiquely 
00069       // loaded when FODB is initialized.
00070       if (!db.isCollectionExist("leads")) {
00071         //SimpleOpenMISInit intialize the synchronized version of FODB.
00072         // all created collection are synchronized by default.
00073         // Synchro listener are automatiquely registered when the collection is created or loaded.
00074         // use the FODBCollectionDescriptor to define a collection that is not synchronized.
00075         FODBCollectionDescriptor coldes = new FODBCollectionDescriptor("leads", Leads.class);
00076         db.createCollection(coldes);
00077         //add index to query the collection by id
00078         FODBStringIndexDescriptor IDDescriptor = new FODBStringIndexDescriptor("ID", FODBIndexDescriptor.UNIQUE, "getId()", 12, 26);
00079         db.addIndex("leads", IDDescriptor);
00080         FODBStringIndexDescriptor AccountrDescriptor = new FODBStringIndexDescriptor("ACCOUNT", FODBIndexDescriptor.MULTIPLE, "getIdaccount()", 12, 26);
00081         db.addIndex("leads", AccountrDescriptor);
00082         //only not closed leads are synchronized.
00083       }
00084       //register the log renderer.
00085       //logrenderer are use to show synchronization result for this collection.
00086       ((SynchroFastObjectDB) db).registerJournalLogRenderer("leads", "Leads synchronization :");
00087 
00088     } catch (Throwable ex) {
00089       LogManager.traceError(0, "account Factory FODB ERROR : Unknown error during creation");
00090       LogManager.traceError(0, ex);
00091     }
00092   }
00093 
00094   public Leads getLeads(String id) throws DatabaseException {
00095     Query q = FastObjectDBManager.getCurrentFODB().query();
00096     q.constrain(Leads.class);
00097     Query subq = q.descend("getId()");
00098     subq.constrain(id).equal();
00099     ObjectSet set = q.execute();
00100     if (set.hasNext()) {
00101       return (Leads) set.next();
00102     } else {
00103       return null;
00104     }
00105   }
00106 
00107   public Array getAllLeads() throws DatabaseException {
00108     Query q = FastObjectDBManager.getCurrentFODB().query();
00109     q.constrain(Leads.class);
00110     q.descend("getId()");
00111     ObjectSet set = q.execute(); 
00112     return ((FODBSodaObjectSet)set).getArrayFromSet();
00113   }
00114 
00115   public Array getLeadsForAccount(String accountid) throws DatabaseException {
00116     Query q = FastObjectDBManager.getCurrentFODB().query();
00117     q.constrain(Leads.class);
00118     Query subq = q.descend("getIdaccount()");
00119     subq.constrain(accountid).equal();
00120     ObjectSet set = q.execute(); 
00121     return ((FODBSodaObjectSet)set).getArrayFromSet();
00122   }
00123 }

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