Class AbstractHibernateDAO<K extends java.io.Serializable,​T extends GeneralDTO<K>,​B extends AbstractHibernateBO<K,​T>,​C extends IGeneralBO<K>>

java.lang.Object
rs.data.impl.dao.AbstractBasicDAO<K,​C>
rs.data.impl.dao.AbstractGeneralDAO<K,​B,​C>
rs.data.impl.dao.AbstractDAO<K,​T,​B,​C>
rs.data.hibernate.dao.AbstractHibernateDAO<K,​T,​B,​C>
Type Parameters:
K - type of Key
T - type of Transfer Object
B - type of Business Object Implementation
C - type of Business Object Interface
All Implemented Interfaces:
IConfigurable, IGeneralDAO<K,​C>
Direct Known Subclasses:
AbstractHibernateLongDAO, AbstractHibernateStringDAO

public abstract class AbstractHibernateDAO<K extends java.io.Serializable,​T extends GeneralDTO<K>,​B extends AbstractHibernateBO<K,​T>,​C extends IGeneralBO<K>>
extends AbstractDAO<K,​T,​B,​C>
Implements the Hibernate specific functions.
Author:
ralph
  • Constructor Details

  • Method Details

    • _findBy

      protected T _findBy​(K id)
      Specified by:
      _findBy in class AbstractDAO<K extends java.io.Serializable,​T extends GeneralDTO<K>,​B extends AbstractHibernateBO<K,​T>,​C extends IGeneralBO<K>>
    • refresh

      public void refresh​(C object)
    • findById

      public java.util.List<T> findById​(java.util.Collection<K> ids)
      Find objects by IDs.
      Parameters:
      ids - collection of IDs
      Returns:
      list of objects with specified IDd
    • getObjectCount

      public int getObjectCount()
      Returns the number of domain objects.
      Returns:
      number of objects.
    • getDefaultObjectCount

      public int getDefaultObjectCount()
      Returns the number of objects with default criteria matched. This method shall be used if you want to count only non-deleted objects.
      Returns:
      number of objects
    • _findAll

      protected java.util.List<T> _findAll​(int firstResult, int maxResults, java.lang.String sortBy)
      Specified by:
      _findAll in class AbstractDAO<K extends java.io.Serializable,​T extends GeneralDTO<K>,​B extends AbstractHibernateBO<K,​T>,​C extends IGeneralBO<K>>
    • _findDefaultAll

      protected java.util.List<T> _findDefaultAll​(int firstResult, int maxResults, java.lang.String sortBy)
      Specified by:
      _findDefaultAll in class AbstractDAO<K extends java.io.Serializable,​T extends GeneralDTO<K>,​B extends AbstractHibernateBO<K,​T>,​C extends IGeneralBO<K>>
    • _iterateAll

      protected java.util.Iterator<T> _iterateAll​(int firstResult, int maxResults, java.lang.String sortBy)
      Specified by:
      _iterateAll in class AbstractDAO<K extends java.io.Serializable,​T extends GeneralDTO<K>,​B extends AbstractHibernateBO<K,​T>,​C extends IGeneralBO<K>>
    • _iterateDefaultAll

      protected java.util.Iterator<T> _iterateDefaultAll​(int firstResult, int maxResults, java.lang.String sortBy)
      Specified by:
      _iterateDefaultAll in class AbstractDAO<K extends java.io.Serializable,​T extends GeneralDTO<K>,​B extends AbstractHibernateBO<K,​T>,​C extends IGeneralBO<K>>
    • _create

      protected void _create​(T object)
      Specified by:
      _create in class AbstractDAO<K extends java.io.Serializable,​T extends GeneralDTO<K>,​B extends AbstractHibernateBO<K,​T>,​C extends IGeneralBO<K>>
    • _save

      protected void _save​(T object)
      Specified by:
      _save in class AbstractDAO<K extends java.io.Serializable,​T extends GeneralDTO<K>,​B extends AbstractHibernateBO<K,​T>,​C extends IGeneralBO<K>>
    • _delete

      protected void _delete​(T object)
      Specified by:
      _delete in class AbstractDAO<K extends java.io.Serializable,​T extends GeneralDTO<K>,​B extends AbstractHibernateBO<K,​T>,​C extends IGeneralBO<K>>
    • _deleteDefaultAll

      protected int _deleteDefaultAll()
      Deletes all objects that match default criteria.
      Specified by:
      _deleteDefaultAll in class AbstractDAO<K extends java.io.Serializable,​T extends GeneralDTO<K>,​B extends AbstractHibernateBO<K,​T>,​C extends IGeneralBO<K>>
      Returns:
      number of object deleted
    • _deleteAll

      protected int _deleteAll()
      Deletes all objects.
      Specified by:
      _deleteAll in class AbstractDAO<K extends java.io.Serializable,​T extends GeneralDTO<K>,​B extends AbstractHibernateBO<K,​T>,​C extends IGeneralBO<K>>
      Returns:
      number of object deleted
    • getSession

      public org.hibernate.Session getSession()
      Returns the Hibernate session. This method will start a new transaction if required.
      Returns:
      hibernate session.
    • getDefaultCriteria

      protected org.hibernate.Criteria getDefaultCriteria()
      Returns a default Hibernate criteria for search. This can be used to simplify queries when tables may contain soft-deleted objects. This abstract implementation return null.
      Returns:
      a default criteria to be used
    • getDefaultCriterions

      protected org.hibernate.criterion.Criterion[] getDefaultCriterions()
      Returns the default criterions.
      Returns:
      the default criterions for a query
    • _findSingleByCriteria

      protected T _findSingleByCriteria​(org.hibernate.Criteria criteria)
      Finds a single object defined by the Hibernate criteria. Note that the criteria might match many objects. Only the first result will be returned.
      Parameters:
      criteria - criteria for search
      Returns:
      first object matching the criteria
    • findSingleByCriteria

      protected C findSingleByCriteria​(org.hibernate.Criteria criteria)
      Finds a single object defined by the Hibernate criteria. Note that the criteria might match many objects. Only the first result will be returned.
      Parameters:
      criteria - criteria for search
      Returns:
      first object matching the criteria
    • buildCriteria

      protected org.hibernate.Criteria buildCriteria​(org.hibernate.criterion.Criterion... criterion)
      Builds an Hibernate criteria with unlimited result count.
      Parameters:
      criterion - list of criterions to be added.
      Returns:
      the Hibernate criteria
    • buildCriteria

      protected org.hibernate.Criteria buildCriteria​(int firstResult, int maxResults, org.hibernate.criterion.Criterion... criterion)
      Builds an Hibernate criteria with unlimited result count.
      Parameters:
      firstResult - index of first result returned
      maxResults - maximum number of results returned
      criterion - list of criterions to be added.
      Returns:
      the Hibernate criteria
    • buildCustomCriteria

      protected org.hibernate.Criteria buildCustomCriteria​(java.lang.Class<?> forClass, int firstResult, int maxResults, org.hibernate.criterion.Criterion... criterion)
      Builds an Hibernate criteria with unlimited result count.
      Parameters:
      forClass - - the class to create the criteria for
      firstResult - index of first result returned
      maxResults - maximum number of results returned
      criterion - list of criterions to be added.
      Returns:
      the Hibernate criteria
    • filterResult

      protected org.hibernate.Criteria filterResult​(org.hibernate.Criteria crit, int firstResult, int maxResults)
      Applies the result count limitation to the Hibernate criteria.
      Parameters:
      crit - criteria to be limited
      firstResult - index of first result returned
      maxResults - maximum number of results returned
      Returns:
      limited criteria.
    • getLastTotal

      public int getLastTotal()
      Returns the number of records of the last retrieval without pagination.
      Returns:
      number of rows in last query
      Since:
      1.3.2
    • getTotal

      protected int getTotal​(org.hibernate.Criteria crit)
      Get the total number of records in this criteria.
      Parameters:
      crit - - criteria (before applying pagination)
      Returns:
      number of records
    • _findByCriteria

      protected java.util.List<T> _findByCriteria​(org.hibernate.Criteria crit)
      Finds all DTOs matching the Hibernate criteria.
      Parameters:
      crit - Hibernate criteria
      Returns:
      the list of objects matching the criteria
    • findByCriteria

      protected java.util.List<C> findByCriteria​(org.hibernate.Criteria crit)
      Finds all BOs matching the Hibernate criteria.
      Parameters:
      crit - Hibernate criteria
      Returns:
      the list of objects matching the criteria
    • executeCriteria

      protected java.util.List<?> executeCriteria​(org.hibernate.Criteria crit)
      Execute an unspecific Hibernate criteria. If the criteria returns T then findByCriteria(org.hibernate.Criteria) must be used.
      Parameters:
      crit - Hibernate criteria
      Returns:
      the list of objects matching the criteria
    • _iterateByCriteria

      protected IDaoIterator<T> _iterateByCriteria​(org.hibernate.criterion.Criterion[] criterions)
      Creates an iterator object for the Hibernate criteria. Use this inside subclasses as a convenience method.
      Parameters:
      criterions - Hibernate criterions
      Returns:
      iterator object for the criteria
    • _iterateByCriteria

      protected IDaoIterator<T> _iterateByCriteria​(org.hibernate.criterion.Criterion[] criterions, org.hibernate.criterion.Order[] orders)
      Creates an iterator object for the Hibernate criteria. Use this inside subclasses as a convenience method.
      Parameters:
      criterions - Hibernate criterions
      orders - Hibernate orders
      Returns:
      iterator object for the criteria
    • _iterateByCriteria

      protected IDaoIterator<T> _iterateByCriteria​(org.hibernate.criterion.Criterion[] criterions, org.hibernate.criterion.Order[] orders, int firstResult, int maxResults)
      Creates an iterator object for the Hibernate criteria. Use this inside subclasses as a convenience method.
      Parameters:
      criterions - Hibernate criterions
      orders - Hibernate orders
      firstResult - index of first result to return
      maxResults - maximum number of results to return
      Returns:
      iterator object for the criteria
    • iterateBy

      protected IDaoIterator<C> iterateBy​(org.hibernate.criterion.Criterion[] criterions, org.hibernate.criterion.Order[] orders, int firstResult, int maxResults)
      Creates an iterator object for the Hibernate criteria. Use this inside subclasses as a convenience method.
      Parameters:
      criterions - Hibernate criterions
      orders - Hibernate orders
      firstResult - index of first result to return
      maxResults - maximum number of results to return
      Returns:
      iterator object for the criteria
    • getRowCount

      protected int getRowCount​(org.hibernate.Criteria crit)
      Counts the number of objects returned by this Hibernate criteria. Use this inside subclasses as a convenience method.
      Parameters:
      crit - Hibernate criteria
      Returns:
      number of objects returned by the criteria
    • deleteByCriteria

      protected int deleteByCriteria​(org.hibernate.criterion.Criterion[] criterions)
      Deletes all objects matching this criteria.
      Parameters:
      criterions - criterions for deletion
      Returns:
      number of objects deleted
    • getObjectCount

      protected int getObjectCount​(org.hibernate.Criteria criteria)
      Returns the result count for this criteria. The Criteria object will be changed and cannot be used as a result-returning query anymore.
      Parameters:
      criteria - Criteria for object (row) count
      Returns:
      the row count.