|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.martiansoftware.trivialpersist.Record
A trivially persistent object. Records contain any number of fields of the following data types:
Floats or doubles may be added in the future.
The names and types of fields are defined in a <tablename>.schema file in the Store's base directory. The .schema file contains one line for each field, in the form fieldname=fieldtype. A silly example:
File order.schema
product_code=string
quantity=long
ordertime=date
rushdelivery=boolean
Method Summary | |
Record |
asWriteable()
Returns a copy of this Record that may be modified and saved. |
int |
compareTo(Object o)
Compares this Record's key with that of the specified object. |
void |
delete()
Deletes this record from the store (and disk). |
boolean |
getBoolean(String fieldName)
Retrieves a boolean value from this record |
Date |
getDate(String fieldName)
Retrieves a date field from this record |
String |
getDate(String fieldName,
DateFormat format)
Retrieves a date field from this record as a String. |
double |
getDouble(String fieldName)
Retrieves a double value from this record |
Key |
getKey()
Returns this record's key |
long |
getLong(String fieldName)
Retrieves a long value from this record |
Object |
getObject(String fieldName)
Returns the Object backing the specified field. |
String |
getString(String fieldName)
Retrieves a string field from this record |
String |
getString(String fieldName,
String defaultValue)
Retrieves a string field from this record |
Table |
getTable()
Returns the Table to which this Record belongs |
boolean |
hasValue(String fieldName)
Returns true iff this record has any value set for the specified field |
boolean |
isDirty()
Returns true iff this Record has unsaved changes |
boolean |
isNew()
Returns true iff this Record has never been saved |
boolean |
isReadOnly()
Returns true iff this Record is read-only |
Record |
save()
Saves this record to disk. |
Record |
setBoolean(String fieldName,
boolean value)
Sets a boolean value for this record |
Record |
setDate(String fieldName,
Date value)
Sets a date field for this record. |
Record |
setDate(String fieldName,
String value,
DateFormat format)
Sets a date field for this record |
Record |
setDouble(String fieldName,
double value)
Sets a double value for this record |
Record |
setLong(String fieldName,
long value)
Sets a long value for this record |
Record |
setString(String fieldName,
String value)
Sets a string field in this record |
Record |
unset(String fieldName)
Removes any value set for the specified field (if any). |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public boolean hasValue(String fieldName)
fieldName
- the name of the field to check for a value
public Record setString(String fieldName, String value)
fieldName
- the name of the field to setvalue
- the string value to set
public String getString(String fieldName)
fieldName
- the name of the field to retrieve
public String getString(String fieldName, String defaultValue)
fieldName
- the name of the field to retrievedefaultValue
- the default value to return if the specified field
has a null value
public Record setDate(String fieldName, Date value)
fieldName
- the name of the field to setvalue
- the Date value to set
public Record setDate(String fieldName, String value, DateFormat format)
fieldName
- the name of the field to setvalue
- the date value to set, encoded as a stringformat
- the date format to use for converting the specified
string to a java.util.Date. If a conversion error occurs, an
IllegalArgumentException is thrown.
public Date getDate(String fieldName)
fieldName
- the name of the date field to retrieve
public String getDate(String fieldName, DateFormat format)
fieldName
- the name of the date field to retrieveformat
- the date format to use in converting the date value
to a string
public Record setBoolean(String fieldName, boolean value)
fieldName
- the name of the field to setvalue
- the boolean value to set
public boolean getBoolean(String fieldName)
fieldName
- the name of the boolean field to retrieve
hasValue(String)
public Record setLong(String fieldName, long value)
fieldName
- the name of the field to setvalue
- the long value to set
public Record setDouble(String fieldName, double value)
fieldName
- the name of the field to setvalue
- the double value to set
public long getLong(String fieldName)
fieldName
- the name of the long value field to retrieve
hasValue(String)
public double getDouble(String fieldName)
fieldName
- the name of the double value field to retrieve
hasValue(String)
public Object getObject(String fieldName)
fieldName
- the name of the field Object to retrieve
public Record unset(String fieldName)
fieldName
- the name of the field to unset.
public Record save() throws TrivialPersistException
TrivialPersistException
- if an error of any kind occurs while
saving.public void delete() throws TrivialPersistException
TrivialPersistException
- if an error of any kind occurs while
deleting this recordpublic int compareTo(Object o)
compareTo
in interface Comparable
o
- the other Record to checkpublic Key getKey()
public boolean isNew()
public Table getTable()
public boolean isDirty()
public boolean isReadOnly()
public Record asWriteable()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |