|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
An interface that describes the canonical methods of a data record in the Oreo Object-Relational Layer.
Basically, a Record should have the semantics of an immutable set of values, where the values follow a scheme given by the metadata in the associated RecordDescriptor instance that can be got at via the method getMetadata()
The immutability semantics have a nuance.
A record's fields can be modified via set()
if the record is in a mutable state. Once a record is frozen
its values are immutable. This typically occurs when the record is
added to an OreoDataSource
container.
In this library, the way to "modify" data is via the getMutableCopy() method. This will give you a copy that can be modified. When that mutable copy is added to the OreoDataSource, the new version will replace the old version. The newer records will be frozen, i.e. immutable. Also, the older record will be marked stale, to indicate to any thread or object holding onto a reference that it has been superseded.
The real virtue of this scheme is that when you are working with a record that is immutable, you have a pretty much iron-clad guarantee that all of the data in the record is "valid" -- at least in the sense that it matches the metadata description given by getMetadata(). You also have none of the typical synchronization worries, where you have to think about the possibility that another thread can change any values out from under you.
Each record has a primary key which may be set automaticaly by
the OreoDataSource when the record first put under
management using insert()
.
RecordDescriptor
,
DefaultRecord
Method Summary | |
void |
clearFields()
reset the fields to their default state The record must be in a mutable state. |
void |
freeze()
make this record immutable. |
java.lang.Object |
get(FieldDescriptor field)
Low-level method to query the value of a field in a Record. |
java.lang.Object |
get(java.lang.String fieldname)
Method to get the value of a field by name. |
java.util.List |
getChildren()
|
RecordDescriptor |
getMetadata()
|
Record |
getMutableCopy()
create a clone. |
Record |
getParent()
|
java.lang.Object |
getPrimaryKey()
Retrieve the value of the record's primary key. |
java.lang.String |
getType()
|
boolean |
hasChildren()
Does this record have children? This should return the same as (!getChildren().isEmpty()) would. |
boolean |
isImmutable()
Have the fields all been set? Once a record is put in a DataSource, its fields are immutable. |
boolean |
isRootElement()
Does this record have a parent? This should return the same as (getParent() == null) but it is worth having a separate method, since, with some schemes, it could be more efficient to ask whether there is a root element or not, as opposed to actually fishing it out. |
boolean |
isStale()
Has this record been deleted or superseded in the associated DataSource? |
void |
set(FieldDescriptor field,
java.lang.Object value)
Low-level method to set an individual field value |
void |
set(java.lang.String fieldname,
java.lang.Object value)
Method to set the value of a field by name. |
void |
setMetadata(RecordDescriptor desc)
Method only used internally. |
void |
setPrimaryKey(java.lang.Object o)
set the value of this record's primary key. |
Method Detail |
public java.lang.String getType()
public java.lang.Object getPrimaryKey()
public void setPrimaryKey(java.lang.Object o)
public Record getMutableCopy()
public boolean isImmutable()
public boolean isStale()
public void freeze() throws DataException
DataException
public RecordDescriptor getMetadata()
RecordDescriptor
public java.lang.Object get(java.lang.String fieldname)
fieldname
-
InvalidFieldException
- if there is no field of that name.public java.lang.Object get(FieldDescriptor field)
field
- to query.
public void set(FieldDescriptor field, java.lang.Object value)
field
- to set.value
- Object wrapping the value
InvalidFieldException
- if there is no field of that name.
ImmutableDataException
- if this record
is immutable @see #getMutableCopy()public void set(java.lang.String fieldname, java.lang.Object value)
fieldname
- the name of the field to set.
InvalidFieldException
- if there is no field of that name.
ImmutableDataException
- if this record
is immutable @see #getMutableCopy()public void clearFields()
ImmutableDataException
- if this record
is immutable @see #getMutableCopy()public void setMetadata(RecordDescriptor desc)
public Record getParent() throws MissingContextException
MissingContextException
public java.util.List getChildren() throws MissingContextException
MissingContextException
public boolean isRootElement() throws MissingContextException
MissingContextException
public boolean hasChildren() throws MissingContextException
MissingContextException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |