@Repository(value="genericDao") public class GenericHibernateDao<E extends PersistentObject,ID extends Serializable> extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static org.apache.logging.log4j.Logger |
logger
The LOGGER instance (that will be available in all subclasses)
|
| Modifier | Constructor and Description |
|---|---|
|
GenericHibernateDao()
Default constructor
|
protected |
GenericHibernateDao(Class<E> clazz)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
protected org.hibernate.Criteria |
createDistinctRootEntityCriteria(org.hibernate.criterion.Criterion... criterion)
Helper method: Creates a criteria for the
entityClass of this dao. |
void |
delete(E e)
Deletes the passed entity.
|
void |
evict(E e)
Detach an entity from the hibernate session
|
List<E> |
findAll()
Returns all Entities by calling findByCriteria(), i.e. without arguments.
|
Map<PersistentObject,PermissionCollection> |
findAllUserGroupPermissionsOfUserGroup(UserGroup userGroup)
This method returns a
Map that maps PersistentObjects
to PermissionCollections for the passed UserGroup. |
Map<PersistentObject,PermissionCollection> |
findAllUserPermissionsOfUser(User user)
|
List<E> |
findAllWhereFieldEquals(String fieldName,
Object fieldEntity,
org.hibernate.criterion.Criterion... criterion)
Returns a list of entity objects that have field named
fieldName, which has an object fieldEntity
as value. |
List<E> |
findAllWithCollectionContaining(String fieldName,
PersistentObject subElement,
org.hibernate.criterion.Criterion... criterion)
Returns a list of entity objects that have a collection named
fieldName, which contains the passed
subElement. |
List<E> |
findByCriteria(org.hibernate.criterion.Criterion... criterion)
Gets the results, that match a variable number of passed criterions.
|
List<E> |
findByCriteriaRestricted(List<String> restrictFieldNames,
org.hibernate.criterion.Criterion... criterion)
Gets the results, that match a variable number of passed criterions, but return a
stripped version of the entities, where only the fieldNames in
restrictFieldNames
have their actual values set. |
PagingResult<E> |
findByCriteriaWithSortingAndPaging(Integer firstResult,
Integer maxResults,
List<org.hibernate.criterion.Order> sorters,
org.hibernate.criterion.Criterion... criterion)
Gets the results, that match a variable number of passed criterions,
considering the paging- and sort-info at the same time.
|
E |
findById(ID id)
Return the real object from the database.
|
E |
findByUniqueCriteria(org.hibernate.criterion.Criterion... criterion)
Gets the unique result, that matches a variable number of passed
criterions.
|
Class<E> |
getEntityClass() |
Number |
getTotalCount(org.hibernate.criterion.Criterion... criterion)
Returns the total count of db entries for the current type.
|
E |
loadById(ID id)
Return a proxy of the object (without hitting the database).
|
void |
saveOrUpdate(E e)
Saves or updates the passed entity.
|
E |
unproxy(E e)
Unproxy the entity (and eagerly fetch properties).
|
protected static final org.apache.logging.log4j.Logger logger
public E findById(ID id)
id - http://www.mkyong.com/hibernate/different-between-session-get-and-session-load/public List<E> findAllWhereFieldEquals(String fieldName, Object fieldEntity, org.hibernate.criterion.Criterion... criterion)
fieldName, which has an object fieldEntity
as value.fieldName - The name of the fieldfieldEntity - The element that should be set as valuecriterion - Additional criterions to apply (optional)public List<E> findAllWithCollectionContaining(String fieldName, PersistentObject subElement, org.hibernate.criterion.Criterion... criterion)
fieldName, which contains the passed
subElement.
The can e.g. be used to return all applications that contain a certain layer.
fieldName - The name of the collection fieldsubElement - The element that should be contained in the collectioncriterion - Additional criterions to apply (optional)public E loadById(ID id)
id - http://www.mkyong.com/hibernate/different-between-session-get-and-session-load/public List<E> findAll() throws org.hibernate.HibernateException
org.hibernate.HibernateExceptionfindByCriteria(Criterion...)public void saveOrUpdate(E e)
e - The entity to save or update in the database.public void delete(E e)
e - The entity to remove from the database.public void evict(E e)
e - public List<E> findByCriteria(org.hibernate.criterion.Criterion... criterion) throws org.hibernate.HibernateException
criterion - A variable number of hibernate criterionsorg.hibernate.HibernateExceptionpublic List<E> findByCriteriaRestricted(List<String> restrictFieldNames, org.hibernate.criterion.Criterion... criterion) throws org.hibernate.HibernateException
restrictFieldNames
have their actual values set.
You can call this with restrictFieldNames = null to get the full
entities back.
You can call this method without criterion arguments to find all entities (stripped down to
the restrictFieldNames).
If this is called as findByCriteriaRestricted(null) the return value equals the
return value of findByCriteria().
restrictFieldNames - criterion - org.hibernate.HibernateExceptionpublic E findByUniqueCriteria(org.hibernate.criterion.Criterion... criterion) throws org.hibernate.HibernateException
criterion - A variable number of hibernate criterionsorg.hibernate.HibernateException - if there is more than one matching resultpublic PagingResult<E> findByCriteriaWithSortingAndPaging(Integer firstResult, Integer maxResults, List<org.hibernate.criterion.Order> sorters, org.hibernate.criterion.Criterion... criterion) throws org.hibernate.HibernateException
firstResult - Starting index for the paging request.maxResults - Max number of result size.criterion - A variable number of hibernate criterionsorg.hibernate.HibernateExceptionpublic Map<PersistentObject,PermissionCollection> findAllUserPermissionsOfUser(User user)
Map that maps PersistentObjects
to PermissionCollections for the passed User. I.e. the keySet
of the map is the collection of all PersistentObjects where the
user has at least one permission and the corresponding value contains
the PermissionCollection for the passed user on the entity.user - public Map<PersistentObject,PermissionCollection> findAllUserGroupPermissionsOfUserGroup(UserGroup userGroup)
Map that maps PersistentObjects
to PermissionCollections for the passed UserGroup. I.e. the keySet
of the map is the collection of all PersistentObjects where the
user group has at least one permission and the corresponding value contains
the PermissionCollection for the passed user group on the entity.userGroup - protected org.hibernate.Criteria createDistinctRootEntityCriteria(org.hibernate.criterion.Criterion... criterion)
entityClass of this dao.
The query results will be handled with a
DistinctRootEntityResultTransformer. The criteria will contain
all passed criterions.public Number getTotalCount(org.hibernate.criterion.Criterion... criterion) throws org.hibernate.HibernateException
criterion - org.hibernate.HibernateExceptionCopyright © 2020 terrestris GmbH & Co. KG. All rights reserved.