org.openmobileis.database.fastobjectdb
Class FastObjectDB

java.lang.Object
  extended byorg.openmobileis.database.fastobjectdb.FastObjectDB
Direct Known Subclasses:
SynchroFastObjectDB

public class FastObjectDB
extends java.lang.Object

Author:
Philippe Delrieu FastObjectDB is the main class of the librairie. All base function are accessed by this class FastObjectDB is an Object collection based database. Object are stored in collection. Object are retrieved using Index that are attached to collections. A SODA like API is use to request collection. FODB creation : db = FastObjectDB.open(dbdir, "testdb"); if (!FODBCollection.isCollectionExist(db, "TESTSEARCH")) { // if not created create it. db.createCollection("TESTSEARCH", TestSearchData.class); FODBUniqueIntIndexDescriptor KeyDescriptor = new FODBUniqueIntIndexDescriptor("KEY", "getKey()", 5); db.addIndex("TESTSEARCH", KeyDescriptor); FODBMultipleIntIndexDescriptor debKeyDescriptor = new FODBMultipleIntIndexDescriptor("DIZ", "getDizaine()", 5, 5); db.addIndex("TESTSEARCH", debKeyDescriptor); }

Field Summary
protected static int ACTION_CREATE
           
protected static int ACTION_OPEN
           
protected  CollectionManager colManager
           
 
Constructor Summary
protected FastObjectDB(java.lang.String dbRootDir, java.lang.String dbName, FODBMainFile fmf, int action)
          The Constructor.
 
Method Summary
 boolean add(java.lang.String colName, java.lang.Object obj)
          Add an element to a Collection of the database.
 boolean addIndex(java.lang.String colName, FODBIndexDescriptor descriptor)
          Add an index to a Collection of the Database.
 boolean createCollection(FODBCollectionDescriptor descriptor)
          Add a new collection to the database.
 boolean createCollection(java.lang.String collectionName, java.lang.Class objectType)
          Add a new collection to the database.
 boolean delete(java.lang.String colName, java.lang.Object obj)
          Delete an element of a Collection
 boolean deleteWithId(java.lang.String colName, java.lang.Object id)
          Delete an object of a Collection with its id
 FODBCollection getCollection(java.lang.String name)
           
 FODBCollection[] getDatabaseCollectionArray()
           
 java.lang.String getName()
           
 java.lang.String getRootDir()
           
 TransactionManager getTransactionManager()
           
 boolean isCollectionEmpty(java.lang.String colName)
           
 boolean isCollectionExist(java.lang.String colName)
           
static FastObjectDB open(java.lang.String dbRootDir, java.lang.String dbName)
          The function is called to open a database.
protected  boolean openCollection(java.lang.String collectionName)
          Open an existing collection.
 org.odbms.Query query()
          use to get base class to query FODB.
 boolean replace(java.lang.String colName, java.lang.Object obj)
          Replace an existing element in a Collection of the database.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ACTION_CREATE

protected static final int ACTION_CREATE
See Also:
Constant Field Values

ACTION_OPEN

protected static final int ACTION_OPEN
See Also:
Constant Field Values

colManager

protected CollectionManager colManager
Constructor Detail

FastObjectDB

protected FastObjectDB(java.lang.String dbRootDir,
                       java.lang.String dbName,
                       FODBMainFile fmf,
                       int action)
                throws BadDataFormatException,
                       FODBException
The Constructor. It is private, it is called by local methods create and open

Parameters:
dbRootDir - - database root directory
dbName - - database name.
fmf - - database main file.
action - - ACTION_CREATE or ACTION_OPEN
Throws:
BadDataFormatException
FODBException
Method Detail

open

public static FastObjectDB open(java.lang.String dbRootDir,
                                java.lang.String dbName)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException,
                                BadDataFormatException,
                                FODBException
The function is called to open a database. If the database does not exist, It's created.

Parameters:
dbRootDir - - database directory
dbName - - database name
Returns:
the database object that has been created.
Throws:
java.io.IOException
java.lang.ClassNotFoundException
BadDataFormatException
FODBException

getRootDir

public java.lang.String getRootDir()

getName

public java.lang.String getName()

getCollection

public FODBCollection getCollection(java.lang.String name)

isCollectionExist

public boolean isCollectionExist(java.lang.String colName)

createCollection

public boolean createCollection(FODBCollectionDescriptor descriptor)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException,
                                BadDataFormatException,
                                FODBException
Add a new collection to the database.

Returns:
true if it succeded, false otherwise.
Throws:
java.io.IOException
java.lang.ClassNotFoundException
BadDataFormatException
FODBException

createCollection

public boolean createCollection(java.lang.String collectionName,
                                java.lang.Class objectType)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException,
                                BadDataFormatException,
                                FODBException
Add a new collection to the database. the synchro parameter is set to true.

Parameters:
collectionName - - name of the new colletion
objectType - - type of objects stored in this collection.
Returns:
true if it succeded, false otherwise.
Throws:
java.io.IOException
java.lang.ClassNotFoundException
BadDataFormatException
FODBDataFileException
FODBCollectionException
FODBException

openCollection

protected boolean openCollection(java.lang.String collectionName)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException,
                                 BadDataFormatException,
                                 FODBException
Open an existing collection. This is not used and should be suppressed.

Parameters:
collectionName - - name of the collection
Returns:
true if it succeded, false otherwise.
Throws:
java.io.IOException
java.lang.ClassNotFoundException
BadDataFormatException
FODBException

isCollectionEmpty

public boolean isCollectionEmpty(java.lang.String colName)
                          throws DatabaseException
Throws:
DatabaseException

addIndex

public boolean addIndex(java.lang.String colName,
                        FODBIndexDescriptor descriptor)
                 throws BadDataFormatException,
                        FODBException
Add an index to a Collection of the Database.

Parameters:
colName - - name of the Collection
descriptor - - descriptor representing the index to add.
Returns:
true if it succeded, false otherwise.
Throws:
BadDataFormatException
FODBException

add

public boolean add(java.lang.String colName,
                   java.lang.Object obj)
            throws FODBException
Add an element to a Collection of the database.

Parameters:
colName - - Name of the collection
obj - - object to add.
Returns:
- true if it succeded, false otherwise.
Throws:
FODBException

replace

public boolean replace(java.lang.String colName,
                       java.lang.Object obj)
                throws FODBException
Replace an existing element in a Collection of the database.

Parameters:
colName - - Name of the Collection
obj - - Object to replace.
Returns:
true if it succeded, false otherwise.
Throws:
FODBException

query

public org.odbms.Query query()
use to get base class to query FODB. The FODB query API use the SODA API (http://http://odbms.org/soda) as a base API. From Soda specification the differences are : * only query on FODB collection : use query.constrain(MyCollectionObject.class) to declare it. * only query using index. use query.descend("IndexedFieldName") to specify an index. Exemple of use: Data class :TestSearchData class signature public final class TestSearchData implements Serializable { public int getKey(); public int getDizaine(); } FODB creation : db = FastObjectDB.open(dbdir, "testdb"); if (!FODBCollection.isCollectionExist(db, "TESTSEARCH")) { // if not created create it. db.createCollection("TESTSEARCH", TestSearchData.class); FODBUniqueIntIndexDescriptor KeyDescriptor = new FODBUniqueIntIndexDescriptor("KEY", "getKey()", 5); db.addIndex("TESTSEARCH", KeyDescriptor); FODBMultipleIntIndexDescriptor debKeyDescriptor = new FODBMultipleIntIndexDescriptor("DIZ", "getDizaine()", 5, 5); db.addIndex("TESTSEARCH", debKeyDescriptor); } The collection TestData where keys are in the interval [0..30]. for (int i=0; i Exemple of query : //query SELECT * FROM TESTSEARCH Query q = db.query(); q.constrain(TestSearchData.class); Query subq = q.descend("getKey()"); //specify an index to request. ObjectSet set = q.execute(); //query SELECT * FROM TESTSEARCH where getKey<14 q = db.query(); q.constrain(TestSearchData.class); subq = q.descend("getKey()"); subq.constrain(new Integer(14)).smaller(); set = q.execute(); //query SELECT * FROM TESTSEARCH where getKey>16 AND getKey<23 q = db.query(); q.constrain(TestSearchData.class); subq = q.descend("getKey()"); Constraint c = subq.constrain(new Integer(16)).greater(); Constraint d = subq.constrain(new Integer(23)).smaller(); c.and(d); set = q.execute(); //query SELECT * FROM TESTSEARCH where getKey>16 AND getDizaine=2 q = db.query(); q.constrain(TestSearchData.class); subq = q.descend("getKey()"); c = subq.constrain(new Integer(16)).greater(); Query subq2 = subq.descend("getDizaine()"); d = subq2.constrain(new Integer(2)).equal(); c.and(d); set = q.execute();

Since:
JDK 1.1
See Also:
Constraint, ObjectSet, Query, FODBSodaQuery

delete

public boolean delete(java.lang.String colName,
                      java.lang.Object obj)
               throws FODBException
Delete an element of a Collection

Parameters:
colName - - name of the Collection.
obj - - object to delete.
Returns:
true if it succeded, false otherwise.
Throws:
FODBException

deleteWithId

public boolean deleteWithId(java.lang.String colName,
                            java.lang.Object id)
                     throws FODBException
Delete an object of a Collection with its id

Parameters:
colName - - name of the Collection.
id - - id of the object to delete.
Returns:
true if it succeded, false otherwise.
Throws:
FODBException

toString

public java.lang.String toString()

getDatabaseCollectionArray

public FODBCollection[] getDatabaseCollectionArray()

getTransactionManager

public TransactionManager getTransactionManager()


Copyright 2006 OpenMobileIS. All Rights Reserved.