Class NarrowingPartTreeJpaQuery

  • All Implemented Interfaces:
    QueryPreparer, org.springframework.data.repository.query.RepositoryQuery

    public class NarrowingPartTreeJpaQuery
    extends org.springframework.data.jpa.repository.query.AbstractJpaQuery
    implements QueryPreparer
    Customized version of PartTreeJpaQuery to support special filtering of results from a repository query method. This is responsible for calling a NarrowExecutor implementation in order to perform the requested query (possibly with enhancements) and return filtered results.
    Author:
    Jeff Fischer
    See Also:
    TrackableRepository, Narrow
    • Constructor Summary

      Constructors 
      Constructor Description
      NarrowingPartTreeJpaQuery​(org.springframework.data.jpa.repository.query.JpaQueryMethod method, javax.persistence.EntityManager em, org.springframework.data.jpa.provider.PersistenceProvider persistenceProvider, org.springframework.data.jpa.repository.query.EscapeCharacter escape, com.broadleafcommerce.data.tracking.core.TrackableBehaviorUtil behaviorUtil, RSQLVisitorHolder<?> rsqlVisitorHolder, JpaFiltersCriteriaBuilder catalogFiltersCriteriaBuilder, org.springframework.data.repository.core.RepositoryMetadata repositoryMetadata, com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager repositoryEntityTypeManager)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected <D> void addSorting​(javax.persistence.criteria.CriteriaQuery<?> query, javax.persistence.criteria.CriteriaBuilder cb, Class<D> type)
      Apply any declared sort stipulations on the query.
      protected javax.persistence.Query applyEntityGraphConfig​(javax.persistence.Query query, org.springframework.data.jpa.repository.query.JpaQueryMethod method)
      Apply any declared entity graph stipulations on the query.
      protected javax.persistence.Query applyHints​(javax.persistence.Query query, org.springframework.data.jpa.repository.query.JpaQueryMethod method)
      Apply any declared Jpa hint stipulations on the query.
      protected javax.persistence.Query bindAndPrepare​(org.springframework.data.jpa.repository.query.ParameterBinder binder, javax.persistence.Query query, Object metadata, org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor accessor)
      Execute the binding of method params on the query
      protected javax.persistence.Query doCreateCountQuery​(org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor accessor)  
      protected javax.persistence.Query doCreateQuery​(org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor accessor)  
      Object execute​(Object[] parameters)  
      protected org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor getJpaParametersParameterAccessor​(org.springframework.data.repository.query.Parameters<?,​?> parameters, Object[] values)
      Get a type and position aware accessor of method parameters.
      protected Object getMetadata​(Object queryMetadataCache, javax.persistence.Query query)
      Get query metadata information
      protected org.springframework.data.jpa.repository.query.ParameterBinder getParameterBinder​(org.springframework.data.jpa.repository.query.JpaParameters parameters, List<?> expressions)
      Get the binder component used to apply params supplied in the method call to the JPA query.
      protected Object getQueryMetadataCache()
      Get the cache of query related metadata
      protected void mergeRsqlCriteriaWithQueryCriteria​(javax.persistence.criteria.CriteriaQuery<?> query, javax.persistence.criteria.Predicate rsqlCriteria)
      Replaces the query's internal criteria with an updated version that is combined with RSQL criteria.
      javax.persistence.Query prepareQueryForExecution​(javax.persistence.Query query, com.broadleafcommerce.data.tracking.core.filtering.NarrowExecutor.QueryInfo info, boolean bindFetchCriteria)
      Perform final preparation of a Jpa Query before execution.
      protected Object processQuery​(Object[] parameters, org.springframework.data.repository.query.ParametersParameterAccessor accessor, com.broadleafcommerce.data.tracking.core.context.ContextInfo context, org.springframework.data.repository.query.ResultProcessor processor, org.springframework.data.jpa.repository.query.JpaQueryCreator creator, javax.persistence.criteria.CriteriaQuery<?> criteriaQuery)
      Execute the criteria query through the NarrowExecutor implementation and return the results.
      • Methods inherited from class org.springframework.data.jpa.repository.query.AbstractJpaQuery

        applyQueryHint, createBinder, createCountQuery, createQuery, getEntityManager, getExecution, getMetamodel, getQueryMethod, getTypeToRead
    • Constructor Detail

      • NarrowingPartTreeJpaQuery

        public NarrowingPartTreeJpaQuery​(org.springframework.data.jpa.repository.query.JpaQueryMethod method,
                                         javax.persistence.EntityManager em,
                                         org.springframework.data.jpa.provider.PersistenceProvider persistenceProvider,
                                         org.springframework.data.jpa.repository.query.EscapeCharacter escape,
                                         com.broadleafcommerce.data.tracking.core.TrackableBehaviorUtil behaviorUtil,
                                         @Nullable
                                         RSQLVisitorHolder<?> rsqlVisitorHolder,
                                         JpaFiltersCriteriaBuilder catalogFiltersCriteriaBuilder,
                                         org.springframework.data.repository.core.RepositoryMetadata repositoryMetadata,
                                         com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager repositoryEntityTypeManager)
    • Method Detail

      • execute

        public Object execute​(Object[] parameters)
        Specified by:
        execute in interface org.springframework.data.repository.query.RepositoryQuery
        Overrides:
        execute in class org.springframework.data.jpa.repository.query.AbstractJpaQuery
      • prepareQueryForExecution

        public javax.persistence.Query prepareQueryForExecution​(javax.persistence.Query query,
                                                                com.broadleafcommerce.data.tracking.core.filtering.NarrowExecutor.QueryInfo info,
                                                                boolean bindFetchCriteria)
        Description copied from interface: QueryPreparer
        Perform final preparation of a Jpa Query before execution.
        Specified by:
        prepareQueryForExecution in interface QueryPreparer
        Parameters:
        query - The query to prepare
        info - The information about the query used during NarrowExecutor processing
        bindFetchCriteria - Whether or not to bind any parameters described in JpaNarrowingHelper.JpaCriterias.getParameterMap()
        Returns:
        the prepared query
      • doCreateQuery

        @NonNull
        protected javax.persistence.Query doCreateQuery​(@NonNull
                                                        org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor accessor)
        Specified by:
        doCreateQuery in class org.springframework.data.jpa.repository.query.AbstractJpaQuery
      • doCreateCountQuery

        @NonNull
        protected javax.persistence.Query doCreateCountQuery​(@NonNull
                                                             org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor accessor)
        Specified by:
        doCreateCountQuery in class org.springframework.data.jpa.repository.query.AbstractJpaQuery
      • processQuery

        protected Object processQuery​(Object[] parameters,
                                      org.springframework.data.repository.query.ParametersParameterAccessor accessor,
                                      com.broadleafcommerce.data.tracking.core.context.ContextInfo context,
                                      org.springframework.data.repository.query.ResultProcessor processor,
                                      org.springframework.data.jpa.repository.query.JpaQueryCreator creator,
                                      javax.persistence.criteria.CriteriaQuery<?> criteriaQuery)
        Execute the criteria query through the NarrowExecutor implementation and return the results.
        Parameters:
        parameters - Repository fragment method parameters
        accessor - Type and position aware accessor of method parameters
        context - ContextInfo from the repository fragment method
        processor - Spring processor of query results
        creator - Source of JPA parameter expressions for the dynamically created criteria query
        criteriaQuery - The dynamically created criteria query (based on the repository fragment method and params)
        Returns:
        The query results
      • mergeRsqlCriteriaWithQueryCriteria

        protected void mergeRsqlCriteriaWithQueryCriteria​(@NonNull
                                                          javax.persistence.criteria.CriteriaQuery<?> query,
                                                          @Nullable
                                                          javax.persistence.criteria.Predicate rsqlCriteria)

        Replaces the query's internal criteria with an updated version that is combined with RSQL criteria. If properties are duplicated between the existing criteria and the new RSQL criteria, they are AND-ed together.

        If there is no existing criteria on the given query, the query is updated to contain the given rsqlCriteria.

        Parameters:
        query - the query whose criteria should be replaced
        rsqlCriteria - pre-parsed RSQL criteria which should be merged with the criteria of the query
      • getParameterBinder

        protected org.springframework.data.jpa.repository.query.ParameterBinder getParameterBinder​(org.springframework.data.jpa.repository.query.JpaParameters parameters,
                                                                                                   List<?> expressions)
        Get the binder component used to apply params supplied in the method call to the JPA query.
        Parameters:
        parameters - The method parameters against query parameters
        expressions - The JPA criteria expressions
        Returns:
        The binder
      • getMetadata

        protected Object getMetadata​(Object queryMetadataCache,
                                     javax.persistence.Query query)
        Get query metadata information
        Parameters:
        queryMetadataCache - Cache of metadata
        query - The query from which to derive metadata
        Returns:
      • getQueryMetadataCache

        protected Object getQueryMetadataCache()
        Get the cache of query related metadata
        Returns:
        the cache of query related metadata
      • getJpaParametersParameterAccessor

        protected org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor getJpaParametersParameterAccessor​(org.springframework.data.repository.query.Parameters<?,​?> parameters,
                                                                                                                                 Object[] values)
        Get a type and position aware accessor of method parameters.
        Parameters:
        parameters - The method parameters against query parameters
        values - The actual method parameter values
        Returns:
        type and position aware accessor of method parameters
      • bindAndPrepare

        protected javax.persistence.Query bindAndPrepare​(org.springframework.data.jpa.repository.query.ParameterBinder binder,
                                                         javax.persistence.Query query,
                                                         Object metadata,
                                                         org.springframework.data.jpa.repository.query.JpaParametersParameterAccessor accessor)
        Execute the binding of method params on the query
        Parameters:
        binder - The parameter binder
        query - The Jpa query
        metadata - The metadata about the query
        accessor - The method parameter accessor
        Returns:
        The finished version of the query with parameters bound
      • applyEntityGraphConfig

        protected javax.persistence.Query applyEntityGraphConfig​(javax.persistence.Query query,
                                                                 org.springframework.data.jpa.repository.query.JpaQueryMethod method)
        Apply any declared entity graph stipulations on the query.
        Parameters:
        query - The jpa query
        method - The entity graph annotated repository method
        Returns:
        The query with information applied
      • applyHints

        @NonNull
        protected javax.persistence.Query applyHints​(@NonNull
                                                     javax.persistence.Query query,
                                                     org.springframework.data.jpa.repository.query.JpaQueryMethod method)
        Apply any declared Jpa hint stipulations on the query.
        Overrides:
        applyHints in class org.springframework.data.jpa.repository.query.AbstractJpaQuery
        Parameters:
        query - The jpa query
        method - The hint annotated repository method
        Returns:
        The query with information applied
      • addSorting

        protected <D> void addSorting​(javax.persistence.criteria.CriteriaQuery<?> query,
                                      javax.persistence.criteria.CriteriaBuilder cb,
                                      Class<D> type)
        Apply any declared sort stipulations on the query.
        Type Parameters:
        D - The query result entity type
        Parameters:
        query - The jpa query
        cb - The jpa criteria builder
        type - The query result entity type