com.atlassian.hibernate
Class HibernateObjectDao

java.lang.Object
  extended by org.springframework.dao.support.DaoSupport
      extended by org.springframework.orm.hibernate.support.HibernateDaoSupport
          extended by com.atlassian.hibernate.HibernateObjectDao
All Implemented Interfaces:
ObjectDao, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
BodyContentHibernateDao, CachableHibernateObjectDao, DefaultGlobalDescriptionDao, HibernateAttachmentDataDao, HibernateContentPermissionSetDao, HibernateDraftDao, HibernateIndexQueueEntryDao, HibernateLabelDao, HibernateLikeEntityDao, HibernateVersionHistoryDao, VersionedHibernateObjectDao

public abstract class HibernateObjectDao
extends org.springframework.orm.hibernate.support.HibernateDaoSupport
implements ObjectDao

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())


Field Summary
protected static org.apache.log4j.Logger log
          Deprecated. Since 4.0. Use a class-private logger.
 
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
 
Constructor Summary
HibernateObjectDao()
           
 
Method Summary
 java.util.List findAll()
          Find all objects of the class provided by getPersistentClass()
 java.util.List findAllSorted(java.lang.String sortField)
          Find all objects currently persisted of a particular type and sort results by named property.
 java.util.List findAllSorted(java.lang.String sortField, boolean cacheable, int offset, int maxResultCount)
          Find all objects currently persisted of a particular type and sort results by named property.
protected  java.util.List findNamedQuery(java.lang.String queryName)
          TODO Deprecate these method variants and use findNamedQueryStringParams(String,boolean,int,int, Object[]).
protected  java.util.List findNamedQuery(java.lang.String queryName, boolean cacheable)
           
protected  java.util.List findNamedQuery(java.lang.String queryName, boolean cacheable, int maxResultCount)
           
protected  java.util.List findNamedQueryStringParam(java.lang.String queryName, java.lang.String paramName, java.lang.Object paramValue)
           
protected  java.util.List findNamedQueryStringParam(java.lang.String queryName, java.lang.String paramName, java.lang.Object paramValue, boolean cacheable)
           
protected  java.util.List findNamedQueryStringParam(java.lang.String queryName, java.lang.String paramName, java.lang.Object paramValue, boolean cacheable, int maxResultCount)
           
protected  java.util.List findNamedQueryStringParams(java.lang.String queryName, boolean cacheable, int offset, int maxResultCount, java.lang.Object... paramNamesAndValues)
           
protected  java.util.List findNamedQueryStringParams(java.lang.String queryName, java.lang.String paramName, java.lang.Object paramValue, java.lang.String param2Name, java.lang.Object param2Value)
           
protected  java.util.List findNamedQueryStringParams(java.lang.String queryName, java.lang.String paramName, java.lang.Object paramValue, java.lang.String param2Name, java.lang.Object param2Value, boolean cacheable)
           
protected  java.util.List findNamedQueryStringParams(java.lang.String queryName, java.lang.String paramName, java.lang.Object paramValue, java.lang.String param2Name, java.lang.Object param2Value, boolean cacheable, int maxResultCount)
           
protected  java.util.List findNamedQueryStringParams(java.lang.String queryName, java.lang.String paramName, java.lang.Object paramValue, java.lang.String param2Name, java.lang.Object param2Value, java.lang.String param3Name, java.lang.Object param3Value)
           
protected  java.util.List findNamedQueryStringParams(java.lang.String queryName, java.lang.String paramName, java.lang.Object paramValue, java.lang.String param2Name, java.lang.Object param2Value, java.lang.String param3Name, java.lang.Object param3Value, boolean cacheable)
           
protected  java.util.List findNamedQueryStringParams(java.lang.String queryName, java.lang.String paramName, java.lang.Object paramValue, java.lang.String param2Name, java.lang.Object param2Value, java.lang.String param3Name, java.lang.Object param3Value, boolean cacheable, int maxResultCount)
           
protected  java.util.List findNamedQueryStringParams(java.lang.String queryName, java.lang.String paramName, java.lang.Object paramValue, java.lang.String param2Name, java.lang.Object param2Value, java.lang.String param3Name, java.lang.Object param3Value, java.lang.String param4Name, java.lang.Object param4Value)
           
