T - S - Self-type - sub-type of store. Generic parameter for predicates, extractors, update tasks and views.
S should be an interface for master store, deputy store and views to implement.public abstract class AbstractStore<T,PK,S extends Store<T,PK,S>> extends Object implements Store<T,PK,S>
| Modifier and Type | Class and Description |
|---|---|
protected class |
AbstractStore.ExtractorTask<V> |
protected class |
AbstractStore.IndexizationTask<V> |
protected class |
AbstractStore.QueryCallable<V> |
protected class |
AbstractStore.QueryItemCallable<V> |
protected class |
AbstractStore.QueryMultipleCallable<V> |
protected class |
AbstractStore.RemoveTask |
protected class |
AbstractStore.SelectorTask |
protected class |
AbstractStore.UpdateCallable |
protected class |
AbstractStore.ValueSelectorTask<V> |
| Constructor and Description |
|---|
AbstractStore() |
| 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.
|
protected abstract Map<S,Map<Extractor<T,? super PK,S>,? super PK>> |
createCache() |
protected abstract S |
createDeputy()
Creates a store which encapsulates current call state (e.g.
|
protected abstract Store.Handle<T,PK,S> |
createHandle(T obj,
PK primaryKey,
Map<S,Map<Extractor<T,? super PK,S>,? super PK>> cache,
Predicate<T,S>[] validators)
Creates handle.
|
protected Store.Handle<T,PK,S> |
createHandle(T obj,
Predicate<T,S>[] validators) |
protected abstract <V,ST extends T> |
createIndex(Predicate<T,S> predicate,
Extractor<ST,V,S> extractor,
Index.Type type,
boolean ordered,
Comparator<V> comparator) |
protected abstract Collection<Store.Handle<T,PK,S>> |
createIndexCollection(boolean unique,
boolean ordered,
Comparator<T> comparator)
Creates collection for index entries
|
protected abstract S |
createLiveView(Predicate<T,S> selector) |
protected abstract ReadWriteLock |
createMasterLock() |
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 abstract ExecutorService |
getExecutorService() |
protected Iterable<Store.Handle<T,PK,S>> |
getHandles(Predicate<T,S> selector) |
protected abstract Collection<AbstractIndex<T,? extends T,PK,?,S>> |
getIndices() |
<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.
|
protected abstract Collection<Store.Handle<T,PK,S>> |
getNoPkStore()
Store for the mode without primary key or pkStore values collection.
|
protected abstract Map<PK,Store.Handle<T,PK,S>> |
getPkStore() |
Iterator<T> |
iterator() |
protected abstract void |
onRemoved(int removed)
Invoked when some handles have been removed.
|
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> query)
Processes values extracted from objects matching the predicate.
|
int |
query(Predicate<T,S> selector,
Store.QueryTask<T,PK,S> query)
Processes objects matching the predicate.
|
int |
queryAll(Store.QueryTask<T,PK,S> query)
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> query)
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.
|
protected void |
updateIndices(Store.Handle<T,PK,S> handle,
boolean isNew)
This method is invoked by handle implementations.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreateUnmodifiableFacade, getPrimaryKeyExtractorreadLock, writeLockpublic AbstractStore()
protected abstract Map<PK,Store.Handle<T,PK,S>> getPkStore()
protected abstract Collection<Store.Handle<T,PK,S>> getNoPkStore()
protected abstract ExecutorService getExecutorService()
protected abstract Store.Handle<T,PK,S> createHandle(T obj, PK primaryKey, Map<S,Map<Extractor<T,? super PK,S>,? super PK>> cache, Predicate<T,S>[] validators)
protected abstract Collection<Store.Handle<T,PK,S>> createIndexCollection(boolean unique, boolean ordered, Comparator<T> comparator)
unique - Collection should be unique (set)ordered - Collection should be ordered by the comparator or by natural order.comparator - protected Store.Handle<T,PK,S> createHandle(T obj, Predicate<T,S>[] validators)
protected abstract Map<S,Map<Extractor<T,? super PK,S>,? super PK>> createCache()
protected abstract S createDeputy()
protected abstract ReadWriteLock createMasterLock()
protected abstract void onRemoved(int removed)
removed - Number of removed handles.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 T getByPrimaryKey(PK primaryKey)
Storepublic Iterable<T> get(Predicate<T,S> selector)
Storeprotected Iterable<Store.Handle<T,PK,S>> getHandles(Predicate<T,S> selector)
selector - 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)
Storeprotected abstract Collection<AbstractIndex<T,? extends T,PK,?,S>> getIndices()
protected abstract <V,ST extends T> AbstractIndex<T,ST,PK,V,S> createIndex(Predicate<T,S> predicate, Extractor<ST,V,S> extractor, Index.Type type, boolean ordered, Comparator<V> comparator)
public <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 int queryAll(Store.QueryTask<T,PK,S> query)
Storepublic int query(Predicate<T,S> selector, Store.QueryTask<T,PK,S> query)
Storepublic <V> int query(Predicate<T,S> selector, Extractor<T,V,S> extractor, Store.QueryTask<V,PK,S> query)
Storepublic <V> int queryMultiple(Predicate<T,S> selector, Extractor<T,Iterable<V>,S> extractor, Predicate<V,S> valueSelector, Store.QueryTask<V,PK,S> query)
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.query - Processor of query results.protected void updateIndices(Store.Handle<T,PK,S> handle, boolean isNew)
handle - isNew - public S createView(Predicate<T,S> selector, Store.ViewType viewType)
Storeprotected abstract S createLiveView(Predicate<T,S> selector)