|
||||||||||
| 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>
org.dellroad.stuff.pobj.SpringPersistentObjectSchemaUpdater<T>
T - type of the root persistent objectpublic class SpringPersistentObjectSchemaUpdater<T>
PersistentObjectSchemaUpdater optimized for use with Spring:
getOrderingTieBreaker() is overridden to break ties by ordering updates in the same order
as they are defined in the bean factory.InitializingBean and verifies all required properties are set.SpringPersistentObjectSchemaUpdates
found in the containing bean factory are automatically configured; this requires that all of the schema updates
are defined in the same ListableBeanFactory.An example of how this class can be combined with custom XML to define an updater and all its updates:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- Persistent object delegate; you supply the XML (un)marshaller -->
<bean id="delegate" class="org.dellroad.stuff.pobj.SpringDelegate"
p:marshaller-ref="marshaller" p:unmarshaller-ref="unmarshaller"/>
<!-- Persistent object schema updater -->
<bean id="schemaUpdater" class="org.dellroad.stuff.pobj.SpringPersistentObjectSchemaUpdater"
p:file="/var/example/pobj.xml" p:delegate-ref="delegate"
p:initialXML="classpath:com/example/initial-pobj.xml"/>
<!-- Persistent object bean -->
<bean scope="prototype" factory-bean="schemaUpdater" factory-method="getPersistentObject"/>
<!-- Define a common location for our schema update XSLTs -->
<bean class="org.dellroad.stuff.pobj.SpringXSLUpdateTransformConfigurer"
p:prefix="classpath:updates/" p:suffix=".xsl"/>
<!-- Schema update #1 -->
<bean id="update1" class="org.dellroad.stuff.pobj.SpringXSLPersistentObjectSchemaUpdate"
transform="file:///usr/share/updates/SomeUpdate.xsl"/>
<!-- Schema update #2: uses "classpath:updates/update2.xsl" thanks to TransformConfigurer -->
<bean id="update2" class="org.dellroad.stuff.pobj.SpringXSLPersistentObjectSchemaUpdate"/>
<!-- Add more schema updates over time as needed and everything just works... -->
</beans>
The PersistentObject itself, fully updated, is accessible via PersistentObjectSchemaUpdater.getPersistentObject().
or, in the above example, via the persistentObject bean.
| Field Summary |
|---|
| Fields inherited from class org.dellroad.stuff.pobj.PersistentObjectSchemaUpdater |
|---|
allowEmptyStart, checkInterval, DEFAULT_CHECK_INTERVAL, delegate, file, NAMESPACE_URI, numBackups, UPDATE_ELEMENT_NAME, UPDATES_ELEMENT_NAME, writeDelay, XML_PREFIX, XMLNS_ATTRIBUTE_NAME |
| Fields inherited from class org.dellroad.stuff.schema.AbstractSchemaUpdater |
|---|
log |
| Constructor Summary | |
|---|---|
SpringPersistentObjectSchemaUpdater()
|
|
| Method Summary | |
|---|---|
void |
afterPropertiesSet()
|
void |
destroy()
|
protected T |
getInitialValue()
Get the initial value for the persistent object when no persistent file is found. |
protected Comparator<SchemaUpdate<PersistentFileTransaction>> |
getOrderingTieBreaker()
Get the preferred ordering of two updates that do not have any predecessor constraints (including implied indirect constraints) between them. |
void |
setBeanFactory(BeanFactory beanFactory)
|
void |
setInitialValue(T initialValue)
Set the initial value to be used on an uninitialized persistent object. |
void |
setInitialXML(Resource resource)
Set the resource containing the initial value, encoded as XML, to be used on an uninitialized persistent object. |
| Methods inherited from class org.dellroad.stuff.pobj.PersistentObjectSchemaUpdater |
|---|
commitTransaction, databaseNeedsInitialization, getAppliedUpdateNames, getPersistentObject, initializeDatabase, openTransaction, recordUpdateApplied, rollbackTransaction, setAllowEmptyStart, setCheckInterval, setDelegate, setFile, setNumBackups, setWriteDelay, start, stop |
| Methods inherited from class org.dellroad.stuff.schema.AbstractSchemaUpdater |
|---|
apply, applyInTransaction, generateMultiUpdateName, getUpdates, initializeAndUpdateDatabase, isIgnoreUnrecognizedUpdates, isValidUpdateName, setIgnoreUnrecognizedUpdates, setUpdates |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SpringPersistentObjectSchemaUpdater()
| Method Detail |
|---|
public void setInitialValue(T initialValue)
Either this or a initial XML resource should be configured to handle the case that no persistent file exists yet.
public void setInitialXML(Resource resource)
setInitialValue(T).
Either this or an explicit initial value should be configured to handle the case that no persistent file exists yet.
protected T getInitialValue()
The implementation in SpringPersistentObjectSchemaUpdater returns the initial value,
if any, otherwise it falls back to decoding the initial value from the initial value
resource, if any. If neither property is configured, null is returned.
getInitialValue in class PersistentObjectSchemaUpdater<T>public void setBeanFactory(BeanFactory beanFactory)
setBeanFactory in interface BeanFactoryAware
public void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface InitializingBeanExceptionpublic void destroy()
destroy in interface DisposableBeanprotected Comparator<SchemaUpdate<PersistentFileTransaction>> getOrderingTieBreaker()
In the case no schema updates are explicitly configured, the Comparator returned by the
implementation in SpringPersistentObjectSchemaUpdater sorts updates in the same order that they appear
in the containing ListableBeanFactory. Otherwise, the
superclass method is used.
getOrderingTieBreaker in class AbstractSchemaUpdater<File,PersistentFileTransaction>Comparator that sorts incomparable updates in the order they should be applied
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||