public abstract class ServiceBase<T extends CdmBase,DAO extends ICdmEntityDao<T>> extends java.lang.Object implements IService<T>, org.springframework.context.ApplicationContextAware
Modifier and Type | Field and Description |
---|---|
protected org.springframework.context.ApplicationContext |
appContext |
protected DAO |
dao |
static boolean |
INCLUDE_UNPUBLISHED |
static boolean |
NO_UNPUBLISHED |
Constructor and Description |
---|
ServiceBase() |
Modifier and Type | Method and Description |
---|---|
protected void |
checkPublished(IPublishable publishable,
boolean includeUnpublished,
java.lang.String message)
Throws an exception if the publishable entity should not be published.
|
void |
clear() |
int |
count(java.lang.Class<? extends T> clazz)
Returns a count of all entities of type
|
DeleteResult |
delete(java.util.Collection<java.util.UUID> persistentObjectUUIDs)
Deletes a collection of persistent objects correponding to the
given list of uuids.
|
DeleteResult |
delete(T persistentObject) |
DeleteResult |
delete(java.util.UUID persistentObjectUUID)
Delete an existing persistent object
|
boolean |
exists(java.util.UUID uuid)
Returns true if an entity of type
|
<S extends T> |
find(java.lang.Class<S> clazz,
java.util.Set<java.util.UUID> uuidSet)
Return a list of persisted entities that match the unique identifier
set supplied as an argument and that do match the supplied class.
|
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
|
java.util.List<T> |
find(java.util.Set<java.util.UUID> uuidSet)
Return a list of persisted entities that match the unique identifier
set supplied as an argument
|
T |
find(java.util.UUID uuid)
Return a persisted entity that matches the unique identifier
supplied as an argument, or null if the entity does not exist
|
java.util.List<T> |
findById(java.util.Set<java.lang.Integer> idSet)
Returns a
List of persisted entities that match the database identifiers. |
T |
findWithoutFlush(java.util.UUID uuid)
Return a persisted entity that matches the unique identifier
supplied as an argument, or null if the entity does not exist.
|
org.hibernate.Session |
getSession() |
java.util.List<java.lang.Object[]> |
group(java.lang.Class<? extends T> clazz,
java.lang.Integer limit,
java.lang.Integer start,
java.util.List<Grouping> groups,
java.util.List<java.lang.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)
|
<S extends T> |
list(java.lang.Class<S> type,
java.lang.Integer limit,
java.lang.Integer start,
java.util.List<OrderHint> orderHints,
java.util.List<java.lang.String> propertyPaths)
Returns a list of entities of type
|
<S extends T> |
list(S example,
java.util.Set<java.lang.String> includeProperties,
java.lang.Integer limit,
java.lang.Integer start,
java.util.List<OrderHint> orderHints,
java.util.List<java.lang.String> propertyPaths)
Method that lists the objects matching the example provided.
|
T |
load(int id,
java.util.List<java.lang.String> propertyPaths)
Return a persisted entity that matches the database identifier
supplied as an argument, or null if the entity does not exist
|
java.util.List<T> |
load(java.util.List<java.util.UUID> uuids,
java.util.List<java.lang.String> propertyPaths)
Finds the cdm entities specified by the
uuids ,
recursively initializes all bean properties given in the
propertyPaths parameter and returns the initialised
entity list; |
T |
load(java.util.UUID uuid)
Finds the cdm entity specified by the
uuid parameter and
initializes all its *ToOne relations. |
T |
load(java.util.UUID uuid,
java.util.List<java.lang.String> propertyPaths)
Finds the cdm entity specified by the
uuid parameter and
recursively initializes all bean properties given in the
propertyPaths parameter. |
java.util.List<T> |
loadByIds(java.util.List<java.lang.Integer> idList,
java.util.List<OrderHint> orderHints,
java.util.List<java.lang.String> propertyPaths)
Loads a batch of entities referenced by their ids.
|
java.util.List<T> |
loadByIds(java.util.List<java.lang.Integer> idList,
java.util.List<java.lang.String> propertyPaths)
Loads a batch of entities referenced by their ids.
|
T |
loadWithUpdate(java.util.UUID uuid)
Simply calls the load method.
|
void |
lock(T t,
org.hibernate.LockOptions lockOptions)
Obtain the specified lock mode on the given object t
NOTE: with hibernate 4 we changed parameter lockMode to lockOptions. |
java.util.List<T> |
merge(java.util.List<T> detachedObjects)
Merges a list of detached objects and returns the new
list of merged objects
|
java.util.List<MergeResult<T>> |
merge(java.util.List<T> detachedObjects,
boolean returnTransientEntity)
This method allows for the possibility of returning the input transient
entities instead of the merged persistent entity
WARNING : This method should never be used when the objective of the merge
is to attach to an existing session which is the standard use case.
|
T |
merge(T newInstance)
Copy the state of the given object onto the persistent object with the same identifier.
|
MergeResult<T> |
merge(T newInstance,
boolean returnTransientEntity)
This method allows for the possibility of returning the input transient
entity instead of the merged persistent entity
WARNING : This method should never be used when the objective of the merge
is to attach to an existing session which is the standard use case.
|
<S extends T> |
page(java.lang.Class<S> type,
java.lang.Integer pageSize,
java.lang.Integer pageNumber,
java.util.List<OrderHint> orderHints,
java.util.List<java.lang.String> propertyPaths)
Returns a paged list of entities of type
|
<S extends T> |
page(java.lang.Class<S> clazz,
java.util.List<Restriction<?>> restrictions,
java.lang.Integer pageSize,
java.lang.Integer pageIndex,
java.util.List<OrderHint> orderHints,
java.util.List<java.lang.String> propertyPaths) |
<S extends T> |
page(java.lang.Class<S> clazz,
java.lang.String param,
java.lang.String queryString,
MatchMode matchmode,
java.util.List<org.hibernate.criterion.Criterion> criteria,
java.lang.Integer pageSize,
java.lang.Integer pageIndex,
java.util.List<OrderHint> orderHints,
java.util.List<java.lang.String> propertyPaths) |
<S extends T> |
pageByParamWithRestrictions(java.lang.Class<S> clazz,
java.lang.String param,
java.lang.String queryString,
MatchMode matchmode,
java.util.List<Restriction<?>> restrictions,
java.lang.Integer pageSize,
java.lang.Integer pageIndex,
java.util.List<OrderHint> orderHints,
java.util.List<java.lang.String> propertyPaths) |
java.util.UUID |
refresh(T persistentObject)
Re-read the state of the given instance from the underlying database.
|
void |
refresh(T t,
org.hibernate.LockOptions lockOptions,
java.util.List<java.lang.String> propertyPaths)
Refreshes a given object t using the specified lockmode
All bean properties given in the
propertyPaths parameter are recursively initialized. |
java.util.Map<java.util.UUID,T> |
save(java.util.Collection<T> newInstances)
Save a collection containing new entities (persists the entities)
|
T |
save(T newInstance)
Save a new entity (persists the entity)
|
java.util.Map<java.util.UUID,T> |
saveOrUpdate(java.util.Collection<T> transientInstances)
Save new entities or update the persistent state of existing
transient entities that have been persisted previously
|
java.util.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) |
java.util.UUID |
update(T transientObject)
Update the persistent state of an existing transient entity
that has been persisted previously
|
protected org.springframework.context.ApplicationContext appContext
public static final boolean NO_UNPUBLISHED
public static final boolean INCLUDE_UNPUBLISHED
protected DAO extends ICdmEntityDao<T> dao
@Transactional(readOnly=true) public void lock(T t, org.hibernate.LockOptions lockOptions)
IService
@Transactional(readOnly=true) public void refresh(T t, org.hibernate.LockOptions lockOptions, java.util.List<java.lang.String> propertyPaths)
IService
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).
NOTE: with hibernate 4 we changed parameter lockMode to lockOptions. LockOptions can be created from LockMode.
@Transactional(readOnly=false) public void clear()
@Transactional(readOnly=true) public int count(java.lang.Class<? extends T> clazz)
IService
@Transactional(readOnly=false) public DeleteResult delete(java.util.UUID persistentObjectUUID)
IService
@Transactional(readOnly=false) public DeleteResult delete(java.util.Collection<java.util.UUID> persistentObjectUUIDs)
IService
@Transactional(readOnly=false) public DeleteResult delete(T persistentObject)
@Transactional(readOnly=true) public boolean exists(java.util.UUID uuid)
IService
@Transactional(readOnly=true) public java.util.List<T> find(java.util.Set<java.util.UUID> uuidSet)
IService
@Transactional(readOnly=true) public <S extends T> java.util.List<S> find(java.lang.Class<S> clazz, java.util.Set<java.util.UUID> uuidSet)
IService
@Transactional(readOnly=true) public java.util.List<T> findById(java.util.Set<java.lang.Integer> idSet)
IService
List
of persisted entities that match the database identifiers.
Returns an empty list if no identifier matches.@Transactional(readOnly=true) public java.util.List<T> loadByIds(java.util.List<java.lang.Integer> idList, java.util.List<java.lang.String> propertyPaths)
IService
@Transactional(readOnly=true) public java.util.List<T> loadByIds(java.util.List<java.lang.Integer> idList, java.util.List<OrderHint> orderHints, java.util.List<java.lang.String> propertyPaths)
IService
@Transactional(readOnly=true) public T find(java.util.UUID uuid)
IService
@Transactional(readOnly=true) public T findWithoutFlush(java.util.UUID uuid)
IService
The difference between this method and find
is
that this method makes the hibernate read query with the
FlushMode
for the session set to 'MANUAL'
WARNING:This method should ONLY be used when it is absolutely
necessary and safe to ensure that the hibernate session is not flushed before a read
query. A use case for this is the CdmCacher
,
(ticket #4276) where a call to load
the CDM Entity using the standard find
method results in recursion
due to the fact that the find
method triggers a hibernate session
flush which eventually could call getNameCache
,
which in turn (in the event that name cache is null) eventually calls the
load
again.
Apart from these kind of exceptional circumstances, the standard find
method should always be used to ensure that the persistence layer is always in sync with the
underlying database.
findWithoutFlush
in interface IService<T extends CdmBase>
null
@Transactional(readOnly=true) public T find(int id)
IService
@Transactional(readOnly=true) public org.hibernate.Session getSession()
getSession
in interface IService<T extends CdmBase>
@Transactional(readOnly=true) public java.util.List<java.lang.Object[]> group(java.lang.Class<? extends T> clazz, java.lang.Integer limit, java.lang.Integer start, java.util.List<Grouping> groups, java.util.List<java.lang.String> propertyPaths)
IService
group
in interface IService<T extends CdmBase>
clazz
- Restrict the query to objects of a certain class, or null for all objects of type T or subclasseslimit
- 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 propertypropertyPaths
- paths initialized on the returned objects - only applied to the objects returned from the first grouping@Transactional(readOnly=true) public <S extends T> java.util.List<S> list(java.lang.Class<S> type, java.lang.Integer limit, java.lang.Integer start, java.util.List<OrderHint> orderHints, java.util.List<java.lang.String> propertyPaths)
IService
list
in interface IService<T extends CdmBase>
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.persistentTitleCachepropertyPaths
- properties to be initialized@Transactional(readOnly=true) public T load(java.util.UUID uuid)
IService
uuid
parameter and
initializes all its *ToOne relations.@Transactional(readOnly=true) public T loadWithUpdate(java.util.UUID uuid)
IService
loadWithUpdate
in interface IService<T extends CdmBase>
@Transactional(readOnly=true) public T load(int id, java.util.List<java.lang.String> propertyPaths)
IService
@Transactional(readOnly=true) public T load(java.util.UUID uuid, java.util.List<java.lang.String> propertyPaths)
IService
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)
@Transactional(readOnly=true) public java.util.List<T> load(java.util.List<java.util.UUID> uuids, java.util.List<java.lang.String> propertyPaths)
IService
uuids
,
recursively initializes all bean properties given in the
propertyPaths
parameter and returns the initialised
entity list;
For detailed description and examples please refer to:
IBeanInitializer.initialize(Object, List)
@Transactional(readOnly=false) public T merge(T newInstance)
IService
@Transactional(readOnly=false) public MergeResult<T> merge(T newInstance, boolean returnTransientEntity)
IService
@Transactional(readOnly=false) public java.util.List<T> merge(java.util.List<T> detachedObjects)
IService
@Transactional(readOnly=false) public java.util.List<MergeResult<T>> merge(java.util.List<T> detachedObjects, boolean returnTransientEntity)
IService
PostMergeEntityListener.onMerge(MergeEvent,Map)
making the two objects identical and allowing the transient object to be used further
as a POJO@Transactional(readOnly=true) public <S extends T> Pager<S> page(java.lang.Class<S> type, java.lang.Integer pageSize, java.lang.Integer pageNumber, java.util.List<OrderHint> orderHints, java.util.List<java.lang.String> propertyPaths)
IService
page
in interface IService<T extends CdmBase>
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.persistentTitleCachepropertyPaths
- properties to be initialized@Transactional(readOnly=true) public java.util.UUID refresh(T persistentObject)
IService
@Transactional(readOnly=false) public java.util.Map<java.util.UUID,T> save(java.util.Collection<T> newInstances)
IService
@Transactional(readOnly=false) public T save(T newInstance)
IService
@Transactional(readOnly=false) public java.util.UUID saveOrUpdate(T transientObject)
IService
saveOrUpdate
in interface IService<T extends CdmBase>
transientObject
- the entity to be persisted@Transactional(readOnly=false) public java.util.Map<java.util.UUID,T> saveOrUpdate(java.util.Collection<T> transientInstances)
IService
saveOrUpdate
in interface IService<T extends CdmBase>
transientInstances
- the entities to be persistedpublic void setApplicationContext(org.springframework.context.ApplicationContext appContext)
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
protected abstract void setDao(DAO dao)
@Transactional(readOnly=false) public java.util.UUID update(T transientObject)
IService
@Transactional(readOnly=true) public <S extends T> java.util.List<S> list(S example, java.util.Set<java.lang.String> includeProperties, java.lang.Integer limit, java.lang.Integer start, java.util.List<OrderHint> orderHints, java.util.List<java.lang.String> propertyPaths)
IService
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 recordsetorderHints
- Supports path like orderHints.propertyNames
which
include *-to-one properties like createdBy.username orpropertyPaths
- paths initialized on the returned objects - only applied to the objects returned from the first grouping@Transactional(readOnly=true) public <S extends T> Pager<S> page(java.lang.Class<S> clazz, java.lang.String param, java.lang.String queryString, MatchMode matchmode, java.util.List<org.hibernate.criterion.Criterion> criteria, java.lang.Integer pageSize, java.lang.Integer pageIndex, java.util.List<OrderHint> orderHints, java.util.List<java.lang.String> propertyPaths)
@Transactional(readOnly=true) public <S extends T> Pager<S> pageByParamWithRestrictions(java.lang.Class<S> clazz, java.lang.String param, java.lang.String queryString, MatchMode matchmode, java.util.List<Restriction<?>> restrictions, java.lang.Integer pageSize, java.lang.Integer pageIndex, java.util.List<OrderHint> orderHints, java.util.List<java.lang.String> propertyPaths)
pageByParamWithRestrictions
in interface IService<T extends CdmBase>
@Transactional(readOnly=true) public <S extends T> Pager<S> page(java.lang.Class<S> clazz, java.util.List<Restriction<?>> restrictions, java.lang.Integer pageSize, java.lang.Integer pageIndex, java.util.List<OrderHint> orderHints, java.util.List<java.lang.String> propertyPaths)
protected void checkPublished(IPublishable publishable, boolean includeUnpublished, java.lang.String message) throws UnpublishedException
publishable
- the publishable entityincludeUnpublished
- should publish be checkedmessage
- the error message to includeUnpublishedException
- thrown if entity is not public and unpublished should not be includedCopyright © 2007-2020 EDIT. All Rights Reserved.