Class JpaCacheLoader<K,V>

java.lang.Object
com.tangosol.util.Base
com.oracle.coherence.jpa.JpaCacheLoader<K,V>
All Implemented Interfaces:
CacheLoader<K,V>
Direct Known Subclasses:
JpaCacheStore

public class JpaCacheLoader<K,V> extends Base implements CacheLoader<K,V>
JPA implementation of the CacheLoader interface.

Use this class as a load-only implementation that uses any JPA implementation to load entities from a data store. The entities must be mapped to the data store and a JPA persistence unit configuration must exist.

Use the JpaCacheStore class for a full load and store implementation.

Author:
mlk 2007.04.20, jh 2007.05.18
See Also:
  • Field Details

    • s_mapFactories

      protected static final Map<String,jakarta.persistence.EntityManagerFactory> s_mapFactories
      Map of all shared entity manager factories for all persistence units.
    • m_sEntityName

      protected String m_sEntityName
      Name of the entity that this CacheLoader is managing.
    • m_sEntityClass

      protected Class<?> m_sEntityClass
      The entity class that this CacheLoader is managing.
    • m_emf

      protected jakarta.persistence.EntityManagerFactory m_emf
      The EntityManagerFactory from which EntityManager instances are obtained.
  • Constructor Details

    • JpaCacheLoader

      public JpaCacheLoader(String sEntityName, String sEntityClassName, String sUnitName)
      Constructor which accepts an entity name, class name, and persistence unit name.
      Parameters:
      sEntityName - the JPA name of the entity
      sEntityClassName - the fully-qualified class name of the entity
      sUnitName - the name of the persistence unit
    • JpaCacheLoader

      public JpaCacheLoader(String sEntityName, String sEntityClassName, String sUnitName, ClassLoader loader)
      Constructor which accepts an entity name, class name, persistence unit name, and classloader.
      Parameters:
      sEntityName - the JPA name of the entity
      sEntityClassName - the fully-qualified class name of the entity
      sUnitName - the name of the persistence unit
      loader - the ClassLoader used to load the entity class
  • Method Details

    • load

      public V load(K oKey)
      Description copied from interface: CacheLoader
      Return the value associated with the specified key, or null if the key does not have an associated value in the underlying store.
      Specified by:
      load in interface CacheLoader<K,V>
      Parameters:
      oKey - key whose associated value is to be returned
      Returns:
      the value associated with the specified key, or null if no value is available for that key
    • loadAll

      public Map<K,V> loadAll(Collection<? extends K> colKeys)
      Description copied from interface: CacheLoader
      Return the values associated with each the specified keys in the passed collection. If a key does not have an associated value in the underlying store, then the return map will not have an entry for that key.

      The default implementation of this method calls CacheLoader.load(K) for each key in the supplied Collection. Implementations that can optimize multi-key operations should override this default implementation.

      Specified by:
      loadAll in interface CacheLoader<K,V>
      Parameters:
      colKeys - a collection of keys to load
      Returns:
      a Map of keys to associated values for the specified keys
    • initialize

      protected void initialize(String sEntityName, String sEntityClassName, String sUnitName, ClassLoader loader)
      Initialize this instance with the relevant metadata for the entity being stored.
      Parameters:
      sEntityName - the JPA name of the entity
      sEntityClassName - the fully-qualified class name of the entity
      sUnitName - the name of the persistence unit
      loader - the ClassLoader used to load the entity class
    • getEntityManager

      protected jakarta.persistence.EntityManager getEntityManager()
      Creates and returns an EntityManager. A new instance is created each time this method is called.
      Returns:
      a new EntityManager to use for a subsequent operation