org.objectweb.telosys.common.tinydb
Class TinyDatabase

java.lang.Object
  extended byorg.objectweb.telosys.common.tinydb.TinyDatabase

public class TinyDatabase
extends java.lang.Object

This class represents a "tiny database" instance
A "tiny database" is a set of "tables" ( based on Java Hashtable instances )
It works as an "in memory database", it can be useful for tests or very small databases
The database dictionary and the database tables are stored in the filesystem by serialization

Since:
v 1.0.3

Constructor Summary
TinyDatabase(java.lang.String sFolder)
          Constructs a new TinyDatabse located in the given folder
 
Method Summary
 TinyTable createTable(java.lang.String sTableName, java.lang.Class keyClass, java.lang.Class recordClass)
          Creates a new table in the database
 boolean dropTable(java.lang.String sTableName)
           
static TinyDatabase getCurrentDatabase()
          Returns the current database
 java.lang.String getDatabaseFolder()
          Returns the database filesystem folder (where the tables are saved as files)
 TinyTable getTable(java.lang.String sTableName)
          Returns the table object for the given table name
If the table doesn't exist an exception is thrown
The table returned is ready to use (its records are loaded)
 TinyTable getTable(java.lang.String sTableName, boolean mustExist)
          Returns the table object for the given table name (or null if the table is unknown and 'mustExist' flag = 'false')
If a table is returned, it is ready to use (its records are loaded)
 java.lang.String[] getTableNames()
          Returns all the table names registered in the database dictionary
 void loadAllTables()
          Loads all the tables in memory
 void saveAllTables()
          Saves all the tables in the filesystem
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TinyDatabase

public TinyDatabase(java.lang.String sFolder)
Constructs a new TinyDatabse located in the given folder

Parameters:
sFolder -
Method Detail

getDatabaseFolder

public java.lang.String getDatabaseFolder()
Returns the database filesystem folder (where the tables are saved as files)

Returns:

getCurrentDatabase

public static TinyDatabase getCurrentDatabase()
Returns the current database

Returns:

loadAllTables

public void loadAllTables()
Loads all the tables in memory


saveAllTables

public void saveAllTables()
Saves all the tables in the filesystem


getTableNames

public java.lang.String[] getTableNames()
Returns all the table names registered in the database dictionary

Returns:

getTable

public TinyTable getTable(java.lang.String sTableName)
Returns the table object for the given table name
If the table doesn't exist an exception is thrown
The table returned is ready to use (its records are loaded)

Parameters:
sTableName - the table name
Returns:

getTable

public TinyTable getTable(java.lang.String sTableName,
                          boolean mustExist)
Returns the table object for the given table name (or null if the table is unknown and 'mustExist' flag = 'false')
If a table is returned, it is ready to use (its records are loaded)

Parameters:
sTableName - the table name
mustExist - if true the table must exist (if it doesn't exist an exception is thrown),
if false a null value is returned if the table doesn't exist
Returns:

createTable

public TinyTable createTable(java.lang.String sTableName,
                             java.lang.Class keyClass,
                             java.lang.Class recordClass)
Creates a new table in the database

Parameters:
sTableName - the name of the table
recordClass - the class of the records stored in this table
Returns:

dropTable

public boolean dropTable(java.lang.String sTableName)