com.niggle.data
Class AbstractMutableDataSource

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--com.niggle.data.AbstractDataSource
                          |
                          +--com.niggle.data.AbstractMutableDataSource
All Implemented Interfaces:
DataChangeNotifier, DataSource, MutableDataSource, java.rmi.Remote, java.io.Serializable
Direct Known Subclasses:
InMemoryRecordSet, JDBCBackedRecordSet, JNDIMutableDataSource

public abstract class AbstractMutableDataSource
extends AbstractDataSource
implements MutableDataSource

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

Author:
Jonathan Revusky
See Also:
Serialized Form

Fields inherited from class java.rmi.server.RemoteObject
ref
 
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.
 void delete(java.lang.Object key)
          This is equivalent to delete(null, key)
protected  void fireDataEvent(DataEvent event)
          Fire a data event to the listeners.
 void forceUpdate(Record oldRec, Record newRec)
          Replace an existing version of a record with a new updated version.
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.niggle.data.AbstractDataSource
get, getName, keys
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.niggle.data.MutableDataSource
delete, insert, select, update
 
Methods inherited from interface com.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: DataChangeNotifier
Add a listener that gets notified if ever a record is inserted, updated or deleted.
Specified by:
addDataListener in interface DataChangeNotifier
Following copied from interface: com.niggle.data.DataChangeNotifier
Parameters:
dl - the listener

removeDataListener

public void removeDataListener(DataListener dl)
                        throws java.io.IOException
Description copied from interface: DataChangeNotifier
Remove a listener that gets notified if ever a record is inserted, updated or deleted.
Specified by:
removeDataListener in interface DataChangeNotifier
Following copied from interface: com.niggle.data.DataChangeNotifier
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

delete

public final void delete(java.lang.Object key)
                  throws java.io.IOException
Description copied from interface: MutableDataSource
This is equivalent to delete(null, key)
Specified by:
delete in interface MutableDataSource

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.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

forceUpdate

public void forceUpdate(Record oldRec,
                        Record newRec)
                 throws java.io.IOException
Description copied from interface: MutableDataSource
Replace an existing version of a record with a new updated version. Automatically replaces the prevous version, even if it has been modified by another process.

The client's version of the original record is passed in order to allow implementations to make the update as fine-grained as possible. Some will simply update the entire records, while others will update only modified fields.

Specified by:
forceUpdate in interface MutableDataSource
Following copied from interface: com.niggle.data.MutableDataSource
Parameters:
rec - the new updated record.
oldRec - the client's copy of the record it removed from the data source.
Throws:
java.io.IOException - thrown in case of a database or communication error. Note that ModifiedRecordException is never thrown by this method.

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.
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