Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

TestFastObjectDB.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
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  *  2004 Creation P.Delrieu
00026  *  2004 Modified by Romain Beaugrand
00027  * 
00028  */
00029 package org.openmobileis.database.fastobjectdb.db.test;
00030 
00031 import java.io.BufferedReader;
00032 import java.io.File;
00033 import java.io.FileReader;
00034 import java.util.HashMap;
00035 
00036 import org.odbms.Constraint;
00037 import org.odbms.ObjectSet;
00038 import org.odbms.Query;
00039 import org.openmobileis.common.util.collection.Array;
00040 import org.openmobileis.common.util.log.LogManager;
00041 import org.openmobileis.database.fastobjectdb.FODBIndexDescriptor;
00042 import org.openmobileis.database.fastobjectdb.FODBIntIndexDescriptor;
00043 import org.openmobileis.database.fastobjectdb.FODBLongIndexDescriptor;
00044 import org.openmobileis.database.fastobjectdb.FODBStringIndexDescriptor;
00045 import org.openmobileis.database.fastobjectdb.FastObjectDB;
00046 import org.openmobileis.database.fastobjectdb.db.BackwardUniqueIndexIterator;
00047 import org.openmobileis.database.fastobjectdb.db.FODBCollection;
00048 import org.openmobileis.database.fastobjectdb.db.ForwardUniqueIndexIterator;
00049 import org.openmobileis.database.fastobjectdb.db.crypto.AcmeBlowfishCypher;
00050 import org.openmobileis.database.fastobjectdb.db.exception.FODBException;
00051 
00059 public final class TestFastObjectDB {
00060 
00061   private static int NB_SEARCH_CREATED_DATA = 30;
00062 
00063   private HashMap keyMap = new HashMap(500);
00064 
00065   private HashMap objectMap = new HashMap(500);
00066 
00067   private FastObjectDB db = null;
00068   
00069   /*class TestRequestThread() {
00070     TestRequestThread(){
00071       }
00072   }*/
00073 
00077   public TestFastObjectDB() {
00078     super();
00079   }
00080 
00081   protected void testTree(Array inputDataList, FastObjectDB db) throws FODBException {
00082     //verify index
00083     for (int i = 0; i < inputDataList.size(); i++) {
00084       String key = (String) inputDataList.get(i);
00085       try {
00086         //    SELECT TESTDATA.KEY FROM TESTDATA where TESTDATA.KEY = 'key'
00087         Query q = db.query();
00088         q.constrain(TestData.class);
00089         Query q2 = q.descend("getKey()");
00090         q2.constrain(key).equal();
00091         ObjectSet set = q.execute();
00092         if (set.size() == 0) {
00093           throw new FODBException("ERROR Key not found :" + key);
00094         } else if (!((TestData) set.next()).getKey().equals(key)) {
00095           throw new FODBException("ERROR Key Not egal to value :" + key);
00096         }
00097       } catch (FODBException ex) {
00098         LogManager.traceError(0, "Bad KEY READ :" + key);
00099         throw ex;
00100       }
00101     }
00102   }
00103 
00104   protected void testRomvedTree(Array inputDataList, FastObjectDB db) throws FODBException {
00105     //verify index
00106     for (int i = 0; i < inputDataList.size(); i++) {
00107       String key = (String) inputDataList.get(i);
00108       try {
00109         //                              SELECT TESTDATA.KEY FROM TESTDATA where TESTDATA.KEY = 'key'
00110         Query q = db.query();
00111         q.constrain(TestData.class);
00112         Query q2 = q.descend("getKey()");
00113         q2.constrain(key).equal();
00114         ObjectSet set = q.execute();
00115         if (set.size() != 0) {
00116           throw new FODBException("ERROR Key found :" + key);
00117         }
00118       } catch (FODBException ex) {
00119         LogManager.traceError(0, "Bad KEY READ :" + key);
00120         throw ex;
00121       }
00122     }
00123   }
00124 
00125   private void testInitIndexIterator(String collectionName, String memberName, Array objList) throws FODBException {
00126     ForwardUniqueIndexIterator iterf = db.getCollection(collectionName).getForwardIndexIterator(memberName);
00127     for (int i = 0; i < NB_SEARCH_CREATED_DATA; i++) {
00128       iterf.initCurrentNode(new Integer(i));
00129       for (int j = i + 1; j < NB_SEARCH_CREATED_DATA; j++) { //validate iteration
00130         TestSearchData data = (TestSearchData) iterf.next();
00131         if (data.getKey() != j) {
00132           throw new FODBException("testInitIndexIterator error bad iteration");
00133         }
00134       }
00135     }
00136     BackwardUniqueIndexIterator iterb = db.getCollection(collectionName).getBackwardIndexIterator(memberName);
00137     for (int i = 0; i < NB_SEARCH_CREATED_DATA; i++) {
00138       iterb.initCurrentNode(new Integer(i));
00139       for (int j = i - 1; j >= 0; j--) { //validate iteration
00140         TestSearchData data = (TestSearchData) iterb.prev();
00141         if (data.getKey() != j) {
00142           throw new FODBException("testInitIndexIterator error bad iteration");
00143         }
00144       }
00145     }
00146 
00147   }
00148 
00149   private void testIndexIterator(String collectionName, String memberName, Array objList) throws FODBException {
00150     ForwardUniqueIndexIterator iterf = db.getCollection(collectionName).getForwardIndexIterator(memberName);
00151     Array indexobj = new Array();
00152     while (iterf.hasNext()) {
00153       indexobj.add(iterf.next());
00154     }
00155     //valide arrays
00156     if (indexobj.size() != objList.size()) {
00157       throw new FODBException("testIndexIterator bad size");
00158     }
00159     for (int i = 0; i < indexobj.size(); i++) {
00160       Object obj = objList.get(i);
00161       if (!indexobj.contains(obj)) {
00162         throw new FODBException("testIndexIterator obj not found :" + obj);
00163       }
00164     }
00165 
00166     //test prev
00167     BackwardUniqueIndexIterator iterb = db.getCollection(collectionName).getBackwardIndexIterator(memberName);
00168     indexobj = new Array();
00169     while (iterb.hasPrev()) {
00170       indexobj.add(iterb.prev());
00171     }
00172     //valide arrays
00173     if (indexobj.size() != objList.size()) {
00174       throw new FODBException("testIndexIterator bad size");
00175     }
00176     for (int i = 0; i < indexobj.size(); i++) {
00177       Object obj = objList.get(i);
00178       if (!indexobj.contains(obj)) {
00179         throw new FODBException("testIndexIterator obj not found :" + obj);
00180       }
00181     }
00182   }
00183 
00184   private void addKeyToMap(String key) {
00185     String begin = null;
00186     if (key.length() >= TestData.NB_BEGIN_KEY_LETTER) {
00187       begin = key.substring(0, TestData.NB_BEGIN_KEY_LETTER);
00188     } else {
00189       begin = key;
00190     }
00191     Integer inter = (Integer) keyMap.get(begin);
00192     if (inter == null) {
00193       inter = new Integer(0);
00194     } else {
00195       keyMap.remove(begin);
00196     }
00197     int old = inter.intValue();
00198     old++;
00199     keyMap.put(begin, new Integer(old));
00200   }
00201 
00202   private void removeKeyToMap(String key) {
00203     String begin = null;
00204     if (key.length() >= TestData.NB_BEGIN_KEY_LETTER) {
00205       begin = key.substring(0, TestData.NB_BEGIN_KEY_LETTER);
00206     } else {
00207       begin = key;
00208     }
00209     Integer inter = (Integer) keyMap.get(begin);
00210     if (inter == null) {
00211       return;
00212     } else {
00213       keyMap.remove(begin);
00214     }
00215     int old = inter.intValue();
00216     old--;
00217     if (old == 0) {
00218       keyMap.remove(begin);
00219     } else {
00220       keyMap.put(begin, new Integer(old));
00221     }
00222   }
00223 
00224   private int getNbKeyForBegin(String begin) {
00225     Integer inter = (Integer) keyMap.get(begin);
00226     if (inter == null)
00227       return 0;
00228     else
00229       return inter.intValue();
00230   }
00231 
00232   public void testFindLike(Array inputDataList, FastObjectDB db) throws FODBException {
00233     for (int i = 0; i < inputDataList.size(); i++) {
00234       String key = (String) inputDataList.get(i);
00235       String begin = null;
00236       if (key.length() >= TestData.NB_BEGIN_KEY_LETTER) {
00237         begin = key.substring(0, TestData.NB_BEGIN_KEY_LETTER);
00238       } else {
00239         begin = key;
00240       }
00241       //  SELECT TESTDATA.KEY FROM TESTDATA where TESTDATA.KEY like '%begin%'
00242       Query q = db.query();
00243       q.constrain(TestData.class);
00244       Query q2 = q.descend("getKey()");
00245       q2.constrain(begin).like();
00246       ObjectSet set = q.execute();
00247       int listnb = this.getNbKeyForBegin(begin);
00248       if (listnb != set.size()) {
00249         throw new FODBException("ERROR BAD NUMBER of KEY LIKE FOUND :" + key);
00250       } else {
00251         for (int j = 0; j < set.size(); j++) {
00252           TestData objkey = (TestData) set.next();
00253           if (!objkey.getKey().startsWith(begin)) {
00254             throw new FODBException("ERROR BAD FIND LIKE VALUE FOR KEY :" + key);
00255           }
00256 
00257         }
00258       }
00259     }
00260 
00261   }
00262 
00263   public void testMultipleIndex(Array inputDataList, FastObjectDB db) throws FODBException {
00264     for (int i = 0; i < inputDataList.size(); i++) {
00265       String key = (String) inputDataList.get(i);
00266       String begin = null;
00267       if (key.length() >= TestData.NB_BEGIN_KEY_LETTER) {
00268         begin = key.substring(0, TestData.NB_BEGIN_KEY_LETTER);
00269       } else {
00270         begin = key;
00271       }
00272       //                SELECT TESTDATA.KEY FROM TESTDATA where TESTDATA.DEBKEY = 'begin'
00273       Query q = db.query();
00274       q.constrain(TestData.class);
00275       Query q2 = q.descend("getDebKey()");
00276       q2.constrain(begin).equal();
00277       ObjectSet set = q.execute();
00278       int listnb = this.getNbKeyForBegin(begin);
00279       if (listnb != set.size()) {
00280         throw new FODBException("ERROR BAD NUMBER of KEY LIKE FOUND :" + key);
00281       } else {
00282         while (set.hasNext()) {
00283           TestData objkey = (TestData) set.next();
00284           if (!objkey.getKey().startsWith(begin)) {
00285             throw new FODBException("ERROR BAD FIND LIKE VALUE FOR KEY :" + key);
00286           }
00287         }
00288       }
00289     }
00290 
00291   }
00292 
00293   public void openDB() {
00294     try {
00295       String tempdir = System.getProperty("user.dir") + File.separator;
00296       db = FastObjectDB.open(tempdir, "testdb");
00297       if (!db.isCollectionExist("TESTDATA")) {
00298         db.createCollection("TESTDATA", TestData.class);
00299         FODBStringIndexDescriptor KeyDescriptor = new FODBStringIndexDescriptor("KEY", FODBIndexDescriptor.UNIQUE, "getKey()", 12, 15);
00300         db.addIndex("TESTDATA", KeyDescriptor);
00301         FODBStringIndexDescriptor debKeyDescriptor = new FODBStringIndexDescriptor("DEBKEY", FODBIndexDescriptor.MULTIPLE, "getDebKey()", 10,
00302             TestData.NB_BEGIN_KEY_LETTER, 5);
00303         db.addIndex("TESTDATA", debKeyDescriptor);
00304       }
00305       FODBCollection col = db.getCollection("TESTDATA");
00306       col.setCollectionCypher(new AcmeBlowfishCypher()); //test with encryption
00307       if (!db.isCollectionExist("TESTDATAWITHARRAY")) {
00308         db.createCollection("TESTDATAWITHARRAY", TestDataWithArray.class);
00309         FODBStringIndexDescriptor intIdDescriptor = new FODBStringIndexDescriptor("ID1", FODBIndexDescriptor.UNIQUE, "getId()", 10, 50);
00310         db.addIndex("TESTDATAWITHARRAY", intIdDescriptor);
00311         FODBLongIndexDescriptor LongIdDescriptor = new FODBLongIndexDescriptor("ID2", FODBIndexDescriptor.UNIQUE, "getIdLong()", 10);
00312         db.addIndex("TESTDATAWITHARRAY", LongIdDescriptor);
00313         FODBStringIndexDescriptor StrDescriptor2 = new FODBStringIndexDescriptor("ELEMENTSTRING", FODBIndexDescriptor.MULTIPLE, "getStringList()", 10, 10);
00314         db.addIndex("TESTDATAWITHARRAY", StrDescriptor2);
00315         FODBIntIndexDescriptor IntDescriptor = new FODBIntIndexDescriptor("ELEMENTINT", FODBIndexDescriptor.MULTIPLE, "getIntList()", 10, 10);
00316         db.addIndex("TESTDATAWITHARRAY", IntDescriptor);
00317         FODBLongIndexDescriptor LongDescriptor = new FODBLongIndexDescriptor("ELEMENTLONG", FODBIndexDescriptor.MULTIPLE, "getLongList()", 15, 64);
00318         db.addIndex("TESTDATAWITHARRAY", LongDescriptor);
00319       }
00320     } catch (Throwable ex) {
00321       ex.printStackTrace();
00322     }
00323   }
00324 
00325   public void testDBSearch() {
00326     LogManager.traceInfo(0, "BEGIN testDBSearch");
00327     try {
00328       if (!db.isCollectionExist("TESTSEARCH")) {
00329         db.createCollection("TESTSEARCH", TestSearchData.class);
00330         FODBIntIndexDescriptor KeyDescriptor = new FODBIntIndexDescriptor("KEY", FODBIndexDescriptor.UNIQUE, "getKey()", 5);
00331         db.addIndex("TESTSEARCH", KeyDescriptor);
00332         FODBIntIndexDescriptor debKeyDescriptor = new FODBIntIndexDescriptor("DIZ", FODBIndexDescriptor.MULTIPLE, "getDizaine()", 5, 5);
00333         db.addIndex("TESTSEARCH", debKeyDescriptor);
00334       } else    {
00335         //remove all key
00336         for (int i = 0; i < NB_SEARCH_CREATED_DATA; i++) {
00337           TestSearchData data = new TestSearchData(i);
00338           db.delete("TESTSEARCH", data);
00339         }
00340       }
00341       
00342       //add db data
00343       Array listdata = new Array(NB_SEARCH_CREATED_DATA);
00344       for (int i = 0; i < NB_SEARCH_CREATED_DATA; i++) {
00345         TestSearchData data = new TestSearchData(i);
00346         db.add("TESTSEARCH", data);
00347         listdata.add(data);
00348    //     this.testIndexIterator("TESTSEARCH", "getKey()", listdata);
00349       }
00350       this.testIndexIterator("TESTSEARCH", "getKey()", listdata);
00351       this.testInitIndexIterator("TESTSEARCH", "getKey()", listdata);
00352 
00353       //query SELECT * FROM TESTSEARCH
00354       Query q = db.query();
00355       q.constrain(TestSearchData.class);
00356       Query subq = q.descend("getKey()"); //specify an index to request.
00357       ObjectSet set = q.execute(); //execute with no constrain to get all objects
00358       this.showSet(set, "QUERY select all : ");
00359 
00360       //query SELECT * FROM TESTSEARCH where getKey=1
00361       q = db.query();
00362       q.constrain(TestSearchData.class);
00363       subq = q.descend("getKey()"); //specify an index to request. change to get default unique index if not present.
00364       subq.constrain(new Integer(1)).equal();
00365       set = q.execute();
00366       this.showSet(set, "QUERY SELECT * FROM TESTSEARCH where getKey=1");
00367 
00368       //query SELECT * FROM TESTSEARCH where getKey<14
00369       q = db.query();
00370       q.constrain(TestSearchData.class);
00371       subq = q.descend("getKey()");
00372       subq.constrain(new Integer(14)).smaller();
00373       set = q.execute();
00374       this.showSet(set, "QUERY SELECT * FROM TESTSEARCH where getKey<14");
00375 
00376       //query SELECT * FROM TESTSEARCH where getKey>24
00377       q = db.query();
00378       q.constrain(TestSearchData.class);
00379       subq = q.descend("getKey()");
00380       subq.constrain(new Integer(24)).greater();
00381       set = q.execute();
00382       this.showSet(set, "QUERY SELECT * FROM TESTSEARCH where getKey>24");
00383 
00384       //query SELECT * FROM TESTSEARCH where getKey>16 AND getKey>23
00385       q = db.query();
00386       q.constrain(TestSearchData.class);
00387       subq = q.descend("getKey()");
00388       Constraint c = subq.constrain(new Integer(16)).greater();
00389       Constraint d = subq.constrain(new Integer(23)).smaller();
00390       c.and(d);
00391       set = q.execute();
00392       this.showSet(set, "QUERY SELECT * FROM TESTSEARCH where getkey>16 and getkey<23");
00393 
00394       //query SELECT * FROM TESTSEARCH where getKey>16 AND getKey>23
00395       q = db.query();
00396       q.constrain(TestSearchData.class);
00397       subq = q.descend("getKey()");
00398       c = subq.constrain(new Integer(16)).greater();
00399       Query subq2 = subq.descend("getDizaine()");
00400       d = subq2.constrain(new Integer(2)).equal();
00401       c.and(d);
00402       set = q.execute();
00403       this.showSet(set, "QUERY SELECT * FROM TESTSEARCH where getkey>16 and getDizaine=2");
00404 
00405       //query SELECT * FROM TESTSEARCH where getkey<16 OR getDizaine=2
00406       q = db.query();
00407       q.constrain(TestSearchData.class);
00408       subq = q.descend("getKey()");
00409       c = subq.constrain(new Integer(16)).smaller();
00410       subq2 = subq.descend("getDizaine()");
00411       d = subq2.constrain(new Integer(2)).equal();
00412       c.or(d);
00413       set = q.execute();
00414       this.showSet(set, "QUERY SELECT * FROM TESTSEARCH where getkey<16 OR getDizaine=2");
00415 
00416       //remove all key
00417       for (int i = 0; i < NB_SEARCH_CREATED_DATA; i++) {
00418         db.delete("TESTSEARCH", new TestSearchData(i));
00419       }
00420     } catch (Throwable ex) {
00421       ex.printStackTrace();
00422     }
00423     LogManager.traceInfo(0, "END testDBSearch");
00424 
00425   }
00426 
00427   private void showSet(ObjectSet set, String info) {
00428     LogManager.traceInfo(0, info);
00429     while (set.hasNext()) {
00430       LogManager.traceInfo(0, set.next());
00431     }
00432   }
00433 
00434   public void TestDBAndIndex() {
00435     try {
00436 
00437       Array inputDataList = new Array(100);
00438       Array inputTestDataList = new Array(100);
00439       String tempdir = System.getProperty("user.dir") + File.separator;
00440       BufferedReader reader = new BufferedReader(new FileReader(tempdir + "inputdata.txt"));
00441       //write index
00442       String line = null;
00443       LogManager.traceInfo(0, "Begin ADD");
00444       while ((line = reader.readLine()) != null) {
00445         int lineIndex = line.indexOf(' ');
00446         if (lineIndex != -1) {
00447           String key = line.substring(0, lineIndex);
00448           TestData data = new TestData(key);
00449           db.add("TESTDATA", data);
00450           inputTestDataList.add(data);
00451           inputDataList.add(key);
00452           this.addKeyToMap(key);
00453           objectMap.put(key, key);
00454   //        this.testIndexIterator("TESTDATA", "getKey()", inputTestDataList);
00455         }
00456 
00457       }
00458       LogManager.traceInfo(0, "END ADD");
00459       this.testIndexIterator("TESTDATA", "getKey()", inputTestDataList);
00460       this.testFindLike(inputDataList, db);
00461       this.testTree(inputDataList, this.db);
00462       this.testMultipleIndex(inputDataList, this.db);
00463       LogManager.traceInfo(0, "END INDEX TEST");
00464 
00465       LogManager.traceInfo(0, "BEGIN DELETE");
00466       Array removeList = (Array) inputDataList.clone();
00467       int increment = 100;
00468       while (inputDataList.size() != 0) {
00469         for (int i = 0; i < inputDataList.size(); i = i + increment) {
00470           String key = ((String) inputDataList.get(i));
00471           db.delete("TESTDATA", new TestData(key));
00472           inputTestDataList.remove(i);
00473           inputDataList.remove(i);
00474           this.removeKeyToMap(key);
00475  //         LogManager.traceInfo(0, "remove key :"+key);
00476  //             this.testIndexIterator("TESTDATA", "getKey()", inputTestDataList);
00477         }
00478   //      this.testTree(inputDataList, this.db);
00479   //      this.testMultipleIndex(inputDataList, this.db);
00480   //      this.testFindLike(inputDataList, this.db);
00481         increment = increment / 2;
00482         if (increment <= 0)
00483           increment = 1;
00484       }
00485       LogManager.traceInfo(0, "END DELETE");
00486 
00487       LogManager.traceInfo(0, "BEGIN TEST DELETED");
00488      this.testRomvedTree(removeList, db);
00489       LogManager.traceInfo(0, "END TEST DELETED");
00490 
00491     } catch (Throwable ex) {
00492       ex.printStackTrace();
00493     }
00494   }
00495 
00496   public void testDataWithArray() {
00497     LogManager.traceInfo(0, "BEGIN testDataWithArray");
00498    try {
00499       TestDataWithArray fruits = new TestDataWithArray("Fruits", 1000L);
00500       fruits.addElement("Fraise");
00501       fruits.addElement("Cerise");
00502       fruits.addElement("Pomme");
00503       fruits.addElement("Banane");
00504       for (int i = 0; i < 2; i++)
00505         fruits.addElement(i);
00506       for (long l = 1980L; l < 1984L; l++)
00507         fruits.addElement(l);
00508       db.add("TESTDATAWITHARRAY", fruits);
00509 
00510       TestDataWithArray legumes = new TestDataWithArray("Legumes", 2000L);
00511       legumes.addElement("Patate");
00512       legumes.addElement("Haricot");
00513       legumes.addElement("Courgette");
00514       legumes.addElement("Concombre");
00515       legumes.addElement("Epinard");
00516       for (int i = 10; i < 12; i++)
00517         legumes.addElement(i);
00518       for (long l = 2005L; l < 2009L; l++)
00519         legumes.addElement(l);
00520       db.add("TESTDATAWITHARRAY", legumes);
00521 
00522       Query q = db.query();
00523       q.constrain(TestDataWithArray.class);
00524       Query subq = q.descend("getId()"); //specify an index to request. change to get default unique index if not present.
00525       ObjectSet set = q.execute();
00526       this.showSet(set, "Tous les objets");
00527       
00528      q = db.query();
00529      q.constrain(TestDataWithArray.class);
00530      subq = q.descend("getId()");
00531      subq.constrain("Fruits").equal();
00532      set = q.execute();
00533      this.showSet(set,"Les Fruits");
00534       
00535      q = db.query();
00536      q.constrain(TestDataWithArray.class);
00537      subq = q.descend("getStringList()");
00538      set = q.execute();
00539      this.showSet(set,"Toutes les String");
00540       
00541      q = db.query();
00542      q.constrain(TestDataWithArray.class);
00543      subq = q.descend("getStringList()");
00544      subq.constrain("Pomme").equal();
00545      set = q.execute();
00546      this.showSet(set,"Est-ce que la Pomme c'est un fruit ?");
00547        
00548      q = db.query();
00549      q.constrain(TestDataWithArray.class);
00550      subq = q.descend("getIntList()");
00551      set = q.execute();
00552      this.showSet(set, "Tous les entiers");
00553      
00554      q.constrain(TestDataWithArray.class); subq = q.descend("getIntList()");
00555      subq.constrain(new Integer(1)).equal(); set = q.execute();
00556      this.showSet(set,"Groupe qui contient 1 (fruits)");
00557      
00558      q.constrain(TestDataWithArray.class); subq = q.descend("getIntList()");
00559      subq.constrain(new Integer(10)).equal(); set = q.execute();
00560      this.showSet(set,"Groupe qui contient 10 (legumes)");
00561      
00562      q.constrain(TestDataWithArray.class); subq = q.descend("getIntList()");
00563      subq.constrain(new Integer(10)).greater(); set = q.execute();
00564      this.showSet(set,"Groupe qui contient > 10 (legumes)");
00565       
00566      q.constrain(TestDataWithArray.class); subq = q.descend("getIntList()");
00567      subq.constrain(new Integer(15)).smaller(); set = q.execute();
00568      this.showSet(set,"Groupe qui contient < 15 (fruits et legumes)");
00569       
00570      q.constrain(TestDataWithArray.class); subq = q.descend("getIntList()");
00571      subq.constrain(new Integer(5)).smaller(); set = q.execute();
00572      this.showSet(set,"Groupe qui contient < 5 (fruits)");
00573      
00574      q.constrain(TestDataWithArray.class); subq = q.descend("getIntList()");
00575      subq.constrain(new Integer(9)).equal(); set = q.execute();
00576      this.showSet(set,"Groupe qui contient 9 (aucun)");
00577  
00578       q = db.query();
00579       q.constrain(TestDataWithArray.class);
00580       subq = q.descend("getLongList()");
00581       subq.constrain(new Long(1981L)).smaller();
00582       set = q.execute();
00583       this.showSet(set, "L'objet qui inf?rieur ? 1981L (fruits)");
00584 
00585       //remove all keys
00586       db.deleteWithId("TESTDATAWITHARRAY", "Fruits");
00587 
00588       System.out.println("db.deleteWithId(\"TESTDATAWITHARRAY\",\"Fruits\");");
00589         
00590       q.constrain(TestDataWithArray.class); subq = q.descend("getIntList()");
00591       subq.constrain(new Integer(5)).equal(); set = q.execute();
00592       this.showSet(set,"Groupe qui contient 5 (fruits)");
00593        
00594       q.constrain(TestDataWithArray.class); subq = q.descend("getIntList()");
00595       subq.constrain(new Integer(12)).equal(); set = q.execute();
00596       this.showSet(set,"Groupe qui contient 12 (legumes)");
00597       
00598       db.deleteWithId("TESTDATAWITHARRAY", "Legumes");
00599       System.out.println("db.deleteWithId(\"TESTDATAWITHARRAY\",\"Legumes\");");
00600     } catch (Throwable ex) {
00601       ex.printStackTrace();
00602     }
00603     LogManager.traceInfo(0, "END testDataWithArray");
00604   }
00605   
00606   public void testMultithread() {
00607     LogManager.traceDebug(0, "testMultithread BEGIN");
00608     LogManager.traceDebug(0, "testMultithread LOAD DB");
00609     String tempdir = System.getProperty("user.dir") + File.separator;
00610     try {
00611     BufferedReader reader = new BufferedReader(new FileReader(tempdir + "inputdata.txt"));
00612     //write index
00613     String line = null;
00614              while ((line = reader.readLine()) != null) {
00615               int lineIndex = line.indexOf(' ');
00616               if (lineIndex != -1) {
00617                 String key = line.substring(0, lineIndex);
00618                 TestData data = new TestData(key);
00619                 db.add("TESTDATA", data);
00620               }
00621             }
00622     } catch (Exception ex)      {
00623       LogManager.traceError(0, ex);
00624       return;
00625     }
00626     LogManager.traceDebug(0, "testMultithread END LOAD DB"); 
00627     
00628     
00629     LogManager.traceDebug(0, "testMultithread BEGIN test MULTITHREAD "); 
00630     TestThreadRequest testth1 = new TestThreadRequest(this.db, 1);
00631     Thread thread1 = new Thread(testth1);
00632     thread1.start();
00633     TestThreadRequest2 testth2 = new TestThreadRequest2(this.db, 2);
00634     Thread thread2 = new Thread(testth2);
00635     thread2.start();
00636     TestThreadRequest testth3 = new TestThreadRequest(this.db, 3);
00637     Thread thread3 = new Thread(testth3);
00638     thread3.start();
00639     TestThreadRequest2 testth4 = new TestThreadRequest2(this.db, 4);
00640     Thread thread4 = new Thread(testth4);
00641     thread4.start();
00642     TestThreadRequest testth5 = new TestThreadRequest(this.db, 5);
00643     Thread thread5 = new Thread(testth5);
00644     thread5.start();
00645     TestThreadRequest2 testth6 = new TestThreadRequest2(this.db, 6);
00646     Thread thread6 = new Thread(testth6);
00647     thread6.start();
00648     
00649     LogManager.traceDebug(0, "testMultithread END test MULTITHREAD "); 
00650     
00651   }
00652 
00653   public static void main(String[] args) {
00654     LogManager.registerLogManager(null);
00655     //set to test in multi user mode
00656  //   PropertiesManager.getManager().addProperty("org.openmobileis.database.fastobjectdb.usermode", "false");
00657     TestFastObjectDB test = new TestFastObjectDB();
00658     test.openDB();
00659     test.TestDBAndIndex();
00660     test.testDBSearch();
00661 
00662     test.testDataWithArray();
00663     test.testMultithread();
00664   }
00665 }

Generated on Wed Dec 14 21:05:35 2005 for OpenMobileIS by  doxygen 1.4.4