public class UnmodifiableStore<T,PK,S extends Store<T,PK,S>> extends Object implements Store<T,PK,S>
| Constructor and Description |
|---|
UnmodifiableStore(S master) |
| 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.
|
protected S |
getMaster() |
<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).
|
Iterator<T> |
iterator() |
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.
|
Lock |
readLock() |
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.
|
Lock |
writeLock() |
public UnmodifiableStore(S master)
public Store.Handle<T,PK,S> put(T obj, Predicate<T,S>... validators)
Storeput in interface Store<T,PK,S extends Store<T,PK,S>>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.public Iterable<T> getAll()
Storepublic int queryAll(Store.QueryTask<T,PK,S> processor)
Storepublic T getByPrimaryKey(PK primaryKey)
Storepublic Iterable<T> get(Predicate<T,S> selector)
Storepublic int query(Predicate<T,S> selector, Store.QueryTask<T,PK,S> processor)
Storepublic <V> int query(Predicate<T,S> selector, Extractor<T,V,S> extractor, Store.QueryTask<V,PK,S> processor)
Storepublic Lock readLock()
readLock in interface ReadWriteLockpublic Lock writeLock()
writeLock in interface ReadWriteLockpublic <V> int queryMultiple(Predicate<T,S> selector, Extractor<T,Iterable<V>,S> extractor, Predicate<V,S> valueSelector, Store.QueryTask<V,PK,S> processor)
StorequeryMultiple in interface Store<T,PK,S extends Store<T,PK,S>>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.public <V> Iterable<V> get(Predicate<T,S> selector, Extractor<T,V,S> extractor, boolean ordered, Comparator<V> comparator)
Storeget in interface Store<T,PK,S extends Store<T,PK,S>>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.public <V> Iterable<V> getMultiple(Predicate<T,S> selector, Extractor<T,Iterable<V>,S> extractor, Predicate<V,S> valueSelector, boolean ordered, Comparator<V> comparator)
StoregetMultiple in interface Store<T,PK,S extends Store<T,PK,S>>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.public void clear()
Storepublic boolean remove(T obj)
Storepublic boolean removeByPrimaryKey(PK primaryKey)
Storepublic int remove(Predicate<T,S> selector)
Storepublic int update(Predicate<T,S> selector, Store.UpdateTask<T,PK,S> updater)
Storepublic <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)
StoreaddIndex in interface Store<T,PK,S extends Store<T,PK,S>>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.ordered - If true index is ordered.comparator - Comparator to use for ordering. If null, then natural order is used.public Extractor<T,PK,S> getPrimaryKeyExtractor()
Storepublic S createView(Predicate<T,S> selector, Store.ViewType viewType)
Store