Class CommonTokenValuesCacheImpl
- java.lang.Object
-
- com.ibm.fhir.persistence.jdbc.cache.CommonTokenValuesCacheImpl
-
- All Implemented Interfaces:
ICommonTokenValuesCache
public class CommonTokenValuesCacheImpl extends Object implements ICommonTokenValuesCache
Implementation of a cache used for lookups of entities related to local and external resource references
-
-
Constructor Summary
Constructors Constructor Description CommonTokenValuesCacheImpl(int codeSystemCacheSize, int tokenValueCacheSize, int canonicalCacheSize)
Public constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCanonicalValue(String url, int id)
Add the url-id mapping to the local cachevoid
addCodeSystem(String codeSystem, int id)
Add the id to the local cachevoid
addTokenValue(CommonTokenValue key, long id)
Add the CommonTokenValue and id to the local cachevoid
clearLocalMaps()
Clear any thread-local cache maps (probably because a transaction was rolled back)Integer
getCanonicalId(String canonicalValue)
Get the cached database id for the given canonical urlInteger
getCodeSystemId(String codeSystem)
Look up the id of the named codeSystemLong
getCommonTokenValueId(String codeSystem, String tokenValue)
Get the database common_token_value_id for the given code system and token value.void
prefillCodeSystems(Map<String,Integer> codeSystems)
Add the contents of the given codeSystems map to the shared cache.void
reset()
Clear the thread-local and shared caches (for test purposes)void
resolveCanonicalValues(Collection<ResourceProfileRec> profileValues, List<ResourceProfileRec> misses)
Look up the ids for the common canonical values in the cachevoid
resolveCodeSystems(Collection<ResourceTokenValueRec> tokenValues, List<ResourceTokenValueRec> misses)
Lookup all the database values we have cached for the code-system names in the given collection.Set<Long>
resolveCommonTokenValueIds(Collection<CommonTokenValue> tokenValues, Set<CommonTokenValue> misses)
Get the database common_token_value_ids for the given list of token values.void
resolveTokenValues(Collection<ResourceTokenValueRec> tokenValues, List<ResourceTokenValueRec> misses)
Look up the ids for the common token values.void
updateSharedMaps()
Called after a transaction commit() to transfer all the staged (thread-local) data over to the shared LRU cache.
-
-
-
Method Detail
-
updateSharedMaps
public void updateSharedMaps()
Called after a transaction commit() to transfer all the staged (thread-local) data over to the shared LRU cache.- Specified by:
updateSharedMaps
in interfaceICommonTokenValuesCache
-
getCodeSystemId
public Integer getCodeSystemId(String codeSystem)
Description copied from interface:ICommonTokenValuesCache
Look up the id of the named codeSystem- Specified by:
getCodeSystemId
in interfaceICommonTokenValuesCache
- Returns:
- the database identity of the code system, or null if no record was found
-
resolveCodeSystems
public void resolveCodeSystems(Collection<ResourceTokenValueRec> tokenValues, List<ResourceTokenValueRec> misses)
Description copied from interface:ICommonTokenValuesCache
Lookup all the database values we have cached for the code-system names in the given collection. Put any objects with cache misses into the corresponding miss lists (so that we know which records we need to generate inserts for)- Specified by:
resolveCodeSystems
in interfaceICommonTokenValuesCache
misses
- the objects we couldn't find in the cache
-
resolveTokenValues
public void resolveTokenValues(Collection<ResourceTokenValueRec> tokenValues, List<ResourceTokenValueRec> misses)
Description copied from interface:ICommonTokenValuesCache
Look up the ids for the common token values. Must be preceded by resolveCodeSystems to make sure we have code-system ids set for each record. This also means that code-systems which don't yet exist must be created before this method can be called (because we need the id)- Specified by:
resolveTokenValues
in interfaceICommonTokenValuesCache
misses
- the objects we couldn't find in the cache
-
resolveCanonicalValues
public void resolveCanonicalValues(Collection<ResourceProfileRec> profileValues, List<ResourceProfileRec> misses)
Description copied from interface:ICommonTokenValuesCache
Look up the ids for the common canonical values in the cache- Specified by:
resolveCanonicalValues
in interfaceICommonTokenValuesCache
- Parameters:
profileValues
- the collection of profile values containing the canonical urlsmisses
- the objects we couldn't find in the cache
-
addCodeSystem
public void addCodeSystem(String codeSystem, int id)
Description copied from interface:ICommonTokenValuesCache
Add the id to the local cache- Specified by:
addCodeSystem
in interfaceICommonTokenValuesCache
-
addTokenValue
public void addTokenValue(CommonTokenValue key, long id)
Description copied from interface:ICommonTokenValuesCache
Add the CommonTokenValue and id to the local cache- Specified by:
addTokenValue
in interfaceICommonTokenValuesCache
-
addCanonicalValue
public void addCanonicalValue(String url, int id)
Description copied from interface:ICommonTokenValuesCache
Add the url-id mapping to the local cache- Specified by:
addCanonicalValue
in interfaceICommonTokenValuesCache
-
reset
public void reset()
Description copied from interface:ICommonTokenValuesCache
Clear the thread-local and shared caches (for test purposes)- Specified by:
reset
in interfaceICommonTokenValuesCache
-
clearLocalMaps
public void clearLocalMaps()
Description copied from interface:ICommonTokenValuesCache
Clear any thread-local cache maps (probably because a transaction was rolled back)- Specified by:
clearLocalMaps
in interfaceICommonTokenValuesCache
-
prefillCodeSystems
public void prefillCodeSystems(Map<String,Integer> codeSystems)
Description copied from interface:ICommonTokenValuesCache
Add the contents of the given codeSystems map to the shared cache. It is assumed that all of these ids are already committed in the database, not newly inserted as part of the current transaction.- Specified by:
prefillCodeSystems
in interfaceICommonTokenValuesCache
-
getCommonTokenValueId
public Long getCommonTokenValueId(String codeSystem, String tokenValue)
Description copied from interface:ICommonTokenValuesCache
Get the database common_token_value_id for the given code system and token value.- Specified by:
getCommonTokenValueId
in interfaceICommonTokenValuesCache
- Returns:
-
resolveCommonTokenValueIds
public Set<Long> resolveCommonTokenValueIds(Collection<CommonTokenValue> tokenValues, Set<CommonTokenValue> misses)
Description copied from interface:ICommonTokenValuesCache
Get the database common_token_value_ids for the given list of token values.- Specified by:
resolveCommonTokenValueIds
in interfaceICommonTokenValuesCache
misses
- the set of the CommonTokenValue objects we couldn't find in the cache- Returns:
-
getCanonicalId
public Integer getCanonicalId(String canonicalValue)
Description copied from interface:ICommonTokenValuesCache
Get the cached database id for the given canonical url- Specified by:
getCanonicalId
in interfaceICommonTokenValuesCache
- Returns:
-
-