public class GenericJpaDao extends Object implements GenericDao
GenericDao that uses a JPA EntityManager.| Constructor and Description |
|---|
GenericJpaDao() |
| Modifier and Type | Method and Description |
|---|---|
<E extends Entity<K>,K> |
delete(E entity,
Class<E> clazz)
Deletes the given entity of the given class.
|
<E extends Entity<K>,K> |
delete(K id,
Class<E> clazz)
Deletes the entity with the given id of the given class.
|
protected <V> List<V> |
find(javax.persistence.criteria.CriteriaQuery<V> criteriaQuery)
Find all entities by the given
CriteriaQuery. |
protected <V> List<V> |
find(javax.persistence.criteria.CriteriaQuery<V> criteriaQuery,
int maxResults)
Finds all entities by the given
CriteriaQuery and limit the result set. |
protected <V> List<V> |
find(javax.persistence.criteria.CriteriaQuery<V> criteriaQuery,
int firstResult,
int maxResults)
Finds all entities by the given
CriteriaQuery and limit the result set. |
<E extends Entity<K>,K> |
find(K id,
Class<E> clazz)
Finds the entity with the given id of the given class.
|
<E extends Entity<K>,K> |
findAll(Class<E> clazz)
Finds all entities of the given class.
|
protected <V> V |
findFirstOrNull(javax.persistence.criteria.CriteriaQuery<V> criteriaQuery)
Finds the first entity by the given
CriteriaQuery or null if no result was found. |
protected <V> V |
findSingle(javax.persistence.criteria.CriteriaQuery<V> criteriaQuery)
Find a single entity by the given
CriteriaQuery, throws an Exception if there is no or more than one
result. |
protected <V> V |
findSingleOrNull(javax.persistence.criteria.CriteriaQuery<V> criteriaQuery)
Finds a single entity by the given
CriteriaQuery, throws an Exception if there is more than one result. |
<E extends Entity<K>,K> |
getCount(Class<E> clazz)
Counts the entities of the given class.
|
protected javax.persistence.criteria.CriteriaBuilder |
getCriteriaBuilder()
Gets the criteria builder of the entity manager.
|
javax.persistence.EntityManager |
getEntityManager() |
org.slf4j.Logger |
getLogger() |
<E extends Entity<K>,K> |
load(K id,
Class<E> clazz)
Loads the entity with the given id of the given class or throws an Exception if it was not found.
|
<E extends Entity<K>,K> |
save(E entity)
Saves the given entity.
|
void |
setEntityManager(javax.persistence.EntityManager entityManager) |
void |
setLogger(org.slf4j.Logger logger) |
public void setEntityManager(javax.persistence.EntityManager entityManager)
public javax.persistence.EntityManager getEntityManager()
public org.slf4j.Logger getLogger()
public void setLogger(org.slf4j.Logger logger)
@Transactional(propagation=MANDATORY) public <E extends Entity<K>,K> void delete(E entity, Class<E> clazz)
GenericDaodelete in interface GenericDao@Transactional(propagation=MANDATORY) public <E extends Entity<K>,K> void delete(K id, Class<E> clazz)
GenericDaodelete in interface GenericDao@Transactional(propagation=MANDATORY,
readOnly=true)
public <E extends Entity<K>,K> E find(K id,
Class<E> clazz)
GenericDaofind in interface GenericDao@Transactional(propagation=MANDATORY,
readOnly=true)
public <E extends Entity<K>,K> List<E> findAll(Class<E> clazz)
GenericDaofindAll in interface GenericDao@Transactional(propagation=MANDATORY,
readOnly=true)
public <E extends Entity<K>,K> E load(K id,
Class<E> clazz)
GenericDaoload in interface GenericDao@Transactional(propagation=MANDATORY) public <E extends Entity<K>,K> E save(E entity)
GenericDaosave in interface GenericDao@Transactional(propagation=MANDATORY,
readOnly=true)
public <E extends Entity<K>,K> long getCount(Class<E> clazz)
GenericDaogetCount in interface GenericDaoprotected javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
protected <V> List<V> find(javax.persistence.criteria.CriteriaQuery<V> criteriaQuery)
CriteriaQuery.protected <V> List<V> find(javax.persistence.criteria.CriteriaQuery<V> criteriaQuery, int maxResults)
CriteriaQuery and limit the result set.maxResults - The maximum number of results to retrieve.protected <V> List<V> find(javax.persistence.criteria.CriteriaQuery<V> criteriaQuery, int firstResult, int maxResults)
CriteriaQuery and limit the result set.firstResult - Position of the first result to retrive.maxResults - The maximum number of results to retrieve.protected <V> V findSingle(javax.persistence.criteria.CriteriaQuery<V> criteriaQuery)
CriteriaQuery, throws an Exception if there is no or more than one
result.protected <V> V findSingleOrNull(javax.persistence.criteria.CriteriaQuery<V> criteriaQuery)
CriteriaQuery, throws an Exception if there is more than one result.protected <V> V findFirstOrNull(javax.persistence.criteria.CriteriaQuery<V> criteriaQuery)
CriteriaQuery or null if no result was found.criteriaQuery - Query to execute.Copyright © 2014 dontdrinkandroot. All rights reserved.