public abstract class BaseEntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,EB extends Entity.EntityBuilder<T,P,E,EB>,Q extends EntityQuery,QB extends EntityQuery.EntityQueryBuilder<Q,QB>,OC extends EntityOperandContainer<T,P>,W extends EntityModification<T,P,E,EB>,WB extends EntityModification.EntityModificationBuilder<T,P,E,EB,W,WB>,A extends EntityActionEvent<E,WB>,L extends EntityActionListener<A>,M extends EntityManager<T,P,E,EB,Q,QB,OC,W,WB>,PROV extends EntityProvider<P,?>,PERS extends EntityPersistence<T,E,Q>> extends Object implements EntityService<T,P,E,Q>
Modifier | Constructor and Description |
---|---|
protected |
BaseEntityService(M manager,
List<PROV> providers,
PERS persistence,
PredicatePostProcessor<E> predicatePostProcessor,
List<L> actionListeners,
CurrentTenantService currentTenantService,
CurrentUserService currentUserService,
EntityAuditHandler auditHandler,
Registry serviceRegistry,
LifeCycle lifeCycle,
TimeProvider timeProvider) |
Modifier and Type | Method and Description |
---|---|
void |
addActionListener(L listener) |
T |
addEntity(E entity,
String description)
Adds the given ad-hoc entity.
|
GlobalId |
addEntityGeneric(E entity,
String description)
Adds the given ad-hoc work entity and returns the persisted global id.
|
T |
addEntityGivenByProvider(E entity,
boolean skipDuplicates,
String description)
Adds the given entity that comes from a provider, after converting all references to other entities from external ids to primary ids.
|
protected E |
addValidatedEntity(E entity,
String description) |
protected E |
adjustEntityGivenByProvider(E entity) |
long |
countEntities(Predicate predicate)
Counts the entities that match the query with the given predicate.
|
long |
countEntities(Predicate predicate,
SearchScope searchScope)
Counts the entities that match the query with the given predicate in the given scope.
|
long |
countEntities(Q query)
Counts the entities that match the given query.
|
long |
countEntities(Q query,
SearchScope searchScope)
Counts the entities that match the given query in the given scope.
|
protected abstract A |
createActionEvent(EntityActionEvent.Type eventType,
E oldEntity,
E newEntity,
WB modificationBuilder,
String description) |
protected E |
ensureExternalIdIsDefined(E entity) |
protected E |
ensureGlobalIdIsDefined(E entity) |
protected E |
ensureIdIsDefined(E entity) |
List<E> |
findEntities(Predicate predicate)
Finds the entities that match the query with the given predicate.
|
List<E> |
findEntities(Predicate predicate,
SearchScope searchScope)
Finds the entities that match the query with the given predicate in the given scope.
|
List<E> |
findEntities(Q query)
Finds the entities that match the given query.
|
List<E> |
findEntities(Q query,
SearchScope searchScope)
Finds the entities that match the given query in the given scope.
|
E |
findEntity(Predicate predicate)
Finds the entity that matches the query with the given predicate.
|
E |
findEntity(Predicate predicate,
SearchScope searchScope)
Finds the entity that matches the query with the given predicate in the given scope.
|
E |
findEntity(Q query)
Finds the entity that matches the given query.
|
E |
findEntity(Q query,
SearchScope searchScope)
Finds the entity that matches the given query in the given scope.
|
E |
findEntityByExternalId(T externalId)
Finds the entity with the given external entity id.
|
E |
findEntityByExternalId(T externalId,
SearchScope searchScope)
Finds the entity with the given external entity id in the given scope.
|
E |
findEntityByGlobalId(GlobalId globalId)
Finds the entity with the given global id.
|
E |
findEntityByGlobalId(GlobalId globalId,
SearchScope searchScope)
Finds the entity with the given entity global id in the given scope.
|
E |
findEntityById(T entityId)
Finds the entity with the given entity id.
|
E |
findEntityById(T entityId,
SearchScope searchScope)
Finds the entity with the given entity id in the given scope.
|
T |
findExternalIdByGlobalId(GlobalId globalId)
Returns the external id of the entity with the given id.
|
T |
findExternalIdByGlobalId(GlobalId globalId,
SearchScope searchScope)
Returns the external id of the entity with the given id in the given scope.
|
T |
findExternalIdById(T id)
Returns the external id of the entity with the given id.
|
T |
findExternalIdById(T id,
SearchScope searchScope)
Returns the external id of the entity with the given id in the given scope.
|
GlobalId |
findGlobalIdByExternalId(T externalId)
Returns the global id of the entity with the given external id in the given scope.
|
GlobalId |
findGlobalIdByExternalId(T externalId,
SearchScope searchScope)
Returns the global id of the entity with the given external id in the given scope.
|
T |
findIdByExternalId(T externalId)
Returns the id of the entity with the given external id.
|
T |
findIdByExternalId(T externalId,
SearchScope searchScope)
Returns the id of the entity with the given external id in the given scope.
|
protected E |
findNonNullEntityByGlobalId(GlobalId globalId) |
protected E |
findNonNullEntityById(T entityId) |
protected com.google.common.base.Optional<PROV> |
findProvider(P providerIdToMatch) |
protected EntityAuditHandler |
getAuditHandler() |
protected TenantId |
getCurrentTenantId() |
protected UserId |
getCurrentUserId() |
protected T |
getDefinedExternalId(E entity,
T defaultId) |
protected GlobalId |
getDefinedGlobalId(E entity) |
protected T |
getDefinedId(E entity) |
E |
getEntityByGlobalId(GlobalId globalId)
Finds the entity with the given entity id.
|
E |
getEntityByGlobalId(GlobalId globalId,
SearchScope searchScope)
Finds the entity with the given entity id in the given scope.
|
E |
getEntityById(T entityId)
Finds the entity with the given entity id.
|
E |
getEntityById(T entityId,
SearchScope searchScope)
Finds the entity with the given entity id in the given scope.
|
protected LifeCycle |
getLifeCycle() |
protected M |
getManager() |
protected PERS |
getPersistence() |
protected List<PROV> |
getProviders() |
protected Registry |
getServiceRegistry() |
protected TenantId |
getSharedTenantId() |
protected TimeProvider |
getTimeProvider() |
void |
init()
Life-cycle method to initialize the service before using the service for the first time.
|
protected T |
insertEntityAndSendChangeEvents(E entity) |
protected boolean |
isMultiTenant() |
protected abstract void |
notifyProviders(E entity,
Set<FieldChange> fieldChanges) |
protected E |
performInsert(E entity,
String description) |
void |
removeActionListener(L listener) |
protected void |
sendActionPerformedEvent(EntityActionEvent.Type eventType,
E oldEntity,
E newEntity,
String description) |
protected void |
sendActionWillBePerformedEvent(EntityActionEvent.Type eventType,
E oldEntity,
E newEntity,
WB modificationBuilder,
String description) |
protected WB |
sendActionWillBePerformedEvent(EntityActionEvent.Type eventType,
E oldEntity,
E complexNewEntity,
W newModification,
String description) |
protected WB |
sendActionWillBePerformedEvent(EntityActionEvent.Type eventType,
E newEntity,
String description) |
protected W |
sendActionWillBePerformedEvent(EntityActionEvent.Type eventType,
E oldEntity,
W newModification,
String description) |
protected abstract E |
trimNonPersistentData(E entity) |
protected abstract void |
updateEntitySpecificCalculatedFieldsBeforeInsert(E newEntity,
EB builder) |
protected abstract void |
validateEntityToAdd(E entity) |
protected BaseEntityService(M manager, List<PROV> providers, PERS persistence, PredicatePostProcessor<E> predicatePostProcessor, List<L> actionListeners, CurrentTenantService currentTenantService, CurrentUserService currentUserService, EntityAuditHandler auditHandler, Registry serviceRegistry, LifeCycle lifeCycle, TimeProvider timeProvider)
protected M getManager()
protected PERS getPersistence()
protected TenantId getCurrentTenantId()
protected TenantId getSharedTenantId()
protected boolean isMultiTenant()
protected UserId getCurrentUserId()
protected EntityAuditHandler getAuditHandler()
protected Registry getServiceRegistry()
protected LifeCycle getLifeCycle()
public void init()
Service
public T findExternalIdById(T id)
EntityService
findExternalIdById
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
id
- the id of the entitypublic T findExternalIdById(T id, SearchScope searchScope)
EntityService
findExternalIdById
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
id
- the id of the entitysearchScope
- the scope in which to search for the external idpublic T findExternalIdByGlobalId(GlobalId globalId)
EntityService
findExternalIdByGlobalId
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
globalId
- the global id of the entitypublic T findExternalIdByGlobalId(GlobalId globalId, SearchScope searchScope)
EntityService
findExternalIdByGlobalId
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
globalId
- the global id of the entitysearchScope
- the scope in which to search for the external idpublic T findIdByExternalId(T externalId)
EntityService
findIdByExternalId
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
externalId
- the external id of the entitypublic T findIdByExternalId(T externalId, SearchScope searchScope)
EntityService
findIdByExternalId
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
externalId
- the external id of the entitysearchScope
- the scope in which to search for the idpublic GlobalId findGlobalIdByExternalId(T externalId)
EntityService
findGlobalIdByExternalId
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
externalId
- the external id of the entitypublic GlobalId findGlobalIdByExternalId(T externalId, SearchScope searchScope)
EntityService
findGlobalIdByExternalId
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
externalId
- the external id of the entitysearchScope
- the scope in which to search for the idpublic E getEntityById(T entityId)
EntityService
getEntityById
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
entityId
- the id of the entity to findpublic E getEntityById(T entityId, SearchScope searchScope)
EntityService
getEntityById
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
entityId
- the id of the entity to findsearchScope
- the scope in which to search for the entitypublic E getEntityByGlobalId(GlobalId globalId)
EntityService
getEntityByGlobalId
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
globalId
- the global id of the entity to findpublic E getEntityByGlobalId(GlobalId globalId, SearchScope searchScope)
EntityService
getEntityByGlobalId
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
globalId
- the global id of the entity to findsearchScope
- the scope in which to search for the entitypublic E findEntityById(T entityId)
EntityService
findEntityById
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
entityId
- the id of the entity to findpublic E findEntityById(T entityId, SearchScope searchScope)
EntityService
findEntityById
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
entityId
- the id of the entity to findsearchScope
- the scope in which to search for the entitypublic E findEntityByGlobalId(GlobalId globalId)
EntityService
findEntityByGlobalId
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
globalId
- the global id of the entity to findpublic E findEntityByGlobalId(GlobalId globalId, SearchScope searchScope)
EntityService
findEntityByGlobalId
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
globalId
- the global id of the entity to findsearchScope
- the scope in which to search for the entity (all-tenant scopes are not supported)public E findEntityByExternalId(T externalId)
EntityService
findEntityByExternalId
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
externalId
- the external id of the entity to findpublic E findEntityByExternalId(T externalId, SearchScope searchScope)
EntityService
findEntityByExternalId
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
externalId
- the external id of the entity to findsearchScope
- the scope in which to search for the entitypublic E findEntity(Predicate predicate)
EntityService
Note: No sorting, paging, nor query hints are applied. This can become a potential query performance issue.
findEntity
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
predicate
- the predicate to apply when executing the querypublic E findEntity(Predicate predicate, SearchScope searchScope)
EntityService
Note: No sorting, paging, nor query hints are applied. This can become a potential query performance issue.
findEntity
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
predicate
- the predicate to apply when executing the querysearchScope
- the scope in which to search for the entitypublic List<E> findEntities(Predicate predicate)
EntityService
Note: No sorting, paging, nor query hints are applied. This can become a potential query performance issue.
findEntities
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
predicate
- the predicate to apply when executing the querypublic List<E> findEntities(Predicate predicate, SearchScope searchScope)
EntityService
Note: No sorting, paging, nor query hints are applied. This can become a potential query performance issue.
findEntities
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
predicate
- the predicate to apply when executing the querysearchScope
- the scope in which to search for the entitiespublic long countEntities(Predicate predicate)
EntityService
countEntities
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
predicate
- the predicate to apply when executing the querypublic long countEntities(Predicate predicate, SearchScope searchScope)
EntityService
countEntities
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
predicate
- the predicate to apply when executing the querysearchScope
- the scope in which to count the number of entitiespublic E findEntity(Q query)
EntityService
findEntity
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
query
- the query to executepublic E findEntity(Q query, SearchScope searchScope)
EntityService
findEntity
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
query
- the query to executesearchScope
- the scope in which to search for the entitypublic List<E> findEntities(Q query)
EntityService
findEntities
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
query
- the query to executepublic List<E> findEntities(Q query, SearchScope searchScope)
EntityService
findEntities
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
query
- the query to executesearchScope
- the scope in which to search for the entitiespublic long countEntities(Q query)
EntityService
countEntities
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
query
- the query to executepublic long countEntities(Q query, SearchScope searchScope)
EntityService
countEntities
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
query
- the query to executesearchScope
- the scope in which to count number of entitiespublic final T addEntity(E entity, String description)
EntityService
public final GlobalId addEntityGeneric(E entity, String description)
EntityService
If the global id is not set, a new global id is generated by the persistence component of the system and guaranteed to be unique. In all other cases, the contributor of the work object needs to ensure that the global id is unique within the tenant.
addEntityGeneric
in interface EntityService<T extends EntityId,P extends Id,E extends Entity<T,P>,Q extends EntityQuery>
entity
- the ad-hoc work object to adddescription
- transient meta information regarding the reason to add the ad-hoc work objectprotected abstract void validateEntityToAdd(E entity)
protected abstract void updateEntitySpecificCalculatedFieldsBeforeInsert(E newEntity, EB builder)
public final T addEntityGivenByProvider(E entity, boolean skipDuplicates, String description)
entity
- the entity that comes from a provider to addskipDuplicates
- if true and entity is already persisted, abort silentlydescription
- transient meta information regarding the reason to add the entity that comes from a providerprotected abstract void notifyProviders(E entity, Set<FieldChange> fieldChanges)
protected final WB sendActionWillBePerformedEvent(EntityActionEvent.Type eventType, E newEntity, String description)
protected final WB sendActionWillBePerformedEvent(EntityActionEvent.Type eventType, E oldEntity, E complexNewEntity, W newModification, String description)
protected final W sendActionWillBePerformedEvent(EntityActionEvent.Type eventType, E oldEntity, W newModification, String description)
protected final void sendActionWillBePerformedEvent(EntityActionEvent.Type eventType, E oldEntity, E newEntity, WB modificationBuilder, String description)
protected final void sendActionPerformedEvent(EntityActionEvent.Type eventType, E oldEntity, E newEntity, String description)
protected abstract A createActionEvent(EntityActionEvent.Type eventType, E oldEntity, E newEntity, WB modificationBuilder, String description)
public void addActionListener(L listener)
public void removeActionListener(L listener)
protected TimeProvider getTimeProvider()
Copyright © 2010 - 2018 edorasware ag. All Rights Reserved.