Class AbstractGenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
- java.lang.Object
-
- com.devonfw.module.jpa.dataaccess.api.QueryHelper
-
- com.devonfw.module.jpa.dataaccess.base.AbstractGenericDao<ID,E>
-
- Type Parameters:
ID- is the generic type if theprimary key.E- is the generic type of the managedPersistenceEntity.
- All Implemented Interfaces:
FeatureForceIncrementModificationCounter<E>,GenericDao<ID,E>
- Direct Known Subclasses:
AbstractDao
public abstract class AbstractGenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>> extends QueryHelper implements GenericDao<ID,E>
This is the abstract base-implementation of theGenericDaointerface.
-
-
Field Summary
Fields Modifier and Type Field Description private javax.persistence.EntityManagerentityManagerprivate static org.slf4j.LoggerLOGLogger instance.-
Fields inherited from class com.devonfw.module.jpa.dataaccess.api.QueryHelper
QUERY_PROPERTY_TIMEOUT
-
-
Constructor Summary
Constructors Constructor Description AbstractGenericDao()The constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete 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()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.voidforceIncrementModificationCounter(E entity)Eget(com.devonfw.module.basic.common.api.reference.Ref<ID,E> reference)protected abstract Class<E>getEntityClass()protected javax.persistence.EntityManagergetEntityManager()protected StringgetEntityName()protected booleanisNew(E entity)Determines if the givenPersistenceEntityis new.Esave(E entity)Saves a given entity.voidsave(Iterable<? extends E> entities)Saves all given entities.voidsetEntityManager(javax.persistence.EntityManager entityManager)protected Collection<ID>toCollection(Iterable<ID> ids)-
Methods inherited from class com.devonfw.module.jpa.dataaccess.api.QueryHelper
applySort, applyTimeout, findPaginatedGeneric, newInClause, newLikeClause, newLikeClause, newNotLikeClause, newStringClause, newStringClause, whereIn, whereLike, whereNotLike, whereString
-
-
-
-
Method Detail
-
getEntityClass
protected abstract Class<E> getEntityClass()
- Returns:
- the
Classreflecting the managed entity.
-
getEntityManager
protected javax.persistence.EntityManager getEntityManager()
- Returns:
- the
EntityManagerinstance.
-
setEntityManager
public void setEntityManager(javax.persistence.EntityManager entityManager)
- Parameters:
entityManager- theEntityManagerto inject.
-
getEntityName
protected String getEntityName()
- Returns:
- the name of the managed entity.
-
save
public E save(E entity)
Description copied from interface:GenericDaoSaves a given entity. Use the returned instance for further operations as the save operation might have changed the entity instance completely.- Specified by:
savein interfaceGenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>- Parameters:
entity- theentityto save- Returns:
- the saved entity
-
isNew
protected boolean isNew(E entity)
Determines if the givenPersistenceEntityis new.- Parameters:
entity- is thePersistenceEntityto check.- Returns:
trueif new,falseotherwise (e.g. managed or detached).
-
save
public void save(Iterable<? extends E> entities)
Description copied from interface:GenericDaoSaves all given entities.- Specified by:
savein interfaceGenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>- Parameters:
entities- theentitiesto save
-
forceIncrementModificationCounter
public void forceIncrementModificationCounter(E entity)
- Specified by:
forceIncrementModificationCounterin interfaceFeatureForceIncrementModificationCounter<ID>
-
findOne
public E findOne(ID id)
Description copied from interface:GenericDaoRetrieves an entity by its id.- Specified by:
findOnein interfaceGenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>- Parameters:
id- must not be null.- Returns:
- the entity with the given id or null if none found
-
find
public E find(ID id)
Description copied from interface:GenericDaoRetrieves an entity by its id.- Specified by:
findin interfaceGenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>- Parameters:
id- must not be null.- Returns:
- the entity with the given id or null if none found
-
get
public E get(com.devonfw.module.basic.common.api.reference.Ref<ID,E> reference)
- Specified by:
getin interfaceGenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>- Parameters:
reference- theRefto thePersistenceEntityto get. Typically an instance ofIdRef.- Returns:
- the
PersistenceEntityasreferencefor the givenRef. Will benullif the givenRefwasnull.
-
exists
public boolean exists(ID id)
Description copied from interface:GenericDaoReturns whether an entity with the given id exists.- Specified by:
existsin interfaceGenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>- Parameters:
id- must not be null.- Returns:
- true if an entity with the given id exists, false otherwise
-
findAll
public List<E> findAll()
- Returns:
- an
Iterableto find ALLmanaged entitiesfrom the persistent store. Not exposed to API by default as this might not make sense for all kind of entities.
-
findAll
public List<E> findAll(Iterable<ID> ids)
Description copied from interface:GenericDaoReturns all instances of the type with the given IDs.
-
toCollection
protected Collection<ID> toCollection(Iterable<ID> ids)
- Parameters:
ids- sequence of id- Returns:
- a collection of these ids to use
Expression.in(Collection)for instance
-
delete
public void delete(ID id)
Description copied from interface:GenericDaoDeletes the entity with the given id.- Specified by:
deletein interfaceGenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>- Parameters:
id- must not be null.
-
delete
public void delete(E entity)
Description copied from interface:GenericDaoDeletes a given entity.- Specified by:
deletein interfaceGenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>- Parameters:
entity- theentityto delete
-
delete
public void delete(Iterable<? extends E> entities)
Description copied from interface:GenericDaoDeletes the given entities.- Specified by:
deletein interfaceGenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>- Parameters:
entities- theentitiesto delete
-
-