Class HibernateObjectDao<T extends com.atlassian.core.bean.EntityObject>

    • Constructor Detail

      • HibernateObjectDao

        public HibernateObjectDao()
    • Method Detail

      • getSessionFactory

        public final org.hibernate.SessionFactory getSessionFactory()
      • setSessionFactory

        public final void setSessionFactory​(org.hibernate.SessionFactory sessionFactory)
      • getHibernateTemplate

        @Deprecated(forRemoval=true)
        public final org.springframework.orm.hibernate5.HibernateTemplate getHibernateTemplate()
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 8.6 Use getSessionFactory() and SessionFactory.getCurrentSession()
      • setHibernateTemplate

        @Deprecated(forRemoval=true)
        public final void setHibernateTemplate​(org.springframework.orm.hibernate5.HibernateTemplate hibernateTemplate)
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 8.6
      • createHibernateTemplate

        @Deprecated(forRemoval=true)
        protected org.springframework.orm.hibernate5.HibernateTemplate createHibernateTemplate​(org.hibernate.SessionFactory sessionFactory)
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 8.6
      • setEventPublisher

        public void setEventPublisher​(com.atlassian.event.api.EventPublisher eventPublisher)
      • getByClassId

        protected @Nullable T getByClassId​(long id)
        Retrieve the object with a particular id from the database. The object must be of the same class as the DAO's getPersistentClass() method returns.
        Parameters:
        id - the id of the object to look up
        Returns:
        the corresponding object, or null if the object does not exist with the appropriate class and id.
      • findByClassIdsFiltered

        public @NonNull PageResponse<T> findByClassIdsFiltered​(Iterable<Long> ids,
                                                               LimitedRequest limitedRequest,
                                                               Predicate<? super T> filter)
        Description copied from interface: ObjectDaoInternal
        Find a list of objects from the same persistent class.
        Specified by:
        findByClassIdsFiltered in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
        Parameters:
        ids - - the ids of the entities to find
        limitedRequest - the pagination request defining the page size to fetch
        filter - a predicate to do in memory filtering of the result set before returning
        Returns:
        a list of objects matching the filters
      • findAll

        public @NonNull List<T> findAll()
        Find all objects of the class provided by getPersistentClass()
        Specified by:
        findAll in interface ObjectDao
        Specified by:
        findAll in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
        Returns:
        a list of all objects of the appropriate class, or the empty list if no objects are found
      • findAllSorted

        public @NonNull List<T> findAllSorted​(String sortField)
        Description copied from interface: ObjectDaoInternal
        Find all objects currently persisted of a particular type and sort results by named property.
        Specified by:
        findAllSorted in interface ObjectDao
        Specified by:
        findAllSorted in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
        Parameters:
        sortField - the name of the property to be sorted on. This should be null if no sorting is required.
      • findAllSorted

        public @NonNull List<T> findAllSorted​(String sortField,
                                              boolean cacheable,
                                              int offset,
                                              int maxResultCount)
        Description copied from interface: ObjectDaoInternal
        Find all objects currently persisted of a particular type and sort results by named property. This version of the method allows more control over the query.
        Specified by:
        findAllSorted in interface ObjectDao
        Specified by:
        findAllSorted in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
        Parameters:
        sortField - the name of the property to be sorted on. This should be null if no sorting is required.
        cacheable - control whether the results should be cached
        offset - the index of the first result to be returned
        maxResultCount - the maximum number of results required. Use -1 to specify no limit.
      • save

        @Deprecated
        public void save​(com.atlassian.core.bean.EntityObject objectToSave)
        Deprecated.
        since 6.10.0. Use saveEntity(EntityObject) instead.
        Save an object. The object's last-modified time will be updated, and if the object is searchable it will be indexed.
        Specified by:
        save in interface ObjectDao
        Specified by:
        save in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
        Parameters:
        objectToSave - the object to save
      • saveEntity

        public void saveEntity​(T objectToSave)
        Description copied from interface: ObjectDaoInternal
        Saves the given object to the database.
        Specified by:
        saveEntity in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
        Parameters:
        objectToSave - the object to save.
      • updateModificationData

        @Deprecated
        protected void updateModificationData​(com.atlassian.core.bean.EntityObject objectToSave)
        Perform any modifications that need to be done to an object every time it is saved. The default implementation updates the last-modified timestamp, and sets the creation timestamp if it has not yet been set.
        Parameters:
        objectToSave - the object that is about to be saved
      • updateEntityModificationData

        protected void updateEntityModificationData​(T objectToSave)
      • saveRaw

        public void saveRaw​(com.atlassian.core.bean.EntityObject objectToSave)
        Save the object without updateModificationData being called. Modification/creation time will not be set, but the object will still be indexed if it is searchable.
        Specified by:
        saveRaw in interface ObjectDao
        Specified by:
        saveRaw in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
        Parameters:
        objectToSave - object to save
      • saveRawEntity

        public void saveRawEntity​(T objectToSave)
        Description copied from interface: ObjectDaoInternal
        Saves the object without updating modification daa.

        If the object is new, this won't set the creation date on the object. If it already exists, then it won't set the date that it was updated.

        Specified by:
        saveRawEntity in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
        Parameters:
        objectToSave - the object to save.
      • remove

        public void remove​(com.atlassian.core.bean.EntityObject objectToRemove)
        Remove an object from the database
        Specified by:
        remove in interface ObjectDao
        Specified by:
        remove in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
        Parameters:
        objectToRemove - the object to remove
      • removeEntity

        public void removeEntity​(T objectToRemove)
        Description copied from interface: ObjectDaoInternal
        Remove object from persistence.
        Specified by:
        removeEntity in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
      • refresh

        public void refresh​(com.atlassian.core.bean.EntityObject objectToRefresh)
        Update the stat of an object based on the current state of the database. The object will be modified in place
        Specified by:
        refresh in interface ObjectDao
        Specified by:
        refresh in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
        Parameters:
        objectToRefresh - the object to refresh
      • refreshEntity

        public void refreshEntity​(T objectToRefresh)
        Description copied from interface: ObjectDaoInternal
        Refreshes the object again with the fresh data from db.
        Specified by:
        refreshEntity in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
      • replicate

        public void replicate​(Object objectToReplicate)
        Description copied from interface: ObjectDaoInternal
        Replicate the object. Replication does not generate a new id if the object does not exist in database and it overwrites the database row if the object already exists in database.
        Specified by:
        replicate in interface ObjectDao
        Specified by:
        replicate in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
      • replicateEntity

        public void replicateEntity​(T objectToReplicate)
        Description copied from interface: ObjectDaoInternal
        Replicate the object. Replication does not generate a new id if the object does not exist in database and it overwrites the database row if the object already exists in database.
        Specified by:
        replicateEntity in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
      • indexEntity

        protected void indexEntity​(T objectToSave)
      • reIndexEntity

        protected void reIndexEntity​(T objectToSave)
      • unIndexEntity

        protected void unIndexEntity​(T objectToSave,
                                     boolean unindexDependents)
      • findNamedQueryStringParam

        protected List findNamedQueryStringParam​(String queryName,
                                                 String paramName,
                                                 Object paramValue)
      • findNamedQueryStringParams

        protected List findNamedQueryStringParams​(String queryName,
                                                  String paramName,
                                                  Object paramValue,
                                                  String param2Name,
                                                  Object param2Value)
      • findNamedQueryStringParams

        @Deprecated
        protected List findNamedQueryStringParams​(String queryName,
                                                  boolean cacheable,
                                                  int offset,
                                                  int maxResultCount,
                                                  Object... paramNamesAndValues)
        Deprecated.
        since 5.8 Use the equivalent method that uses the HibernateObjectDao.Cacheability enum instead of the cacheable boolean flag
      • getCountResult

        @Deprecated
        protected int getCountResult​(@Nullable List<Number> results)
        Deprecated.
        since 7.0.1. Use DataAccessUtils.intResult(Collection) instead.
      • findSingleObject

        @Deprecated
        protected <T extends com.atlassian.core.bean.EntityObject> @Nullable T findSingleObject​(List<T> results)
        Deprecated.
        since 5.2. Entity ID comparison is not a recommended way to select a result. Use uniqueResult(java.util.List), Query.uniqueResult(), Criteria.uniqueResult(), or manually handle it yourself.
        Attempts to select a single result from a list of results. If the list has only one item, then that item is returned. If the list has more than one item, then the item with the lowest ID is returned. If the list is empty, null is returned.
      • uniqueResult

        protected <E extends com.atlassian.core.bean.EntityObject> E uniqueResult​(List<E> results)
                                                                           throws org.hibernate.NonUniqueResultException
        Attempts to select a single result from a list of results. If the list has only one item, then that item is returned. If the list has more than one item, then an exception will be thrown unless all items in the list are the same object. If the list is empty, null is returned.
        Returns:
        The single unique object in the list, or null if list is empty
        Throws:
        org.hibernate.NonUniqueResultException - If more than one unique objects is found in the list.
      • checkDaoConfig

        protected final void checkDaoConfig()
        Specified by:
        checkDaoConfig in class org.springframework.dao.support.DaoSupport
      • applyTransactionTimeout

        protected static void applyTransactionTimeout​(org.hibernate.query.Query query,
                                                      org.hibernate.SessionFactory sessionFactory)
      • applyTransactionTimeout

        protected static void applyTransactionTimeout​(org.hibernate.Criteria criteria,
                                                      org.hibernate.SessionFactory sessionFactory)