P
- The business domain typepublic class BaseCrudEntityService<P> extends Object implements CrudEntityService<P>
CrudEntityService
can extend from this class as a
convenience to inherit CRUD behavior for a particular business domain type. By default, this
class in turn defers to CrudEntityHelper
in order to allow easier refactoring of core
functionality.
If a service implementation spans several repository types, then it is recommended to inject the
CrudEntityHelper
rather than extend this class.
Constructor and Description |
---|
BaseCrudEntityService(TrackableRepository<T> repository,
CrudEntityHelper helper) |
Modifier and Type | Method and Description |
---|---|
protected P |
convertFromPersistentDomain(Trackable domain,
ContextInfo contextInfo) |
protected Trackable |
convertToPersistentDomain(P businessInstance,
Class<Trackable> persistentType,
ContextInfo contextInfo) |
P |
create(P businessInstance,
ContextInfo context)
Create an instance of an entity based on a business instance containing relavant property
values.
|
List<P> |
createAll(List<P> businessInstances,
ContextInfo context)
Create multiple narrowed instances of an entity at once based on the business instances
containing relevant property values.
|
BulkPersistenceResponse<P> |
createAllAllowingPartialSuccess(List<P> businessInstances,
ContextInfo context)
Creates multiple narrowed instances of an entity at once based on the business instances
containing relevant property values.
|
void |
delete(String id,
ContextInfo context)
Perform a delete operation on the entity identified by the context id.
|
protected CrudEntityHelper |
getHelper() |
protected TrackableRepository<Trackable> |
getRepository() |
protected SortPositionStrategy<P> |
getSortPositionStrategy() |
List<P> |
readAll(ContextInfo context)
Read a list of narrowed instances in the form of the business instance.
|
org.springframework.data.domain.Page<P> |
readAll(org.springframework.data.domain.Pageable pageable,
ContextInfo context)
Read a page of narrowed instances in the form of the business instance.
|
List<P> |
readAll(org.springframework.data.domain.Sort sort,
ContextInfo context)
Read a list of narrowed instances in the form of the business instance.
|
Iterable<P> |
readAllByContextId(Iterable<String> ids,
ContextInfo context)
Retrieve all business instances based on a list of context ids.
|
P |
readByContextId(String id,
ContextInfo context)
Read a single instance of an entity in the form of a business domain.
|
P |
replace(String id,
P businessInstance,
ContextInfo context)
Replace a single, narrowed instance of an entity based on a business instance containing
relevant property values.
|
List<P> |
replaceAll(List<Update<P>> replacements,
ContextInfo context)
Replace multiple narrowed instances of an entity at once based on the business instance
containing relevant property values.
|
BulkPersistenceResponse<P> |
replaceAllAllowingPartialSuccess(List<Update<P>> replacements,
ContextInfo context)
Replace multiple narrowed instances of an entity at once based on the business instances
containing relevant property values.
|
void |
setSortPositionStrategy(SortPositionStrategy<P> sortPositionStrategy) |
P |
update(String id,
P businessInstance,
ContextInfo context)
Update a single, narrowed instance of an entity based on a business instance containing
relevant property values.
|
List<P> |
updateAll(List<Update<P>> updates,
ContextInfo context)
A bulk operation that updates all of the items managed by the backing repository in the form
of the business entity containing property values.
|
BulkPersistenceResponse<P> |
updateAllAllowingPartialSuccess(List<Update<P>> updates,
ContextInfo context)
Updates all of the items managed by the backing repository in the form of the business
instances containing property values.
|
P |
updateSort(SortPositionRequest sortPositionRequest,
ContextInfo context)
Apply a sort field value change
|
public BaseCrudEntityService(TrackableRepository<T> repository, CrudEntityHelper helper)
@Autowired public void setSortPositionStrategy(@Nullable SortPositionStrategy<P> sortPositionStrategy)
public P readByContextId(@NonNull String id, @Nullable ContextInfo context)
CrudEntityService
readByContextId
in interface CrudEntityService<P>
id
- The context id for the entity. This is the id by which the business recognizes the
item.context
- Context information used to discriminate the correct version of an entity by
context id when multiple verions may be available across sandboxes, catalogs and
applications.public Iterable<P> readAllByContextId(@NonNull Iterable<String> ids, @Nullable ContextInfo context)
CrudEntityService
readAllByContextId
in interface CrudEntityService<P>
ids
- A list of context ids for the entitys. This is the id by which the business
recognizes the item.context
- Context information used to discriminate the correct version of an entity by
context id when multiple verions may be available across sandboxes, catalogs and
applications.public org.springframework.data.domain.Page<P> readAll(@NonNull org.springframework.data.domain.Pageable pageable, @Nullable ContextInfo context)
CrudEntityService
readAll
in interface CrudEntityService<P>
pageable
- The current page informationcontext
- Context information used to discriminate the correct version of an entity by
context id when multiple verions may be available across sandboxes, catalogs and
applications.public List<P> readAll(@Nullable ContextInfo context)
CrudEntityService
readAll
in interface CrudEntityService<P>
context
- Context information used to discriminate the correct version of an entity by
context id when multiple verions may be available across sandboxes, catalogs and
applications.public List<P> readAll(@NonNull org.springframework.data.domain.Sort sort, @Nullable ContextInfo context)
CrudEntityService
readAll
in interface CrudEntityService<P>
sort
- The sort to be performed on the resultscontext
- Context information used to discriminate the correct version of an entity by
context id when multiple verions may be available across sandboxes, catalogs and
applications.public P update(@NonNull String id, @NonNull P businessInstance, @Nullable ContextInfo context)
CrudEntityService
TrackableRepository
for more information on entity
persistence behavior in light of sandboxing and multitenant concerns.update
in interface CrudEntityService<P>
id
- The context id for the entity. This is the id by which the business recognizes the
item.businessInstance
- The payload type that domain class should be converted to. In
general, the payload is what the rest API responds with.context
- Context information used to discriminate the correct version of an entity by
context id when multiple verions may be available across sandboxes, catalogs and
applications.EntityMissingException
if not available.CrudEntityService.updateAll(List, ContextInfo)
,
CrudEntityService.updateAllAllowingPartialSuccess(List, ContextInfo)
public List<P> updateAll(@NonNull List<Update<P>> updates, @Nullable ContextInfo context)
CrudEntityService
All items contained within updates
must exist in the backing repository and pass
validation, else the entire batch will fail
For an alternative that allows partial success, see
CrudEntityService.updateAllAllowingPartialSuccess(List, ContextInfo)
.
updateAll
in interface CrudEntityService<P>
updates
- each update to the repository domaincontext
- Context information used to discriminate the correct version of an entity by
context id when multiple verions may be available across sandboxes, catalogs and
applications.EntityMissingException
if not available.CrudEntityService.update(String, Object, ContextInfo)
,
CrudEntityService.updateAllAllowingPartialSuccess(List, ContextInfo)
public BulkPersistenceResponse<P> updateAllAllowingPartialSuccess(List<Update<P>> updates, ContextInfo context)
CrudEntityService
Each item contained within updates
must exist in the backing repository and pass
validation, or it will be added to the failed list in the response and not persisted. All
successfully found and validated items will be persisted.
For an alternative that does not allow partial success, see
CrudEntityService.updateAll(List, ContextInfo)
.
updateAllAllowingPartialSuccess
in interface CrudEntityService<P>
updates
- each update to the repository domaincontext
- Context information used to discriminate the correct version of an entity by
context id when multiple verions may be available across sandboxes, catalogs and
applications.CrudEntityService.updateAll(List, ContextInfo)
public P updateSort(@NonNull SortPositionRequest sortPositionRequest, @Nullable ContextInfo context)
CrudEntityService
updateSort
in interface CrudEntityService<P>
sortPositionRequest
- Information about the item being moved and the position to which
it's movingcontext
- ontext information used to discriminate the correct version of an entity by
context id when multiple verions may be available across sandboxes, catalogs and
applications.public P replace(@NonNull String id, @NonNull P businessInstance, @Nullable ContextInfo context)
CrudEntityService
replace
in interface CrudEntityService<P>
id
- The context id for the entity. This is the id by which the business recognizes the
item.businessInstance
- The payload type that domain class should be converted to. In
general, the payload is what the rest API responds with.context
- Context information used to discriminate the correct version of an entity by
context id when multiple verions may be available across sandboxes, catalogs and
applications.EntityMissingException
if not available.CrudEntityService.replaceAll(List, ContextInfo)
,
CrudEntityService.replaceAllAllowingPartialSuccess(List, ContextInfo)
public List<P> replaceAll(List<Update<P>> replacements, ContextInfo context)
CrudEntityService
All items contained within replacements
must exist in the backing repository and pass
validation, else the entire batch will fail
See CrudEntityService.replaceAllAllowingPartialSuccess(List, ContextInfo)
for an alternative that
allows partial success.
replaceAll
in interface CrudEntityService<P>
replacements
- all replacements to the repository domaincontext
- Context information used to discriminate the correct version of an entity by
context id when multiple verions may be available across sandboxes, catalogs and
applications.EntityMissingException
if any of the items were not foundCrudEntityService.replaceAllAllowingPartialSuccess(List, ContextInfo)
public BulkPersistenceResponse<P> replaceAllAllowingPartialSuccess(List<Update<P>> replacements, ContextInfo context)
CrudEntityService
Each item contained within replacements
must exist in the backing repository and pass
validation, or it will be added to the failed list in the response and not persisted. All
successfully found and validated items will be persisted.
See CrudEntityService.replaceAll(List, ContextInfo)
for an alternative that does not allow partial
success.
replaceAllAllowingPartialSuccess
in interface CrudEntityService<P>
replacements
- all replacements to the repository domaincontext
- Context information used to discriminate the correct version of an entity by
context id when multiple verions may be available across sandboxes, catalogs and
applications.CrudEntityService.replaceAll(List, ContextInfo)
public P create(@NonNull P businessInstance, @Nullable ContextInfo context)
CrudEntityService
create
in interface CrudEntityService<P>
businessInstance
- The business domain instance. In general, the
DomainMapperManager
is responsible for converting to a repository platform
type for persistence.context
- Context information used to discriminate the correct version of an entity by
context id when multiple verions may be available across sandboxes, catalogs and
applications.CrudEntityService.createAll(List, ContextInfo)
,
CrudEntityService.createAllAllowingPartialSuccess(List, ContextInfo)
public List<P> createAll(@NonNull List<P> businessInstances, @Nullable ContextInfo context)
CrudEntityService
All items contained within businessInstances
must pass validation, else the entire
batch will fail.
See CrudEntityService.createAllAllowingPartialSuccess(List, ContextInfo)
for an alternative where
partial success is allowed.
createAll
in interface CrudEntityService<P>
businessInstances
- all instances to create in the data storecontext
- Context information used to discriminate the correct version of an entity by
context id when multiple versions may be available across sandboxes, catalogs and
applications.CrudEntityService.createAllAllowingPartialSuccess(List, ContextInfo)
public BulkPersistenceResponse<P> createAllAllowingPartialSuccess(List<P> businessInstances, ContextInfo context)
CrudEntityService
Each item contained within businessInstances
will be validated, and if it fails
validation, it will be added to the failed list in the response and not persisted. All
successfully validated items will be persisted.
See CrudEntityService.createAll(List, ContextInfo)
for an alternative that does not allow partial
success.
createAllAllowingPartialSuccess
in interface CrudEntityService<P>
businessInstances
- all instances to create in the data storecontext
- Context information used to discriminate the correct version of an entity by
context id when multiple versions may be available across sandboxes, catalogs and
applications.CrudEntityService.createAll(List, ContextInfo)
public void delete(@NonNull String id, @Nullable ContextInfo context)
CrudEntityService
DomainMapper.deleteMap(Object, ContextInfo)
.delete
in interface CrudEntityService<P>
id
- The context id for the entity. This is the id by which the business recognizes the
item.context
- Context information used to discriminate the correct version of an entity by
context id when multiple verions may be available across sandboxes, catalogs and
applications.protected P convertFromPersistentDomain(Trackable domain, ContextInfo contextInfo)
protected Trackable convertToPersistentDomain(P businessInstance, Class<Trackable> persistentType, ContextInfo contextInfo)
@NonNull protected TrackableRepository<Trackable> getRepository()
@NonNull protected CrudEntityHelper getHelper()
@NonNull protected SortPositionStrategy<P> getSortPositionStrategy()
Copyright © 2021. All rights reserved.