IdentifiableMemoryPersistence<T extends IIdentifiable<K>, K> class Null safety

Abstract persistence component that stores data in memory and implements a number of CRUD operations over data items with unique ids. The data items must implement IIdentifiable interface.

In basic scenarios child classes shall only override getPageByFilter, getListByFilter or deleteByFilter operations with specific filter function. All other operations can be used out of the box.

In complex scenarios child classes can implement additional operations by accessing cached items via this._items property and calling save method on updates.

See MemoryPersistence

Configuration parameters

  • options:
    • max_page_size: Maximum number of items returned in a single page (default: 100)

References

  • *:logger:*:*:1.0 (optional) ILogger components to pass log messages

Examples

class MyMemoryPersistence extends IdentifiableMemoryPersistence<MyData, string> {

    dynamic _composeFilter(FilterParams filter) {
        filter = filter ?? FilterParams();
        var name = filter.getAsNullableString("name");
        return (item) {
            if (name != null && item.name != name)
                return false;
            return true;
        };
    }

    Future<DataPage<MyData>> getPageByFilter(String? correlationId, FilterParams filter, PagingParams paging){
        return super.getPageByFilter(correlationId, composeFilter(filter), paging, null, null);
    }

}

var persistence = MyMemoryPersistence();

var item = persistence.create("123", { id: "1", name: "ABC" }) var page = persistence.getPageByFilter( "123", FilterParams.fromTuples("name", "ABC"), null);

print(page.data); // Result: { id: "1", name: "ABC" }

item = persistence.deleteById("123", "1"); ...

Inheritance
Implemented types
Implementers

Constructors

IdentifiableMemoryPersistence([ILoader<T>? loader, ISaver<T>? saver])
Creates a new instance of the persistence.

Properties

hashCode int
The hash code for this object.
read-onlyinherited
items List<T>
read / writeinherited
loader ILoader<T>?
read / writeinherited
logger CompositeLogger
read / writeinherited
maxPageSize int
read / writeinherited
opened bool
read / writeinherited
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited
saver ISaver<T>?
read / writeinherited

Methods

clear(String? correlationId) Future
Clears component state.
inherited
close(String? correlationId) Future
Closes component and frees used resources.
inherited
configure(ConfigParams config) → void
Configures component by passing configuration parameters.
override
create(String? correlationId, T? item) Future<T?>
Creates a data item.
override
deleteByFilterEx(String? correlationId, Function filter) Future
Deletes data items that match to a given filter.
inherited
deleteById(String? correlationId, K? id) Future<T?>
Deleted a data item by it's unique id.
override
deleteByIds(String? correlationId, List<K> ids) Future
Deletes multiple data items by their unique ids.
getCountByFilterEx(String? correlationId, Function? filter) Future<int>
Gets a count of data items retrieved by a given filter.
inherited
getListByFilterEx(String? correlationId, Function? filter, Function? sort, dynamic select) Future<List<T>>
Gets a list of data items retrieved by a given filter and sorted according to sort parameters.
inherited
getListByIds(String? correlationId, List<K> ids) Future<List<T>>
Gets a list of data items retrieved by given unique ids.
getOneById(String? correlationId, K id) Future<T?>
Gets a data item by its unique id.
override
getOneRandom(String? correlationId, Function? filter) Future<T?>
Gets a random item from items that match to a given filter.
inherited
getPageByFilterEx(String? correlationId, Function? filter, PagingParams? paging, Function? sort, [dynamic select]) Future<DataPage<T>>
Gets a page of data items retrieved by a given filter and sorted according to sort parameters.
inherited
isOpen() bool
Checks if the component is opened.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
open(String? correlationId) Future
Opens the component.
inherited
save(String? correlationId) Future
Saves items to external data source using configured saver component.
inherited
set(String? correlationId, T? item) Future<T?>
Sets a data item. If the data item exists it updates it, otherwise it create a new data item.
override
setReferences(IReferences references) → void
Sets references to dependent components.
inherited
toString() String
A string representation of this object.
inherited
update(String? correlationId, T? item) Future<T?>
Updates a data item.
override
updatePartially(String? correlationId, K id, AnyValueMap data) Future<T?>
Updates only few selected fields in a data item.

Operators

operator ==(Object other) bool
The equality operator.
inherited