com.revusky.oreo
Interface Record

All Known Implementing Classes:
DefaultRecord, RecordReference

public interface Record

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 a MutableDataSource 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 MutableDataSource, 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 MutableDataSource when the record first put under management using insert().

Author:
Jonathan Revusky
See Also:
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.
 RecordDescriptor getMetadata()
           
 Record getMutableCopy()
          create a clone.
 java.lang.Object getPrimaryKey()
          Retrieve the value of the record's primary key.
 java.lang.String getType()
           
 boolean isImmutable()
          Have the fields all been set? Once a record is put in a DataSource, its fields are immutable.
 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 concrete implementations will probably wrap this.
 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

getType

public java.lang.String getType()
Returns:
the name of this record type subclasses must implement this. e.g. "reminder"

getPrimaryKey

public java.lang.Object getPrimaryKey()
Retrieve the value of the record's primary key.
Returns:
the value of this record's primary key, or null if it has not been set.

setPrimaryKey

public void setPrimaryKey(java.lang.Object o)
set the value of this record's primary key. The record must be in a mutable state AND the primary key must be unset.

getMutableCopy

public Record getMutableCopy()
create a clone. A shallow copy of the record values should be enough for immutable records Note that a newly cloned object is in a mutable state, so that you can modify it.

isImmutable

public boolean isImmutable()
Have the fields all been set? Once a record is put in a DataSource, its fields are immutable.

isStale

public boolean isStale()
Has this record been deleted or superseded in the associated DataSource?

freeze

public void freeze()
            throws java.io.IOException
make this record immutable. This will typically only be called by a MutableDataSource object.

getMetadata

public RecordDescriptor getMetadata()
Returns:
an object that describes the data held in this record.
See Also:
RecordDescriptor

get

public java.lang.Object get(java.lang.String fieldname)
Method to get the value of a field by name. Concrete implementations may wrap this with a higher-level get/set API.
Parameters:
fieldname -  
Throws:
InvalidFieldException - if there is no field of that name.

get

public java.lang.Object get(FieldDescriptor field)
Low-level method to query the value of a field in a Record. concrete implementations will probably wrap this.
Parameters:
field - to query.
Returns:
an Object wrapper around field value.

set

public void set(FieldDescriptor field,
                java.lang.Object value)
Low-level method to set an individual field value concrete implementations will probably wrap this.
Parameters:
field - to set.
value - Object wrapping the value
Throws:
InvalidFieldException - if there is no field of that name.
ImmutableDataException - if this record is immutable @see #getMutableCopy()

set

public void set(java.lang.String fieldname,
                java.lang.Object value)
Method to set the value of a field by name. Concrete implementations may wrap this with a higher-level get/set API.
Parameters:
fieldname - the name of the field to set.
Throws:
InvalidFieldException - if there is no field of that name.
ImmutableDataException - if this record is immutable @see #getMutableCopy()

clearFields

public void clearFields()
reset the fields to their default state The record must be in a mutable state.
Throws:
ImmutableDataException - if this record is immutable @see #getMutableCopy()

setMetadata

public void setMetadata(RecordDescriptor desc)
Method only used internally.