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 theGenericDao
interface.
-
-
Field Summary
-
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 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()
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.void
forceIncrementModificationCounter(E entity)
E
get(com.devonfw.module.basic.common.api.reference.Ref<ID,E> reference)
protected abstract Class<E>
getEntityClass()
protected javax.persistence.EntityManager
getEntityManager()
protected String
getEntityName()
protected boolean
isNew(E entity)
Determines if the givenPersistenceEntity
is new.E
save(E entity)
Saves a given entity.void
save(Iterable<? extends E> entities)
Saves all given entities.void
setEntityManager(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
Class
reflecting the managed entity.
-
getEntityManager
protected javax.persistence.EntityManager getEntityManager()
- Returns:
- the
EntityManager
instance.
-
setEntityManager
public void setEntityManager(javax.persistence.EntityManager entityManager)
- Parameters:
entityManager
- theEntityManager
to inject.
-
getEntityName
protected String getEntityName()
- Returns:
- the name of the managed entity.
-
save
public E save(E entity)
Description copied from interface:GenericDao
Saves a given entity. Use the returned instance for further operations as the save operation might have changed the entity instance completely.- Specified by:
save
in interfaceGenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
- Parameters:
entity
- theentity
to save- Returns:
- the saved entity
-
isNew
protected boolean isNew(E entity)
Determines if the givenPersistenceEntity
is new.- Parameters:
entity
- is thePersistenceEntity
to check.- Returns:
true
if new,false
otherwise (e.g. managed or detached).
-
save
public void save(Iterable<? extends E> entities)
Description copied from interface:GenericDao
Saves all given entities.- Specified by:
save
in interfaceGenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
- Parameters:
entities
- theentities
to save
-
forceIncrementModificationCounter
public void forceIncrementModificationCounter(E entity)
- Specified by:
forceIncrementModificationCounter
in interfaceFeatureForceIncrementModificationCounter<ID>
-
findOne
public E findOne(ID id)
Description copied from interface:GenericDao
Retrieves an entity by its id.- Specified by:
findOne
in 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:GenericDao
Retrieves an entity by its id.- Specified by:
find
in 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:
get
in interfaceGenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
- 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
public boolean exists(ID id)
Description copied from interface:GenericDao
Returns whether an entity with the given id exists.- Specified by:
exists
in 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
Iterable
to find ALLmanaged entities
from 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:GenericDao
Returns 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:GenericDao
Deletes the entity with the given id.- Specified by:
delete
in 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:GenericDao
Deletes a given entity.- Specified by:
delete
in interfaceGenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
- Parameters:
entity
- theentity
to delete
-
delete
public void delete(Iterable<? extends E> entities)
Description copied from interface:GenericDao
Deletes the given entities.- Specified by:
delete
in interfaceGenericDao<ID,E extends com.devonfw.module.basic.common.api.entity.PersistenceEntity<ID>>
- Parameters:
entities
- theentities
to delete
-
-