P
- The business domain typepublic class BaseMappableCrudEntityService<P> extends Object implements MappableCrudEntityService<P>
MappableCrudEntityService
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 MappableCrudEntityHelper
in order to allow easier
refactoring of core functionality.
If a service implementation spans several repository types, then it is recommended to inject the
MappableCrudEntityHelper
rather than extend this class.
Constructor and Description |
---|
BaseMappableCrudEntityService(R repository,
MappableCrudEntityHelper helper) |
Modifier and Type | Method and Description |
---|---|
protected P |
convertFromPersistentDomain(Object domain) |
<D,R extends org.springframework.data.repository.CrudRepository<D,String> & com.broadleafcommerce.common.extension.DomainTypeAware> |
create(P businessInstance)
Create an instance of an entity based on a business instance containing relevant property
values.
|
<D,R extends org.springframework.data.repository.CrudRepository<D,String> & com.broadleafcommerce.common.extension.DomainTypeAware> |
createAll(List<P> businessInstances)
Create multiple instances of an entity at once based on the business instances containing
relevant property values.
|
<D,R extends org.springframework.data.repository.CrudRepository<D,String> & com.broadleafcommerce.common.extension.DomainTypeAware> |
createAllAllowingPartialSuccess(List<P> businessInstances)
Creates multiple instances of an entity at once based on the business instances containing
relevant property values.
|
void |
delete(String id)
Perform a delete operation on the entity identified by the id.
|
protected MappableCrudEntityHelper |
getHelper() |
protected org.springframework.data.repository.PagingAndSortingRepository<?,String> |
getRepository() |
List<P> |
readAll()
Read a list of instances in the form of the business instance.
|
org.springframework.data.domain.Page<P> |
readAll(org.springframework.data.domain.Pageable pageable)
Read a page of entity instances in the form of business instances.
|
List<P> |
readAll(org.springframework.data.domain.Sort sort)
Read a list of instances in the form of the business instance.
|
List<P> |
readAllByIds(Iterable<String> ids)
Reads all entity instances matching the provided ids.
|
P |
readById(String id)
Read a single instance of an entity in the form of a business domain.
|
P |
replace(String id,
P businessInstance)
Replace a single instance of an entity based on a business instance containing relavant
property values.
|
List<P> |
replaceAll(List<Update<P>> replacements)
Replace multiple instances of an entity at once based on the business instance containing
relevant property values.
|
BulkPersistenceResponse<P> |
replaceAllAllowingPartialSuccess(List<Update<P>> replacements)
Replace multiple instances of an entity at once based on the business instances containing
relevant property values.
|
P |
update(String id,
P businessInstance)
Update a single instance of an entity based on a business instance containing relevant
property values.
|
List<P> |
updateAll(List<Update<P>> updates)
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)
Updates all of the items managed by the backing repository in the form of the business
instances containing property values.
|
public BaseMappableCrudEntityService(R repository, MappableCrudEntityHelper helper)
public P readById(@NonNull String id)
MappableCrudEntityService
readById
in interface MappableCrudEntityService<P>
id
- The id for the entity.@NonNull public List<P> readAllByIds(@NonNull Iterable<String> ids)
MappableCrudEntityService
readAllByIds
in interface MappableCrudEntityService<P>
ids
- Iterable
of ids to readList
of matching instancespublic List<P> readAll()
MappableCrudEntityService
readAll
in interface MappableCrudEntityService<P>
public org.springframework.data.domain.Page<P> readAll(@NonNull org.springframework.data.domain.Pageable pageable)
MappableCrudEntityService
readAll
in interface MappableCrudEntityService<P>
pageable
- information about which page of results to return. May be
Pageable.unpaged()
, may not be null
.public List<P> readAll(@NonNull org.springframework.data.domain.Sort sort)
MappableCrudEntityService
readAll
in interface MappableCrudEntityService<P>
sort
- The sort to be performed on the resultspublic P update(@NonNull String id, @NonNull P businessInstance)
MappableCrudEntityService
update
in interface MappableCrudEntityService<P>
id
- The id for the entity.businessInstance
- The payload type that domain class should be converted to. In
general, the payload is what the rest API responds with.EntityMissingException
if not available.MappableCrudEntityService.updateAll(List)
,
MappableCrudEntityService.updateAllAllowingPartialSuccess(List)
public List<P> updateAll(List<Update<P>> updates)
MappableCrudEntityService
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
MappableCrudEntityService.updateAllAllowingPartialSuccess(List)
.
updateAll
in interface MappableCrudEntityService<P>
updates
- each update to the repository domainEntityMissingException
if not available.MappableCrudEntityService.update(String, Object)
,
MappableCrudEntityService.updateAllAllowingPartialSuccess(List)
public BulkPersistenceResponse<P> updateAllAllowingPartialSuccess(List<Update<P>> updates)
MappableCrudEntityService
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 MappableCrudEntityService.updateAll(List)
.
updateAllAllowingPartialSuccess
in interface MappableCrudEntityService<P>
updates
- each update to the repository domainMappableCrudEntityService.updateAll(List)
public P replace(@NonNull String id, @NonNull P businessInstance)
MappableCrudEntityService
replace
in interface MappableCrudEntityService<P>
id
- The id for the entity.businessInstance
- The payload type that domain class should be converted to. In
general, the payload is what the rest API responds with.EntityMissingException
if not available.MappableCrudEntityService.replaceAll(List)
,
MappableCrudEntityService.replaceAllAllowingPartialSuccess(List)
public List<P> replaceAll(List<Update<P>> replacements)
MappableCrudEntityService
All items contained within replacements
must exist in the backing repository and pass
validation, else the entire batch will fail
See MappableCrudEntityService.replaceAllAllowingPartialSuccess(List)
for an alternative that allows partial
success.
replaceAll
in interface MappableCrudEntityService<P>
replacements
- all replacements to the repository domainEntityMissingException
if any of the items were not foundMappableCrudEntityService.replaceAllAllowingPartialSuccess(List)
public BulkPersistenceResponse<P> replaceAllAllowingPartialSuccess(List<Update<P>> replacements)
MappableCrudEntityService
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 MappableCrudEntityService.replaceAll(List)
for an alternative that does not allow partial success.
replaceAllAllowingPartialSuccess
in interface MappableCrudEntityService<P>
replacements
- all replacements to the repository domainMappableCrudEntityService.replaceAll(List)
public <D,R extends org.springframework.data.repository.CrudRepository<D,String> & com.broadleafcommerce.common.extension.DomainTypeAware> P create(@NonNull P businessInstance)
MappableCrudEntityService
DomainTypeAware
interface.create
in interface MappableCrudEntityService<P>
businessInstance
- The business domain instance. In general, the
DomainMapperManager
is responsible for converting to a repository platform
type for persistence.MappableCrudEntityService.createAll(List)
,
MappableCrudEntityService.createAllAllowingPartialSuccess(List)
public <D,R extends org.springframework.data.repository.CrudRepository<D,String> & com.broadleafcommerce.common.extension.DomainTypeAware> List<P> createAll(List<P> businessInstances)
MappableCrudEntityService
All items contained within businessInstances
must pass validation, else the entire
batch will fail.
See MappableCrudEntityService.createAllAllowingPartialSuccess(List)
for an alternative where partial success
is allowed.
createAll
in interface MappableCrudEntityService<P>
businessInstances
- all instances to create in the data storeMappableCrudEntityService.createAllAllowingPartialSuccess(List)
public <D,R extends org.springframework.data.repository.CrudRepository<D,String> & com.broadleafcommerce.common.extension.DomainTypeAware> BulkPersistenceResponse<P> createAllAllowingPartialSuccess(List<P> businessInstances)
MappableCrudEntityService
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 MappableCrudEntityService.createAll(List)
for an alternative that does not allow partial success.
createAllAllowingPartialSuccess
in interface MappableCrudEntityService<P>
businessInstances
- all instances to create in the data storeMappableCrudEntityService.createAll(List)
public void delete(@NonNull String id)
MappableCrudEntityService
delete
in interface MappableCrudEntityService<P>
id
- The id for the entity.@NonNull protected org.springframework.data.repository.PagingAndSortingRepository<?,String> getRepository()
@NonNull protected MappableCrudEntityHelper getHelper()
Copyright © 2021. All rights reserved.