Package io.permazen.spring
Class SpringXMLKVDatabase
java.lang.Object
io.permazen.kv.simple.SimpleKVDatabase
io.permazen.kv.simple.MemoryKVDatabase
io.permazen.kv.simple.XMLKVDatabase
io.permazen.spring.SpringXMLKVDatabase
- All Implemented Interfaces:
KVDatabase,Serializable
XMLKVDatabase that adds support for loading the default initial content from any Spring Resource.
For example, this allows initial content to be loaded from the classpath.
Instances are serializable if the configured StreamRepository and default initial content resource are.
- See Also:
-
Field Summary
Fields inherited from class io.permazen.kv.simple.SimpleKVDatabase
DEFAULT_HOLD_TIMEOUT, DEFAULT_WAIT_TIMEOUT, kv, log -
Constructor Summary
ConstructorsConstructorDescriptionSpringXMLKVDatabase(File file) Normal constructor.SpringXMLKVDatabase(StreamRepository repository) Constructor allowing storage in any user-suppliedStreamRepository. -
Method Summary
Modifier and TypeMethodDescriptionprotected InputStreamGet the initial content for an uninitialized database.voidsetInitialContentFile(File initialContentFile) Configure theResourcecontaining default initial content for an uninitialized database from the specified file.voidsetInitialContentResource(Resource initialContentResource) Configure theResourcecontaining default initial content for an uninitialized database.Methods inherited from class io.permazen.kv.simple.XMLKVDatabase
checkForOutOfBandUpdate, checkState, createTransaction, getGeneration, postCommit, readXML, reload, start, writeXMLMethods inherited from class io.permazen.kv.simple.SimpleKVDatabase
createTransaction, getHoldTimeout, getWaitTimeout, preCommit, setHoldTimeout, setWaitTimeout, stop
-
Constructor Details
-
SpringXMLKVDatabase
Normal constructor. Uses aFileStreamRepositorybacked by the specified file.- Parameters:
file- persistent XML file- Throws:
IllegalArgumentException- iffileis null
-
SpringXMLKVDatabase
Constructor allowing storage in any user-suppliedStreamRepository.- Parameters:
repository- XML file storage- Throws:
IllegalArgumentException- iffileis null
-
-
Method Details
-
setInitialContentResource
Configure theResourcecontaining default initial content for an uninitialized database. This method is invoked bygetInitialContent()when, on the first load, the backing XML file is not found.- Parameters:
initialContentResource- resource containing default initial XML database content, or null for none
-
setInitialContentFile
Configure theResourcecontaining default initial content for an uninitialized database from the specified file.- Overrides:
setInitialContentFilein classXMLKVDatabase- Parameters:
initialContentFile- file containing default initial XML database content, or null for none
-
getInitialContent
Get the initial content for an uninitialized database. This method is invoked when, on the first load, the backing XML file is not found. It should return a stream that reads initial content for the database, if any, otherwise null.The implementation in
SpringXMLKVDatabasereturns anInputStreamacquired from theResourceconfigured bysetInitialContentResource(), if any, otherwise null.- Overrides:
getInitialContentin classXMLKVDatabase- Returns:
- default initial XML database content, or null for none
- Throws:
IOException- if an error occurs accessing the initial content file
-