eu.etaxonomy.cdm.api.service
Class ServiceBase<T extends CdmBase,DAO extends ICdmEntityDao<T>>

java.lang.Object
  extended by eu.etaxonomy.cdm.api.service.ServiceBase<T,DAO>
All Implemented Interfaces:
IService<T>, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware
Direct Known Subclasses:
CommonServiceImpl, GrantedAuthorityServiceImpl, GroupServiceImpl, LocationServiceImpl, ServiceImpl, UserService, VersionableServiceBase

public abstract class ServiceBase<T extends CdmBase,DAO extends ICdmEntityDao<T>>
extends Object
implements IService<T>, org.springframework.context.ApplicationContextAware


Field Summary
protected  org.springframework.context.ApplicationContext appContext
           
protected  DAO dao
           
 
Constructor Summary
ServiceBase()
           
 
Method Summary
 void clear()
           
 int count(Class<? extends T> clazz)
          Returns a count of all entities of type optionally restricted to objects belonging to a class that that extends
 UUID delete(T persistentObject)
          Delete an existing persistent object
 boolean exists(UUID uuid)
          Returns true if an entity of type with a unique identifier matching the identifier supplied exists in the database, or false if no such entity can be found.
 T find(int id)
          Return a persisted entity that matches the database identifier supplied as an argument, or null if the entity does not exist
 List<T> find(Set<UUID> uuidSet)
          Return a list of persisted entities that match the unique identifier set supplied as an argument
 T find(UUID uuid)
          Return a persisted entity that matches the unique identifier supplied as an argument, or null if the entity does not exist
 List<T> findById(Set<Integer> idSet)
          Returns a List of persisted entities that match the database identifiers.
 org.hibernate.Session getSession()
           
 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 be able to return a pager, 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, List<OrderHint> orderHints, List<String> propertyPaths)
          Returns a list of entities of type optionally restricted to objects belonging to a class that that extends
 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.
 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)
          Obtain the specified lock mode on the given object t
 T merge(T newInstance)
          Copy the state of the given object onto the persistent object with the same identifier.
 Pager<T> page(Class<? extends T> type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths)
          Returns a paged list of entities of type optionally restricted to objects belonging to a class that that extends
 UUID refresh(T persistentObject)
          Re-read the state of the given instance from the underlying database.
 void refresh(T t, org.hibernate.LockMode lockMode, List<String> propertyPaths)
          Refreshes a given object t using the specified lockmode All bean properties given in the propertyPaths parameter are recursively initialized.
 List<T> rows(String tableName, int limit, int start)
          FIXME Candidate for harmonization is this method used, and if so, should it be exposed in the service layer? it seems a bit incongruous that we use an ORM to hide the fact that there is a database, then expose a method that talks about "rows" .
 Map<UUID,T> save(Collection<T> newInstances)
          Save a collection containing new entities (persists the entities)
 UUID save(T newInstance)
          Save a new entity (persists the entity)
 Map<UUID,T> saveOrUpdate(Collection<T> transientInstances)
          Save new entities or update the persistent state of existing transient entities that have been persisted previously
 UUID saveOrUpdate(T transientObject)
          Save a new entity or update the persistent state of an existing transient entity that has been persisted previously
 void setApplicationContext(org.springframework.context.ApplicationContext appContext)
           
protected abstract  void setDao(DAO dao)
           
 UUID update(T transientObject)
          Update the persistent state of an existing transient entity that has been persisted previously
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

appContext

protected org.springframework.context.ApplicationContext appContext

dao

protected DAO extends ICdmEntityDao<T> dao
Constructor Detail

ServiceBase

public ServiceBase()
Method Detail

lock

@Transactional(readOnly=true)
public void lock(T t,
                               org.hibernate.LockMode lockMode)
Description copied from interface: IService
Obtain the specified lock mode on the given object t

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

refresh

@Transactional(readOnly=true)
public void refresh(T t,
                                  org.hibernate.LockMode lockMode,
                                  List<String> propertyPaths)
Description copied from interface: IService
Refreshes a given object t using the specified lockmode All bean properties given in the propertyPaths parameter are recursively initialized.

For detailed description and examples please refer to: IBeanInitializer.initialize(Object, List) NOTE: in the case of lockmodes that hit the database (e.g. LockMode.READ), you will need to re-initialize child propertiesto avoid a HibernateLazyInitializationException (even if the properties of the child were initialized prior to the refresh).

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

