|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.dellroad.stuff.schema.AbstractSchemaUpdater<File,PersistentFileTransaction>
org.dellroad.stuff.pobj.PersistentObjectSchemaUpdater<T>
T - type of the root persistent objectpublic class PersistentObjectSchemaUpdater<T>
Support superclass for PersistentObject schema updaters.
This class holds a nested PersistentObject and ensures that it's up to date when started.
Use getPersistentObject() to access it.
Updates are tracked by "secretly" inserting
elements into the serialized XML document; these updates are transparently removed when the document is read back.
In this way the document and its set of applied updates always travel together.
<pobj:updates>
Subclasses will typically override getInitialValue() for when there is no persistent file yet.
| Field Summary | |
|---|---|
protected boolean |
allowEmptyStart
|
protected long |
checkInterval
|
static long |
DEFAULT_CHECK_INTERVAL
Default check interval for "out-of-band" updates to the persistent file (1000Lms). |
protected PersistentObjectDelegate<T> |
delegate
|
protected File |
file
|
static String |
NAMESPACE_URI
XML namespace URI used for nested update elements. |
protected int |
numBackups
|
static QName |
UPDATE_ELEMENT_NAME
XML element name for a single update. |
static QName |
UPDATES_ELEMENT_NAME
XML element name for the updates list. |
protected long |
writeDelay
|
static String |
XML_PREFIX
Preferred XML namespace prefix for NAMESPACE_URI elements. |
static QName |
XMLNS_ATTRIBUTE_NAME
XML namespace URI used for namespace declarations. |
| Fields inherited from class org.dellroad.stuff.schema.AbstractSchemaUpdater |
|---|
log |
| Constructor Summary | |
|---|---|
PersistentObjectSchemaUpdater()
|
|
| Method Summary | |
|---|---|
protected void |
commitTransaction(PersistentFileTransaction transaction)
Commit a previously opened transaction. |
protected boolean |
databaseNeedsInitialization(PersistentFileTransaction transaction)
Determine if the database needs initialization. |
protected Set<String> |
getAppliedUpdateNames(PersistentFileTransaction transaction)
Determine which updates have already been applied to the database. |
protected T |
getInitialValue()
Get the initial value for the persistent object when no persistent file is found. |
PersistentObject<T> |
getPersistentObject()
Get the PersistentObject. |
protected void |
initializeDatabase(PersistentFileTransaction transaction)
Initialize an uninitialized database. |
protected PersistentFileTransaction |
openTransaction(File file)
Begin a transaction on the given database. |
protected void |
recordUpdateApplied(PersistentFileTransaction transaction,
String name)
Record an update as having been applied to the database. |
protected void |
rollbackTransaction(PersistentFileTransaction transaction)
Roll back a previously opened transaction. |
void |
setAllowEmptyStart(boolean allowEmptyStart)
Configure whether to all "empty starts". |
void |
setCheckInterval(long checkInterval)
Configure the check interval for "out-of-band" updates to the persistent file. |
void |
setDelegate(PersistentObjectDelegate<T> delegate)
Configure the PersistentObjectDelegate. |
void |
setFile(File file)
Configure the file used to store this object persistently. |
void |
setNumBackups(int numBackups)
Configure the number of backups to make of the persistent file. |
void |
setWriteDelay(long writeDelay)
Configure the maximum delay after an update operation before a write-back to the persistent file must be initiated. |
void |
start()
Start this instance. |
void |
stop()
Stop this instance. |
| Methods inherited from class org.dellroad.stuff.schema.AbstractSchemaUpdater |
|---|
apply, applyInTransaction, generateMultiUpdateName, getOrderingTieBreaker, getUpdates, initializeAndUpdateDatabase, isIgnoreUnrecognizedUpdates, isValidUpdateName, setIgnoreUnrecognizedUpdates, setUpdates |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String NAMESPACE_URI
public static final String XML_PREFIX
NAMESPACE_URI elements.
public static final QName UPDATES_ELEMENT_NAME
public static final QName UPDATE_ELEMENT_NAME
public static final QName XMLNS_ATTRIBUTE_NAME
public static final long DEFAULT_CHECK_INTERVAL
protected File file
protected long writeDelay
protected long checkInterval
protected int numBackups
protected boolean allowEmptyStart
protected PersistentObjectDelegate<T> delegate
| Constructor Detail |
|---|
public PersistentObjectSchemaUpdater()
| Method Detail |
|---|
public void setFile(File file)
public void setWriteDelay(long writeDelay)
public void setCheckInterval(long checkInterval)
DEFAULT_CHECK_INTERVAL.
public void setDelegate(PersistentObjectDelegate<T> delegate)
PersistentObjectDelegate. Required property.
public void setNumBackups(int numBackups)
PersistentObject.getNumBackups()public void setAllowEmptyStart(boolean allowEmptyStart)
PersistentObjectpublic void start()
IllegalArgumentException - if an invalid file, write delay, or delegate is configured
PersistentObjectException - if an error occurspublic void stop()
PersistentObjectException - if a delayed write back is pending and error occurs during writingpublic PersistentObject<T> getPersistentObject()
PersistentObject.
IllegalStateException - if this instance is not startedprotected T getInitialValue()
The implementation in PersistentObjectSchemaUpdater just returns null, which leaves the
initial root object unset. Subclasses should override as desired to provide an initial value.
The returned value must properly validate.
protected boolean databaseNeedsInitialization(PersistentFileTransaction transaction)
throws Exception
AbstractSchemaUpdater
If so, AbstractSchemaUpdater.initializeDatabase(T) will eventually be invoked.
databaseNeedsInitialization in class AbstractSchemaUpdater<File,PersistentFileTransaction>transaction - open transaction
Exception - if an error occurs while accessing the database
protected void initializeDatabase(PersistentFileTransaction transaction)
throws Exception
AbstractSchemaUpdater
initializeDatabase in class AbstractSchemaUpdater<File,PersistentFileTransaction>transaction - open transaction
Exception - if an error occurs while accessing the database
protected PersistentFileTransaction openTransaction(File file)
throws Exception
AbstractSchemaUpdater
openTransaction in class AbstractSchemaUpdater<File,PersistentFileTransaction>file - database
Exception - if an error occurs while accessing the database
protected void commitTransaction(PersistentFileTransaction transaction)
throws Exception
AbstractSchemaUpdater
commitTransaction in class AbstractSchemaUpdater<File,PersistentFileTransaction>transaction - open transaction previously returned from openTransaction()
Exception - if an error occurs while accessing the database
protected void rollbackTransaction(PersistentFileTransaction transaction)
throws Exception
AbstractSchemaUpdatercommitTransaction() throws an exception.
rollbackTransaction in class AbstractSchemaUpdater<File,PersistentFileTransaction>transaction - open transaction previously returned from openTransaction()
Exception - if an error occurs while accessing the database
protected Set<String> getAppliedUpdateNames(PersistentFileTransaction transaction)
throws Exception
AbstractSchemaUpdater
getAppliedUpdateNames in class AbstractSchemaUpdater<File,PersistentFileTransaction>transaction - open transaction
Exception - if an error occurs while accessing the database
protected void recordUpdateApplied(PersistentFileTransaction transaction,
String name)
throws Exception
AbstractSchemaUpdater
recordUpdateApplied in class AbstractSchemaUpdater<File,PersistentFileTransaction>transaction - open transactionname - update name
IllegalStateException - if the update has already been recorded in the database
Exception - if an error occurs while accessing the database
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||