Package net.solarnetwork.dao
Interface GenericDao<T extends Entity<K>,K>
- Type Parameters:
T- the entity type managed by this DAOK- 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
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumEnumeration of standard entity event types.static enumEnumeration of a set of standard sort keys. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringAn event property key for anIdentity.getId()value.static final StringAn event property key for anEntityinstance.static final StringAn event topic template for entity events.static final List<SortDescriptor>Sort descriptor list to sort by creation date in ascending order.static final List<SortDescriptor>Sort descriptor list to sort by creation date in descending order.static final List<SortDescriptor>Sort descriptor list to sort by creation date, then ID, both in ascending order.static final List<SortDescriptor>Sort descriptor list to sort by creation date, then ID, both in descending order.static final List<SortDescriptor>Sort descriptor list to sort by ID in ascending order.static final List<SortDescriptor>Sort descriptor list to sort by ID in descending order. -
Method Summary
Modifier and TypeMethodDescriptioncreateEntityEventProperties(I id, E entity) Create an entity event.voidRemove a persisted entity.static StringentityEventTopic(String entityName, String eventType) Generate an event topic out of an entity name and event type.default StringentityEventTopic(GenericDao.EntityEventType eventType) Get an event topic for an event type.Get a persisted entity by its primary key.getAll(List<SortDescriptor> sorts) Get all persisted entities, optionally sorted in some way.Get the entity class supported by this DAO.Persist an entity, creating or updating as appropriate.
-
Field Details
-
SORT_BY_CREATED_ASCENDING
Sort descriptor list to sort by creation date in ascending order. -
SORT_BY_CREATED_DESCENDING
Sort descriptor list to sort by creation date in descending order. -
SORT_BY_ID_ASCENDING
Sort descriptor list to sort by ID in ascending order. -
SORT_BY_ID_DESCENDING
Sort descriptor list to sort by ID in descending order. -
SORT_BY_CREATED_ID_ASCENDING
Sort descriptor list to sort by creation date, then ID, both in ascending order. -
SORT_BY_CREATED_ID_DESCENDING
Sort descriptor list to sort by creation date, then ID, both in descending order. -
ENTITY_EVENT_ENTITY_PROPERTY
An event property key for anEntityinstance.- See Also:
-
ENTITY_EVENT_ENTITY_ID_PROPERTY
An event property key for anIdentity.getId()value.- See Also:
-
ENTITY_EVENT_TOPIC_TEMPLATE
An event topic template for entity events.The event properties must include
ENTITY_EVENT_ENTITY_ID_PROPERTYand may includeENTITY_EVENT_ENTITY_PROPERTY.- See Also:
-
-
Method Details
-
entityEventTopic
Generate an event topic out of an entity name and event type.This method uses the
ENTITY_EVENT_TOPIC_TEMPLATEtemplate to format the topic value, passing the method arguments as format parameters.- Parameters:
entityName- an entity nameeventType- an event type- Returns:
- the event topic
-
entityEventTopic
Get an event topic for an event type.This method uses the
getObjectType()simple name as the entity name, and callsentityEventTopic(String, String)to format the event topic- Parameters:
eventType- the event type- Returns:
- the event topic
-
createEntityEventProperties
Create an entity event.- Type Parameters:
E- the entity typeI- the primary key type- Parameters:
id- the primary keyentity- the optional entity- Returns:
- the new event instance
-
getObjectType
Get the entity class supported by this DAO.- Returns:
- class
-
save
Persist an entity, creating or updating as appropriate.- Parameters:
entity- the domain object so store- Returns:
- the primary key of the stored object
-
get
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
Get all persisted entities, optionally sorted in some way.The
sortDescriptorsparameter 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
Remove a persisted entity.- Parameters:
entity- the entity to delete
-