java.lang.Objectorg.objectweb.telosys.common.tinydb.TinyTable
This class represents one "table" of a "tiny database"
A "table" is based on a Hashtable instance, it contains 0..N "records" associated with a "key",
It provides standard entity persistance operations : insert, find, update, delete, insert or update
A table doesn't store the record object itself but a copy, in order to avoid unwanted changes
Constructor Summary | |
protected |
TinyTable(java.lang.String tableName,
java.lang.Class keyClass,
java.lang.Class recordClass,
java.lang.String tableFile)
Constructs a table |
Method Summary | |
boolean |
deleteRecord(java.lang.Object key)
Deletes the record associated with the given key If there's no record for this key nothing is deleted (it's not an error) |
java.lang.Object |
findRecord(java.lang.Object key)
Finds the record associated with the given key |
java.lang.Class |
getKeyClass()
Returns the class of the keys for this table |
java.lang.Class |
getRecordClass()
Returns the class of the records stored in this table |
java.lang.String |
getTableFile()
Returns the filename of this table (filesystem file path) |
java.lang.String |
getTableName()
Returns the logical name of this table |
void |
insertOrUpdateRecord(java.lang.Object key,
java.lang.Object record)
Inserts or update the given record associated with the given key If a record exists for the key it is updated, else it is inserted |
void |
insertRecord(java.lang.Object key,
java.lang.Object record)
Inserts the given record associated with the given key If a record already exists for this key, a "duplicate key" exception if throwned |
boolean |
isLoaded()
Return true if the table records have been loaded (at least on time) from the file |
java.util.Hashtable |
loadTable()
Loads (or reloads) the table records from the file |
void |
saveTable()
Saves the table records in the file |
boolean |
updateRecord(java.lang.Object key,
java.lang.Object record)
Updates the record associated with the given key If there's no record for this key nothing is updated (it's not an error) |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
protected TinyTable(java.lang.String tableName, java.lang.Class keyClass, java.lang.Class recordClass, java.lang.String tableFile)
tableName
- the logical name of the tablekeyClass
- the class of the key used to identify a recordrecordClass
- the class of the records stored in the tabletableFile
- the file where the table is physically stored
java.lang.RuntimeException
- if one of the parameters is nullMethod Detail |
public java.lang.String getTableName()
public java.lang.String getTableFile()
public java.lang.Class getKeyClass()
public java.lang.Class getRecordClass()
public boolean isLoaded()
public java.util.Hashtable loadTable()
java.lang.RuntimeException
- if FileSystem I/O errorpublic void saveTable()
java.lang.RuntimeException
- if FileSystem I/O errorpublic java.lang.Object findRecord(java.lang.Object key)
key
- the key (must not be null )
java.lang.RuntimeException
- if an error occurspublic void insertOrUpdateRecord(java.lang.Object key, java.lang.Object record)
key
- the key (must not be null )record
-
java.lang.RuntimeException
- if an error occurspublic void insertRecord(java.lang.Object key, java.lang.Object record)
key
- the key (must not be null )record
-
java.lang.RuntimeException
- if an error occurs or if duplicate keypublic boolean updateRecord(java.lang.Object key, java.lang.Object record)
key
- the key (must not be null )record
-
java.lang.RuntimeException
- if an error occurspublic boolean deleteRecord(java.lang.Object key)
key
- the key (must not be null )
java.lang.RuntimeException
- if an error occurs