ID
- is the type of the primary key
of the managed
GenericEntity
.ENTITY
- is the type
of the managed entity. We strongly recommend to
extend PersistenceEntity
.@ComponentSpecification(plugin=true) public interface GenericDao<ID,ENTITY extends GenericEntity<ID>>
specific type
of GenericEntity
. It is
responsible for loading
, saving
and
searching
entities
of the
according type
. GenericEntity
there should exist one instance of this
interface. Typically when you create a custom entity
you will also create a custom
interface and implementation of an according GenericDao
. If there is no custom implementation of a
GenericDao
for some type of GenericEntity
, a generic implementation is used as fallback. PersistenceManager
can be seen as the manager of all GenericDao
and acts as front-end
to them.GenericEntity
,
PersistenceManager
Modifier and Type | Method and Description |
---|---|
ENTITY |
create()
This method creates a new, empty, and transient instance of the
managed entity. |
void |
delete(ENTITY entity)
This method deletes the given
entity from the persistent store. |
void |
deleteById(ID id)
This method deletes the
entity identified by the given id from the
persistent store. |
ENTITY |
find(ID id)
This method loads the
GenericEntity with the given id from the persistent store. |
ENTITY |
findIfExists(ID id)
This method loads the
GenericEntity with the given id from the persistent store. |
Class<? extends ENTITY> |
getEntityClass()
|
ENTITY |
getReference(ID id)
This method creates a lazy reference proxy of the
GenericEntity with the given id
from the persistent store. |
void |
save(ENTITY entity)
This method saves the given
entity in the persistent store. |
ENTITY create() throws ReflectionException
managed
entity.
The default implementation is Class.newInstance()
, however more specific implementations are
possible. This allows to use interfaces for entities and use the persistence layer as API without knowing
the implementation. However you are still free to ignore this method and work with the POJO approach.ReflectionException
- is the instantiation failed.ENTITY find(ID id) throws ObjectNotFoundException
GenericEntity
with the given id
from the persistent store.id
- is the primary key
of the requested entity
.entity
.ObjectNotFoundException
- if the requested entity
could NOT be found. Unlike
the JPA we throw this exception instead of returning null
as this is typically an
exceptional situation and it is better to have a precise exception than a NPE. Otherwise use
findIfExists(Object)
.EntityManager.find(Class, Object)
ENTITY findIfExists(ID id)
GenericEntity
with the given id
from the persistent store.id
- is the primary key
of the requested entity
.entity
or null
if it does NOT exist in
persistent store.EntityManager.find(Class, Object)
ENTITY getReference(ID id)
GenericEntity
with the given id
from the persistent store.id
- is the primary key
of the requested entity
.entity
.EntityManager.getReference(Class, Object)
void save(ENTITY entity)
entity
in the persistent store. If the entity
is
new
it is initially created in the
persistent store (after commit). If the entity
is configured to have a generated
primary key
a unique ID is generated and assigned. Otherwise, if the
entity
is already managed
, the entity
is updated in the persistent store. managed
entity
are automatically saved even if this method has NOT been invoked. However,
it is a good practice to always invoke this method after modifying a
managed
entity
to make your code more explicit. This will also guarantee that potential custom-logic of your
DAO
is invoked.entity
- is the GenericEntity
to save.void delete(ENTITY entity)
entity
from the persistent store. entity
is transient
this method has no effect. entity
- is the GenericEntity
to save.void deleteById(ID id)
id
- is the primary key
of the entity
to delete.Copyright © 2001–2014 mmm-Team. All rights reserved.