Class JpaCacheStore<K,V>

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

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

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

NOTE: The persistence unit is assumed to be set to use RESOURCE_LOCAL transactions.

Author:
mlk 2007.04.20, jh 2007.05.18
  • Constructor Details

    • JpaCacheStore

      public JpaCacheStore(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
    • JpaCacheStore

      public JpaCacheStore(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

    • store

      public void store(K oKey, V oValue)
      Description copied from interface: CacheStore
      Store the specified value under the specified key in the underlying store. This method is intended to support both key/value creation and value update for a specific key.
      Specified by:
      store in interface CacheStore<K,V>
      Parameters:
      oKey - key to store the value under
      oValue - value to be stored
    • storeAll

      public void storeAll(Map<? extends K,? extends V> mapEntries)
      Description copied from interface: CacheStore
      Store the specified values under the specified keys in the underlying store. This method is intended to support both key/value creation and value update for the specified keys.

      If this operation fails (by throwing an exception) after a partial success, the convention is that entries which have been stored successfully are to be removed from the specified mapEntries, indicating that the store operation for the entries left in the map has failed or has not been attempted.

      The default implementation of this method calls CacheStore.store(K, V) for each entry in the supplied Map. Once stored successfully, an entry is removed from the Map (if possible). Implementations that can optimize multi-entry operations should override this default implementation.

      Specified by:
      storeAll in interface CacheStore<K,V>
      Parameters:
      mapEntries - a Map of any number of keys and values to store
    • erase

      public void erase(K oKey)
      Description copied from interface: CacheStore
      Remove the specified key from the underlying store if present.
      Specified by:
      erase in interface CacheStore<K,V>
      Parameters:
      oKey - key whose mapping is being removed from the cache
    • eraseAll

      public void eraseAll(Collection<? extends K> colKeys)
      Description copied from interface: CacheStore
      Remove the specified keys from the underlying store if present.

      If this operation fails (by throwing an exception) after a partial success, the convention is that keys which have been erased successfully are to be removed from the specified colKeys, indicating that the erase operation for the keys left in the collection has failed or has not been attempted.

      The default implementation of this method calls CacheStore.erase(K) for each key in the supplied Collection. Once erased successfully, the key is removed from the Collection (if possible). Implementations that can optimize multi-key operations should override this default implementation.

      Specified by:
      eraseAll in interface CacheStore<K,V>
      Parameters:
      colKeys - keys whose mappings are being removed from the cache
    • rollback

      protected void rollback(jakarta.persistence.EntityTransaction tx)
      Rollback the given EntityTransaction if it is not null and is active.
      Parameters:
      tx - the EntityTransaction; may be null