public class EntityLookupCache<K extends Serializable,V,VK extends Serializable> extends Object
The keys must have good equals
and hashCode
implementations and
must respect the case-sensitivity of the use-case.
All keys will be unique to the given cache region, allowing the cache to be shared between instances of this class.
Generics:
Modifier and Type | Class and Description |
---|---|
static interface |
EntityLookupCache.EntityLookupCallbackDAO<K1 extends Serializable,V1,VK1 extends Serializable>
Interface to support lookups of the entities using keys and values.
|
static class |
EntityLookupCache.EntityLookupCallbackDAOAdaptor<K2 extends Serializable,V2,VK2 extends Serializable>
Adaptor for implementations that support immutable entities.
|
Constructor and Description |
---|
EntityLookupCache(EntityLookupCache.EntityLookupCallbackDAO<K,V,VK> entityLookup)
Construct the lookup cache without any cache.
|
EntityLookupCache(org.alfresco.repo.cache.SimpleCache cache,
EntityLookupCache.EntityLookupCallbackDAO<K,V,VK> entityLookup)
Construct the lookup cache, using the
default cache region . |
EntityLookupCache(org.alfresco.repo.cache.SimpleCache cache,
String cacheRegion,
EntityLookupCache.EntityLookupCallbackDAO<K,V,VK> entityLookup)
Construct the lookup cache, using the given cache region.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Cache-only operation: Remove all cache entries
NOTE: This operation removes ALL entries for ALL cache regions.
|
org.alfresco.util.Pair<K,V> |
createOrGetByValue(V value,
ControlDAO controlDAO)
Attempt to create the entity and, failing that, look it up.
This method takes the opposite approach to getOrCreateByValue(Object) , which assumes the entity's
existence: in this case the entity is assumed to NOT exist. |
int |
deleteByKey(K key)
Delete the entity associated with the given key.
|
int |
deleteByValue(V value)
Delete the entity having the given value..
|
org.alfresco.util.Pair<K,V> |
getByKey(K key)
Find the entity associated with the given key.
|
org.alfresco.util.Pair<K,V> |
getByValue(V value)
Find the entity associated with the given value.
|
K |
getKey(VK valueKey)
Cache-only operation: Get the key for a given value key (note: not 'value' but 'value key').
|
org.alfresco.util.Pair<K,V> |
getOrCreateByValue(V value)
Find the entity associated with the given value and create it if it doesn't exist.
|
V |
getValue(K key)
Cache-only operation: Get the value for a given key
|
void |
removeByKey(K key)
Cache-only operation: Remove all cache values associated with the given key.
|
void |
removeByValue(V value)
Cache-only operation: Remove all cache values associated with the given value
|
void |
setValue(K key,
V value)
Cache-only operation: Update the cache's value
|
int |
updateValue(K key,
V value)
Update the entity associated with the given key.
|
public EntityLookupCache(EntityLookupCache.EntityLookupCallbackDAO<K,V,VK> entityLookup)
entityLookup
- the instance that is able to find and persist entitiespublic EntityLookupCache(org.alfresco.repo.cache.SimpleCache cache, EntityLookupCache.EntityLookupCallbackDAO<K,V,VK> entityLookup)
default cache region
.cache
- the cache that will back the two-way lookupsentityLookup
- the instance that is able to find and persist entitiespublic EntityLookupCache(org.alfresco.repo.cache.SimpleCache cache, String cacheRegion, EntityLookupCache.EntityLookupCallbackDAO<K,V,VK> entityLookup)
All keys will be unique to the given cache region, allowing the cache to be shared between instances of this class.
cache
- the cache that will back the two-way lookups; null to have no backing
in a cache.cacheRegion
- the region within the cache to use.entityLookup
- the instance that is able to find and persist entitiespublic org.alfresco.util.Pair<K,V> getByKey(K key)
entity callback
will be used if necessary.
It is up to the client code to decide if a null return value indicates a concurrency violation
or not; the former would normally result in a concurrency-related exception such as
ConcurrencyFailureException
.key
- The entity key, which may be valid or invalid (null not allowed)public org.alfresco.util.Pair<K,V> getByValue(V value)
entity callback
will be used if no entry exists in the cache.
It is up to the client code to decide if a null return value indicates a concurrency violation
or not; the former would normally result in a concurrency-related exception such as
ConcurrencyFailureException
.value
- The entity value, which may be valid or invalid (null is allowed)public org.alfresco.util.Pair<K,V> createOrGetByValue(V value, ControlDAO controlDAO)
getOrCreateByValue(Object)
, which assumes the entity's
existence: in this case the entity is assumed to NOT exist.
The EntityLookupCache.EntityLookupCallbackDAO.createValue(Object)
and EntityLookupCache.EntityLookupCallbackDAO.findByValue(Object)
will be used if necessary.value
- The entity value (null is allowed)controlDAO
- an essential DAO required in order to ensure a transactionally-safe attempt at data creationpublic org.alfresco.util.Pair<K,V> getOrCreateByValue(V value)
EntityLookupCache.EntityLookupCallbackDAO.findByValue(Object)
and EntityLookupCache.EntityLookupCallbackDAO.createValue(Object)
will be used if necessary.value
- The entity value (null is allowed)public int updateValue(K key, V value)
EntityLookupCache.EntityLookupCallbackDAO.updateValue(Serializable, Object)
callback
will be used if necessary.
It is up to the client code to decide if a 0 return value indicates a concurrency violation
or not; usually the former will generate ConcurrencyFailureException
or something recognised
by the RetryingTransactionHelper
.key
- The entity key, which may be valid or invalid (null not allowed)value
- The new entity value (may be null)public K getKey(VK valueKey)
valueKey
- The entity value key, which must be valid (null not allowed)public V getValue(K key)
key
- The entity key, which may be valid or invalid (null not allowed)public void setValue(K key, V value)
key
- The entity key, which may be valid or invalid (null not allowed)value
- The new entity value (may be null)public int deleteByKey(K key)
EntityLookupCache.EntityLookupCallbackDAO.deleteByKey(Serializable)
callback will be used if necessary.
It is up to the client code to decide if a 0 return value indicates a concurrency violation
or not; usually the former will generate ConcurrencyFailureException
or something recognised
by the RetryingTransactionHelper
.key
- the entity key, which may be valid or invalid (null not allowed)public int deleteByValue(V value)
EntityLookupCache.EntityLookupCallbackDAO.deleteByValue(Object)
callback will be used if necessary.
It is up to the client code to decide if a 0 return value indicates a concurrency violation
or not; usually the former will generate ConcurrencyFailureException
or something recognised
by the RetryingTransactionHelper
.value
- the entity value, which may be valid or invalid (null allowed)public void removeByKey(K key)
public void removeByValue(V value)
value
- The entity value (null is allowed)public void clear()
Copyright © 2005–2017 Alfresco Software. All rights reserved.