Class BaseMappableCrudEntityService<P>
- java.lang.Object
-
- com.broadleafcommerce.data.tracking.core.service.BaseMappableCrudEntityService<P>
-
- Type Parameters:
P- The business domain type
- All Implemented Interfaces:
MappableCrudEntityService<P>
- Direct Known Subclasses:
BaseRsqlMappableCrudEntityService
public class BaseMappableCrudEntityService<P> extends Object implements MappableCrudEntityService<P>
Real-world service implementations ofMappableCrudEntityServicecan extend from this class as a convenience to inherit CRUD behavior for a particular business domain type. By default, this class in turn defers toMappableCrudEntityHelperin order to allow easier refactoring of core functionality.If a service implementation spans several repository types, then it is recommended to inject the
MappableCrudEntityHelperrather than extend this class.- Author:
- Nathan Moore (nathandmoore)
-
-
Constructor Summary
Constructors Constructor Description BaseMappableCrudEntityService(R repository, MappableCrudEntityHelper helper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected PconvertFromPersistentDomain(Object domain)<D,R extends org.springframework.data.repository.CrudRepository<D,String> & com.broadleafcommerce.common.extension.DomainTypeAware>
Pcreate(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>
List<P>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>
BulkPersistenceResponse<P>createAllAllowingPartialSuccess(List<P> businessInstances)Creates multiple instances of an entity at once based on the business instances containing relevant property values.voiddelete(String id)Perform a delete operation on the entity identified by the id.protected MappableCrudEntityHelpergetHelper()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.PreadById(String id)Read a single instance of an entity in the form of a business domain.Preplace(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.Pupdate(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.
-
-
-
Constructor Detail
-
BaseMappableCrudEntityService
public BaseMappableCrudEntityService(R repository, MappableCrudEntityHelper helper)
-
-
Method Detail
-
readById
public P readById(@NonNull String id)
Description copied from interface:MappableCrudEntityServiceRead a single instance of an entity in the form of a business domain.- Specified by:
readByIdin interfaceMappableCrudEntityService<P>- Parameters:
id- The id for the entity.- Returns:
- The entity instance in the form of a business instance
-
readAllByIds
@NonNull public List<P> readAllByIds(@NonNull Iterable<String> ids)
Description copied from interface:MappableCrudEntityServiceReads all entity instances matching the provided ids.- Specified by:
readAllByIdsin interfaceMappableCrudEntityService<P>- Parameters:
ids-Iterableof ids to read- Returns:
Listof matching instances
-
readAll
public List<P> readAll()
Description copied from interface:MappableCrudEntityServiceRead a list of instances in the form of the business instance.- Specified by:
readAllin interfaceMappableCrudEntityService<P>- Returns:
- The list of data in the form of business instances
-
readAll
public org.springframework.data.domain.Page<P> readAll(@NonNull org.springframework.data.domain.Pageable pageable)
Description copied from interface:MappableCrudEntityServiceRead a page of entity instances in the form of business instances.- Specified by:
readAllin interfaceMappableCrudEntityService<P>- Parameters:
pageable- information about which page of results to return. May bePageable.unpaged(), may not benull.- Returns:
- the requested page of entity instances in the form of business instances
-
readAll
public List<P> readAll(@NonNull org.springframework.data.domain.Sort sort)
Description copied from interface:MappableCrudEntityServiceRead a list of instances in the form of the business instance. Also apply the given sort.- Specified by:
readAllin interfaceMappableCrudEntityService<P>- Parameters:
sort- The sort to be performed on the results- Returns:
- The list of sorted data in the form of business instances
-
update
public P update(@NonNull String id, @NonNull P businessInstance)
Description copied from interface:MappableCrudEntityServiceUpdate a single instance of an entity based on a business instance containing relevant property values.- Specified by:
updatein interfaceMappableCrudEntityService<P>- Parameters:
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.- Returns:
- The updated entity instance in the form of a payload instance, or
EntityMissingExceptionif not available. - See Also:
MappableCrudEntityService.updateAll(List),MappableCrudEntityService.updateAllAllowingPartialSuccess(List)
-
updateAll
public List<P> updateAll(List<Update<P>> updates)
Description copied from interface:MappableCrudEntityServiceA bulk operation that updates all of the items managed by the backing repository in the form of the business entity containing property values.All items contained within
updatesmust exist in the backing repository and pass validation, else the entire batch will failFor an alternative that allows partial success, see
MappableCrudEntityService.updateAllAllowingPartialSuccess(List).- Specified by:
updateAllin interfaceMappableCrudEntityService<P>- Parameters:
updates- each update to the repository domain- Returns:
- all of the updated entity instance in the form of a payload instance, or
EntityMissingExceptionif not available. - See Also:
MappableCrudEntityService.update(String, Object),MappableCrudEntityService.updateAllAllowingPartialSuccess(List)
-
updateAllAllowingPartialSuccess
public BulkPersistenceResponse<P> updateAllAllowingPartialSuccess(List<Update<P>> updates)
Description copied from interface:MappableCrudEntityServiceUpdates all of the items managed by the backing repository in the form of the business instances containing property values.Each item contained within
updatesmust 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).- Specified by:
updateAllAllowingPartialSuccessin interfaceMappableCrudEntityService<P>- Parameters:
updates- each update to the repository domain- Returns:
- a response containing a list of any entities which failed, and a list of the successfully updated entity instances in the form of a payload instance
- See Also:
MappableCrudEntityService.updateAll(List)
-
replace
public P replace(@NonNull String id, @NonNull P businessInstance)
Description copied from interface:MappableCrudEntityServiceReplace a single instance of an entity based on a business instance containing relavant property values.- Specified by:
replacein interfaceMappableCrudEntityService<P>- Parameters:
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.- Returns:
- The replaced entity instance in the form of a payload instance, or
EntityMissingExceptionif not available. - See Also:
MappableCrudEntityService.replaceAll(List),MappableCrudEntityService.replaceAllAllowingPartialSuccess(List)
-
replaceAll
public List<P> replaceAll(List<Update<P>> replacements)
Description copied from interface:MappableCrudEntityServiceReplace multiple instances of an entity at once based on the business instance containing relevant property values.All items contained within
replacementsmust exist in the backing repository and pass validation, else the entire batch will failSee
MappableCrudEntityService.replaceAllAllowingPartialSuccess(List)for an alternative that allows partial success.- Specified by:
replaceAllin interfaceMappableCrudEntityService<P>- Parameters:
replacements- all replacements to the repository domain- Returns:
- all of the replaced entity instances in the form of a payload instance, or
EntityMissingExceptionif any of the items were not found - See Also:
MappableCrudEntityService.replaceAllAllowingPartialSuccess(List)
-
replaceAllAllowingPartialSuccess
public BulkPersistenceResponse<P> replaceAllAllowingPartialSuccess(List<Update<P>> replacements)
Description copied from interface:MappableCrudEntityServiceReplace multiple instances of an entity at once based on the business instances containing relevant property values.Each item contained within
replacementsmust 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.- Specified by:
replaceAllAllowingPartialSuccessin interfaceMappableCrudEntityService<P>- Parameters:
replacements- all replacements to the repository domain- Returns:
- a response containing a list of any entities which failed, and a list of the successfully replaced entity instances in the form of a payload instance
- See Also:
MappableCrudEntityService.replaceAll(List)
-
create
public <D,R extends org.springframework.data.repository.CrudRepository<D,String> & com.broadleafcommerce.common.extension.DomainTypeAware> P create(@NonNull P businessInstance)
Description copied from interface:MappableCrudEntityServiceCreate an instance of an entity based on a business instance containing relevant property values. In this case, the implementation should be aware of the back repository entity type. This is generally discovered via repository implementations that use theDomainTypeAwareinterface.- Specified by:
createin interfaceMappableCrudEntityService<P>- Parameters:
businessInstance- The business domain instance. In general, theDomainMapperManageris responsible for converting to a repository platform type for persistence.- Returns:
- The new entity instance in the form of a business type instance.
- See Also:
MappableCrudEntityService.createAll(List),MappableCrudEntityService.createAllAllowingPartialSuccess(List)
-
createAll
public <D,R extends org.springframework.data.repository.CrudRepository<D,String> & com.broadleafcommerce.common.extension.DomainTypeAware> List<P> createAll(List<P> businessInstances)
Description copied from interface:MappableCrudEntityServiceCreate multiple instances of an entity at once based on the business instances containing relevant property values.All items contained within
businessInstancesmust pass validation, else the entire batch will fail.See
MappableCrudEntityService.createAllAllowingPartialSuccess(List)for an alternative where partial success is allowed.- Specified by:
createAllin interfaceMappableCrudEntityService<P>- Parameters:
businessInstances- all instances to create in the data store- Returns:
- all of the created entity instances in the form of a payload instance
- See Also:
MappableCrudEntityService.createAllAllowingPartialSuccess(List)
-
createAllAllowingPartialSuccess
public <D,R extends org.springframework.data.repository.CrudRepository<D,String> & com.broadleafcommerce.common.extension.DomainTypeAware> BulkPersistenceResponse<P> createAllAllowingPartialSuccess(List<P> businessInstances)
Description copied from interface:MappableCrudEntityServiceCreates multiple instances of an entity at once based on the business instances containing relevant property values.Each item contained within
businessInstanceswill 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.- Specified by:
createAllAllowingPartialSuccessin interfaceMappableCrudEntityService<P>- Parameters:
businessInstances- all instances to create in the data store- Returns:
- a response containing a list of any entities which failed, and a list of the successfully created entity instances in the form of a payload instance
- See Also:
MappableCrudEntityService.createAll(List)
-
delete
public void delete(@NonNull String id)Description copied from interface:MappableCrudEntityServicePerform a delete operation on the entity identified by the id.- Specified by:
deletein interfaceMappableCrudEntityService<P>- Parameters:
id- The id for the entity.
-
getRepository
@NonNull protected org.springframework.data.repository.PagingAndSortingRepository<?,String> getRepository()
-
getHelper
@NonNull protected MappableCrudEntityHelper getHelper()
-
-