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:
ObjectDao,ObjectDaoInternal<T>,org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
DefaultGlobalDescriptionDao,HibernateAbstractPageDao,HibernateAttachmentDataDao,HibernateAuditRecordDao,HibernateContentPermissionSetDao,HibernateDraftDao,HibernateLabelDao,HibernateVersionHistoryDao,HibernateZduStatusDao,VersionedHibernateObjectDao
public abstract class HibernateObjectDao<T extends com.atlassian.core.bean.EntityObject> extends org.springframework.dao.support.DaoSupport implements ObjectDaoInternal<T>
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
ObjectDaoInternal.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. (updateModificationDatawill not be called if an object is saved throughsaveRawEntity(EntityObject))- Since:
- 6.1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHibernateObjectDao.Cacheability
-
Constructor Summary
Constructors Constructor Description HibernateObjectDao()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected static voidapplyTransactionTimeout(org.hibernate.Criteria criteria, org.hibernate.SessionFactory sessionFactory)protected static voidapplyTransactionTimeout(org.hibernate.query.Query query, org.hibernate.SessionFactory sessionFactory)protected voidcheckDaoConfig()protected org.springframework.orm.hibernate5.HibernateTemplatecreateHibernateTemplate(org.hibernate.SessionFactory sessionFactory)Deprecated, for removal: This API element is subject to removal in a future version.since 8.6@NonNull List<T>findAll()Find all objects of the class provided by getPersistentClass()@NonNull List<T>findAllSorted(String sortField)Find all objects currently persisted of a particular type and sort results by named property.@NonNull List<T>findAllSorted(String sortField, boolean cacheable, int offset, int maxResultCount)Find all objects currently persisted of a particular type and sort results by named property.<E> @NonNull PageResponse<E>findByClassIds(Iterable<Long> ids, LimitedRequest limitedRequest, com.google.common.base.Predicate<? super E> filter)Deprecated.since 6.10.0.@NonNull PageResponse<T>findByClassIdsFiltered(Iterable<Long> ids, LimitedRequest limitedRequest, Predicate<? super T> filter)Find a list of objects from the same persistent class.protected ListfindNamedQuery(String queryName)Deprecated.since 6.10.0.protected ListfindNamedQuery(String queryName, HibernateObjectDao.Cacheability cacheability)protected ListfindNamedQuery(String queryName, HibernateObjectDao.Cacheability cacheability, int maxResultCount)protected ListfindNamedQueryStringParam(String queryName, String paramName, Object paramValue)protected ListfindNamedQueryStringParam(String queryName, String paramName, Object paramValue, HibernateObjectDao.Cacheability cacheability)protected ListfindNamedQueryStringParam(String queryName, String paramName, Object paramValue, HibernateObjectDao.Cacheability cacheability, int maxResultCount)protected ListfindNamedQueryStringParams(String queryName, boolean cacheable, int offset, int maxResultCount, Object... paramNamesAndValues)Deprecated.since 5.8 Use the equivalent method that uses theHibernateObjectDao.Cacheabilityenum instead of the cacheable boolean flagprotected ListfindNamedQueryStringParams(String queryName, HibernateObjectDao.Cacheability cacheability, int offset, int maxResultCount, Object... paramNamesAndValues)protected ListfindNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value)protected ListfindNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, HibernateObjectDao.Cacheability cacheability)protected ListfindNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, HibernateObjectDao.Cacheability cacheability, int maxResultCount)protected ListfindNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value)protected ListfindNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, HibernateObjectDao.Cacheability cacheability)protected ListfindNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, HibernateObjectDao.Cacheability cacheability, int maxResultCount)protected ListfindNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, String param4Name, Object param4Value)protected ListfindNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, String param4Name, Object param4Value, HibernateObjectDao.Cacheability cacheability)protected ListfindNamedQueryStringParams(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 TgetByClassId(long id)Retrieve the object with a particular id from the database.protected intgetCountResult(@Nullable List<Number> results)Deprecated.since 7.0.1.org.springframework.orm.hibernate5.HibernateTemplategetHibernateTemplate()Deprecated, for removal: This API element is subject to removal in a future version.since 8.6 UsegetSessionFactory()andSessionFactory.getCurrentSession()org.hibernate.SessionFactorygetSessionFactory()protected voidindex(com.atlassian.core.bean.EntityObject objectToSave)Deprecated.since 6.10.0.protected voidindexEntity(T objectToSave)voidrefresh(com.atlassian.core.bean.EntityObject objectToRefresh)Update the stat of an object based on the current state of the database.voidrefreshEntity(T objectToRefresh)Refreshes the object again with the fresh data from db.protected voidreIndex(com.atlassian.core.bean.EntityObject objectToSave)Deprecated.since 6.10.0.protected voidreIndexEntity(T objectToSave)voidremove(com.atlassian.core.bean.EntityObject objectToRemove)Remove an object from the databasevoidremoveEntity(T objectToRemove)Remove object from persistence.voidreplicate(Object objectToReplicate)Replicate the object.voidreplicateEntity(T objectToReplicate)Replicate the object.voidsave(com.atlassian.core.bean.EntityObject objectToSave)Deprecated.since 6.10.0.voidsaveEntity(T objectToSave)Saves the given object to the database.voidsaveRaw(com.atlassian.core.bean.EntityObject objectToSave)Save the object without updateModificationData being called.voidsaveRawEntity(T objectToSave)Saves the object without updating modification daa.voidsetEventPublisher(com.atlassian.event.api.EventPublisher eventPublisher)voidsetHibernateTemplate(org.springframework.orm.hibernate5.HibernateTemplate hibernateTemplate)Deprecated, for removal: This API element is subject to removal in a future version.since 8.6voidsetIndexer(Indexer indexer)Deprecated.since 7.5.voidsetSessionFactory(org.hibernate.SessionFactory sessionFactory)protected voidunIndex(com.atlassian.core.bean.EntityObject objectToSave, boolean unindexDependents)Deprecated.since 6.10.0.protected voidunIndexEntity(T objectToSave, boolean unindexDependents)protected <E extends com.atlassian.core.bean.EntityObject>
EuniqueResult(List<E> results)Attempts to select a single result from a list of results.protected voidupdateEntityModificationData(T objectToSave)protected voidupdateModificationData(com.atlassian.core.bean.EntityObject objectToSave)Deprecated.since 6.10.0.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.atlassian.confluence.internal.persistence.ObjectDaoInternal
getPersistentClass
-
-
-
-
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 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
-
setIndexer
@Deprecated public void setIndexer(Indexer indexer)
Deprecated.since 7.5. UsesetEventPublisher(EventPublisher)to publish index changes.
-
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.
-
findByClassIds
@Deprecated public <E> @NonNull PageResponse<E> findByClassIds(Iterable<Long> ids, LimitedRequest limitedRequest, com.google.common.base.Predicate<? super E> filter)
Deprecated.since 6.10.0. UsefindByClassIdsFiltered(Iterable, LimitedRequest, Predicate)instead.Description copied from interface:ObjectDaoInternalFind a list of objects from the same persistent class.- Specified by:
findByClassIdsin interfaceObjectDao- Specified by:
findByClassIdsin interfaceObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>- Type Parameters:
E- the type of entity to return- Parameters:
ids- - the ids of the entities to findlimitedRequest- the pagination request defining the page size to fetchfilter- a predicate to do in memory filtering of the result set before returning- Returns:
- a list of objects matching the filters
-
findByClassIdsFiltered
public @NonNull PageResponse<T> findByClassIdsFiltered(Iterable<Long> ids, LimitedRequest limitedRequest, Predicate<? super T> filter)
Description copied from interface:ObjectDaoInternalFind a list of objects from the same persistent class.- Specified by:
findByClassIdsFilteredin interfaceObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>- Parameters:
ids- - the ids of the entities to findlimitedRequest- the pagination request defining the page size to fetchfilter- 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:
findAllin interfaceObjectDao- Specified by:
findAllin interfaceObjectDaoInternal<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:ObjectDaoInternalFind all objects currently persisted of a particular type and sort results by named property.- Specified by:
findAllSortedin interfaceObjectDao- Specified by:
findAllSortedin interfaceObjectDaoInternal<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:ObjectDaoInternalFind 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:
findAllSortedin interfaceObjectDao- Specified by:
findAllSortedin interfaceObjectDaoInternal<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 cachedoffset- the index of the first result to be returnedmaxResultCount- 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. UsesaveEntity(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:
savein interfaceObjectDao- Specified by:
savein interfaceObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>- Parameters:
objectToSave- the object to save
-
saveEntity
public void saveEntity(T objectToSave)
Description copied from interface:ObjectDaoInternalSaves the given object to the database.- Specified by:
saveEntityin interfaceObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>- Parameters:
objectToSave- the object to save.
-
updateModificationData
@Deprecated protected void updateModificationData(com.atlassian.core.bean.EntityObject objectToSave)
Deprecated.since 6.10.0. UseupdateEntityModificationData(com.atlassian.core.bean.EntityObject)instead.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:
saveRawin interfaceObjectDao- Specified by:
saveRawin interfaceObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>- Parameters:
objectToSave- object to save
-
saveRawEntity
public void saveRawEntity(T objectToSave)
Description copied from interface:ObjectDaoInternalSaves 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:
saveRawEntityin interfaceObjectDaoInternal<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:
removein interfaceObjectDao- Specified by:
removein interfaceObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>- Parameters:
objectToRemove- the object to remove
-
removeEntity
public void removeEntity(T objectToRemove)
Description copied from interface:ObjectDaoInternalRemove object from persistence.- Specified by:
removeEntityin interfaceObjectDaoInternal<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:
refreshin interfaceObjectDao- Specified by:
refreshin interfaceObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>- Parameters:
objectToRefresh- the object to refresh
-
refreshEntity
public void refreshEntity(T objectToRefresh)
Description copied from interface:ObjectDaoInternalRefreshes the object again with the fresh data from db.- Specified by:
refreshEntityin interfaceObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
-
replicate
public void replicate(Object objectToReplicate)
Description copied from interface:ObjectDaoInternalReplicate 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:
replicatein interfaceObjectDao- Specified by:
replicatein interfaceObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
-
replicateEntity
public void replicateEntity(T objectToReplicate)
Description copied from interface:ObjectDaoInternalReplicate 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:
replicateEntityin interfaceObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
-
index
@Deprecated protected void index(com.atlassian.core.bean.EntityObject objectToSave)
Deprecated.since 6.10.0. UseindexEntity(EntityObject)instead.
-
indexEntity
protected void indexEntity(T objectToSave)
-
reIndex
@Deprecated protected void reIndex(com.atlassian.core.bean.EntityObject objectToSave)
Deprecated.since 6.10.0. UsereIndexEntity(EntityObject)instead.
-
reIndexEntity
protected void reIndexEntity(T objectToSave)
-
unIndex
@Deprecated protected void unIndex(com.atlassian.core.bean.EntityObject objectToSave, boolean unindexDependents)
Deprecated.since 6.10.0. UseunIndexEntity(EntityObject, boolean)instead.
-
unIndexEntity
protected void unIndexEntity(T objectToSave, boolean unindexDependents)
-
findNamedQuery
@Deprecated protected List findNamedQuery(String queryName)
Deprecated.since 6.10.0. UsefindNamedQueryStringParams(String, Cacheability, int, int, Object[])instead.
-
findNamedQuery
protected List findNamedQuery(String queryName, HibernateObjectDao.Cacheability cacheability)
-
findNamedQuery
protected List findNamedQuery(String queryName, HibernateObjectDao.Cacheability cacheability, int maxResultCount)
-
findNamedQueryStringParam
protected List findNamedQueryStringParam(String queryName, String paramName, Object paramValue)
-
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
protected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value)
-
findNamedQueryStringParams
protected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, HibernateObjectDao.Cacheability cacheability)
-
findNamedQueryStringParams
protected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, HibernateObjectDao.Cacheability cacheability, int maxResultCount)
-
findNamedQueryStringParams
protected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value)
-
findNamedQueryStringParams
protected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, HibernateObjectDao.Cacheability cacheability)
-
findNamedQueryStringParams
protected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, HibernateObjectDao.Cacheability cacheability, int maxResultCount)
-
findNamedQueryStringParams
protected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, String param4Name, Object param4Value)
-
findNamedQueryStringParams
protected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, String param4Name, Object param4Value, HibernateObjectDao.Cacheability cacheability)
-
findNamedQueryStringParams
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)
-
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.Cacheabilityenum instead of the cacheable boolean flag
-
findNamedQueryStringParams
protected List findNamedQueryStringParams(String queryName, HibernateObjectDao.Cacheability cacheability, int offset, int maxResultCount, Object... paramNamesAndValues)
-
getCountResult
@Deprecated protected int getCountResult(@Nullable List<Number> results)
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
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:
checkDaoConfigin 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)
-
-