Class HibernateDao<T>

java.lang.Object
com.atlassian.crowd.util.persistence.hibernate.StatelessDao
com.atlassian.crowd.util.persistence.hibernate.HibernateDao<T>
Direct Known Subclasses:
AliasDAOHibernate, AppIssuesWithMailsScanResultDAOHibernate, ApplicationDAOHibernate, ApplicationDefaultGroupMembershipConfigurationDaoHibernate, ApplicationSamlConfigurationDAOHibernate, AuditDAOHibernate, ClusterHeartbeatDAOHibernate, ClusterInfoDAOHibernate, ClusterLockDAOHibernate, CrowdRememberMeTokenDAOHibernate, DirectoryDAOHibernate, DirectoryInfoDaoHibernate, DirectorySynchronisationStatusDAOHibernate, DirectorySynchronisationTokenDaoHibernate, ExpirableUserTokenDaoHibernate, GroupAdministrationGrantGroupDaoHibernate, InternalDirectoryEntityHibernateDao, LicensedUserDaoHibernate, LicensingSummaryDaoHibernate, MembershipDAOHibernate, PropertyDAOHibernate, SAMLTrustDAOHibernate, TokenDAOHibernate, TombstoneDAOHibernate, UserAdministrationGrantGroupDaoHibernate, UserPermissionDAOHibernate, WebhookDAOHibernate

