eu.etaxonomy.cdm.persistence.dao.hibernate.common
Class CdmEntityDaoBase<T extends CdmBase>

java.lang.Object
  extended by eu.etaxonomy.cdm.persistence.dao.hibernate.common.DaoBase
      extended by eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase<T>
All Implemented Interfaces:
ICdmEntityDao<T>
Direct Known Subclasses:
CdmGenericDaoImpl, FeatureDaoImpl, GrantedAuthorityDaoImpl, GroupDaoImpl, HomotypicalGroupDaoHibernateImpl, LsidAuthorityDaoImpl, MediaRepresentationHibernateImpl, MediaRepresentationPartHibernateImpl, OrderedTermVocabularyDaoImpl, OriginalSourceDaoImpl, ReferencedEntityDaoImpl, StatisticalMeasurementValueDaoImpl, UserDaoImpl, VersionableDaoBase

@Repository
public abstract class CdmEntityDaoBase<T extends CdmBase>
extends DaoBase
implements ICdmEntityDao<T>

Author:
a.mueller FIXME CdmEntityDaoBase is abstract, can it be annotated with @Repository?

Field Summary
protected  IBeanInitializer defaultBeanInitializer
           
protected  int flushAfterNo
           
protected  Class<T> type
           
protected  org.apache.lucene.util.Version version
           
 
Constructor Summary
CdmEntityDaoBase(Class<T> type)
           
 
Method Summary
protected  void addCriteria(org.hibernate.Criteria criteria, List<org.hibernate.criterion.Criterion> criterion)
           
protected  void addExample(org.hibernate.Criteria criteria, T example, Set<String> includeProperties)
           
protected  void addGroups(org.hibernate.Criteria criteria, List<Grouping> groups)
           
protected  void addOrder(org.hibernate.search.FullTextQuery fullTextQuery, List<OrderHint> orderHints)
           
 void clear()
           
 int count()
           
 int count(Class<? extends T> clazz)
          Returns the number of objects of type - which must extend T
 int count(T example, Set<String> includeProperties)
          Method that counts the number of objects matching the example provided.
protected  int countByParam(Class<? extends T> clazz, String param, String queryString, MatchMode matchmode, List<org.hibernate.criterion.Criterion> criterion)
           
protected  void countGroups(org.hibernate.criterion.DetachedCriteria criteria, List<Grouping> groups)
           
 UUID delete(T persistentObject)
           
 Boolean exists(UUID uuid)
           
 T findById(int id)
           
