Class GenericHibernateDao<E extends PersistentObject,​ID extends Serializable>

    • Field Detail

      • logger

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

      • GenericHibernateDao

        public GenericHibernateDao()
        Default constructor
      • GenericHibernateDao

        protected GenericHibernateDao​(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 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.
        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 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.

        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 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 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 List<E> findByCriteriaRestricted​(List<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​(Integer firstResult,
                                                                  Integer maxResults,
                                                                  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 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 Class<E> getEntityClass()
        Returns:
        the entityClass