com.revusky.niggle.data
Class AbstractMutableDataSource

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

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.
 void close()
          A method that should be called to free any resources associated with the data source.
protected  void fireDataEvent(DataEvent event)
          Fire a data event to the listeners.
protected  void freeze(Record rec)
          Called to mark the record as immutable.
 java.util.List getRecords(java.lang.Object key)
           
 void init(java.util.Properties props)
          TODO
protected  void markStale(Record rec)
          Mark the record as "stale".
protected static java.lang.String normalizeKey(java.lang.String type, java.lang.Object key)
           
 void removeDataListener(DataListener dl)
          Remove a listener that gets notified if ever a record is inserted, updated or deleted.
 java.util.List select(RecordFilter filter)
          This is equivalent to select(null, filter)
 void wipeCache()
          If this data source is backed by some external mechanism, like an RDBMS, wipes the in-memory cache, if one is being maintained.
 
Methods inherited from class com.revusky.niggle.data.AbstractDataSource
get, getName, keys
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.revusky.niggle.data.MutableDataSource
delete, insert, select, update
 
Methods inherited from interface com.revusky.niggle.data.DataSource
get, get, getName, keys, keys
 

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.niggle.data.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.niggle.data.MutableDataSource
Parameters:
dl - the listener

fireDataEvent

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

freeze

protected void freeze(Record rec)
               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.

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.String normalizeKey(java.lang.String type,
                                               java.lang.Object key)
                                        throws java.io.IOException
Returns:
the "normalized" key given the record type.

init

public void init(java.util.Properties props)
          throws java.io.IOException
TODO
Specified by:
init in interface DataSource
Overrides:
init in class AbstractDataSource

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.niggle.data.DataSource
Returns:
a List of records based on a lookup key. The result can be an empty list, but never null.

select

public final java.util.List select(RecordFilter filter)
                            throws java.io.IOException
Description copied from interface: MutableDataSource
This is equivalent to select(null, filter)
Specified by:
select in interface MutableDataSource

wipeCache

public void wipeCache()
               throws java.io.IOException
Description copied from interface: MutableDataSource
If this data source is backed by some external mechanism, like an RDBMS, wipes the in-memory cache, if one is being maintained. Otherwise, it does nothing.
Specified by:
wipeCache in interface MutableDataSource

close

public void close()
           throws java.io.IOException
Description copied from interface: DataSource
A method that should be called to free any resources associated with the data source. Note that no other methods should be called on this object after this one. (In many implementations, this method will likely do nothing.)
Specified by:
close in interface DataSource