public abstract class

HibernateObjectDao

extends HibernateDaoSupport
implements ObjectDao
java.lang.Object
   ↳ org.springframework.dao.support.DaoSupport
     ↳ org.springframework.orm.hibernate.support.HibernateDaoSupport
       ↳ com.atlassian.hibernate.HibernateObjectDao
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Generic DAO for hibernate objects. Takes care of indexing and de-indexing, 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() 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 saveRaw())

Summary

Fields
protected static final Logger log
[Expand]
Inherited Fields
From class org.springframework.dao.support.DaoSupport
Public Constructors
HibernateObjectDao()
Public Methods
List findAll()
Find all objects of the class provided by getPersistentClass()
List findAllSorted(String sortField, boolean cacheable, int offset, int maxResultCount)
Find all objects currently persisted of a particular type and sort results by named property.
List findAllSorted(String sortField)
Find all objects currently persisted of a particular type and sort results by named property.
void refresh(EntityObject objectToRefresh)
Update the stat of an object based on the current state of the database.
void remove(EntityObject objectToRemove)
Remove an object from the database
void replicate(Object objectToReplicate)
Replicate the object.
void save(EntityObject objectToSave)
Save an object.
void saveRaw(EntityObject objectToSave)
Save the object without updateModificationData being called.
void setIndexer(Indexer indexer)
Protected Methods
List findNamedQuery(String queryName, boolean cacheable, int maxResultCount)
List findNamedQuery(String queryName)
TODO Deprecate these method variants and use findNamedQueryStringParams(String, boolean, int, int, Object[]).
List findNamedQuery(String queryName, boolean cacheable)
List findNamedQueryStringParam(String queryName, String paramName, Object paramValue)
List findNamedQueryStringParam(String queryName, String paramName, Object paramValue, boolean cacheable)
List findNamedQueryStringParam(String queryName, String paramName, Object paramValue, boolean cacheable, int maxResultCount)
List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, boolean cacheable, int maxResultCount)
List findNamedQueryStringParams(String queryName, boolean cacheable, int offset, int maxResultCount, Object... paramNamesAndValues)
List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, boolean cacheable, int maxResultCount)
List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value)
List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, boolean cacheable)
List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, String param4Name, Object param4Value, boolean cacheable, int maxResultCount)
List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, String param4Name, Object param4Value, boolean cacheable)
List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, String param4Name, Object param4Value)
List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value)
List findNamedQueryStringParams(String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, boolean cacheable)
<T extends EntityObject> T findSingleObject(List<T> results)
EntityObject getByClassId(long id)
Retrieve the object with a particular id from the database.
int getCountResult(List<Integer> results)
void index(EntityObject objectToSave)
void reIndex(EntityObject objectToSave)
void unIndex(EntityObject objectToSave, boolean unindexDependents)
void updateModificationData(EntityObject objectToSave)
Perform any modifications that need to be done to an object every time it is saved.
[Expand]
Inherited Methods
From class org.springframework.orm.hibernate.support.HibernateDaoSupport
From class org.springframework.dao.support.DaoSupport
From class java.lang.Object
From interface bucket.core.persistence.ObjectDao
From interface org.springframework.beans.factory.InitializingBean

Fields

protected static final Logger log

Public Constructors

public HibernateObjectDao ()

Public Methods

public List 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

public List findAllSorted (String sortField, boolean cacheable, int offset, int maxResultCount)

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.

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.

public List findAllSorted (String sortField)

Find all objects currently persisted of a particular type and sort results by named property.

Parameters
sortField the name of the property to be sorted on. This should be null if no sorting is required.

public void refresh (EntityObject objectToRefresh)

Update the stat of an object based on the current state of the database. The object will be modified in place

Parameters
objectToRefresh the object to refresh

public void remove (EntityObject objectToRemove)

Remove an object from the database

Parameters
objectToRemove the object to remove

public void replicate (Object objectToReplicate)

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.

public void save (EntityObject objectToSave)

Save an object. The object's last-modified time will be updated, and if the object is searchable it will be indexed.

public void saveRaw (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.

Parameters
objectToSave object to save

public void setIndexer (Indexer indexer)

Protected Methods

protected List findNamedQuery (String queryName, boolean cacheable, int maxResultCount)

protected List findNamedQuery (String queryName)

TODO Deprecate these method variants and use findNamedQueryStringParams(String, boolean, int, int, Object[]).

protected List findNamedQuery (String queryName, boolean cacheable)

protected List findNamedQueryStringParam (String queryName, String paramName, Object paramValue)

protected List findNamedQueryStringParam (String queryName, String paramName, Object paramValue, boolean cacheable)

protected List findNamedQueryStringParam (String queryName, String paramName, Object paramValue, boolean cacheable, int maxResultCount)

protected List findNamedQueryStringParams (String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, boolean cacheable, int maxResultCount)

protected List findNamedQueryStringParams (String queryName, boolean cacheable, int offset, int maxResultCount, Object... paramNamesAndValues)

protected List findNamedQueryStringParams (String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, boolean cacheable, int maxResultCount)

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)

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)

protected List findNamedQueryStringParams (String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, String param4Name, Object param4Value, boolean cacheable)

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)

protected List findNamedQueryStringParams (String queryName, String paramName, Object paramValue, String param2Name, Object param2Value, String param3Name, Object param3Value, boolean cacheable)

protected T findSingleObject (List<T> results)

protected EntityObject 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.

protected int getCountResult (List<Integer> results)

protected void index (EntityObject objectToSave)

protected void reIndex (EntityObject objectToSave)

protected void unIndex (EntityObject objectToSave, boolean unindexDependents)

protected void updateModificationData (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