com.revusky.oreo
Class AbstractMutableDataSource

java.lang.Object
  |
  +--com.revusky.oreo.AbstractDataSource
        |
        +--com.revusky.oreo.AbstractMutableDataSource
All Implemented Interfaces:
DataSource, MutableDataSource, java.rmi.Remote
Direct Known Subclasses:
InMemoryRecordSet, JDBCBackedRecordSet, XMLFileDataSource

public abstract class AbstractMutableDataSource
extends AbstractDataSource
implements MutableDataSource

A convenient base class for MutableDataSource implementations. Implements some methods that are likely to be used by most.

Author:
Jonathan Revusky

Constructor Summary
AbstractMutableDataSource()
          Our constructor must throw the exception since the superclass's constructor does.
 
Method Summary
 void addDataListener(DataListener dl)
          Add a listener that gets notified if ever a record is inserted, updated or deleted.
protected  void fireDataEvent(DataEvent event)
          Fire a data event to the listeners.
protected  void freeze(Record rec)
          This is equivalent to calling freeze(rec, true);
protected  void freeze(Record rec, boolean validate)
          Called to mark the record as immutable.
 java.util.List getRecords(java.lang.Object key)
           
protected  void markStale(Record rec)
          Mark the record as "stale".
protected static java.lang.Object normalizeKey(java.lang.String type, java.lang.String key)
           
 void removeDataListener(DataListener dl)
          Remove a listener that gets notified if ever a record is inserted, updated or deleted.
 
Methods inherited from class com.revusky.oreo.AbstractDataSource
close, get, getName, init, keys, wipeCache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.revusky.oreo.MutableDataSource
delete, insert, playEvent, select, update
 
Methods inherited from interface com.revusky.oreo.DataSource
close, get, get, getName, init, keys, keys, wipeCache
 

Constructor Detail

AbstractMutableDataSource

public AbstractMutableDataSource()
                          throws java.io.IOException
Our constructor must throw the exception since the superclass's constructor does.
Method Detail

addDataListener

public void addDataListener(DataListener dl)
                     throws java.io.IOException
Description copied from interface: MutableDataSource
Add a listener that gets notified if ever a record is inserted, updated or deleted.
Specified by:
addDataListener in interface MutableDataSource
Following copied from interface: com.revusky.oreo.MutableDataSource
Parameters:
dl - the listener

removeDataListener

public void removeDataListener(DataListener dl)
                        throws java.io.IOException
Description copied from interface: MutableDataSource
Remove a listener that gets notified if ever a record is inserted, updated or deleted.
Specified by:
removeDataListener in interface MutableDataSource
Following copied from interface: com.revusky.oreo.MutableDataSource
Parameters:
dl - the listener

fireDataEvent

protected void fireDataEvent(DataEvent event)
Fire a data event to the listeners.

freeze

protected void freeze(Record rec,
                      boolean validate)
               throws java.io.IOException
Called to mark the record as immutable. A subclass might override this routine, particularly one that uses a different implementation of the Record interface.
Parameters:
rec - the Record to freeze
validate - You can make this true if you don't want validation to take place. Be careful with this. You might use this if you are absolutely sure that there is no way that the data you are slurping in could be invalid. Thus you avoid superfluous checks.

freeze

protected final void freeze(Record rec)
                     throws java.io.IOException
This is equivalent to calling freeze(rec, true);

markStale

protected void markStale(Record rec)
Mark the record as "stale". It has either been deleted or superseded by a newer version.

normalizeKey

protected static java.lang.Object normalizeKey(java.lang.String type,
                                               java.lang.String key)
                                        throws java.io.IOException
Returns:
the "normalized" key given the record type.

getRecords

public final java.util.List getRecords(java.lang.Object key)
                                throws java.io.IOException
Specified by:
getRecords in interface DataSource
Following copied from interface: com.revusky.oreo.DataSource
Returns:
a List of records based on a lookup key. The result can be an empty list, but never null.