protected  java.util.List findNamedQueryStringParams(java.lang.String queryName, java.lang.String paramName, java.lang.Object paramValue, java.lang.String param2Name, java.lang.Object param2Value, java.lang.String param3Name, java.lang.Object param3Value, java.lang.String param4Name, java.lang.Object param4Value, boolean cacheable)
           
protected  java.util.List findNamedQueryStringParams(java.lang.String queryName, java.lang.String paramName, java.lang.Object paramValue, java.lang.String param2Name, java.lang.Object param2Value, java.lang.String param3Name, java.lang.Object param3Value, java.lang.String param4Name, java.lang.Object param4Value, boolean cacheable, int maxResultCount)
           
protected
<T extends com.atlassian.core.bean.EntityObject>
T
findSingleObject(java.util.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  com.atlassian.core.bean.EntityObject getByClassId(long id)
          Retrieve the object with a particular id from the database.
protected  int getCountResult(java.util.List<java.lang.Integer> results)
           
protected  void index(com.atlassian.core.bean.EntityObject objectToSave)
           
 void refresh(com.atlassian.core.bean.EntityObject objectToRefresh)
          Update the stat of an object based on the current state of the database.
protected  void reIndex(com.atlassian.core.bean.EntityObject objectToSave)
           
 void remove(com.atlassian.core.bean.EntityObject objectToRemove)
          Remove an object from the database
 void replicate(java.lang.Object objectToReplicate)
          Replicate the object.
 void save(com.atlassian.core.bean.EntityObject objectToSave)
          Save an object.
 void saveRaw(com.atlassian.core.bean.EntityObject objectToSave)
          Save the object without updateModificationData being called.
 void setIndexer(com.atlassian.bonnie.Indexer indexer)
           
protected  void unIndex(com.atlassian.core.bean.EntityObject objectToSave, boolean unindexDependents)
           
protected
<T extends com.atlassian.core.bean.EntityObject>
T
uniqueResult(java.util.List<T> results)
          Attempts to select a single result from a list of results.
protected  void updateModificationData(com.atlassian.core.bean.EntityObject objectToSave)
          Perform any modifications that need to be done to an object every time it is saved.
 
Methods inherited from class org.springframework.orm.hibernate.support.HibernateDaoSupport
checkDaoConfig, convertHibernateAccessException, createHibernateTemplate, getHibernateTemplate, getSession, getSession, getSessionFactory, releaseSession, setHibernateTemplate, setSessionFactory
 
Methods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface bucket.core.persistence.ObjectDao
getPersistentClass
 

Field Detail

log

@Deprecated
protected static final org.apache.log4j.Logger log
Deprecated. Since 4.0. Use a class-private logger.
Constructor Detail

HibernateObjectDao

public HibernateObjectDao()
Method Detail

setIndexer

public void setIndexer(com.atlassian.bonnie.Indexer indexer)

getByClassId

protected com.atlassian.core.bean.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.

findAll

public java.util.List findAll()
Find all objects of the class provided by getPersistentClass()

Specified by:
findAll in interface ObjectDao
Returns:
a list of all objects of the appropriate class, or the empty list if no objects are found

findAllSorted

public java.util.List findAllSorted(java.lang.String sortField)
Description copied from interface: ObjectDao
Find all objects currently persisted of a particular type and sort results by named property.

Specified by:
findAllSorted in interface ObjectDao
Parameters:
sortField - the name of the property to be sorted on. This should be null if no sorting is required.

findAllSorted

public java.util.List findAllSorted(java.lang.String sortField,
                                    boolean cacheable,
                                    int offset,
                                    int maxResultCount)
Description copied from interface: ObjectDao
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 interface ObjectDao
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.

save

public void save(com.atlassian.core.bean.EntityObject objectToSave)
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 interface ObjectDao
Parameters:
objectToSave -

updateModificationData

protected void updateModificationData(com.atlassian.core.bean.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

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 interface ObjectDao
Parameters:
objectToSave - object to save

remove

public void remove(com.atlassian.core.bean.EntityObject objectToRemove)
Remove an object from the database

Specified by:
remove in interface ObjectDao
Parameters:
objectToRemove - the object to remove

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 interface ObjectDao
Parameters:
objectToRefresh - the object to refresh

replicate

public void replicate(java.lang.Object objectToReplicate)
Description copied from interface: ObjectDao
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 interface ObjectDao

index

protected void index(com.atlassian.core.bean.EntityObject objectToSave)

reIndex

protected void reIndex(com.atlassian.core.bean.EntityObject objectToSave)

unIndex

protected void unIndex(com.atlassian.core.bean.EntityObject objectToSave,
                       boolean unindexDependents)

findNamedQuery

protected java.util.List findNamedQuery(java.lang.String queryName)
TODO Deprecate these method variants and use findNamedQueryStringParams(String,boolean,int,int, Object[]).


findNamedQuery

protected java.util.List findNamedQuery(java.lang.String queryName,
                                        boolean cacheable)

findNamedQuery

protected java.util.List findNamedQuery(java.lang.String queryName,
                                        boolean cacheable,
                                        int maxResultCount)

findNamedQueryStringParam

protected java.util.List findNamedQueryStringParam(java.lang.String queryName,
                                                   java.lang.String paramName,
                                                   java.lang.Object paramValue)

findNamedQueryStringParam

protected java.util.List findNamedQueryStringParam(java.lang.String queryName,
                                                   java.lang.String paramName,
                                                   java.lang.Object paramValue,
                                                   boolean cacheable)

findNamedQueryStringParam

protected java.util.List findNamedQueryStringParam(java.lang.String queryName,
                                                   java.lang.String paramName,
                                                   java.lang.Object paramValue,
                                                   boolean cacheable,
                                                   int maxResultCount)

findNamedQueryStringParams

protected java.util.List findNamedQueryStringParams(java.lang.String queryName,
                                                    java.lang.String paramName,
                                                    java.lang.Object paramValue,
                                                    java.lang.String param2Name,
                                                    java.lang.Object param2Value)

findNamedQueryStringParams

protected java.util.List findNamedQueryStringParams(java.lang.String queryName,
                                                    java.lang.String paramName,
                                                    java.lang.Object paramValue,
                                                    java.lang.String param2Name,
                                                    java.lang.Object param2Value,
                                                    boolean cacheable)

findNamedQueryStringParams

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

findNamedQueryStringParams

protected java.util.List findNamedQueryStringParams(java.lang.String queryName,
                                                    java.lang.String paramName,
                                                    java.lang.Object paramValue,
                                                    java.lang.String param2Name,
                                                    java.lang.Object param2Value,
                                                    java.lang.String param3Name,
                                                    java.lang.Object param3Value)

findNamedQueryStringParams

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

findNamedQueryStringParams

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

findNamedQueryStringParams

protected java.util.List findNamedQueryStringParams(java.lang.String queryName,
                                                    java.lang.String paramName,
                                                    java.lang.Object paramValue,
                                                    java.lang.String param2Name,
                                                    java.lang.Object param2Value,
                                                    java.lang.String param3Name,
                                                    java.lang.Object param3Value,
                                                    java.lang.String param4Name,
                                                    java.lang.Object param4Value)

findNamedQueryStringParams

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

findNamedQueryStringParams

protected java.util.List findNamedQueryStringParams(java.lang.String queryName,
                                                    java.lang.String paramName,
                                                    java.lang.Object paramValue,
                                                    java.lang.String param2Name,
                                                    java.lang.Object param2Value,
                                                    java.lang.String param3Name,
                                                    java.lang.Object param3Value,
                                                    java.lang.String param4Name,
                                                    java.lang.Object param4Value,
                                                    boolean cacheable,
                                                    int maxResultCount)

findNamedQueryStringParams

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

getCountResult

protected int getCountResult(java.util.List<java.lang.Integer> results)

findSingleObject

@Deprecated
protected <T extends com.atlassian.core.bean.EntityObject> T findSingleObject(java.util.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.

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 <T extends com.atlassian.core.bean.EntityObject> T uniqueResult(java.util.List<T> results)
                                                               throws net.sf.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:
net.sf.hibernate.NonUniqueResultException - If more than one unique objects is found in the list.


Copyright © 2003-2013 Atlassian. All Rights Reserved.