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)tomergean entity. - Delete: call
delete(PersistenceEntity)ordelete(Object).
entityMyEntityyou should create an interface interfaceMyEntityDaothat inherits from thisGenericDaointerface. Also you create an implementation of that interfaceMyEntityDaoImplthat you derive fromAbstractGenericDao.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voiddelete(E entity)Deletes a given entity.voiddelete(ID id)Deletes the entity with the given id.voiddelete(Iterable<? extends E> entities)Deletes the given entities.booleanexists(ID id)Returns whether an entity with the given id exists.Efind(ID id)Retrieves an entity by its id.List<E>findAll(Iterable<ID> ids)Returns all instances of the type with the given IDs.EfindOne(ID id)Retrieves an entity by its id.Eget(com.devonfw.module.basic.common.api.reference.Ref<ID,E> reference)Esave(E entity)Saves a given entity.voidsave(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- theentityto save- Returns:
- the saved entity
-
save
void save(Iterable<? extends E> entities)
Saves all given entities.- Parameters:
entities- theentitiesto 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- ifidisnull
-
get
E get(com.devonfw.module.basic.common.api.reference.Ref<ID,E> reference)
- Parameters:
reference- theRefto thePersistenceEntityto get. Typically an instance ofIdRef.- Returns:
- the
PersistenceEntityasreferencefor the givenRef. Will benullif the givenRefwasnull.
-
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 givenidisnull
-
delete
void delete(E entity)
Deletes a given entity.- Parameters:
entity- theentityto delete
-
-