Interface GenericDao<T extends Entity<K>,K>

Type Parameters:
T - the entity type managed by this DAO
K - the entity primary key type

public interface GenericDao<T extends Entity<K>,K>
A simple Data Access Object (DAO) API for managing persistent entity objects.
Since:
1.59
Version:
2.0
Author:
matt
  • Field Details

    • SORT_BY_CREATED_ASCENDING

      static final List<SortDescriptor> SORT_BY_CREATED_ASCENDING
      Sort descriptor list to sort by creation date in ascending order.
    • SORT_BY_CREATED_DESCENDING

      static final List<SortDescriptor> SORT_BY_CREATED_DESCENDING
      Sort descriptor list to sort by creation date in descending order.
    • SORT_BY_ID_ASCENDING

      static final List<SortDescriptor> SORT_BY_ID_ASCENDING
      Sort descriptor list to sort by ID in ascending order.
    • SORT_BY_ID_DESCENDING

      static final List<SortDescriptor> SORT_BY_ID_DESCENDING
      Sort descriptor list to sort by ID in descending order.
    • SORT_BY_CREATED_ID_ASCENDING

      static final List<SortDescriptor> SORT_BY_CREATED_ID_ASCENDING
      Sort descriptor list to sort by creation date, then ID, both in ascending order.
    • SORT_BY_CREATED_ID_DESCENDING

      static final List<SortDescriptor> SORT_BY_CREATED_ID_DESCENDING
      Sort descriptor list to sort by creation date, then ID, both in descending order.
    • ENTITY_EVENT_ENTITY_PROPERTY

      static final String ENTITY_EVENT_ENTITY_PROPERTY
      An event property key for an Entity instance.
      See Also:
    • ENTITY_EVENT_ENTITY_ID_PROPERTY

      static final String ENTITY_EVENT_ENTITY_ID_PROPERTY
      An event property key for an Identity.getId() value.
      See Also:
    • ENTITY_EVENT_TOPIC_TEMPLATE

      static final String ENTITY_EVENT_TOPIC_TEMPLATE
      An event topic template for entity events.

      The event properties must include ENTITY_EVENT_ENTITY_ID_PROPERTY and may include ENTITY_EVENT_ENTITY_PROPERTY.

      See Also:
  • Method Details

    • entityEventTopic

      static String entityEventTopic(String entityName, String eventType)
      Generate an event topic out of an entity name and event type.

      This method uses the ENTITY_EVENT_TOPIC_TEMPLATE template to format the topic value, passing the method arguments as format parameters.

      Parameters:
      entityName - an entity name
      eventType - an event type
      Returns:
      the event topic
    • entityEventTopic

      default String entityEventTopic(GenericDao.EntityEventType eventType)
      Get an event topic for an event type.

      This method uses the getObjectType() simple name as the entity name, and calls entityEventTopic(String, String) to format the event topic

      Parameters:
      eventType - the event type
      Returns:
      the event topic
    • createEntityEventProperties

      static <E extends Entity<I>, I> Map<String,Object> createEntityEventProperties(I id, E entity)
      Create an entity event.
      Type Parameters:
      E - the entity type
      I - the primary key type
      Parameters:
      id - the primary key
      entity - the optional entity
      Returns:
      the new event instance
    • getObjectType

      Class<? extends T> getObjectType()
      Get the entity class supported by this DAO.
      Returns:
      class
    • save

      K save(T entity)
      Persist an entity, creating or updating as appropriate.
      Parameters:
      entity - the domain object so store
      Returns:
      the primary key of the stored object
    • get

      T get(K id)
      Get a persisted entity by its primary key.
      Parameters:
      id - the primary key to retrieve
      Returns:
      the domain object, or null if not available
    • getAll

      Collection<T> getAll(List<SortDescriptor> sorts)
      Get all persisted entities, optionally sorted in some way.

      The sortDescriptors parameter can be null, in which case the sort order is not defined and implementation specific.

      Parameters:
      sorts - list of sort descriptors to sort the results by
      Returns:
      list of all persisted entities, or empty list if none available
    • delete

      void delete(T entity)
      Remove a persisted entity.
      Parameters:
      entity - the entity to delete