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. (updateModificationData
will 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 class
HibernateObjectDao.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 void
applyTransactionTimeout(org.hibernate.Criteria criteria, org.hibernate.SessionFactory sessionFactory)
protected static void
applyTransactionTimeout(org.hibernate.query.Query query, org.hibernate.SessionFactory sessionFactory)
protected void
checkDaoConfig()
protected org.springframework.orm.hibernate5.HibernateTemplate
createHibernateTemplate(org.hibernate.SessionFactory sessionFactory)
@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 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.org.springframework.orm.hibernate5.HibernateTemplate
getHibernateTemplate()
org.hibernate.SessionFactory
getSessionFactory()
protected void
index(com.atlassian.core.bean.EntityObject objectToSave)
Deprecated.since 6.10.0.protected void
indexEntity(T objectToSave)
void
refresh(com.atlassian.core.bean.EntityObject objectToRefresh)
Update the stat of an object based on the current state of the database.void
refreshEntity(T objectToRefresh)
Refreshes the object again with the fresh data from db.protected void
reIndex(com.atlassian.core.bean.EntityObject objectToSave)
Deprecated.since 6.10.0.protected void
reIndexEntity(T objectToSave)
void
remove(com.atlassian.core.bean.EntityObject objectToRemove)
Remove an object from the databasevoid
removeEntity(T objectToRemove)
Remove object from persistence.void
replicate(Object objectToReplicate)
Replicate the object.void
replicateEntity(T objectToReplicate)
Replicate the object.void
save(com.atlassian.core.bean.EntityObject objectToSave)
Deprecated.since 6.10.0.void
saveEntity(T objectToSave)
Saves the given object to the database.void
saveRaw(com.atlassian.core.bean.EntityObject objectToSave)
Save the object without updateModificationData being called.void
saveRawEntity(T objectToSave)
Saves the object without updating modification daa.void
setEventPublisher(com.atlassian.event.api.EventPublisher eventPublisher)
void
setHibernateTemplate(org.springframework.orm.hibernate5.HibernateTemplate hibernateTemplate)
void
setIndexer(Indexer indexer)
Deprecated.since 7.5.void
setSessionFactory(org.hibernate.SessionFactory sessionFactory)
protected void
unIndex(com.atlassian.core.bean.EntityObject objectToSave, boolean unindexDependents)
Deprecated.since 6.10.0.protected void
unIndexEntity(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 void
updateEntityModificationData(T objectToSave)
protected void
updateModificationData(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
public final org.springframework.orm.hibernate5.HibernateTemplate getHibernateTemplate()
-
setHibernateTemplate
public final void setHibernateTemplate(org.springframework.orm.hibernate5.HibernateTemplate hibernateTemplate)
-
createHibernateTemplate
protected org.springframework.orm.hibernate5.HibernateTemplate createHibernateTemplate(org.hibernate.SessionFactory sessionFactory)
-
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:ObjectDaoInternal
Find a list of objects from the same persistent class.- Specified by:
findByClassIds
in interfaceObjectDao
- Specified by:
findByClassIds
in 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:ObjectDaoInternal
Find a list of objects from the same persistent class.- Specified by:
findByClassIdsFiltered
in 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:
findAll
in interfaceObjectDao
- Specified by:
findAll
in 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:ObjectDaoInternal
Find all objects currently persisted of a particular type and sort results by named property.- Specified by:
findAllSorted
in interfaceObjectDao
- Specified by:
findAllSorted
in 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: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 interfaceObjectDao
- Specified by:
findAllSorted
in 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:
save
in interfaceObjectDao
- Specified by:
save
in interfaceObjectDaoInternal<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 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:
saveRaw
in interfaceObjectDao
- Specified by:
saveRaw
in interfaceObjectDaoInternal<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 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:
remove
in interfaceObjectDao
- Specified by:
remove
in interfaceObjectDaoInternal<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 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:
refresh
in interfaceObjectDao
- Specified by:
refresh
in interfaceObjectDaoInternal<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 interfaceObjectDaoInternal<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 interfaceObjectDao
- Specified by:
replicate
in interfaceObjectDaoInternal<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 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.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 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:
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)
-
-