Class FilePersistence<T>
java.lang.Object
org.pipservices3.data.persistence.MemoryPersistence<T>
org.pipservices3.data.persistence.FilePersistence<T>
- All Implemented Interfaces:
org.pipservices3.commons.config.IConfigurable
,org.pipservices3.commons.refer.IReferenceable
,org.pipservices3.commons.run.ICleanable
,org.pipservices3.commons.run.IClosable
,org.pipservices3.commons.run.IOpenable
public abstract class FilePersistence<T>
extends MemoryPersistence<T>
implements org.pipservices3.commons.config.IConfigurable
Abstract persistence component that stores data in flat files
and caches them in memory.
This is the most basic persistence component that is only
able to store data items of any type. Specific CRUD operations
over the data items must be implemented in child classes by
accessing this._items
property and calling save()
method.
### Configuration parameters ###
- path: path to the file where data is stored
### References ###
- *:logger:*:*:1.0 (optional) ILogger components to pass log messages
### Example ###
class MyJsonFilePersistence extends FilePersistence<MyData> {
public MyJsonFilePersistence(String path) {
super(MyData.class, new JsonFilePersister(path));
}
public MyData getByName(String correlationId, String name) {
MyData item = find(name); // search method
...
return item;
}
public MyData set(String correlatonId, MyData item) {
this._items = filter(); // filter method
...
this._items.add(item);
this.save(correlationId);
}
}
- See Also:
-
Field Summary
FieldsFields inherited from class org.pipservices3.data.persistence.MemoryPersistence
_items, _loader, _lock, _logger, _maxPageSize, _opened, _saver, _type, _typeName
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
FilePersistence
(Class<T> type) Creates a new instance of the persistence.protected
FilePersistence
(Class<T> type, JsonFilePersister<T> persister) Creates a new instance of the persistence. -
Method Summary
Modifier and TypeMethodDescriptionvoid
configure
(org.pipservices3.commons.config.ConfigParams config) Configures component by passing configuration parameters.Methods inherited from class org.pipservices3.data.persistence.MemoryPersistence
clear, close, create, deleteByFilter, getCountByFilter, getListByFilter, getListByFilter, getOneRandom, getPageByFilter, getPageByFilter, isOpen, open, save, setReferences
-
Field Details
-
_persister
-
-
Constructor Details
-
FilePersistence
Creates a new instance of the persistence.- Parameters:
type
- the class type
-
FilePersistence
Creates a new instance of the persistence.- Parameters:
type
- the class typepersister
- (optional) a persister component that loads and saves data from/to flat file.
-
-
Method Details
-
configure
public void configure(org.pipservices3.commons.config.ConfigParams config) throws org.pipservices3.commons.errors.ConfigException Configures component by passing configuration parameters.- Specified by:
configure
in interfaceorg.pipservices3.commons.config.IConfigurable
- Overrides:
configure
in classMemoryPersistence<T>
- Parameters:
config
- configuration parameters to be set.- Throws:
org.pipservices3.commons.errors.ConfigException
-