Interface SparselyPopulatedQueryExtensionHandler

All Superinterfaces:
ExtensionHandler

public interface SparselyPopulatedQueryExtensionHandler extends ExtensionHandler
Extension handler (generally for DAO usage) that allows contribution to a query (presumably from another module). The primary use case is to handle querying for sparsely populated caches in multitenant scenarios. Take for example, a price list scenario where there may be thousands of standard sites all inheriting from a template catalog containing some basic pricelist information. Rather than having a cache of these same basic price lists for every site, it is advantageous to have a single cache of the common pricelists. Then, if one or more standard sites override one of these pricelists, then a sparse cache is maintained per site with that site's overrides only.

This functionality is achieved by running several versions of a query based on the desired ResultType. Requesting results for a ResultType of STANDARD drives results filtered specifically to a standard site, which is multitenant module concept. A ResultType of TEMPLATE drives results specifically for template site catalog or profile (also a multitenant concept). In the absence of the multitenant module, ExtensionManager instance of this type should have no effect.
Author:
Jeff Fischer
See Also:
  • Method Details

    • refineRetrieve

      ExtensionResultStatusType refineRetrieve(Class<?> type, ResultType resultType, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.CriteriaQuery criteria, jakarta.persistence.criteria.Root root, List<jakarta.persistence.criteria.Predicate> restrictions)
      Add additional restrictions to the fetch query
      Parameters:
      type - the class type for the query
      resultType - pass a ResultType of IGNORE to explicitly ignore refineRetrieve, even if the multitenant module is loaded
      builder -
      criteria -
      root -
      restrictions - any additional JPA criteria restrictions should be added here
      Returns:
      the status of the extension operation
    • refineParameterRetrieve

      ExtensionResultStatusType refineParameterRetrieve(Class<?> type, ResultType resultType, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.CriteriaQuery criteria, jakarta.persistence.criteria.Root root, List<jakarta.persistence.criteria.Predicate> restrictions)
      Add additional restrictions to the fetch query. Uses parameters, rather than embedding values directly in the query. This is more efficient from a Hibernate statement cache and database prepared statement cache perspective. Use in conjunction with refineQuery(Class, ResultType, TypedQuery) to pass the actual parameter values before retrieving the query results.
      Parameters:
      type - the class type for the query
      resultType - pass a ResultType of IGNORE to explicitly ignore refineRetrieve, even if the multitenant module is loaded
      builder -
      criteria -
      root -
      restrictions - any additional JPA criteria restrictions should be added here
      Returns:
      the status of the extension operation
    • refineQuery

      ExtensionResultStatusType refineQuery(Class<?> type, ResultType resultType, jakarta.persistence.TypedQuery query)
      Finish the query - possibly setting parameters
      Parameters:
      type - the class type for the query
      resultType - pass a ResultType of IGNORE to explicitly ignore refineQuery, even if the multitenant module is loaded
      query - the final Query instance to embellish
      Returns:
    • setup

      ExtensionResultStatusType setup(Class<?> type, ResultType resultType)
      Perform any setup operations. This is usually done before executing the query and can serve to prepare the BroadleafRequestContext (if applicable).
      Parameters:
      type - the class type for the query
      resultType - pass a ResultType of IGNORE to explicitly ignore setup, even if the multitenant module is loaded
      Returns:
      the status of the extension operation
    • breakdown

      ExtensionResultStatusType breakdown(Class<?> type, ResultType resultType)
      Perform any breakdown operations. This is usually done after executing the query and can serve to reset the BroadleafRequestContext (if applicable)
      Parameters:
      type - the class type for the query
      resultType - pass a ResultType of IGNORE to explicitly ignore breakdown, even if the multitenant module is loaded
      Returns:
      the status of the extension operation
    • refineOrder

      ExtensionResultStatusType refineOrder(Class<?> type, ResultType resultType, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.CriteriaQuery criteria, jakarta.persistence.criteria.Root root, List<jakarta.persistence.criteria.Order> sorts)
      Add sorting to the fetch query
      Parameters:
      type - the class type for the query
      resultType -
      builder -
      criteria -
      root -
      sorts - any additional JPA order expressions should be added here
      Returns:
      the status of the extension operation
    • refineResults

      ExtensionResultStatusType refineResults(Class<?> type, ResultType resultType, List queryResults, ExtensionResultHolder<List> response)
      Filter the results from the database in Java
      Parameters:
      type - the class type for the query
      resultType -
      queryResults - the results of the fetch query from the database
      response - the container for the filtered results
      Returns:
      the status of the extension operation
    • getResultType

      ExtensionResultStatusType getResultType(Object testObject, ExtensionResultHolder<ResultType> response)
      By examining the multitenant information related to a test object, return whether the object is related to a standard site, or a template profile or catalog, if applicable.
      Parameters:
      testObject - the multitenant object to test
      response - the response container
      Returns:
      the status of the extension operation
    • getCacheKey

      ExtensionResultStatusType getCacheKey(Object testObject, String qualifier, ResultType resultType, ExtensionResultHolder<String> response)
      Build the cache key to be used for either the STANDARD or TEMPLATE style cache, driven by the resultType.
      Parameters:
      testObject - object to examine for a portion of the cache key
      qualifier - the suffix for the cache key
      resultType - the type of cache key to create (STANDARD or TEMPLATE)
      response - the response container
      Returns:
      the status of the extension operation
    • getCacheKey

      ExtensionResultStatusType getCacheKey(String qualifier, ResultType resultType, ExtensionResultHolder<String> response)
      Build the cache key to be used for either the STANDARD or TEMPLATE style cache, driven by the resultType.
      Parameters:
      qualifier - the suffix for the cache key
      resultType - the type of cache key to create (STANDARD or TEMPLATE)
      response - the response container
      Returns:
      the status of the extension operation
    • getCacheKeys

      ExtensionResultStatusType getCacheKeys(String qualifier, ResultType resultType, ExtensionResultHolder<List<String>> response)
      Build the cache keys to be used for either the STANDARD or TEMPLATE style cache, driven by the resultType. If current site(BRC.getSite) is the TEMPLATE then find all sites that are children(they have parent site=current) And use them to construct a list of keys. This can be helpful when you do a change on a template site and need to invalidate cached items for standard sites.
      Parameters:
      qualifier - the suffix for the cache key
      resultType - the type of cache key to create (STANDARD or TEMPLATE)
      response - the response container
      Returns:
      the status of the extension operation
    • getCacheKeyListForTemplateSite

      ExtensionResultStatusType getCacheKeyListForTemplateSite(String qualifier, ExtensionResultHolder<List<String>> response)
      Build a list of cache keys that are related to a TEMPLATE template site
      Parameters:
      qualifier - the suffix for the cache key
      response - the response container
      Returns:
      the status of the extension operation
    • buildStatus

      ExtensionResultStatusType buildStatus(Class<?> type, List queryResults, ExtensionResultHolder<List<StandardCacheItem>> response)
      Convert the list of query results into a list that denotes not only the query results, but also whether or not each member represents a deleted/archived item, or an active/normal item.
      Parameters:
      type - the class type for the query
      queryResults - the results of the fetch query from the database
      response - the response container - the list is sorted with deleted item appearing first
      Returns:
      the status of the extension operation
    • isValidState

      Determine if the current thread is in a valid state for sparse cache handling
      Parameters:
      response -
      Returns:
    • getNormalizedId

      ExtensionResultStatusType getNormalizedId(Object testObject, ExtensionResultHolder<Long> response)
      Get a common id for an object that is consistent for a standard site (whether or not the test object is overridden in the standard site)
      Parameters:
      testObject - the object whose id is normalized
      response - the container for the normalized id
      Returns:
      the status of the extension operation