Class HibernateObjectDao<T extends com.atlassian.core.bean.EntityObject>
java.lang.Object
org.springframework.dao.support.DaoSupport
com.atlassian.confluence.core.persistence.hibernate.HibernateObjectDao<T>
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
ConfluenceHibernateObjectDao
,DefaultGlobalDescriptionDao
,HibernateAbstractPageDao
,HibernateAttachmentDataDao
,HibernateAuditRecordDao
,HibernateContentPermissionSetDao
,HibernateDraftDao
,HibernateLabelDao
,HibernateVersionHistoryDao
,HibernateZduStatusDao
public abstract class HibernateObjectDao<T extends com.atlassian.core.bean.EntityObject>
extends org.springframework.dao.support.DaoSupport
Generic DAO for hibernate objects. Takes care of indexing and unindexing, and setting
creation and update times for objects.
For this reason, you should always do object CRUD through the DAO, you shouldn't trust Hibernate to do it for you: Hibernate will save the object, but skip the additional stuff the DAO does.
Subclasses will need to implement the getPersistentClass()
method to return the class
that the DAO is serving: that way getByClassId() will perform correctly.
Subclasses should also override updateModificationData(EntityObject)
if they want to perform
any additional modifications on objects that are being saved through the DAO. Just
remember to call super. (updateModificationData
will not be called if an
object is saved through #saveRawEntity(EntityObject)
)
- Since:
- 6.1.0
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static void
applyTransactionTimeout
(org.hibernate.Criteria criteria, org.hibernate.SessionFactory sessionFactory) protected static void
applyTransactionTimeout
(org.hibernate.query.Query query, org.hibernate.SessionFactory sessionFactory) protected final void
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.6findAll()
Find all objects of the class provided by getPersistentClass()findAllSorted
(String sortField) findAllSorted
(String sortField, boolean cacheable, int offset, int maxResultCount) protected List
findNamedQuery
(String queryName) Deprecated.since 6.10.0.protected List
findNamedQuery
(String queryName, HibernateObjectDao.Cacheability cacheability) protected List
findNamedQuery
(String queryName, HibernateObjectDao.Cacheability cacheability, int maxResultCount) protected List
findNamedQueryStringParam
(String queryName, String paramName, Object paramValue) protected List
findNamedQueryStringParam
(String queryName, String paramName, Object paramValue, HibernateObjectDao.Cacheability cacheability) protected List
findNamedQueryStringParam
(String queryName, String paramName, Object paramValue, HibernateObjectDao.Cacheability cacheability, int maxResultCount) protected List
findNamedQueryStringParams
(String queryName, boolean cacheable, int offset, int maxResultCount, Object... paramNamesAndValues) Deprecated.since 5.8 Use the equivalent method that uses theHibernateObjectDao.Cacheability
enum instead of the cacheable boolean flagprotected List
findNamedQueryStringParams
(String queryName, HibernateObjectDao.Cacheability cacheability, int offset, int maxResultCount, Object... paramNamesAndValues) protected List
findNamedQueryStringParams
(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value) protected List
findNamedQueryStringParams
(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, HibernateObjectDao.Cacheability cacheability) protected List
findNamedQueryStringParams
(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, HibernateObjectDao.Cacheability cacheability, int maxResultCount) protected List
findNamedQueryStringParams
(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value) protected List
findNamedQueryStringParams
(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, HibernateObjectDao.Cacheability cacheability) protected List
findNamedQueryStringParams
(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, HibernateObjectDao.Cacheability cacheability, int maxResultCount) protected List
findNamedQueryStringParams
(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, String param4Name, Object param4Value) protected List
findNamedQueryStringParams
(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, String param4Name, Object param4Value, HibernateObjectDao.Cacheability cacheability) protected List
findNamedQueryStringParams
(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, String param4Name, Object param4Value, HibernateObjectDao.Cacheability cacheability, int maxResultCount) protected <T extends com.atlassian.core.bean.EntityObject>
@Nullable TfindSingleObject
(List<T> results) Deprecated.since 5.2.protected @Nullable T
getByClassId
(long id) Retrieve the object with a particular id from the database.protected int
getCountResult
(@Nullable List<Number> results) Deprecated.since 7.0.1.final org.springframework.orm.hibernate5.HibernateTemplate
Deprecated, for removal: This API element is subject to removal in a future version.since 8.6 UsegetSessionFactory()
andSessionFactory.getCurrentSession()
final org.hibernate.SessionFactory
protected void
protected void
reIndex
(com.atlassian.core.bean.EntityObject objectToSave) protected void
Remove an object from the databasevoid
Save an object.final void
saveEntity
(T objectToSave) Deprecated, for removal: This API element is subject to removal in a future version.since 9.0 usesave(T)
protected void
Save the object without updateModificationData being called.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.6final void
setSessionFactory
(org.hibernate.SessionFactory sessionFactory) protected <E> E
uniqueResult
(List<E> results) Attempts to select a single result from a list of results.protected void
updateModificationData
(T objectToSave) Perform any modifications that need to be done to an object every time it is saved.Methods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
-
Constructor Details
-
HibernateObjectDao
public HibernateObjectDao()
-
-
Method Details
-
getPersistentClass
-
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 UsegetSessionFactory()
andSessionFactory.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 -
getByClassId
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.
-
findAll
Find all objects of the class provided by getPersistentClass()- Returns:
- a list of all objects of the appropriate class, or the empty list if no objects are found
-
findAllSorted
-
findAllSorted
-
save
Save an object. The object's last-modified time will be updated, and if the object is searchable it will be indexed.- Parameters:
objectToSave
- the object to save
-
saveEntity
Deprecated, for removal: This API element is subject to removal in a future version.since 9.0 usesave(T)
-
updateModificationData
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
-
saveRaw
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.- Parameters:
objectToSave
- object to save
-
remove
Remove an object from the database- Parameters:
objectToRemove
- the object to remove
-
publishEvent
-
reIndex
protected void reIndex(com.atlassian.core.bean.EntityObject objectToSave) -
findNamedQuery
Deprecated.since 6.10.0. UsefindNamedQueryStringParams(String, Cacheability, int, int, Object[])
instead. -
findNamedQuery
-
findNamedQuery
protected List findNamedQuery(String queryName, HibernateObjectDao.Cacheability cacheability, int maxResultCount) -
findNamedQueryStringParam
-
findNamedQueryStringParam
protected List findNamedQueryStringParam(String queryName, String paramName, Object paramValue, HibernateObjectDao.Cacheability cacheability) -
findNamedQueryStringParam
protected List findNamedQueryStringParam(String queryName, String paramName, Object paramValue, HibernateObjectDao.Cacheability cacheability, int maxResultCount) -
findNamedQueryStringParams
-
findNamedQueryStringParams
-
findNamedQueryStringParams
-
findNamedQueryStringParams
-
findNamedQueryStringParams
-
findNamedQueryStringParams
-
findNamedQueryStringParams
-
findNamedQueryStringParams
-
findNamedQueryStringParams
-
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 theHibernateObjectDao.Cacheability
enum instead of the cacheable boolean flag -
findNamedQueryStringParams
protected List findNamedQueryStringParams(String queryName, HibernateObjectDao.Cacheability cacheability, int offset, int maxResultCount, Object... paramNamesAndValues) -
getCountResult
Deprecated.since 7.0.1. UseDataAccessUtils.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. UseuniqueResult(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
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 classorg.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)
-