T - Object type.PK - Primary key type.S - Self-type - sub-type of store. Generic parameter for predicates, extractors, update tasks and views.public interface Store<T,PK,S extends Store<T,PK,S>> extends ReadWriteLock, Iterable<T>
| Modifier and Type | Interface and Description |
|---|---|
static interface |
Store.Handle<T,PK,S extends Store<T,PK,S>>
Object handle.
|
static interface |
Store.QueryTask<T,PK,S extends Store<?,PK,S>>
Task to perform processing on objects (without updating).
|
static interface |
Store.StoreIterator<T>
Some stores may return StoreIterator, which
needs to be closed if iterator operation is
terminated before hasNext() returns false.
|
static interface |
Store.UpdateTask<T,PK,S extends Store<T,PK,S>>
Task to update objects.
|
static class |
Store.ViewType |
| Modifier and Type | Method and Description |
|---|---|
<V,ST extends T> |
addIndex(Predicate<T,S> predicate,
Extractor<ST,V,S> extractor,
Index.Type type,
boolean ordered,
Comparator<V> comparator)
Adds index to the store to speed-up extraction operations.
|
void |
clear()
Removes all entries from the store.
|
S |
createUnmodifiableFacade()
Creates unmodifiable facade for this store.
|
S |
createView(Predicate<T,S> selector,
Store.ViewType viewType)
Creates a view - a store which sees only objects matching the given selector.
|
Iterable<T> |
get(Predicate<T,S> selector)
Retrieves objects matching the predicate.
|
<V> Iterable<V> |
get(Predicate<T,S> selector,
Extractor<T,V,S> extractor,
boolean ordered,
Comparator<V> comparator)
Retrieves values from objects matching the predicate.
|
Iterable<T> |
getAll()
Retrieves all objects from the store.
|
T |
getByPrimaryKey(PK primaryKey)
Retrieves object with given primary key.
|
<V> Iterable<V> |
getMultiple(Predicate<T,S> selector,
Extractor<T,Iterable<V>,S> extractor,
Predicate<V,S> valueSelector,
boolean ordered,
Comparator<V> comparator)
Retrieves values from objects matching the predicate.
|
Extractor<T,PK,S> |
getPrimaryKeyExtractor()
If primary key is set, then the store shall use equals on the
value returned from the primaryKeyExtractor
instead of equals on the object to compare objects for removal and update (put).
|
Store.Handle<T,PK,S> |
put(T obj,
Predicate<T,S>... validators)
Puts object to the store.
|
<V> int |
query(Predicate<T,S> selector,
Extractor<T,V,S> extractor,
Store.QueryTask<V,PK,S> processor)
Processes values extracted from objects matching the predicate.
|
int |
query(Predicate<T,S> selector,
Store.QueryTask<T,PK,S> processor)
Processes objects matching the predicate.
|
int |
queryAll(Store.QueryTask<T,PK,S> processor)
Processes all objects in the store.
|
<V> int |
queryMultiple(Predicate<T,S> selector,
Extractor<T,Iterable<V>,S> extractor,
Predicate<V,S> valueSelector,
Store.QueryTask<V,PK,S> processor)
Processes multiple values extracted from objects matching the predicate.
|
int |
remove(Predicate<T,S> selector)
Removes objects matching the predicate.
|
boolean |
remove(T obj)
Removes specified object from the store.
|
boolean |
removeByPrimaryKey(PK primaryKey)
Removes object by primary key.
|
int |
update(Predicate<T,S> selector,
Store.UpdateTask<T,PK,S> updater)
Updates objects matching the predicate.
|
readLock, writeLockStore.Handle<T,PK,S> put(T obj, Predicate<T,S>... validators)
obj - Object to put to the store.validators - Predicate(s) which are checked when object is retrieved from the store.
If there is more than one predicate, predicates are connected with AND. If validator(s) evaluate to
false, the object handle is considered invalid, i.e. object is considered removed from the store.
Once validator(s) evaluate to false, they shall always evaluate to false. One of use of validators
can be to expire object in the store, i.e. after some time validator returns false and object is cleared
from the database. If validators evaluate to false at put time, object is not put to the store and
put() returns null. Validators evaluation result is not cached.int queryAll(Store.QueryTask<T,PK,S> processor)
processor - T getByPrimaryKey(PK primaryKey)
primaryKey - IllegalStateException - if object store is configured without
primary key.Iterable<T> get(Predicate<T,S> selector)
selector - int query(Predicate<T,S> selector, Store.QueryTask<T,PK,S> processor)
selector - <V> int query(Predicate<T,S> selector, Extractor<T,V,S> extractor, Store.QueryTask<V,PK,S> processor)
selector - extractor - Extractor.processor - Processor of query results.<V> int queryMultiple(Predicate<T,S> selector, Extractor<T,Iterable<V>,S> extractor, Predicate<V,S> valueSelector, Store.QueryTask<V,PK,S> processor)
selector - Objects shall match this predicate. If null, all objects match.extractor - ExtractorvalueSelector - Values from matched objects shall match this predicate. If null, all values match.
Value selectors are executed in separate tasks from extractor.
Separation of value selection logic from value extraction logic makes
sense if value selection logic is relatively heavy and parallelization of its
execution will reduce overall query execution time.processor - Processor of query results.<V> Iterable<V> get(Predicate<T,S> selector, Extractor<T,V,S> extractor, boolean ordered, Comparator<V> comparator)
V - selector - Object selector.extractor - Value extractor. If null, then object itself is returned.ordered - If true, then returned result is ordered by comparator or by natural order if
comparator is null.comparator - Comparator to use for ordering.<V> Iterable<V> getMultiple(Predicate<T,S> selector, Extractor<T,Iterable<V>,S> extractor, Predicate<V,S> valueSelector, boolean ordered, Comparator<V> comparator)
V - selector - Objects shall match this predicate. If null, all objects match.extractor - Value extractor.valueSelector - Values from matched objects shall match this predicate. If null, all values match.
Value selectors are executed in separate tasks from extractor.
Separation of value selection logic from value extraction logic makes
sense if value selection logic is relatively heavy and parallelization of its
execution will reduce overall query execution time.ordered - If true, then returned result is ordered by comparator or by natural order if
comparator is null.comparator - Comparator to use for ordering.void clear()
boolean remove(T obj)
obj - Object to remove.boolean removeByPrimaryKey(PK primaryKey)
primaryKey - int remove(Predicate<T,S> selector)
predicate - int update(Predicate<T,S> selector, Store.UpdateTask<T,PK,S> updater)
selector - updater - <V,ST extends T> Index<T,ST,PK,V,S> addIndex(Predicate<T,S> predicate, Extractor<ST,V,S> extractor, Index.Type type, boolean ordered, Comparator<V> comparator)
V - Value type extracted by extractor for ordering.ST - Type of index elements, which can be a sub-type of store element type.
index creation parameters.predicate - Only store items matching the predicate are indexed.extractor - Extractor of the index key.Index - type.ordered - If true index is ordered.comparator - Comparator to use for ordering. If null, then natural order is used.Extractor<T,PK,S> getPrimaryKeyExtractor()
primaryKeyExtractor - Primary key extractor.IllegalStateException - If primary key is already set.S createView(Predicate<T,S> selector, Store.ViewType viewType)
selector - View selector.materialized - If true, view elements are calculated at modify time instead of query time.S createUnmodifiableFacade()