|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.niggle.data.AbstractDataSource | +--com.niggle.data.AbstractMutableDataSource | +--com.niggle.data.inmemory.InMemoryRecordSet
A simple implementation of the com.niggle.data.MutableDataSource interface. All records are kept in an flat array all in RAM. If you use this container, you handle persistence by registering a DataListener via addDataListener that keeps the persistent representation in synch as records are inserted, deleted, or updated.
Constructor Summary | |
InMemoryRecordSet()
|
Method Summary | |
void |
close()
A method that should be called to free any resources associated with the data source. |
void |
delete(java.lang.String type,
java.lang.Object key)
Delete a record given its primary lookup key. |
Record |
get(java.lang.String type,
java.lang.Object key)
|
void |
init(java.util.Properties props)
TODO |
void |
insert(Record record)
Adds a new record to the managed pool. |
java.util.List |
keys(java.lang.String type)
|
void |
loadRecords(java.io.ObjectInput input)
Slurp the records into this InMemoryRecordSet object with a stream-based idiom. |
protected void |
loadRecordsFromFlatFile(java.lang.String filename)
Wrapper around loadRecords() to read records from a flat file. |
protected java.lang.Object |
nextKey()
Returns the next available primary key, assuming that it is an integer. |
java.util.List |
select(java.lang.String type,
RecordFilter filter)
Fetches a list of records matching filter. |
void |
update(Record record)
Replaces an existing version of a record with a new updated version. |
Methods inherited from class com.niggle.data.AbstractMutableDataSource |
addDataListener, delete, fireDataEvent, freeze, getRecords, markStale, normalizeKey, removeDataListener, select, wipeCache |
Methods inherited from class com.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.niggle.data.DataSource |
get, getName, keys |
Constructor Detail |
public InMemoryRecordSet() throws java.io.IOException
Method Detail |
public void loadRecords(java.io.ObjectInput input) throws java.io.IOException
public void update(Record record) throws java.io.IOException
MutableDataSource
Not all underlying storage mediums will be able to support these semantics. Check your implementation carefully.
com.niggle.data.MutableDataSource
rec
- the new updated record.ModifiedRecordException
- thrown if the record was modified
by another process since rec was requested from a data source.java.io.IOException
- thrown in case of any other database or
communication error.public void insert(Record record) throws java.io.IOException
MutableDataSource
com.niggle.data.MutableDataSource
rec
- the record to addDuplicateRecordException
- if another record already exists
with same primary key as 'rec'.java.io.IOException
- if the record cannot be
initialized (i.e. has missing fields or invalid
field values, etc.), or in case of a low-level error.public java.util.List select(java.lang.String type, RecordFilter filter) throws java.io.IOException
MutableDataSource
com.niggle.data.MutableDataSource
the
- type of record we are interested in, possibly nullfilter
- the record filter, or null.public Record get(java.lang.String type, java.lang.Object key) throws java.io.IOException
com.niggle.data.DataSource
type
- the type of the record, if this is null,
then any type will do.key
- the lookup keypublic void init(java.util.Properties props) throws java.io.IOException
AbstractMutableDataSource
init
in class AbstractMutableDataSource
public java.util.List keys(java.lang.String type) throws java.io.IOException
com.niggle.data.DataSource
type
- the record type we are interested,
under some circumstances, this may be null.public void delete(java.lang.String type, java.lang.Object key) throws java.io.IOException
MutableDataSource
com.niggle.data.MutableDataSource
type
- the record type we want to delete
If this is null, we delete indistinctly with no sanity check.key
- the key to the object to delete.MissingRecordException
- thrown if the record to be
deleted could not be found.DataException
- thrown if the key maps to more than
one record.java.io.IOException
- thrown in case of any other database or
communication error.public void close() throws java.io.IOException
DataSource
close
in class AbstractMutableDataSource
protected java.lang.Object nextKey()
protected void loadRecordsFromFlatFile(java.lang.String filename) throws java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |