Class AbstractDataCache

  • All Implemented Interfaces:
    java.io.Serializable, DataCache, org.apache.openjpa.lib.conf.Configurable, org.apache.openjpa.lib.util.Clearable, org.apache.openjpa.lib.util.Closeable, org.apache.openjpa.lib.util.EventManager
    Direct Known Subclasses:
    ConcurrentDataCache

    public abstract class AbstractDataCache
    extends org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
    implements DataCache, org.apache.openjpa.lib.conf.Configurable
    Abstract DataCache implementation that provides various statistics, logging, and timeout functionality common across cache implementations.
    Author:
    Patrick Linskey, Abe White
    See Also:
    Serialized Form
    • Field Detail

      • log

        protected org.apache.openjpa.lib.log.Log log
        The log to use.
      • _includedTypes

        protected java.util.Set<java.lang.String> _includedTypes
      • _excludedTypes

        protected java.util.Set<java.lang.String> _excludedTypes
      • _evictOnBulkUpdate

        protected boolean _evictOnBulkUpdate
    • Constructor Detail

      • AbstractDataCache

        public AbstractDataCache()
    • Method Detail

      • getName

        public java.lang.String getName()
        Description copied from interface: DataCache
        Returns a string name that can be used by end-user-visible code to identify this cache.
        Specified by:
        getName in interface DataCache
      • setName

        public void setName​(java.lang.String name)
        Description copied from interface: DataCache
        Sets a string name to be used to identify this cache to end-user needs.
        Specified by:
        setName in interface DataCache
      • setEnableStatistics

        public void setEnableStatistics​(boolean enable)
      • getEnableStatistics

        public void getEnableStatistics()
      • getEvictionSchedule

        public java.lang.String getEvictionSchedule()
      • setEvictionSchedule

        public void setEvictionSchedule​(java.lang.String s)
      • commit

        public void commit​(java.util.Collection<DataCachePCData> additions,
                           java.util.Collection<DataCachePCData> newUpdates,
                           java.util.Collection<DataCachePCData> existingUpdates,
                           java.util.Collection<java.lang.Object> deletes)
        Description copied from interface: DataCache
        Perform a batch update of the cache. Add all DataCachePCData objects in additions and in newUpdates, make the appropriate modifications to all DataCachePCDatas in existingUpdates, and delete all OIDs in deletes. All changes made to cached data must be made via this method. It is this method that is responsible for performing any side-effects that should happen on meaningful cache changes. Implementations should bear in mind that the deletes collection may contain oids that are also in the additions map. This is possible because it is valid for a user to delete an object with a particular oid and then add that object in the same batch.
        Specified by:
        commit in interface DataCache
        Parameters:
        additions - A collection of DataCachePCData objects. These represent data that have been newly created, and thus must be added to the cache.
        newUpdates - A collection of DataCachePCData objects. These represent data that have been modified but were not originally in the cache, and thus must be added to the cache.
        existingUpdates - A collection of DataCachePCData objects. These represent data that have been modified and were originally loaded from the cache. It is up to the cache implementation to decide if these values must be re-enlisted in the cache. Some caches may return live data from DataCache.get(java.lang.Object) invocations, in which case these values need not be re-enlisted.
        deletes - A collection of object IDs that have been deleted and must therefore be dropped from the cache.
      • contains

        public boolean contains​(java.lang.Object key)
        Description copied from interface: DataCache
        Returns true if this cache contains data corresponding to oid; otherwise returns false.
        Specified by:
        contains in interface DataCache
      • containsAll

        public java.util.BitSet containsAll​(java.util.Collection<java.lang.Object> keys)
        Description copied from interface: DataCache
        Returns the indexes of the oids in this cache.
        Specified by:
        containsAll in interface DataCache
      • getAll

        public java.util.Map<java.lang.Object,​DataCachePCData> getAll​(java.util.List<java.lang.Object> keys)
        Returns the objects for the given key List.
        Specified by:
        getAll in interface DataCache
      • removeAll

        public java.util.BitSet removeAll​(java.util.Collection<java.lang.Object> keys)
        Description copied from interface: DataCache
        Remove the values stored under the given oids.
        Specified by:
        removeAll in interface DataCache
        Returns:
        the indexes of the removed oids
        See Also:
        DataCache.remove(java.lang.Object)
      • removeAll

        public void removeAll​(java.lang.Class<?> cls,
                              boolean subClasses)
        Remove the objects of the given class from the cache.
        Specified by:
        removeAll in interface DataCache
      • pin

        public boolean pin​(java.lang.Object key)
        Description copied from interface: DataCache
        Pin the value stored under oid into the cache. This method guarantees that oid's value will not be dropped by the caching algorithm. This method does not affect the behavior of DataCache.remove(java.lang.Object).
        Specified by:
        pin in interface DataCache
        Returns:
        true if oid's value was pinned into the cache; false if the oid is not in the cache.
      • pinAll

        public java.util.BitSet pinAll​(java.util.Collection<java.lang.Object> keys)
        Description copied from interface: DataCache
        Pin all oids to the cache.
        Specified by:
        pinAll in interface DataCache
        Returns:
        the indexes of the pinned oids
        See Also:
        DataCache.pin(java.lang.Object)
      • pinAll

        public void pinAll​(java.lang.Class<?> cls,
                           boolean subs)
        Description copied from interface: DataCache
        Pin all oids for the given type.
        Specified by:
        pinAll in interface DataCache
        subs - Whether to include subclasses.
      • unpin

        public boolean unpin​(java.lang.Object key)
        Description copied from interface: DataCache
        Unpin the value stored under oid from the cache. This method reverses a previous invocation of DataCache.pin(java.lang.Object). This method does not remove anything from the cache; it merely makes oid's value a candidate for flushing from the cache.
        Specified by:
        unpin in interface DataCache
        Returns:
        true if oid's value was unpinned from the cache; false if the oid is not in the cache.
      • unpinAll

        public java.util.BitSet unpinAll​(java.util.Collection<java.lang.Object> keys)
        Description copied from interface: DataCache
        Unpin all oids from the cache.
        Specified by:
        unpinAll in interface DataCache
        Returns:
        the indexes of the unpinned oids
        See Also:
        DataCache.unpin(java.lang.Object)
      • unpinAll

        public void unpinAll​(java.lang.Class<?> cls,
                             boolean subs)
        Description copied from interface: DataCache
        Unpin all oids associaed with the given type from the cache.
        Specified by:
        unpinAll in interface DataCache
        subs - Whether to include subclasses.
      • close

        public void close()
        Description copied from interface: DataCache
        Free the resources used by this cache.
        Specified by:
        close in interface org.apache.openjpa.lib.util.Closeable
        Specified by:
        close in interface DataCache
      • close

        protected void close​(boolean clear)
      • isClosed

        public boolean isClosed()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • 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.
      • keyRemoved

        protected void keyRemoved​(java.lang.Object key,
                                  boolean expired)
        Invoke when a key is removed from this cache. Propagates the expiration event on to all expiration listeners registered with this class.
      • getInternal

        protected abstract DataCachePCData getInternal​(java.lang.Object oid)
        Return the object for the given oid.
      • putInternal

        protected abstract DataCachePCData putInternal​(java.lang.Object oid,
                                                       DataCachePCData pc)
        Add the given object to the cache, returning the old object under the given oid.
      • putAllInternal

        protected void putAllInternal​(java.util.Collection<DataCachePCData> pcs)
        Add all of the given objects to the cache.
      • removeInternal

        protected abstract DataCachePCData removeInternal​(java.lang.Object oid)
        Remove the object under the given oid from the cache.
      • removeAllInternal

        protected abstract void removeAllInternal​(java.lang.Class<?> cls,
                                                  boolean subclasses)
        Evict objects in cache by class.
      • removeAllInternal

        protected void removeAllInternal​(java.util.Collection<java.lang.Object> oids)
        Remove all objects under the given oids from the cache.
      • removeAllTypeNamesInternal

        protected void removeAllTypeNamesInternal​(java.util.Collection<java.lang.String> classNames)
        Remove all objects of the given class names from the cache.
      • clearInternal

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

        protected abstract boolean pinInternal​(java.lang.Object oid)
        Pin an object to the cache.
      • unpinInternal

        protected abstract boolean unpinInternal​(java.lang.Object oid)
        Unpin an object from the cache.
      • getPartition

        public DataCache getPartition​(java.lang.String name,
                                      boolean create)
        Description copied from interface: DataCache
        Gets the named partition. Note that a partition itself is another cache.
        Specified by:
        getPartition in interface DataCache
        Parameters:
        name - name of the given partition.
        create - if true optionally create a new partition.
        Returns:
        a partition of the given name. Or null, if either no such partition exists or can not be created.
      • getPartitionNames

        public java.util.Set<java.lang.String> getPartitionNames()
        Description copied from interface: DataCache
        Gets the name of the known partitions.
        Specified by:
        getPartitionNames in interface DataCache
        Returns:
        empty set if no partition exists.
      • isPartitioned

        public boolean isPartitioned()
        Description copied from interface: DataCache
        Affirms if this cache maintains partitions.
        Specified by:
        isPartitioned in interface DataCache
      • setConfiguration

        public void setConfiguration​(org.apache.openjpa.lib.conf.Configuration conf)
        Specified by:
        setConfiguration in interface org.apache.openjpa.lib.conf.Configurable
      • startConfiguration

        public void startConfiguration()
        Specified by:
        startConfiguration in interface org.apache.openjpa.lib.conf.Configurable
      • endConfiguration

        public void endConfiguration()
        Specified by:
        endConfiguration in interface org.apache.openjpa.lib.conf.Configurable
      • fireEvent

        protected void fireEvent​(java.lang.Object event,
                                 java.lang.Object listener)
        Specified by:
        fireEvent in class org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
      • getTypes

        public java.util.Set<java.lang.String> getTypes()
      • getExcludedTypes

        public java.util.Set<java.lang.String> getExcludedTypes()
      • setTypes

        public void setTypes​(java.util.Set<java.lang.String> types)
      • setTypes

        public void setTypes​(java.lang.String types)
      • setExcludedTypes

        public void setExcludedTypes​(java.util.Set<java.lang.String> types)
      • setExcludedTypes

        public void setExcludedTypes​(java.lang.String types)
      • getEvictOnBulkUpdate

        public boolean getEvictOnBulkUpdate()
        Description copied from interface: DataCache
        Returns whether the the cache needs to be updated when bulk updates as executed. Defaults to true.
        Specified by:
        getEvictOnBulkUpdate in interface DataCache
      • setEvictOnBulkUpdate

        public void setEvictOnBulkUpdate​(boolean b)