ResetFODBUpdatePostInstall.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2009 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 
00026 package org.openmobileis.bundle.update.terminal;
00027 
00028 import org.odbms.ObjectSet;
00029 import org.odbms.Query;
00030 import org.openmobileis.common.util.PropertiesManager;
00031 import org.openmobileis.common.util.log.LogManager;
00032 import org.openmobileis.database.fastobjectdb.FODBIndexDescriptor;
00033 import org.openmobileis.database.fastobjectdb.FODBStringIndexDescriptor;
00034 import org.openmobileis.database.fastobjectdb.FastObjectDB;
00035 import org.openmobileis.database.fastobjectdb.FastObjectDBManager;
00036 import org.openmobileis.database.fastobjectdb.db.test.TestData;
00037 import org.openmobileis.database.fastobjectdb.synchro.client.SynchroFastObjectDBManager;
00038 
00043 public class ResetFODBUpdatePostInstall implements FullUpdatePostInstallInterface {
00044 
00048         public ResetFODBUpdatePostInstall() {
00049                 // TODO Auto-generated constructor stub
00050         }
00051 
00052         /* (non-Javadoc)
00053          * @see org.openmobileis.bundle.update.terminal.FullUpdatePostInstallInterface#updateInstall()
00054          */
00055         public void updateInstall() {
00056                 try {
00057                         if (!FastObjectDBManager.getManager().isFodbStarted()) {
00058                                 //init db propeties.
00059                                 PropertiesManager.getManager().addProperty("fastobjectdb.database.path", System.getProperty("user.dir") + "/database");
00060                                 PropertiesManager.getManager().addProperty("fastobjectdb.database.name", "db");
00061                                 //init synchro properties
00062                                 PropertiesManager.getManager().addProperty("org.openmobileis.synchro.client.openmsp.numsyncpropsfile", System.getProperty("user.dir") + "/WEB-INF/conf/numsync.txt");
00063                                 FastObjectDBManager.registerManager(new SynchroFastObjectDBManager()); //init synchro db to be use as default db
00064                                 FastObjectDBManager.getManager().getCurrentFODB();
00065                         }
00066                         FastObjectDBManager.getManager().resetDB();
00067                         
00068                 } catch (Throwable ex) {
00069                         ex.printStackTrace();
00070                 }
00071 
00072         }
00073 
00074         public static void main(String[] args) {
00075                 LogManager.registerLogManager(null);
00076                 ResetFODBUpdatePostInstall update = new ResetFODBUpdatePostInstall();
00077                 update.updateInstall();
00078                 try {
00079 
00080                         FastObjectDB db = FastObjectDBManager.getManager().getCurrentFODB();
00081 
00082                         if (!db.isCollectionExist("TESTDATA")) {
00083                                 db.createCollection("TESTDATA", TestData.class);
00084                                 FODBStringIndexDescriptor KeyDescriptor = new FODBStringIndexDescriptor("KEY", FODBIndexDescriptor.UNIQUE, "getKey()", 12, 15);
00085                                 db.addIndex("TESTDATA", KeyDescriptor);
00086                                 FODBStringIndexDescriptor debKeyDescriptor = new FODBStringIndexDescriptor("DEBKEY", FODBIndexDescriptor.MULTIPLE, "getDebKey()", 10, TestData.NB_BEGIN_KEY_LETTER, 5);
00087                                 db.addIndex("TESTDATA", debKeyDescriptor);
00088                         }
00089       TestData data = new TestData("key1");      
00090       db.add("TESTDATA", data);
00091       //query SELECT * FROM TESTSEARCH
00092       Query q = db.query();
00093       q.constrain(TestData.class);
00094       q.descend("getKey()"); //specify an index to request.
00095       ObjectSet set = q.execute(); //execute with no constrain to get all objects     
00096       LogManager.traceInfo(0, set.next());
00097       
00098       update.updateInstall();
00099       
00100       //query SELECT * FROM TESTSEARCH
00101       q = db.query();
00102       q.constrain(TestData.class);
00103       q.descend("getKey()"); //specify an index to request.
00104       set = q.execute(); //execute with no constrain to get all objects     
00105       LogManager.traceInfo(0, Boolean.toString(set.hasNext()));
00106      
00107       db.add("TESTDATA", data);
00108       
00109       //query SELECT * FROM TESTSEARCH
00110       q = db.query();
00111       q.constrain(TestData.class);
00112       q.descend("getKey()"); //specify an index to request.
00113       set = q.execute(); //execute with no constrain to get all objects     
00114       LogManager.traceInfo(0, set.next());
00115 
00116                 } catch (Throwable ex) {
00117                         ex.printStackTrace();
00118                 }
00119 
00120         }
00121 
00122 }

Generated on Mon Jan 11 21:19:16 2010 for OpenMobileIS by  doxygen 1.5.4