Interface GenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
-
- Type Parameters:
ID
- is the generic type if theprimary key
.E
- is the generic type of thePersistenceEntity
.
- All Superinterfaces:
FeatureForceIncrementModificationCounter<E>
- All Known Subinterfaces:
Dao<E>
,MasterDataDao<E>
- All Known Implementing Classes:
AbstractDao
,AbstractGenericDao
,AbstractMasterDataDao
public interface GenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>> extends FeatureForceIncrementModificationCounter<E>
This is the interface for a Data Access Object (DAO). It acts as a manager responsible for the persistence operations on a specificentity
<E>.
This is base interface contains the CRUD operations:- Create: call
save(PersistenceEntity)
on a new entity. - Retrieve: use
find*
methods such asfindOne(Object)
. More specific queries will be added in dedicated DAO interfaces. - Update: done automatically by JPA vendor (hibernate) on commit or call
save(PersistenceEntity)
tomerge
an entity. - Delete: call
delete(PersistenceEntity)
ordelete(Object)
.
entity
MyEntity
you should create an interface interfaceMyEntityDao
that inherits from thisGenericDao
interface. Also you create an implementation of that interfaceMyEntityDaoImpl
that you derive fromAbstractGenericDao
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
delete(E entity)
Deletes a given entity.void
delete(ID id)
Deletes the entity with the given id.void
delete(Iterable<? extends E> entities)
Deletes the given entities.boolean
exists(ID id)
Returns whether an entity with the given id exists.E
find(ID id)
Retrieves an entity by its id.List<E>
findAll(Iterable<ID> ids)
Returns all instances of the type with the given IDs.E
findOne(ID id)
Retrieves an entity by its id.E
get(com.devonfw.module.basic.common.api.reference.Ref<ID,E> reference)
E
save(E entity)
Saves a given entity.void
save(Iterable<? extends E> entities)
Saves all given entities.-
Methods inherited from interface com.devonfw.module.jpa.dataaccess.api.feature.FeatureForceIncrementModificationCounter
forceIncrementModificationCounter
-
-
-
-
Method Detail
-
save
E save(E entity)
Saves a given entity. Use the returned instance for further operations as the save operation might have changed the entity instance completely.- Parameters:
entity
- theentity
to save- Returns:
- the saved entity
-
save
void save(Iterable<? extends E> entities)
Saves all given entities.- Parameters:
entities
- theentities
to save
-
find
E find(ID id)
Retrieves an entity by its id.- Parameters:
id
- must not be null.- Returns:
- the entity with the given id or null if none found
- Throws:
RuntimeException
- if the requested entity does not exists (usefindOne(Object)
to prevent).
-
findOne
E findOne(ID id) throws IllegalArgumentException
Retrieves an entity by its id.- Parameters:
id
- must not be null.- Returns:
- the entity with the given id or null if none found
- Throws:
IllegalArgumentException
- ifid
isnull
-
get
E get(com.devonfw.module.basic.common.api.reference.Ref<ID,E> reference)
- Parameters:
reference
- theRef
to thePersistenceEntity
to get. Typically an instance ofIdRef
.- Returns:
- the
PersistenceEntity
asreference
for the givenRef
. Will benull
if the givenRef
wasnull
.
-
exists
boolean exists(ID id)
Returns whether an entity with the given id exists.- Parameters:
id
- must not be null.- Returns:
- true if an entity with the given id exists, false otherwise
-
delete
void delete(ID id) throws IllegalArgumentException
Deletes the entity with the given id.- Parameters:
id
- must not be null.- Throws:
IllegalArgumentException
- in case the givenid
isnull
-
delete
void delete(E entity)
Deletes a given entity.- Parameters:
entity
- theentity
to delete
-
-