Class AbstractQueryCache

All Implemented Interfaces:
Serializable, QueryCache, TypesChangedListener, Configurable, Closeable, EventManager
Direct Known Subclasses:
ConcurrentQueryCache

public abstract class AbstractQueryCache extends AbstractConcurrentEventManager implements QueryCache, Configurable
Abstract QueryCache implementation that provides various statistics, logging, and timeout functionality common across cache implementations.
Author:
Patrick Linskey, Abe White
See Also:
  • Field Details

  • Constructor Details

    • AbstractQueryCache

      public AbstractQueryCache()
  • Method Details

    • setEnableStatistics

      public void setEnableStatistics(boolean enable)
    • getEnableStatistics

      public boolean getEnableStatistics()
    • getStatistics

      public QueryStatistics<QueryKey> getStatistics()
      Description copied from interface: QueryCache
      Gets the simple statistics for query results. If the statistics gathering is disabled, an empty statistics is returned.
      Specified by:
      getStatistics in interface QueryCache
    • initialize

      public void initialize(DataCacheManager manager)
      Description copied from interface: QueryCache
      Initialize any resources associated with the given DataCacheManager.
      Specified by:
      initialize in interface QueryCache
    • onTypesChanged

      public void onTypesChanged(TypesChangedEvent ev)
      Description copied from interface: TypesChangedListener
      Notification that instances of persistent types have changed.
      Specified by:
      onTypesChanged in interface TypesChangedListener
    • get

      public QueryResult get(QueryKey key)
      Description copied from interface: QueryCache
      Return a list of oids for the given query key. This is an unmodifiable list.
      Specified by:
      get in interface QueryCache
      Returns:
      The query results matching the given key, or null if none
    • put

      public QueryResult put(QueryKey qk, QueryResult oids)
      Description copied from interface: QueryCache
      Set the list of OIDs for the given query key. A reference to the given list will be stored in the query cache, so the list should not be modified after invoking this method.
      Specified by:
      put in interface QueryCache
      Returns:
      The previously cached value, or null if the key was not previously cached. See Map.put(K, V) for more information.
    • remove

      public QueryResult remove(QueryKey key)
      Description copied from interface: QueryCache
      Remove the value stored under the given query key. This method is typically not invoked directly from outside the QueryCache class. Instead, the cache should be updated by implementing RemoteCommitListener, which will result in all queries that may be invalid being dropped.
      Specified by:
      remove in interface QueryCache
      Returns:
      The previously cached value, or null if the key was not previously cached. See Map.remove(java.lang.Object) for more information.
    • pin

      public boolean pin(QueryKey key)
      Description copied from interface: QueryCache
      Pin the value stored under qk into the cache. This method guarantees that qk's value will not be expired if the cache exceeds its capacity. It causes this data to be ignored when determining whether or not the cache is full, effectively increasing the total amount of data stored in the cache. This method does not affect the behavior of QueryCache.remove(org.apache.openjpa.datacache.QueryKey) or TypesChangedListener.onTypesChanged(org.apache.openjpa.datacache.TypesChangedEvent).
      Specified by:
      pin in interface QueryCache
      Returns:
      true if key's value was pinned into the cache; false if the key is not in the cache.
    • unpin

      public boolean unpin(QueryKey key)
      Description copied from interface: QueryCache
      Unpin the value stored under key into the cache. This method reverses a previous invocation of QueryCache.pin(org.apache.openjpa.datacache.QueryKey). This method does not remove anything from the cache; it merely makes key's value a candidate for flushing from the cache.
      Specified by:
      unpin in interface QueryCache
      Returns:
      true if key's value was unpinned from the cache; false if the key is not in the cache.
    • clear

      public void clear()
      Description copied from interface: QueryCache
      Remove all data from this cache.
      Specified by:
      clear in interface QueryCache
    • close

      public void close()
      Description copied from interface: QueryCache
      Free the resources used by this cache.
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface QueryCache
    • close

      protected void close(boolean clear)
    • isClosed

      public boolean isClosed()
    • addTypesChangedListener

      public void addTypesChangedListener(TypesChangedListener listen)
      Description copied from interface: QueryCache
      Add a new types event listener to this cache.
      Specified by:
      addTypesChangedListener in interface QueryCache
    • removeTypesChangedListener

      public boolean removeTypesChangedListener(TypesChangedListener listen)
      Description copied from interface: QueryCache
      Remove an types event listener from this cache.
      Specified by:
      removeTypesChangedListener in interface QueryCache
    • afterCommit

      public void afterCommit(RemoteCommitEvent event)
      This method is part of the RemoteCommitListener interface. If your cache subclass relies on OpenJPA for clustering support, make it implement RemoteCommitListener. This method will take care of invalidating entries from remote commits, by delegating to onTypesChanged(org.apache.openjpa.datacache.TypesChangedEvent).
    • keySet

      protected abstract Collection keySet()
      Return a threadsafe view of the keys in this cache. This collection must be iterable without risk of concurrent modification exceptions. It does not have to implement contains() efficiently or use set semantics.
    • getInternal

      protected abstract QueryResult getInternal(QueryKey qk)
      Return the list for the given key.
    • putInternal

      protected abstract QueryResult putInternal(QueryKey qk, QueryResult oids)
      Add the given result to the cache, returning the old result under the given key.
    • removeInternal

      protected abstract QueryResult removeInternal(QueryKey qk)
      Remove the result under the given key from the cache.
    • removeAllInternal

      protected void removeAllInternal(Collection qks)
      Remove all results under the given keys from the cache.
    • clearInternal

      protected abstract void clearInternal()
      Clear the cache.
    • pinInternal

      protected abstract boolean pinInternal(QueryKey qk)
      Pin an object to the cache.
    • unpinInternal

      protected abstract boolean unpinInternal(QueryKey qk)
      Unpin an object from the cache.
    • setConfiguration

      public void setConfiguration(Configuration conf)
      Description copied from interface: Configurable
      Invoked prior to setting bean properties.
      Specified by:
      setConfiguration in interface Configurable
    • startConfiguration

      public void startConfiguration()
      Description copied from interface: Configurable
      Invoked before bean property configuration is begun on this object.
      Specified by:
      startConfiguration in interface Configurable
    • endConfiguration

      public void endConfiguration()
      Description copied from interface: Configurable
      Invoked upon completion of bean property configuration for this object.
      Specified by:
      endConfiguration in interface Configurable
    • fireEvent

      protected void fireEvent(Object event, Object listener)
      Description copied from class: AbstractConcurrentEventManager
      Implement this method to fire the given event to the given listener.
      Specified by:
      fireEvent in class AbstractConcurrentEventManager
    • newListenerCollection

      protected Collection newListenerCollection()
      Individual query results will be registered as types changed listeners. We want such query results to be gc'd once the only reference is held by the list of expiration listeners.
      Overrides:
      newListenerCollection in class AbstractConcurrentEventManager
    • setEvictPolicy

      public void setEvictPolicy(String evictPolicy)
      Sets the eviction policy for the query cache
      Parameters:
      evictPolicy - -- String value that specifies the eviction policy
    • getEvictPolicy

      public AbstractQueryCache.EvictPolicy getEvictPolicy()
      Returns the evictionPolicy for QueryCache
      Returns:
      -- returns a String value of evictPolicy attribute
    • updateEntityTimestamp

      protected void updateEntityTimestamp(Map<String,Long> timestampMap)
      Updates the entity timestamp map with the current time in milliseconds
      Parameters:
      timestampMap - -- a map that contains entityname and its last updated timestamp
    • getAllEntityTimestamp

      public List<Long> getAllEntityTimestamp(List<String> keyList)
      Returns a list of timestamps in the form of Long objects which are the last updated time stamps for the given entities in the keylist.
      Parameters:
      keyList - -- List of entity names
      Returns:
      -- Returns a list that has the timestamp for the given entities
    • setName

      public void setName(String n)
    • getName

      public String getName()
    • count

      public int count()