Class CachingGenericDao<T extends net.solarnetwork.dao.Entity<K>,K,D extends net.solarnetwork.dao.GenericDao<T,K>>

java.lang.Object
net.solarnetwork.central.common.dao.CachingGenericDao<T,K,D>
Type Parameters:
T - the entity type managed by this DAO
K - the entity primary key type
D - the delegate DAO type
All Implemented Interfaces:
net.solarnetwork.dao.GenericDao<T,K>
Direct Known Subclasses:
CachingUserMetadataDao

public class CachingGenericDao<T extends net.solarnetwork.dao.Entity<K>,K,D extends net.solarnetwork.dao.GenericDao<T,K>> extends Object implements net.solarnetwork.dao.GenericDao<T,K>
Proxy implementation of GenericDao with caching support.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface net.solarnetwork.dao.GenericDao

    net.solarnetwork.dao.GenericDao.EntityEventType, net.solarnetwork.dao.GenericDao.StandardSortKey
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final javax.cache.Cache<K,T>
    The cache.
    protected final D
    The delegate DAO.
    protected final Executor
    A background task executor.

    Fields inherited from interface net.solarnetwork.dao.GenericDao

    ENTITY_EVENT_ENTITY_ID_PROPERTY, ENTITY_EVENT_ENTITY_PROPERTY, ENTITY_EVENT_TOPIC_TEMPLATE, SORT_BY_CREATED_ASCENDING, SORT_BY_CREATED_DESCENDING, SORT_BY_CREATED_ID_ASCENDING, SORT_BY_CREATED_ID_DESCENDING, SORT_BY_ID_ASCENDING, SORT_BY_ID_DESCENDING
  • Constructor Summary

    Constructors
    Constructor
    Description
    CachingGenericDao(D delegate, javax.cache.Cache<K,T> cache, Executor executor)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    delete(T entity)
     
    entityEventTopic(net.solarnetwork.dao.GenericDao.EntityEventType eventType)
     
    protected void
    Evict all keys matching a predicate.
    get(K id)
     
    getAll(List<net.solarnetwork.domain.SortDescriptor> sorts)
     
    Class<? extends T>
     
    save(T entity)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface net.solarnetwork.dao.GenericDao

    entityKey
  • Field Details

    • delegate

      protected final D extends net.solarnetwork.dao.GenericDao<T,K> delegate
      The delegate DAO.
    • cache

      protected final javax.cache.Cache<K,T extends net.solarnetwork.dao.Entity<K>> cache
      The cache.
    • executor

      protected final Executor executor
      A background task executor.
  • Constructor Details

    • CachingGenericDao

      public CachingGenericDao(D delegate, javax.cache.Cache<K,T> cache, Executor executor)
      Constructor.
      Parameters:
      delegate - the delegate DAO
      cache - the cache
      executor - task executor
      Throws:
      IllegalArgumentException - if any argument is null
  • Method Details

    • entityEventTopic

      public String entityEventTopic(net.solarnetwork.dao.GenericDao.EntityEventType eventType)
      Specified by:
      entityEventTopic in interface net.solarnetwork.dao.GenericDao<T extends net.solarnetwork.dao.Entity<K>,K>
    • getObjectType

      public Class<? extends T> getObjectType()
      Specified by:
      getObjectType in interface net.solarnetwork.dao.GenericDao<T extends net.solarnetwork.dao.Entity<K>,K>
    • save

      public K save(T entity)
      Specified by:
      save in interface net.solarnetwork.dao.GenericDao<T extends net.solarnetwork.dao.Entity<K>,K>
    • get

      public T get(K id)
      Specified by:
      get in interface net.solarnetwork.dao.GenericDao<T extends net.solarnetwork.dao.Entity<K>,K>
    • getAll

      public Collection<T> getAll(List<net.solarnetwork.domain.SortDescriptor> sorts)
      Specified by:
      getAll in interface net.solarnetwork.dao.GenericDao<T extends net.solarnetwork.dao.Entity<K>,K>
    • delete

      public void delete(T entity)
      Specified by:
      delete in interface net.solarnetwork.dao.GenericDao<T extends net.solarnetwork.dao.Entity<K>,K>
    • evictKeysMatching

      protected void evictKeysMatching(Predicate<K> filter)
      Evict all keys matching a predicate.

      This method will submit a task to the configured Executor to perform the eviction, and then return immediately.

      Parameters:
      filter - the predicate to match keys of entries to evict from the cache