clear

@Transactional(readOnly=false)
public void clear()
Specified by:
clear in interface IService<T extends CdmBase>

count

@Transactional(readOnly=true)
public int count(Class<? extends T> clazz)
Description copied from interface: IService
Returns a count of all entities of type optionally restricted to objects belonging to a class that that extends

Specified by:
count in interface IService<T extends CdmBase>
Parameters:
clazz - the class of entities to be counted (can be null to count all entities of type )
Returns:
a count of entities

delete

@Transactional(readOnly=false)
public UUID delete(T persistentObject)
Description copied from interface: IService
Delete an existing persistent object

Specified by:
delete in interface IService<T extends CdmBase>
Parameters:
persistentObject - the object to be deleted
Returns:
the unique identifier of the deleted entity

exists

@Transactional(readOnly=true)
public boolean exists(UUID uuid)
Description copied from interface: IService
Returns true if an entity of type with a unique identifier matching the identifier supplied exists in the database, or false if no such entity can be found.

Specified by:
exists in interface IService<T extends CdmBase>
Parameters:
uuid - the unique identifier of the entity required
Returns:
an entity of type matching the uuid, or null if that entity does not exist

find

@Transactional(readOnly=true)
public List<T> find(Set<UUID> uuidSet)
Description copied from interface: IService
Return a list of persisted entities that match the unique identifier set supplied as an argument

Specified by:
find in interface IService<T extends CdmBase>
Parameters:
uuidSet - the set of unique identifiers of the entities required
Returns:
a list of entities of type

findById

@Transactional(readOnly=true)
public List<T> findById(Set<Integer> idSet)
Description copied from interface: IService
Returns a List of persisted entities that match the database identifiers. Returns an empty list if no identifier matches.

Specified by:
findById in interface IService<T extends CdmBase>
Returns:

find

@Transactional(readOnly=true)
public T find(UUID uuid)
Description copied from interface: IService
Return a persisted entity that matches the unique identifier supplied as an argument, or null if the entity does not exist

Specified by:
find in interface IService<T extends CdmBase>
Parameters:
uuid - the unique identifier of the entity required
Returns:
an entity of type , or null if the entity does not exist

find

@Transactional(readOnly=true)
public T find(int id)
Description copied from interface: IService
Return a persisted entity that matches the database identifier supplied as an argument, or null if the entity does not exist

Specified by:
find in interface IService<T extends CdmBase>
Parameters:
id - the database identifier of the entity required
Returns:
an entity of type , or null if the entity does not exist

getSession

@Transactional(readOnly=true)
public org.hibernate.Session getSession()
Specified by:
getSession in interface IService<T extends CdmBase>

group

@Transactional(readOnly=true)
public List<Object[]> group(Class<? extends T> clazz,
                                          Integer limit,
                                          Integer start,
                                          List<Grouping> groups,
                                          List<String> propertyPaths)
