Class RsqlMappableCrudEntityHelper
- java.lang.Object
-
- com.broadleafcommerce.data.tracking.core.service.RsqlMappableCrudEntityHelper
-
public class RsqlMappableCrudEntityHelper extends Object
Helper class responsible for providing additional support for RSQL filtering for business domain services. This service is intended to be used in support ofRsqlMappableCrudEntityService.Typically, it is sufficient to extend
BaseRsqlMappableCrudEntityServicein order to gain access to this helper; however, if a service implementation spans several repository types, it is recommend to inject this class instead. In such a case, this helper also provides access to aMappableCrudEntityHelperbean.@Servicepublic class DefaultMyService<P extends MyPayload> implements MyService<P>{private final RsqlMappableCrudEntityService<MyPayload> helper;private final MyRepository repository;public DefaultMyService(MyRepository repository, DomainMapperManager mapper) { this.helper = new RsqlMappableCrudEntityService(repository, mapper); this repository = repository; } }- Author:
- Jeff Fischer
-
-
Constructor Summary
Constructors Constructor Description RsqlMappableCrudEntityHelper(MappableCrudEntityHelper crudEntityHelper, List<RsqlQueryTransformer> rsqlQueryTransformers)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <D,R extends org.springframework.data.repository.CrudRepository<D,String> & MappableRsqlFilterExecutor<D>>
RcastToRsqlRepository(org.springframework.data.repository.CrudRepository<D,String> repository)Since most of the methods in the service require a repository that implements bothCrudRepositoryandMappableRsqlFilterExecutor, this method provides a convenient way to handle that casting.MappableCrudEntityHelpergetCrudEntityHelper()Provides access to the internalMappableCrudEntityHelperso as to avoid having to inject it again.protected List<RsqlQueryTransformer>getRsqlQueryTransformers()<P,D,R extends MappableRsqlFilterExecutor<D>>
org.springframework.data.domain.Page<P>readAll(cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageable, R repository)Retrieve all domain instances using a structured query string to drive the query criteria.<P,D,R extends MappableRsqlFilterExecutor<D>>
org.springframework.data.domain.Page<P>readAll(cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Sort sort, org.springframework.data.domain.Pageable pageable, R repository)Retrieve all domain instances using a structured query string to drive the query criteria.<P,D,R extends MappableRsqlFilterExecutor<D>>
List<P>readAll(cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Sort sort, R repository)Retrieve all domain instances using a structured query string to drive the query criteria.<P,D,R extends MappableRsqlFilterExecutor<D>>
List<P>readAll(cz.jirutka.rsql.parser.ast.Node filters, R repository)Retrieve all domain instances using a structured query string to drive the query criteria.cz.jirutka.rsql.parser.ast.Nodetransform(cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.common.extension.DomainTypeAware repository)Transformsfiltersfrom properties that target a projection into ones that apply to a backing repository provider domain object
-
-
-
Constructor Detail
-
RsqlMappableCrudEntityHelper
public RsqlMappableCrudEntityHelper(MappableCrudEntityHelper crudEntityHelper, List<RsqlQueryTransformer> rsqlQueryTransformers)
-
-
Method Detail
-
readAll
public <P,D,R extends MappableRsqlFilterExecutor<D>> List<P> readAll(@NonNull cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Sort sort, @NonNull R repository)
Retrieve all domain instances using a structured query string to drive the query criteria. The filters string is parsed by an internal implementation and the result is added to the query before executing the fetch against the persistence store. SeeFilterParserfor more information.This version also accepts a formatted sort string that declares the sorting characteristics for the query.
- Parameters:
filters- the RSQLNodeused to restrict result, must not be nullsort- The string containing the structured list of sorts to applyrepository- A repository that implementsMappableRsqlFilterExecutorto perform the persistence operation- Returns:
- The list of narrowed, sorted entities
-
readAll
public <P,D,R extends MappableRsqlFilterExecutor<D>> List<P> readAll(@NonNull cz.jirutka.rsql.parser.ast.Node filters, @NonNull R repository)
Retrieve all domain instances using a structured query string to drive the query criteria. The filters string is parsed by an internal implementation and the result is added to the query before executing the fetch against the persistence store. SeeFilterParserfor more information.- Parameters:
filters- the RSQLNodeused to restrict result, must not be nullrepository- A repository that implementsMappableRsqlFilterExecutorto perform the persistence operation- Returns:
- The list of narrowed, sorted entities
-
readAll
public <P,D,R extends MappableRsqlFilterExecutor<D>> org.springframework.data.domain.Page<P> readAll(@NonNull cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Sort sort, @NonNull org.springframework.data.domain.Pageable pageable, @NonNull R repository)
Retrieve all domain instances using a structured query string to drive the query criteria. The filters string is parsed by an internal implementation and the result is added to the query before executing the fetch against the persistence store. SeeFilterParserfor more information.This version also accepts a Sort to apply to the result set
- Parameters:
filters- the RSQLNodeused to restrict result, must not be nullsort- sort to apply to the querypageable- may bePageable.unpaged(), must not be null.repository- A repository that implementsMappableRsqlFilterExecutorto perform the persistence operation- Returns:
- The subset (page) of narrowed entities
-
readAll
public <P,D,R extends MappableRsqlFilterExecutor<D>> org.springframework.data.domain.Page<P> readAll(@NonNull cz.jirutka.rsql.parser.ast.Node filters, @NonNull org.springframework.data.domain.Pageable pageable, @NonNull R repository)
Retrieve all domain instances using a structured query string to drive the query criteria. The filters string is parsed by an internal implementation and the result is added to the query before executing the fetch against the persistence store. SeeFilterParserfor more information.- Parameters:
filters- the RSQLNodeused to restrict result, must not be nullpageable- may bePageable.unpaged(), must not be null.repository- A repository that implementsMappableRsqlFilterExecutorto perform the persistence operation- Returns:
- The subset (page) of narrowed entities
-
transform
@NonNull public cz.jirutka.rsql.parser.ast.Node transform(@Nullable cz.jirutka.rsql.parser.ast.Node filters, @NonNull com.broadleafcommerce.common.extension.DomainTypeAware repository)Transformsfiltersfrom properties that target a projection into ones that apply to a backing repository provider domain object- Parameters:
filters- RSQL filters targeting a projection domainrepository- ADomainTypeAwareimplementing repository from which to glean entity information for the transformation- Returns:
- null if
filtersis null, otherwise an RSQL query suitable for targeting a repository domain object. - See Also:
RsqlQueryTransformer
-
castToRsqlRepository
public final <D,R extends org.springframework.data.repository.CrudRepository<D,String> & MappableRsqlFilterExecutor<D>> R castToRsqlRepository(org.springframework.data.repository.CrudRepository<D,String> repository)
Since most of the methods in the service require a repository that implements bothCrudRepositoryandMappableRsqlFilterExecutor, this method provides a convenient way to handle that casting.- Type Parameters:
D- a domain typeR- used to do the multi-interface check.- Parameters:
repository- Since most services that use this helper will useCrudRepository(or an extension thereof), this method expects that as the argument.- Returns:
- A
CrudRepositorythat also implementsMappableRsqlFilterExecutorcast in such a way as to allow type checking for both interfaces for use with this service's methods.
-
getCrudEntityHelper
@NonNull public MappableCrudEntityHelper getCrudEntityHelper()
Provides access to the internalMappableCrudEntityHelperso as to avoid having to inject it again.- Returns:
- the internal
MappableCrudEntityHelper - See Also:
MappableCrudEntityHelper
-
getRsqlQueryTransformers
@NonNull protected List<RsqlQueryTransformer> getRsqlQueryTransformers()
-
-