public abstract class HibernateDao<T> extends StatelessDao
Generic persistence class for storing Hibernate persistence objects.
  • Field Details

  • Constructor Details

    • HibernateDao

      public HibernateDao()
  • Method Details

    • getPersistentClass

      public abstract Class<T> getPersistentClass()
      All subclasses of HibernateDao must implement this method for load(Serializable) to work correctly.
      Returns:
      the entity class for this DAO
    • load

      public T load(Serializable id) throws ObjectNotFoundException
      Loads a persisted entity from the persistence store.
      Parameters:
      id - The unique identifier of the object to load from the persistence store.
      Returns:
      The populated object from the database.
      Throws:
      ObjectNotFoundException - when the requested entity is not found.
    • load

      protected <V extends Serializable, E extends Exception> T load(V id, Function<V,E> exceptionMapper) throws E
      Loads a persisted entity from the persistence store.
      Parameters:
      id - The unique identifier of the object to load from the persistence store.
      Returns:
      The populated object from the database.
      Throws:
      E - when entity not found
    • loadOptional

      protected Optional<T> loadOptional(Serializable id)
      Parameters:
      id - The unique identifier of the object to load from the persistence store.
      Returns:
      An Optional containing the populated object from the database or an empty optional
    • findByProperties

      protected org.hibernate.query.Query<T> findByProperties(Map<String,Object> properties)
      Parameters:
      properties - entity properties to be matched
      Returns:
      he Query object for matching properties.
    • getCountByProperties

      protected long getCountByProperties(Map<String,Object> properties)
    • findByProperty

      protected org.hibernate.query.Query<T> findByProperty(String name, Object value)
      Parameters:
      name - property name to match
      value - property value to match
      Returns:
      he Query object for matching properties.
    • findByPropertiesOptional

      protected Optional<T> findByPropertiesOptional(Map<String,Object> properties)
      Parameters:
      properties - entity properties to be matched
      Returns:
      optional result matching properties.
    • findByPropertyOrThrow

      protected T findByPropertyOrThrow(String name, Object value) throws ObjectNotFoundException
      Parameters:
      name - property name to match
      value - property value to match
      Returns:
      matching entity
      Throws:
      ObjectNotFoundException - when the requested entity is not found.
    • findByPropertyOptional

      protected Optional<T> findByPropertyOptional(String name, Object value)
      Parameters:
      name - property name to match
      value - property value to match
      Returns:
      optional matching entity
    • findByProperty

      protected <V, E extends Exception> T findByProperty(String name, V value, Function<V,E> exceptionMapper) throws E
      Parameters:
      name - property name to match
      value - property value to match
      exceptionMapper - will be used to throw exception when entity not found
      Returns:
      matching entity
      Throws:
      E - when entity not found
    • createQuery

      protected <T> org.hibernate.query.Query<T> createQuery(Class persistentClass, Map<String,Object> properties, List<io.atlassian.fugue.Pair<String,Boolean>> orderByProperties)
      Returns the query with matching properties.
      Parameters:
      persistentClass - persistence class
      properties - entity properties to be matched
      Returns:
      matched entity or Optional.empty()
      Throws:
      org.hibernate.NonUniqueResultException - if more than one result was found
    • createQuery

      protected <T> org.hibernate.query.Query<T> createQuery(Map<String,Object> properties)
    • createDeleteQuery

      protected <T> org.hibernate.query.Query<T> createDeleteQuery(Class persistentClass, Map<String,Object> properties)
    • createDeleteQuery

      protected <T> org.hibernate.query.Query<T> createDeleteQuery(Map<String,Object> properties)
    • toPredicates

      protected <T> javax.persistence.criteria.Predicate[] toPredicates(Map<String,Object> properties, javax.persistence.criteria.CriteriaBuilder builder, javax.persistence.criteria.Root<T> root)
      Prepares a collection of predicates matching each of the properties with it's corresponding value
      Type Parameters:
      T - model class
      Parameters:
      properties - map of property with value to be matched
      builder - criteria builder
      root - root
      Returns:
      an array of predicates
    • loadReference

      public <U> U loadReference(Class<U> persistentClass, long id)
      This method calls the session.load method to obtain a proxy (or actual instance if the object is in session) by NOT hitting the database immediately.

      Do NOT call this method unless you are SURE that the object with the supplied identifier exists.

      Parameters:
      persistentClass - the type of the entity to load
      id - unique identifier to load.
      Returns:
      a proxy object (or actual instance if the object is in session)
    • loadReference

      public T loadReference(long id)
      This method calls the session.load method to obtain a proxy (or actual instance if the object is in session) by NOT hitting the database immediately.

      Do NOT call this method unless you are SURE that the object with the supplied identifier exists.

      Parameters:
      id - unique identifier to load.
      Returns:
      a proxy object (or actual instance if the object is in session)
    • remove

      public void remove(Object persistentObject) throws org.springframework.dao.DataAccessException
      Removes the DAO object from the persistence store.
      Parameters:
      persistentObject - The object to remove.
      Throws:
      org.springframework.dao.DataAccessException - A persistence exception has occurred.
    • removeByIdIfPresent

      public void removeByIdIfPresent(Serializable id)
      Removes the DAO object with matching id from the persistence store, if present.
      Parameters:
      id - id of the object to be removed
    • save

      public void save(Object persistentObject) throws org.springframework.dao.DataAccessException
      Saves a new DAO object to the persistence store.
      Parameters:
      persistentObject - The object to save.
      Throws:
      org.springframework.dao.DataAccessException - A persistence exception has occurred.
    • saveOrUpdate

      public void saveOrUpdate(Object persistentObject) throws org.springframework.dao.DataAccessException
      Saves or updates DAO object to the persistence store.
      Parameters:
      persistentObject - The object to save or update.
      Throws:
      org.springframework.dao.DataAccessException - A persistence exception has occurred.
    • setBatchFinder

      @Autowired public void setBatchFinder(BatchFinder batchFinder)
    • setBatchProcessor

      @Autowired public void setBatchProcessor(SessionBatchProcessor batchProcessor)
    • setStatelessSessionBatchProcessor

      @Autowired public void setStatelessSessionBatchProcessor(StatelessSessionBatchProcessor statelessSessionBatchProcessor)
    • update

      public void update(Object persistentObject) throws org.springframework.dao.DataAccessException
      Updates an existing DAO object, if the object does not exist it will be added to the persistence store.
      Parameters:
      persistentObject - The object to update.
      Throws:
      org.springframework.dao.DataAccessException - A persistence exception has occurred.
    • session

      protected org.hibernate.Session session()
    • executeHQLQuery

      protected <R> List<R> executeHQLQuery(HQLQuery hqlQuery)
      Creates a Hibernate Query equivalent to the provided Crowd Query and HQLQuery and executes it.
      Returns:
      a results of the query
    • setClock

      public void setClock(Clock timeSource)
    • findAllInternal

      protected List<T> findAllInternal()