public abstract class QueryResultAssociativeStore<KeyType,ValueType>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
NOT_ALLOW_MODIFICATIONS
Error literal returned when associative store modification is attempted without a setter available
|
Constructor and Description |
---|
QueryResultAssociativeStore() |
Modifier and Type | Method and Description |
---|---|
void |
addCallbackOnQueryResultUpdate(IQueryResultUpdateListener<KeyType,ValueType> listener,
boolean fireNow)
Registers a listener for this query result associative store that is invoked every time when a key-value pair is inserted
or removed from the associative store.
|
protected boolean |
checkModificationThroughQueryResultSetter(KeyType key,
ValueType value,
Direction direction,
int expectedChange,
int size)
Checks whether the model modification performed by the
IQueryResultSetter resulted in the insertion or
removal of exactly the required key-value pair. |
protected abstract java.util.Collection<java.util.Map.Entry<KeyType,ValueType>> |
getCacheEntries()
Returns the entries in the cache as a collection.
|
protected java.util.Collection<IQueryResultUpdateListener<KeyType,ValueType>> |
getListeners() |
protected org.apache.log4j.Logger |
getLogger() |
protected IQueryResultSetter<KeyType,ValueType> |
getSetter() |
protected abstract boolean |
internalCacheContainsEntry(KeyType key,
ValueType value) |
protected abstract boolean |
internalCachePut(KeyType key,
ValueType value) |
protected abstract boolean |
internalCacheRemove(KeyType key,
ValueType value) |
protected abstract int |
internalCacheSize() |
protected void |
internalClear() |
protected boolean |
internalPut(KeyType key,
ValueType value)
Implementations of QueryResultAssociativeStore can put a new key-value pair into the associative store with this method.
|
protected boolean |
internalRemove(KeyType key,
ValueType value)
Implementations of QueryResultAssociativeStore can remove a key-value pair from the associative store with this method.
|
protected boolean |
modifyThroughQueryResultSetter(KeyType key,
ValueType value,
Direction direction)
This method is used for calling the query result setter to put or remove a value by modifying the model.
|
protected void |
notifyListeners(Direction direction,
KeyType key,
ValueType value)
This method notifies the listeners that the query result associative store has changed.
|
void |
removeCallbackOnQueryResultUpdate(IQueryResultUpdateListener<KeyType,ValueType> listener)
Unregisters a callback registered by
addCallbackOnQueryResultUpdate(IQueryResultUpdateListener, boolean)
. |
protected void |
setListeners(java.util.Collection<IQueryResultUpdateListener<KeyType,ValueType>> listeners) |
protected void |
setLogger(org.apache.log4j.Logger logger) |
void |
setQueryResultSetter(IQueryResultSetter<KeyType,ValueType> setter) |
protected void |
setSetter(IQueryResultSetter<KeyType,ValueType> setter) |
protected static final java.lang.String NOT_ALLOW_MODIFICATIONS
protected java.util.Collection<IQueryResultUpdateListener<KeyType,ValueType>> getListeners()
protected void setListeners(java.util.Collection<IQueryResultUpdateListener<KeyType,ValueType>> listeners)
listeners
- the listeners to setprotected IQueryResultSetter<KeyType,ValueType> getSetter()
protected void setSetter(IQueryResultSetter<KeyType,ValueType> setter)
setter
- the setter to setprotected void setLogger(org.apache.log4j.Logger logger)
logger
- the logger to setprotected abstract java.util.Collection<java.util.Map.Entry<KeyType,ValueType>> getCacheEntries()
public void addCallbackOnQueryResultUpdate(IQueryResultUpdateListener<KeyType,ValueType> listener, boolean fireNow)
The listener can be unregistered via removeCallbackOnQueryResultUpdate(IQueryResultUpdateListener)
.
listener
- the listener that will be notified of each key-value pair that is inserted or removed, starting from
now.fireNow
- if true, notifyPut will be immediately invoked on all current key-values as a one-time effect.public void removeCallbackOnQueryResultUpdate(IQueryResultUpdateListener<KeyType,ValueType> listener)
addCallbackOnQueryResultUpdate(IQueryResultUpdateListener, boolean)
.listener
- the listener that will no longer be notified.protected void notifyListeners(Direction direction, KeyType key, ValueType value)
direction
- the type of the change (insert or delete)key
- the key of the pair that changedvalue
- the value of the pair that changedprotected boolean internalPut(KeyType key, ValueType value)
No validation or null-checking is performed during the method!
key
- the key which identifies where the new value is putvalue
- the value that is put into the collection of the keyprotected boolean internalRemove(KeyType key, ValueType value)
No validation or null-checking is performed during the method!
key
- the key which identifies where the value is removed fromvalue
- the value that is removed from the collection of the keyprotected abstract int internalCacheSize()
protected abstract boolean internalCacheContainsEntry(KeyType key, ValueType value)
public void setQueryResultSetter(IQueryResultSetter<KeyType,ValueType> setter)
setter
- the setter to setprotected org.apache.log4j.Logger getLogger()
protected void internalClear()
protected boolean modifyThroughQueryResultSetter(KeyType key, ValueType value, Direction direction)
The given key-value pair is first validated (see IQueryResultSetter.validate(Object, Object)
, then the
put or remove method is called (see IQueryResultSetter.put(Object, Object)
and
IQueryResultSetter.remove(Object, Object)
). If the setter reported that the model has been changed, the
change is checked.
If the model modification did not change the result set in the desired way, a warning is logged.
If the setter throws any Throwable
, it is either rethrown in case of Error
and logged otherwise.
key
- the key of the pair to be inserted or removedvalue
- the value of the pair to be inserted or removeddirection
- specifies whether a put or a remove is performedprotected boolean checkModificationThroughQueryResultSetter(KeyType key, ValueType value, Direction direction, int expectedChange, int size)
IQueryResultSetter
resulted in the insertion or
removal of exactly the required key-value pair.key
- the key for the pair that was inserted or removedvalue
- the value for the pair that was inserted or removeddirection
- the direction of the changesize
- the size of the cache before the change