Description copied from interface: IService
Returns a sublist of objects matching the grouping projections supplied using the groups parameter It would be nice to be able to return a pager, 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 IService<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 (can be null, equivalent of starting at the beginning 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.

list

@Transactional(readOnly=true)
public List<T> list(Class<? extends T> type,
                                  Integer limit,
                                  Integer start,
                                  List<OrderHint> orderHints,
                                  List<String> propertyPaths)
Description copied from interface: IService
Returns a list of entities of type optionally restricted to objects belonging to a class that that extends

Specified by:
list in interface IService<T extends CdmBase>
Parameters:
type - The type of entities to return (can be null to count all entities of type )
limit - The maximum number of objects returned (can be null for all matching objects)
start - The offset from the start of the result set (0 - based, can be null - equivalent of starting at the beginning of the recordset)
orderHints - Supports path like orderHints.propertyNames which include *-to-one properties like createdBy.username or authorTeam.persistentTitleCache
propertyPaths - properties to be initialized
Returns:

load

@Transactional(readOnly=true)
public T load(UUID uuid)
Description copied from interface: IService
Finds the cdm entity specified by the uuid parameter and initializes all its *ToOne relations.

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

load

@Transactional(readOnly=true)
public T load(UUID uuid,
                            List<String> propertyPaths)
Description copied from interface: IService
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 IService<T extends CdmBase>
Returns:

merge

@Transactional(readOnly=false)
public T merge(T newInstance)
Description copied from interface: IService
Copy the state of the given object onto the persistent object with the same identifier.

Specified by:
merge in interface IService<T extends CdmBase>
Parameters:
newInstance - the entity to be merged
Returns:
The unique identifier of the persisted entity

page

@Transactional(readOnly=true)
public Pager<T> page(Class<? extends T> type,
                                   Integer pageSize,
                                   Integer pageNumber,
                                   List<OrderHint> orderHints,
                                   List<String> propertyPaths)
Description copied from interface: IService
Returns a paged list of entities of type optionally restricted to objects belonging to a class that that extends

Specified by:
page in interface IService<T extends CdmBase>
Parameters:
type - The type of entities to return (can be null to count all entities of type )
pageSize - The maximum number of objects returned (can be null for all matching objects)
pageNumber - The offset (in pageSize chunks) from the start of the result set (0 - based, can be null, equivalent of starting at the beginning of the recordset)
orderHints - Supports path like orderHints.propertyNames which include *-to-one properties like createdBy.username or authorTeam.persistentTitleCache
propertyPaths - properties to be initialized
Returns:
a pager of objects of type

refresh

@Transactional(readOnly=true)
public UUID refresh(T persistentObject)
Description copied from interface: IService
Re-read the state of the given instance from the underlying database. Hibernate claims that it is inadvisable to use refresh in long-running-sessions. I don't really see where we would get into a situation where problems as discussed this forum thread would apply for our scenario http://forum.hibernate.org/viewtopic.php?t=974544

Specified by:
refresh in interface IService<T extends CdmBase>
Parameters:
persistentObject - the object to be refreshed
Returns:
the unique identifier

rows

@Transactional(readOnly=true)
public List<T> rows(String tableName,
                                  int limit,
                                  int start)
FIXME Candidate for harmonization is this method used, and if so, should it be exposed in the service layer? it seems a bit incongruous that we use an ORM to hide the fact that there is a database, then expose a method that talks about "rows" . . .

Specified by:
rows in interface IService<T extends CdmBase>

save

@Transactional(readOnly=false)
public Map<UUID,T> save(Collection<T> newInstances)
Description copied from interface: IService
Save a collection containing new entities (persists the entities)

Specified by:
save in interface IService<T extends CdmBase>
Parameters:
newInstances - the new entities to be persisted
Returns:
A Map containing the new entities, keyed using the generated UUID's of those entities

save

@Transactional(readOnly=false)
public UUID save(T newInstance)
Description copied from interface: IService
Save a new entity (persists the entity)

Specified by:
save in interface IService<T extends CdmBase>
Parameters:
newInstance - the new entity to be persisted
Returns:
A generated UUID for the new persistent entity

saveOrUpdate

@Transactional(readOnly=false)
public UUID saveOrUpdate(T transientObject)
Description copied from interface: IService
Save a new entity or update the persistent state of an existing transient entity that has been persisted previously

Specified by:
saveOrUpdate in interface IService<T extends CdmBase>
Parameters:
transientObject - the entity to be persisted
Returns:
The unique identifier of the persisted entity

saveOrUpdate

@Transactional(readOnly=false)
public Map<UUID,T> saveOrUpdate(Collection<T> transientInstances)
Description copied from interface: IService
Save new entities or update the persistent state of existing transient entities that have been persisted previously

Specified by:
saveOrUpdate in interface IService<T extends CdmBase>
Parameters:
transientInstances - the entities to be persisted
Returns:
The unique identifier of the persisted entity

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext appContext)
Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware

setDao

protected abstract void setDao(DAO dao)

update

@Transactional(readOnly=false)
public UUID update(T transientObject)
Description copied from interface: IService
Update the persistent state of an existing transient entity that has been persisted previously

Specified by:
update in interface IService<T extends CdmBase>
Parameters:
transientObject - the entity to be persisted
Returns:
The unique identifier of the persisted entity

list

@Transactional(readOnly=true)
public List<T> list(T example,
                                  Set<String> includeProperties,
                                  Integer limit,
                                  Integer start,
                                  List<OrderHint> orderHints,
                                  List<String> propertyPaths)
Description copied from interface: IService
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 IService<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.