Class GenericHibernateDao<E extends PersistentObject,​ID extends java.io.Serializable>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.apache.logging.log4j.Logger LOG
      The LOGGER instance (that will be available in all subclasses)
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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
      java.util.List<E> findAll()
      Returns all Entities by calling findByCriteria(), i.e.
      java.util.Map<PersistentObject,​PermissionCollection> findAllUserGroupPermissionsOfUserGroup​(UserGroup userGroup)
      This method returns a Map that maps PersistentObjects to PermissionCollections for the passed UserGroup.
      java.util.Map<PersistentObject,​PermissionCollection> findAllUserPermissionsOfUser​(User user)
      This method returns a Map that maps PersistentObjects to PermissionCollections for the passed User.
      java.util.List<E> findAllWhereFieldEquals​(java.lang.String fieldName, java.lang.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.
      java.util.List<E> findAllWithCollectionContaining​(java.lang.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.
      java.util.List<E> findByCriteria​(org.hibernate.criterion.Criterion... criterion)
      Gets the results, that match a variable number of passed criterions.
      java.util.List<E> findByCriteriaRestricted​(java.util.List<java.lang.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​(java.lang.Integer firstResult, java.lang.Integer maxResults, java.util.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.
      java.lang.Class<E> getEntityClass()  
      java.lang.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).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        protected final org.apache.logging.log4j.Logger LOG
        The LOGGER instance (that will be available in all subclasses)
    • Constructor Detail

      • GenericHibernateDao

        public GenericHibernateDao()
        Default constructor
      • GenericHibernateDao

        protected GenericHibernateDao​(java.lang.Class<E> clazz)
        Constructor
        Parameters:
        clazz -
    • Method Detail

      • findById

        public E findById​(ID id)
        Return the real object from the database. Returns null if the object does not exist.
        Parameters:
        id -
        Returns:
        The object from the database or null if it does not exist
      • findAllWhereFieldEquals

        public java.util.List<E> findAllWhereFieldEquals​(java.lang.String fieldName,
                                                         java.lang.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.
        Parameters:
        fieldName - The name of the field
        fieldEntity - The element that should be set as value
        criterion - Additional criterions to apply (optional)
        Returns:
        The list of objects
      • findAllWithCollectionContaining

        public java.util.List<E> findAllWithCollectionContaining​(java.lang.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.

        The can e.g. be used to return all applications that contain a certain layer.

        Parameters:
        fieldName - The name of the collection field
        subElement - The element that should be contained in the collection
        criterion - Additional criterions to apply (optional)
        Returns:
        The list of objects
      • loadById

        public E loadById​(ID id)
        Return a proxy of the object (without hitting the database). This should only be used if it is assumed that the object really exists and where non-existence would be an actual error.
        Parameters:
        id -
        Returns:
      • findAll

        public java.util.List<E> findAll()
                                  throws org.hibernate.HibernateException
        Returns all Entities by calling findByCriteria(), i.e. without arguments.
        Returns:
        All entities
        Throws:
        org.hibernate.HibernateException
        See Also:
        findByCriteria(Criterion...)
      • saveOrUpdate

        public void saveOrUpdate​(E e)
        Saves or updates the passed entity.
        Parameters:
        e - The entity to save or update in the database.
      • delete

        public void delete​(E e)
        Deletes the passed entity.
        Parameters:
        e - The entity to remove from the database.
      • unproxy

        public E unproxy​(E e)
        Unproxy the entity (and eagerly fetch properties).
      • evict

        public void evict​(E e)
        Detach an entity from the hibernate session
        Parameters:
        e -
      • findByCriteria

        public java.util.List<E> findByCriteria​(org.hibernate.criterion.Criterion... criterion)
                                         throws org.hibernate.HibernateException
        Gets the results, that match a variable number of passed criterions. Call this method without arguments to find all entities.
        Parameters:
        criterion - A variable number of hibernate criterions
        Returns:
        Entities matching the passed hibernate criterions
        Throws:
        org.hibernate.HibernateException
      • findByCriteriaRestricted

        public java.util.List<E> findByCriteriaRestricted​(java.util.List<java.lang.String> restrictFieldNames,
                                                          org.hibernate.criterion.Criterion... criterion)
                                                   throws org.hibernate.HibernateException
        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.

        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().

        Parameters:
        restrictFieldNames -
        criterion -
        Returns:
        Throws:
        org.hibernate.HibernateException
      • findByUniqueCriteria

        public E findByUniqueCriteria​(org.hibernate.criterion.Criterion... criterion)
                               throws org.hibernate.HibernateException
        Gets the unique result, that matches a variable number of passed criterions.
        Parameters:
        criterion - A variable number of hibernate criterions
        Returns:
        Entity matching the passed hibernate criterions
        Throws:
        org.hibernate.HibernateException - if there is more than one matching result
      • findByCriteriaWithSortingAndPaging

        public PagingResult<E> findByCriteriaWithSortingAndPaging​(java.lang.Integer firstResult,
                                                                  java.lang.Integer maxResults,
                                                                  java.util.List<org.hibernate.criterion.Order> sorters,
                                                                  org.hibernate.criterion.Criterion... criterion)
                                                           throws org.hibernate.HibernateException
        Gets the results, that match a variable number of passed criterions, considering the paging- and sort-info at the same time.
        Parameters:
        firstResult - Starting index for the paging request.
        maxResults - Max number of result size.
        criterion - A variable number of hibernate criterions
        Returns:
        Throws:
        org.hibernate.HibernateException
      • createDistinctRootEntityCriteria

        protected org.hibernate.Criteria createDistinctRootEntityCriteria​(org.hibernate.criterion.Criterion... criterion)
        Helper method: Creates a criteria for the entityClass of this dao. The query results will be handled with a DistinctRootEntityResultTransformer. The criteria will contain all passed criterions.
        Returns:
      • getTotalCount

        public java.lang.Number getTotalCount​(org.hibernate.criterion.Criterion... criterion)
                                       throws org.hibernate.HibernateException
        Returns the total count of db entries for the current type.
        Parameters:
        criterion -
        Returns:
        Throws:
        org.hibernate.HibernateException
      • getEntityClass

        public java.lang.Class<E> getEntityClass()
        Returns:
        the entityClass