protected  List<T> findByParam(Class<? extends T> clazz, String param, String queryString, MatchMode matchmode, List<org.hibernate.criterion.Criterion> criterion, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths)
           
 T findByUuid(UUID uuid)
           
 org.hibernate.Session getSession()
           
 Class<T> getType()
          Convenience method which makes it easy to discover what type of object this DAO returns at runtime
 List<Object[]> group(Class<? extends T> clazz, Integer limit, Integer start, List<Grouping> groups, List<String> propertyPaths)
          Returns a sublist of objects matching the grouping projections supplied using the groups parameter It would be nice to have an equivalent countGroups method, but for the moment hibernate doesn't seem to support this (HHH-3238 - impossible to get the rowcount for a criteria that has projections)
 List<T> list(Class<? extends T> type, Integer limit, Integer start)
          Returns a sublist of CdmBase instances of type stored in the database.
 List<T> list(Class<? extends T> type, Integer limit, Integer start, List<OrderHint> orderHints)
           
 List<T> list(Class<? extends T> clazz, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths)
          Returns a sublist of CdmBase instances stored in the database.
 List<T> list(Collection<UUID> uuids, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths)
           
 List<T> list(Integer limit, Integer start)
          Returns a sublist of CdmBase instances stored in the database.
 List<T> list(Integer limit, Integer start, List<OrderHint> orderHints)
          Returns a sublist of CdmBase instances stored in the database.
 List<T> list(Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths)
          Returns a sublist of CdmBase instances stored in the database.
 List<T> list(T example, Set<String> includeProperties, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths)
          Method that lists the objects matching the example provided.
 List<T> listByIds(Collection<Integer> ids, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths)
           
 T load(int id, List<String> propertyPaths)
          Finds the cdm entity specified by the id parameter and recursively initializes all bean properties given in the propertyPaths parameter.
 T load(UUID uuid)
          Finds the cdm entity specified by the uuid parameter and initializes all its *ToOne relations.
 T load(UUID uuid, List<String> propertyPaths)
          Finds the cdm entity specified by the uuid parameter and recursively initializes all bean properties given in the propertyPaths parameter.
 void lock(T t, org.hibernate.LockMode lockMode)
          Obtains the specified LockMode on the supplied object
 T merge(T transientObject)
           
 UUID refresh(T persistentObject)
           
 void refresh(T t, org.hibernate.LockMode lockMode, List<String> propertyPaths)
          Refreshes the state of the supplied object using the given LockMode (e.g.
 T replace(T x, T y)
          Globally replace all references to instance t1 with t2 (including NOTE: This replaces all non-bidirectional relationships where type T is on the "owning" side of the relationship (since the "owned" objects are, in theory, sub-components of the entity and this kind of global replace doesn't really make sense Consequently it is a good idea to either map such owned relationships with cascading semantics (i.e.
 List<T> rows(String tableName, int limit, int start)
           
 UUID save(T newInstance)
           
 Map<UUID,T> saveAll(Collection<T> cdmObjCollection)
           
 UUID saveCdmObj(CdmBase cdmObj)
           
 UUID saveOrUpdate(T transientObject)
           
 Map<UUID,T> saveOrUpdateAll(Collection<T> cdmObjCollection)
           
 void setDefaultBeanInitializer(IBeanInitializer defaultBeanInitializer)
           
protected  void setPagingParameter(org.hibernate.envers.query.AuditQuery query, Integer pageSize, Integer pageNumber)
           
protected  void setPagingParameter(org.hibernate.Query query, Integer pageSize, Integer pageNumber)
           
 UUID update(T transientObject)
           
 
Methods inherited from class eu.etaxonomy.cdm.persistence.dao.hibernate.common.DaoBase
addOrder, flush, getSessionFactory, setSessionFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface eu.etaxonomy.cdm.persistence.dao.common.ICdmEntityDao
flush
 

Field Detail

flushAfterNo

protected int flushAfterNo

type

protected Class<T extends CdmBase> type

version

protected org.apache.lucene.util.Version version

defaultBeanInitializer

@Autowired
protected IBeanInitializer defaultBeanInitializer
Constructor Detail

CdmEntityDaoBase

public CdmEntityDaoBase(Class<T> type)
Method Detail

setDefaultBeanInitializer

public void setDefaultBeanInitializer(IBeanInitializer defaultBeanInitializer)

lock

public void lock(T t,
                 org.hibernate.LockMode lockMode)
Description copied from interface: ICdmEntityDao
Obtains the specified LockMode on the supplied object

Specified by:
lock in interface ICdmEntityDao<T extends CdmBase>

refresh

public void refresh(T t,
                    org.hibernate.LockMode lockMode,
                    List<String> propertyPaths)
Description copied from interface: ICdmEntityDao
Refreshes the state of the supplied object using the given LockMode (e.g. use LockMode.READ to bypass the second-level cache and session cache and query the database directly) All bean properties given in the propertyPaths parameter are recursively initialized.

For detailed description and examples please refer to: IBeanInitializer.initialize(Object, List)

Specified by:
refresh in interface ICdmEntityDao<T extends CdmBase>

saveCdmObj

public UUID saveCdmObj(CdmBase cdmObj)
                throws org.springframework.dao.DataAccessException
Throws:
org.springframework.dao.DataAccessException

saveAll

public Map<UUID,T> saveAll(Collection<T> cdmObjCollection)
Specified by:
saveAll in interface ICdmEntityDao<T extends CdmBase>

saveOrUpdateAll

public Map<UUID,T> saveOrUpdateAll(Collection<T> cdmObjCollection)
Specified by:
saveOrUpdateAll in interface ICdmEntityDao<T extends CdmBase>

replace

public T replace(T x,
                 T y)
Description copied from interface: ICdmEntityDao
Globally replace all references to instance t1 with t2 (including NOTE: This replaces all non-bidirectional relationships where type T is on the "owning" side of the relationship (since the "owned" objects are, in theory, sub-components of the entity and this kind of global replace doesn't really make sense Consequently it is a good idea to either map such owned relationships with cascading semantics (i.e. CascadeType.DELETE, @OneToMany(orphanRemoval=true)) allowing them to be saved, updated, and deleted along with the owning entity automatically.

Specified by:
replace in interface ICdmEntityDao<T extends CdmBase>
Parameters:
x - the object to replace, must not be null
y - the object that will replace. If y is null, then x will be removed from all collections and all properties that refer to x will be replaced with null
Returns:
T the replaced object

getSession

public org.hibernate.Session getSession()
                                 throws org.springframework.dao.DataAccessException
Specified by:
getSession in interface ICdmEntityDao<T extends CdmBase>
Overrides:
getSession in class DaoBase
Throws:
org.springframework.dao.DataAccessException

clear

public void clear()
           throws org.springframework.dao.DataAccessException
Specified by:
clear in interface ICdmEntityDao<T extends CdmBase>
Throws:
org.springframework.dao.DataAccessException

merge

public T merge(T transientObject)
                        throws org.springframework.dao.DataAccessException
Specified by:
merge in interface ICdmEntityDao<T extends CdmBase>
Throws:
org.springframework.dao.DataAccessException

saveOrUpdate

public UUID saveOrUpdate(T transientObject)
                  throws org.springframework.dao.DataAccessException
Specified by:
saveOrUpdate in interface ICdmEntityDao<T extends CdmBase>
Returns:
Throws:
org.springframework.dao.DataAccessException

save

public UUID save(T newInstance)
          throws org.springframework.dao.DataAccessException
Specified by:
save in interface ICdmEntityDao<T extends CdmBase>
Returns:
Throws:
org.springframework.dao.DataAccessException

update

public UUID update(T transientObject)
            throws org.springframework.dao.DataAccessException
Specified by:
update in interface ICdmEntityDao<T extends CdmBase>
Returns:
Throws:
org.springframework.dao.DataAccessException

refresh

public UUID refresh(T persistentObject)
             throws org.springframework.dao.DataAccessException
Specified by:
refresh in interface ICdmEntityDao<T extends CdmBase>
Returns:
Throws:
org.springframework.dao.DataAccessException

delete

public UUID delete(T persistentObject)
            throws org.springframework.dao.DataAccessException
Specified by:
delete in interface ICdmEntityDao<T extends CdmBase>
Returns:
Throws:
org.springframework.dao.DataAccessException

findById

public T findById(int id)
                           throws org.springframework.dao.DataAccessException
Specified by:
findById in interface ICdmEntityDao<T extends CdmBase>
Returns:
Throws:
org.springframework.dao.DataAccessException

findByUuid

public T findByUuid(UUID uuid)
                             throws org.springframework.dao.DataAccessException
Specified by:
findByUuid in interface ICdmEntityDao<T extends CdmBase>
Returns:
Throws:
org.springframework.dao.DataAccessException

listByIds

public List<T> listByIds(Collection<Integer> ids,
                         Integer pageSize,
                         Integer pageNumber,
                         List<OrderHint> orderHints,
                         List<String> propertyPaths)
                                  throws org.springframework.dao.DataAccessException
Specified by:
listByIds in interface ICdmEntityDao<T extends CdmBase>
Returns:
Throws:
org.springframework.dao.DataAccessException

list

public List<T> list(Collection<UUID> uuids,
                    Integer pageSize,
                    Integer pageNumber,
                    List<OrderHint> orderHints,
                    List<String> propertyPaths)
                             throws org.springframework.dao.DataAccessException
Specified by:
list in interface ICdmEntityDao<T extends CdmBase>
Returns:
Throws:
org.springframework.dao.DataAccessException

findByParam

protected List<T> findByParam(Class<? extends T> clazz,
                              String param,
                              String queryString,
                              MatchMode matchmode,
                              List<org.hibernate.criterion.Criterion> criterion,
                              Integer pageSize,
                              Integer pageNumber,
                              List<OrderHint> orderHints,
                              List<String> propertyPaths)

load

public T load(UUID uuid)
Description copied from interface: ICdmEntityDao
Finds the cdm entity specified by the uuid parameter and initializes all its *ToOne relations.

Specified by:
load in interface ICdmEntityDao<T extends CdmBase>
Returns:

load

public T load(int id,
              List<String> propertyPaths)
Description copied from interface: ICdmEntityDao
Finds the cdm entity specified by the id parameter and recursively initializes all bean properties given in the propertyPaths parameter.

For detailed description and examples please refer to: IBeanInitializer.initialize(Object, List)

Specified by:
load in interface ICdmEntityDao<T extends CdmBase>
propertyPaths - properties to be initialized
Returns:

load

public T load(UUID uuid,
              List<String> propertyPaths)
Description copied from interface: ICdmEntityDao
Finds the cdm entity specified by the uuid parameter and recursively initializes all bean properties given in the propertyPaths parameter.

For detailed description and examples please refer to: IBeanInitializer.initialize(Object, List)

Specified by:
load in interface ICdmEntityDao<T extends CdmBase>
propertyPaths - properties to be initialized
Returns:

exists

public Boolean exists(UUID uuid)
Specified by:
exists in interface ICdmEntityDao<T extends CdmBase>
Returns:

count

public int count()
Specified by:
count in interface ICdmEntityDao<T extends CdmBase>

count

public int count(Class<? extends T> clazz)
Description copied from interface: ICdmEntityDao
Returns the number of objects of type - which must extend T

Specified by:
count in interface ICdmEntityDao<T extends CdmBase>
Returns:

list

public List<T> list(Integer limit,
                    Integer start)
Description copied from interface: ICdmEntityDao
Returns a sublist of CdmBase instances stored in the database. A maximum of 'limit' objects are returned, starting at object with index 'start'.

Specified by:
list in interface ICdmEntityDao<T extends CdmBase>
Parameters:
limit - the maximum number of entities returned (can be null to return all entities)
Returns:

group

public List<Object[]> group(Class<? extends T> clazz,
                            Integer limit,
                            Integer start,
                            List<Grouping> groups,
                            List<String> propertyPaths)
Description copied from interface: ICdmEntityDao
Returns a sublist of objects matching the grouping projections supplied using the groups parameter It would be nice to have an equivalent countGroups method, but for the moment hibernate doesn't seem to support this (HHH-3238 - impossible to get the rowcount for a criteria that has projections)

Specified by:
group in interface ICdmEntityDao<T extends CdmBase>
Parameters:
clazz - Restrict the query to objects of a certain class, or null for all objects of type T or subclasses
limit - the maximum number of entities returned (can be null to return all entities)
start - The (0-based) offset from the start of the recordset
groups - The grouping objects representing a projection, plus an optional ordering on that projected property
propertyPaths - paths initialized on the returned objects - only applied to the objects returned from the first grouping
Returns:
a list of arrays of objects, each matching the grouping objects supplied in the parameters.

countGroups

protected void countGroups(org.hibernate.criterion.DetachedCriteria criteria,
                           List<Grouping> groups)

addGroups

protected void addGroups(org.hibernate.Criteria criteria,
                         List<Grouping> groups)

addCriteria

protected void addCriteria(org.hibernate.Criteria criteria,
                           List<org.hibernate.criterion.Criterion> criterion)

addOrder

protected void addOrder(org.hibernate.search.FullTextQuery fullTextQuery,
                        List<OrderHint> orderHints)

list

public List<T> list(Integer limit,
                    Integer start,
                    List<OrderHint> orderHints)
Description copied from interface: ICdmEntityDao
Returns a sublist of CdmBase instances stored in the database. A maximum of 'limit' objects are returned, starting at object with index 'start'.

Specified by:
list in interface ICdmEntityDao<T extends CdmBase>
Parameters:
limit - the maximum number of entities returned (can be null to return all entities)
orderHints - Supports path like orderHints.propertyNames which include *-to-one properties like createdBy.username or authorTeam.persistentTitleCache
Returns:

list

public List<T> list(Integer limit,
                    Integer start,
                    List<OrderHint> orderHints,
                    List<String> propertyPaths)
Description copied from interface: ICdmEntityDao
Returns a sublist of CdmBase instances stored in the database. A maximum of 'limit' objects are returned, starting at object with index 'start'. The bean properties specified by the parameter propertyPaths and recursively initialized for each of the entities in the resultset For detailed description and examples redarding propertyPaths please refer to: IBeanInitializer.initialize(Object, List)

Specified by:
list in interface ICdmEntityDao<T extends CdmBase>
Parameters:
limit - the maximum number of entities returned (can be null to return all entities)
orderHints - Supports path like orderHints.propertyNames which include *-to-one properties like createdBy.username or authorTeam.persistentTitleCache
Returns:

list

public List<T> list(Class<? extends T> clazz,
                    Integer limit,
                    Integer start,
                    List<OrderHint> orderHints,
                    List<String> propertyPaths)
Description copied from interface: ICdmEntityDao
Returns a sublist of CdmBase instances stored in the database. A maximum of 'limit' objects are returned, starting at object with index 'start'.

Specified by:
list in interface ICdmEntityDao<T extends CdmBase>
limit - the maximum number of entities returned (can be null to return all entities)
orderHints - Supports path like orderHints.propertyNames which include *-to-one properties like createdBy.username or authorTeam.persistentTitleCache
Returns:

list

public List<T> list(Class<? extends T> type,
                    Integer limit,
                    Integer start,
                    List<OrderHint> orderHints)

list

public List<T> list(Class<? extends T> type,
                    Integer limit,
                    Integer start)
Description copied from interface: ICdmEntityDao
Returns a sublist of CdmBase instances of type stored in the database. A maximum of 'limit' objects are returned, starting at object with index 'start'.

Specified by:
list in interface ICdmEntityDao<T extends CdmBase>
limit - the maximum number of entities returned (can be null to return all entities)
Returns:

rows

public List<T> rows(String tableName,
                    int limit,
                    int start)
Specified by:
rows in interface ICdmEntityDao<T extends CdmBase>

getType

public Class<T> getType()
Description copied from interface: ICdmEntityDao
Convenience method which makes it easy to discover what type of object this DAO returns at runtime

Specified by:
getType in interface ICdmEntityDao<T extends CdmBase>
Returns:

setPagingParameter

protected void setPagingParameter(org.hibernate.Query query,
                                  Integer pageSize,
                                  Integer pageNumber)

setPagingParameter

protected void setPagingParameter(org.hibernate.envers.query.AuditQuery query,
                                  Integer pageSize,
                                  Integer pageNumber)

count

public int count(T example,
                 Set<String> includeProperties)
Description copied from interface: ICdmEntityDao
Method that counts the number of objects matching the example provided. The includeProperties property is used to specify which properties of the example are used. If includeProperties is null or empty, then all literal properties are used (restrictions are applied as in the Hibernate Query-By-Example API call Example.create(object)). If includeProperties is not empty then only literal properties that are named in the set are used to create restrictions, *PLUS* any *ToOne related entities. Related entities are matched on ID, not by their internal literal values (e.g. the call is criteria.add(Restrictions.eq(property,relatedObject)), not criteria.createCriteria(property).add(Example.create(relatedObject)))

Specified by:
count in interface ICdmEntityDao<T extends CdmBase>
Returns:
a count of matching objects

addExample

protected void addExample(org.hibernate.Criteria criteria,
                          T example,
                          Set<String> includeProperties)

countByParam

protected int countByParam(Class<? extends T> clazz,
                           String param,
                           String queryString,
                           MatchMode matchmode,
                           List<org.hibernate.criterion.Criterion> criterion)

list

public List<T> list(T example,
                    Set<String> includeProperties,
                    Integer limit,
                    Integer start,
                    List<OrderHint> orderHints,
                    List<String> propertyPaths)
Description copied from interface: ICdmEntityDao
Method that lists the objects matching the example provided. The includeProperties property is used to specify which properties of the example are used. If includeProperties is null or empty, then all literal properties are used (restrictions are applied as in the Hibernate Query-By-Example API call Example.create(object)). If includeProperties is not empty then only literal properties that are named in the set are used to create restrictions, *PLUS* any *ToOne related entities. Related entities are matched on ID, not by their internal literal values (e.g. the call is criteria.add(Restrictions.eq(property,relatedObject)), not criteria.createCriteria(property).add(Example.create(relatedObject)))

Specified by:
list in interface ICdmEntityDao<T extends CdmBase>
limit - the maximum number of entities returned (can be null to return all entities)
start - The (0-based) offset from the start of the recordset
orderHints - Supports path like orderHints.propertyNames which include *-to-one properties like createdBy.username or
propertyPaths - paths initialized on the returned objects - only applied to the objects returned from the first grouping
Returns:
a list of matching objects


Copyright © 2007-2013 EDIT. All Rights Reserved.