com.revusky.oreo.xml
Class XMLFileDataSource
java.lang.Object
|
+--com.revusky.oreo.AbstractDataSource
|
+--com.revusky.oreo.AbstractMutableDataSource
|
+--com.revusky.oreo.xml.XMLFileDataSource
- All Implemented Interfaces:
- DataListener, DataSource, java.util.EventListener, MutableDataSource, java.rmi.Remote
- public class XMLFileDataSource
- extends AbstractMutableDataSource
- implements DataListener
A class that uses an XML-based persistence scheme.
All of the records are held in memory.
You must specify a DATA_PATH property when configuring
an instance of this data source. This must be a directory
on which your process has read/write privileges.
You may optionally specify the base filename. If none
is specified, it will use the name of the data source.
You can specify the optional parameter ENCODING
to indicate the encoding in which the XML files will be stored.
The default is UTF-8.
You may also specify a COMPACT_FREQUENCY parameter,
which says how frequently to rotate the transaction log.
The default (if no value is specified) is 1000.
When the log is rotated, this datasource archives
a snapshot+log in gzip format. Compression seems
logical, since the XML format is so extremely fat and redundant!
Method Summary |
void |
delete(Record record)
Delete a record |
Record |
get(java.lang.String type,
java.lang.Object key)
|
void |
handleEvent(DataEvent event)
handle the event when the MutableDataSource we are listening
to has modified data |
void |
init(java.util.Properties properties)
A method that initializes a DataSource with a set of
initialization properties. |
void |
insert(Record record)
Adds a new record to the managed pool. |
java.util.List |
keys(java.lang.String type)
|
void |
playEvent(DataEvent event)
"play" an event
This will be mostly used in restarting an app
and reconstructing the state of the data from logs. |
java.util.List |
select(RecordFilter filter)
Fetches a list of records matching filter. |
void |
update(Record oldRec,
Record newRec)
Replaces an existing version of a record with a new updated version. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
XMLFileDataSource
public XMLFileDataSource()
throws java.io.IOException
init
public void init(java.util.Properties properties)
throws java.io.IOException
- Description copied from interface:
DataSource
- A method that initializes a DataSource with a set of
initialization properties. This is called internally
within Oreo and should not be called by application
code. As an implementor, you should make sure
that this method is only called once, for example,
throw a RuntimeException if an attempt is made to call this
on a DataSource a second time.
- Overrides:
init
in class AbstractDataSource
delete
public void delete(Record record)
throws java.io.IOException
- Description copied from interface:
MutableDataSource
- Delete a record
- Following copied from interface:
com.revusky.oreo.MutableDataSource
- Parameters:
the
- record to delete.
update
public void update(Record oldRec,
Record newRec)
throws java.io.IOException
- Description copied from interface:
MutableDataSource
- Replaces an existing version of a record with a new updated version.
Some implementations may use the oldRec parameter
to guarantee that there are no concurrency issues.
In such case, it would throw a ConcurrentModificationException
- Following copied from interface:
com.revusky.oreo.MutableDataSource
- Parameters:
oldRec
- the record to replace.newRec
- the new record.- Throws:
java.io.IOException
- thrown in case of any other database or
communication error.
insert
public void insert(Record record)
throws java.io.IOException
- Description copied from interface:
MutableDataSource
- Adds a new record to the managed pool.
- Following copied from interface:
com.revusky.oreo.MutableDataSource
- Parameters:
rec
- the record to add- Throws:
DuplicateRecordException
- 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.
select
public java.util.List select(RecordFilter filter)
throws java.io.IOException
- Description copied from interface:
MutableDataSource
- Fetches a list of records matching filter. If filter is null,
returns all the records in the container.
- Following copied from interface:
com.revusky.oreo.MutableDataSource
- Parameters:
filter
- the record filter, or null.- Returns:
- a List of all the records that are an instance of a
given class. If no records match the filter, an empty List.
get
public Record get(java.lang.String type,
java.lang.Object key)
throws java.io.IOException
- Following copied from interface:
com.revusky.oreo.DataSource
- Parameters:
type
- the type of the record, if this is null,
then any type will do.key
- the lookup key- Returns:
- a Record of the given type, with
the given lookup key. If the data source allows multiple records,
only returns the first one found. Use getRecords() in that situation.
returns null if none is found.
keys
public java.util.List keys(java.lang.String type)
throws java.io.IOException
- Following copied from interface:
com.revusky.oreo.DataSource
- Parameters:
type
- the record type we are interested,
under some circumstances, this may be null.- Returns:
- a list of all valid lookup keys that correspond
to a given record type.
handleEvent
public void handleEvent(DataEvent event)
throws java.io.IOException
- Description copied from interface:
DataListener
- handle the event when the MutableDataSource we are listening
to has modified data
- Specified by:
handleEvent
in interface DataListener
playEvent
public void playEvent(DataEvent event)
throws java.io.IOException
- Description copied from interface:
MutableDataSource
- "play" an event
This will be mostly used in restarting an app
and reconstructing the state of the data from logs.
Note that data listeners are not notified.