public abstract class HibernateObjectDao<T extends com.atlassian.core.bean.EntityObject> extends org.springframework.dao.support.DaoSupport implements ObjectDaoInternal<T>
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 through saveRawEntity(EntityObject)
)
Modifier and Type | Class and Description |
---|---|
static class |
HibernateObjectDao.Cacheability |
Modifier and Type | Field and Description |
---|---|
protected static org.apache.log4j.Logger |
log
Deprecated.
Since 4.0. Use a class-private logger.
|
NON_CACHEABLE
Constructor and Description |
---|
HibernateObjectDao() |
Modifier and Type | Method and 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) |
List<T> |
findAll()
Find all objects of the class provided by getPersistentClass()
|
List<T> |
findAllSorted(String sortField)
Find all objects currently persisted of a particular type and sort results by named property.
|
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> PageResponse<E> |
findByClassIds(Iterable<Long> ids,
LimitedRequest limitedRequest,
com.google.common.base.Predicate<? super E> filter)
Deprecated.
since 6.10.0. Use
findByClassIdsFiltered(Iterable, LimitedRequest, Predicate) instead. |
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. Use
findNamedQueryStringParams(String, Cacheability, int, int, Object[]) instead. |
protected List |
findNamedQuery(String queryName,
boolean cacheable)
Deprecated.
since 5.8 Use the equivalent method that uses the
HibernateObjectDao.Cacheability enum instead of the cacheable boolean flag |
protected List |
findNamedQuery(String queryName,
boolean cacheable,
int maxResultCount)
Deprecated.
since 5.8 Use the equivalent method that uses the
HibernateObjectDao.Cacheability enum instead of the cacheable boolean flag |
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,
boolean cacheable)
Deprecated.
since 5.8 Use the equivalent method that uses the
HibernateObjectDao.Cacheability enum instead of the cacheable boolean flag |
protected List |
findNamedQueryStringParam(String queryName,
String paramName,
Object paramValue,
boolean cacheable,
int maxResultCount)
Deprecated.
since 5.8 Use the equivalent method that uses the
HibernateObjectDao.Cacheability enum instead of the cacheable boolean flag |
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 the
HibernateObjectDao.Cacheability enum instead of the cacheable boolean flag |
protected 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,
boolean cacheable)
Deprecated.
since 5.8 Use the equivalent method that uses the
HibernateObjectDao.Cacheability enum instead of the cacheable boolean flag |
protected List |
findNamedQueryStringParams(String queryName,
String paramName,
Object paramValue,
String param2Name,
Object param2Value,
boolean cacheable,
int maxResultCount)
Deprecated.
since 5.8 Use the equivalent method that uses the
HibernateObjectDao.Cacheability enum instead of the cacheable boolean flag |
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,
boolean cacheable)
Deprecated.
since 5.8 Use the equivalent method that uses the
HibernateObjectDao.Cacheability enum instead of the cacheable boolean flag |
protected List |
findNamedQueryStringParams(String queryName,
String paramName,
Object paramValue,
String param2Name,
Object param2Value,
String param3Name,
Object param3Value,
boolean cacheable,
int maxResultCount)
Deprecated.
since 5.8 Use the equivalent method that uses the
HibernateObjectDao.Cacheability enum instead of the cacheable boolean flag |
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,
boolean cacheable)
Deprecated.
since 5.8 Use the equivalent method that uses the
HibernateObjectDao.Cacheability enum instead of the cacheable boolean flag |
protected List |
findNamedQueryStringParams(String queryName,
String paramName,
Object paramValue,
String param2Name,
Object param2Value,
String param3Name,
Object param3Value,
String param4Name,
Object param4Value,
boolean cacheable,
int maxResultCount)
Deprecated.
since 5.8 Use the equivalent method that uses the
HibernateObjectDao.Cacheability enum instead of the cacheable boolean flag |
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> |
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. |
protected T |
getByClassId(long id)
Retrieve the object with a particular id from the database.
|
protected int |
getCountResult(List<Number> results) |
org.springframework.orm.hibernate5.HibernateTemplate |
getHibernateTemplate() |
protected org.hibernate.Session |
getSession() |
org.hibernate.SessionFactory |
getSessionFactory() |
protected void |
index(com.atlassian.core.bean.EntityObject objectToSave)
Deprecated.
since 6.10.0. Use
indexEntity(EntityObject) instead. |
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. Use
reIndexEntity(EntityObject) instead. |
protected void |
reIndexEntity(T objectToSave) |
void |
remove(com.atlassian.core.bean.EntityObject objectToRemove)
Remove an object from the database
|
void |
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. Use
saveEntity(EntityObject) instead. |
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 |
setHibernateTemplate(org.springframework.orm.hibernate5.HibernateTemplate hibernateTemplate) |
void |
setIndexer(com.atlassian.bonnie.Indexer indexer) |
void |
setSessionFactory(org.hibernate.SessionFactory sessionFactory) |
protected void |
unIndex(com.atlassian.core.bean.EntityObject objectToSave,
boolean unindexDependents)
Deprecated.
since 6.10.0. Use
unIndexEntity(EntityObject, boolean) instead. |
protected void |
unIndexEntity(T objectToSave,
boolean unindexDependents) |
protected <E extends com.atlassian.core.bean.EntityObject> |
uniqueResult(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. Use
updateEntityModificationData(com.atlassian.core.bean.EntityObject) instead. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getPersistentClass
@Deprecated protected static final org.apache.log4j.Logger log
public final org.hibernate.SessionFactory getSessionFactory()
public final void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
public final org.springframework.orm.hibernate5.HibernateTemplate getHibernateTemplate()
public final void setHibernateTemplate(org.springframework.orm.hibernate5.HibernateTemplate hibernateTemplate)
protected org.springframework.orm.hibernate5.HibernateTemplate createHibernateTemplate(org.hibernate.SessionFactory sessionFactory)
public void setIndexer(com.atlassian.bonnie.Indexer indexer)
@Nullable protected T getByClassId(long id)
id
- the id of the object to look up@Deprecated @Nonnull public <E> PageResponse<E> findByClassIds(Iterable<Long> ids, LimitedRequest limitedRequest, com.google.common.base.Predicate<? super E> filter)
findByClassIdsFiltered(Iterable, LimitedRequest, Predicate)
instead.ObjectDaoInternal
findByClassIds
in interface ObjectDao
findByClassIds
in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
E
- the type of entity to returnids
- - 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@Nonnull public PageResponse<T> findByClassIdsFiltered(Iterable<Long> ids, LimitedRequest limitedRequest, Predicate<? super T> filter)
ObjectDaoInternal
findByClassIdsFiltered
in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
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@Nonnull public List<T> findAll()
findAll
in interface ObjectDao
findAll
in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
@Nonnull public List<T> findAllSorted(String sortField)
ObjectDaoInternal
findAllSorted
in interface ObjectDao
findAllSorted
in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
sortField
- the name of the property to be sorted on. This should be null if no sorting is required.@Nonnull public List<T> findAllSorted(String sortField, boolean cacheable, int offset, int maxResultCount)
ObjectDaoInternal
findAllSorted
in interface ObjectDao
findAllSorted
in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
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.@Deprecated public void save(com.atlassian.core.bean.EntityObject objectToSave)
saveEntity(EntityObject)
instead.save
in interface ObjectDao
save
in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
objectToSave
- the object to savepublic void saveEntity(T objectToSave)
ObjectDaoInternal
saveEntity
in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
objectToSave
- the object to save.@Deprecated protected void updateModificationData(com.atlassian.core.bean.EntityObject objectToSave)
updateEntityModificationData(com.atlassian.core.bean.EntityObject)
instead.objectToSave
- the object that is about to be savedprotected void updateEntityModificationData(T objectToSave)
public void saveRaw(com.atlassian.core.bean.EntityObject objectToSave)
saveRaw
in interface ObjectDao
saveRaw
in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
objectToSave
- object to savepublic void saveRawEntity(T objectToSave)
ObjectDaoInternal
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.
saveRawEntity
in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
objectToSave
- the object to save.public void remove(com.atlassian.core.bean.EntityObject objectToRemove)
remove
in interface ObjectDao
remove
in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
objectToRemove
- the object to removepublic void removeEntity(T objectToRemove)
ObjectDaoInternal
removeEntity
in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
public void refresh(com.atlassian.core.bean.EntityObject objectToRefresh)
refresh
in interface ObjectDao
refresh
in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
objectToRefresh
- the object to refreshpublic void refreshEntity(T objectToRefresh)
ObjectDaoInternal
refreshEntity
in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
public void replicate(Object objectToReplicate)
ObjectDaoInternal
replicate
in interface ObjectDao
replicate
in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
public void replicateEntity(T objectToReplicate)
ObjectDaoInternal
replicateEntity
in interface ObjectDaoInternal<T extends com.atlassian.core.bean.EntityObject>
@Deprecated protected void index(com.atlassian.core.bean.EntityObject objectToSave)
indexEntity(EntityObject)
instead.protected void indexEntity(T objectToSave)
@Deprecated protected void reIndex(com.atlassian.core.bean.EntityObject objectToSave)
reIndexEntity(EntityObject)
instead.protected void reIndexEntity(T objectToSave)
@Deprecated protected void unIndex(com.atlassian.core.bean.EntityObject objectToSave, boolean unindexDependents)
unIndexEntity(EntityObject, boolean)
instead.protected void unIndexEntity(T objectToSave, boolean unindexDependents)
@Deprecated protected List findNamedQuery(String queryName)
findNamedQueryStringParams(String, Cacheability, int, int, Object[])
instead.@Deprecated protected List findNamedQuery(String queryName, boolean cacheable)
HibernateObjectDao.Cacheability
enum instead of the cacheable boolean flagprotected List findNamedQuery(String queryName, HibernateObjectDao.Cacheability cacheability)
@Deprecated protected List findNamedQuery(String queryName, boolean cacheable, int maxResultCount)
HibernateObjectDao.Cacheability
enum instead of the cacheable boolean flagprotected List findNamedQuery(String queryName, HibernateObjectDao.Cacheability cacheability, int maxResultCount)
protected List findNamedQueryStringParam(String queryName, String paramName, Object paramValue)
@Deprecated protected List findNamedQueryStringParam(String queryName, String paramName, Object paramValue, boolean cacheable)
HibernateObjectDao.Cacheability
enum instead of the cacheable boolean flagprotected List findNamedQueryStringParam(String queryName, String paramName, Object paramValue, HibernateObjectDao.Cacheability cacheability)
@Deprecated protected List findNamedQueryStringParam(String queryName, String paramName, Object paramValue, boolean cacheable, int maxResultCount)
HibernateObjectDao.Cacheability
enum instead of the cacheable boolean flagprotected List findNamedQueryStringParam(String queryName, String paramName, Object paramValue, HibernateObjectDao.Cacheability cacheability, int maxResultCount)
protected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value)
@Deprecated protected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, boolean cacheable)
HibernateObjectDao.Cacheability
enum instead of the cacheable boolean flagprotected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, HibernateObjectDao.Cacheability cacheability)
@Deprecated protected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, boolean cacheable, int maxResultCount)
HibernateObjectDao.Cacheability
enum instead of the cacheable boolean flagprotected 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)
@Deprecated protected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, boolean cacheable)
HibernateObjectDao.Cacheability
enum instead of the cacheable boolean flagprotected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, HibernateObjectDao.Cacheability cacheability)
@Deprecated protected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, boolean cacheable, int maxResultCount)
HibernateObjectDao.Cacheability
enum instead of the cacheable boolean flagprotected 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)
@Deprecated protected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, String param4Name, Object param4Value, boolean cacheable)
HibernateObjectDao.Cacheability
enum instead of the cacheable boolean flagprotected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, String param4Name, Object param4Value, HibernateObjectDao.Cacheability cacheability)
@Deprecated protected List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, String param4Name, Object param4Value, boolean cacheable, int maxResultCount)
HibernateObjectDao.Cacheability
enum instead of the cacheable boolean flagprotected 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)
@Deprecated protected List findNamedQueryStringParams(String queryName, boolean cacheable, int offset, int maxResultCount, Object... paramNamesAndValues)
HibernateObjectDao.Cacheability
enum instead of the cacheable boolean flagprotected List findNamedQueryStringParams(String queryName, HibernateObjectDao.Cacheability cacheability, int offset, int maxResultCount, Object... paramNamesAndValues)
@Deprecated @Nullable protected <T extends com.atlassian.core.bean.EntityObject> T findSingleObject(List<T> results)
uniqueResult(java.util.List)
, Query.uniqueResult()
,
Criteria.uniqueResult()
, or manually handle it yourself.protected <E extends com.atlassian.core.bean.EntityObject> E uniqueResult(List<E> results) throws org.hibernate.NonUniqueResultException
org.hibernate.NonUniqueResultException
- If more than one unique objects is found in the list.protected final void checkDaoConfig()
checkDaoConfig
in class org.springframework.dao.support.DaoSupport
protected org.hibernate.Session getSession()
protected static void applyTransactionTimeout(org.hibernate.query.Query query, org.hibernate.SessionFactory sessionFactory)
protected static void applyTransactionTimeout(org.hibernate.Criteria criteria, org.hibernate.SessionFactory sessionFactory)
Copyright © 2003–2019 Atlassian. All rights reserved.