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
ConstructorDescriptionSpringXMLKVDatabase
(File file) Normal constructor.SpringXMLKVDatabase
(StreamRepository repository) Constructor allowing storage in any user-suppliedStreamRepository
. -
Method Summary
Modifier and TypeMethodDescriptionprotected InputStream
Get the initial content for an uninitialized database.void
setInitialContentFile
(File initialContentFile) Configure theResource
containing default initial content for an uninitialized database from the specified file.void
setInitialContentResource
(Resource initialContentResource) Configure theResource
containing default initial content for an uninitialized database.Methods inherited from class io.permazen.kv.simple.XMLKVDatabase
checkForOutOfBandUpdate, checkState, createTransaction, getGeneration, postCommit, readXML, reload, start, writeXML
Methods inherited from class io.permazen.kv.simple.SimpleKVDatabase
createTransaction, getHoldTimeout, getWaitTimeout, preCommit, setHoldTimeout, setWaitTimeout, stop
-
Constructor Details
-
SpringXMLKVDatabase
Normal constructor. Uses aFileStreamRepository
backed by the specified file.- Parameters:
file
- persistent XML file- Throws:
IllegalArgumentException
- iffile
is null
-
SpringXMLKVDatabase
Constructor allowing storage in any user-suppliedStreamRepository
.- Parameters:
repository
- XML file storage- Throws:
IllegalArgumentException
- iffile
is null
-
-
Method Details
-
setInitialContentResource
Configure theResource
containing 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 theResource
containing default initial content for an uninitialized database from the specified file.- Overrides:
setInitialContentFile
in 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
SpringXMLKVDatabase
returns anInputStream
acquired from theResource
configured bysetInitialContentResource()
, if any, otherwise null.- Overrides:
getInitialContent
in classXMLKVDatabase
- Returns:
- default initial XML database content, or null for none
- Throws:
IOException
- if an error occurs accessing the initial content file
-