Class CommonValuesCacheImpl

  • All Implemented Interfaces:
    ICommonValuesCache

    public class CommonValuesCacheImpl
    extends java.lang.Object
    implements ICommonValuesCache
    Implementation of a cache used for lookups of entities related to tokens, canonicals and code systems
    • Constructor Summary

      Constructors 
      Constructor Description
      CommonValuesCacheImpl​(int codeSystemCacheSize, int tokenValueCacheSize, int canonicalCacheSize)
      Public constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addCanonicalValue​(java.lang.String url, long id)
      Add the url-id mapping to the local cache
      void addCodeSystem​(java.lang.String codeSystem, int id)
      Add the id to the local cache
      void addTokenValue​(CommonTokenValue key, long id)
      Add the CommonTokenValue and id to the local cache
      void clearLocalMaps()
      Clear any thread-local cache maps (probably because a transaction was rolled back)
      java.lang.Long getCanonicalId​(java.lang.String canonicalValue)
      Get the cached database id for the given canonical url
      java.lang.Integer getCodeSystemId​(java.lang.String codeSystem)
      Look up the id of the named codeSystem
      java.lang.Long getCommonTokenValueId​(java.lang.String codeSystem, java.lang.String tokenValue)
      Get the database common_token_value_id for the given code system and token value.
      void prefillCodeSystems​(java.util.Map<java.lang.String,​java.lang.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​(java.util.Collection<ResourceProfileRec> profileValues, java.util.List<ResourceProfileRec> misses)
      Look up the ids for the common canonical values in the cache
      void resolveCodeSystems​(java.util.Collection<ResourceTokenValueRec> tokenValues, java.util.List<ResourceTokenValueRec> misses)
      Lookup all the database values we have cached for the code-system names in the given collection.
      java.util.Set<java.lang.Long> resolveCommonTokenValueIds​(java.util.Collection<CommonTokenValue> tokenValues, java.util.Set<CommonTokenValue> misses)
      Get the database common_token_value_ids for the given list of token values.
      void resolveTokenValues​(java.util.Collection<ResourceTokenValueRec> tokenValues, java.util.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.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CommonValuesCacheImpl

        public CommonValuesCacheImpl​(int codeSystemCacheSize,
                                     int tokenValueCacheSize,
                                     int canonicalCacheSize)
        Public constructor
        Parameters:
        codeSystemCacheSize -
        tokenValueCacheSize -
        canonicalCacheSize -
    • 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 interface ICommonValuesCache
      • getCodeSystemId

        public java.lang.Integer getCodeSystemId​(java.lang.String codeSystem)
        Description copied from interface: ICommonValuesCache
        Look up the id of the named codeSystem
        Specified by:
        getCodeSystemId in interface ICommonValuesCache
        Returns:
        the database identity of the code system, or null if no record was found
      • resolveCodeSystems

        public void resolveCodeSystems​(java.util.Collection<ResourceTokenValueRec> tokenValues,
                                       java.util.List<ResourceTokenValueRec> misses)
        Description copied from interface: ICommonValuesCache
        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 interface ICommonValuesCache
        misses - the objects we couldn't find in the cache
      • resolveTokenValues

        public void resolveTokenValues​(java.util.Collection<ResourceTokenValueRec> tokenValues,
                                       java.util.List<ResourceTokenValueRec> misses)
        Description copied from interface: ICommonValuesCache
        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 interface ICommonValuesCache
        misses - the objects we couldn't find in the cache
      • resolveCanonicalValues

        public void resolveCanonicalValues​(java.util.Collection<ResourceProfileRec> profileValues,
                                           java.util.List<ResourceProfileRec> misses)
        Description copied from interface: ICommonValuesCache
        Look up the ids for the common canonical values in the cache
        Specified by:
        resolveCanonicalValues in interface ICommonValuesCache
        Parameters:
        profileValues - the collection of profile values containing the canonical urls
        misses - the objects we couldn't find in the cache
      • prefillCodeSystems

        public void prefillCodeSystems​(java.util.Map<java.lang.String,​java.lang.Integer> codeSystems)
        Description copied from interface: ICommonValuesCache
        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 interface ICommonValuesCache
      • getCommonTokenValueId

        public java.lang.Long getCommonTokenValueId​(java.lang.String codeSystem,
                                                    java.lang.String tokenValue)
        Description copied from interface: ICommonValuesCache
        Get the database common_token_value_id for the given code system and token value.
        Specified by:
        getCommonTokenValueId in interface ICommonValuesCache
        Returns:
      • resolveCommonTokenValueIds

        public java.util.Set<java.lang.Long> resolveCommonTokenValueIds​(java.util.Collection<CommonTokenValue> tokenValues,
                                                                        java.util.Set<CommonTokenValue> misses)
        Description copied from interface: ICommonValuesCache
        Get the database common_token_value_ids for the given list of token values.
        Specified by:
        resolveCommonTokenValueIds in interface ICommonValuesCache
        misses - the set of the CommonTokenValue objects we couldn't find in the cache
        Returns:
      • getCanonicalId

        public java.lang.Long getCanonicalId​(java.lang.String canonicalValue)
        Description copied from interface: ICommonValuesCache
        Get the cached database id for the given canonical url
        Specified by:
        getCanonicalId in interface ICommonValuesCache
        Returns: