public class TinyTable extends Object implements Serializable
| Modifier | Constructor and Description |
|---|---|
protected |
TinyTable(String tableName,
Class<?> keyClass,
Class<?> recordClass,
String tableFile)
Constructs a table
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
deleteRecord(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) |
Object |
findRecord(Object key)
Finds the record associated with the given key
|
Class<?> |
getKeyClass()
Returns the class of the keys for this table
|
Class<?> |
getRecordClass()
Returns the class of the records stored in this table
|
String |
getTableFile()
Returns the filename of this table (filesystem file path)
|
String |
getTableName()
Returns the logical name of this table
|
void |
insertOrUpdateRecord(Object key,
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(Object key,
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
|
Hashtable<Object,Object> |
loadTable()
Loads (or reloads) the table records from the file
|
void |
saveTable()
Saves the table records in the file
|
boolean |
updateRecord(Object key,
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) |
protected TinyTable(String tableName, Class<?> keyClass, Class<?> recordClass, 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 storedRuntimeException - if one of the parameters is nullpublic String getTableName()
public String getTableFile()
public Class<?> getKeyClass()
public Class<?> getRecordClass()
public boolean isLoaded()
public Hashtable<Object,Object> loadTable()
RuntimeException - if FileSystem I/O errorpublic void saveTable()
RuntimeException - if FileSystem I/O errorpublic Object findRecord(Object key)
key - the key (must not be null )RuntimeException - if an error occurspublic void insertOrUpdateRecord(Object key, Object record)
key - the key (must not be null )record - RuntimeException - if an error occurspublic void insertRecord(Object key, Object record)
key - the key (must not be null )record - RuntimeException - if an error occurs or if duplicate keypublic boolean updateRecord(Object key, Object record)
key - the key (must not be null )record - RuntimeException - if an error occurspublic boolean deleteRecord(Object key)
key - the key (must not be null )RuntimeException - if an error occursCopyright © 2016. All rights reserved.