com.revusky.niggle.data.inmemory
Class CrudeDataPersister
java.lang.Object
|
+--com.revusky.niggle.data.inmemory.CrudeDataPersister
- All Implemented Interfaces:
- DataListener, java.util.EventListener
- public class CrudeDataPersister
- extends java.lang.Object
- implements DataListener
A data listener that persists using an extremely
crude scheme. When a record is added,
it appends it to the flat file. When a record is deleted,
it appends an AntiRecord (dummy record)
to a flat file.
Periodically, it writes the entire flat file from scratch.
At that time, obsolete records are not written effectively purging all
knowlege of their existence.
This can be a decent first pass while working
up an application, but is not scaleable, of course.
The flat files use a readable ASCII format, not the usual
Java serialised object format.
- Author:
- Jonathan Revusky
Constructor Summary |
CrudeDataPersister(MutableDataSource dataSource,
java.lang.String filename,
int persistFrequency)
This constructor automatically
adds this object to the list of listeners
of the specified DataSource |
Method Summary |
void |
recordDeleted(DataEvent event)
invoked when the MutableDataSource whose events
we are listening to has just deleted a record. |
void |
recordInserted(DataEvent event)
invoked when the MutableDataSource whose events
we are listening to has just inserted a new record. |
void |
recordUpdated(DataEvent event)
invoked when the MutableDataSource whose events
we are listening to has just updated an existing record. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CrudeDataPersister
public CrudeDataPersister(MutableDataSource dataSource,
java.lang.String filename,
int persistFrequency)
throws java.io.IOException
- This constructor automatically
adds this object to the list of listeners
of the specified DataSource
- Parameters:
dataSource
- the DataSource whose events to
listen for and persist.filename
- the flat file to persist to.
recordDeleted
public void recordDeleted(DataEvent event)
throws java.io.IOException
- Description copied from interface:
DataListener
- invoked when the MutableDataSource whose events
we are listening to has just deleted a record.
- Specified by:
recordDeleted
in interface DataListener
recordUpdated
public void recordUpdated(DataEvent event)
throws java.io.IOException
- Description copied from interface:
DataListener
- invoked when the MutableDataSource whose events
we are listening to has just updated an existing record.
- Specified by:
recordUpdated
in interface DataListener
recordInserted
public void recordInserted(DataEvent event)
throws java.io.IOException
- Description copied from interface:
DataListener
- invoked when the MutableDataSource whose events
we are listening to has just inserted a new record.
- Specified by:
recordInserted
in interface DataListener