Class AbstractQuery

java.lang.Object
de.hybris.platform.servicelayer.search.AbstractQuery
Direct Known Subclasses:
FlexibleSearchQuery, GenericSearchQuery

public abstract class AbstractQuery extends Object

Base class for any search query containers which keeps common informations needed for executing search.

Attention: For performance reasons the default value for isNeedTotal() is false!
This means: When using setCount(int) in the SearchResult the SearchResult.getTotalCount() will be equal to the used value.

Please note that this class is not thread-safe and not intended to be living longer than one request.

  • Constructor Details

    • AbstractQuery

      public AbstractQuery()
  • Method Details

    • isDisableSearchRestrictions

      public boolean isDisableSearchRestrictions()
      Returns:
      true, if disable search restrictions should be set in the session. Default value is false.
    • setDisableSearchRestrictions

      public void setDisableSearchRestrictions(boolean disableSearchRestrictions)
      Set this value to true if you want to disable search restrictions.
    • setTypeExclusive

      public void setTypeExclusive(boolean typeExclusive)
    • setFailOnUnknownFields

      public void setFailOnUnknownFields(boolean isFailOnUnknownFields)
      Set this value to true (default value) and it causes an error when using an unknown field name.
      Parameters:
      isFailOnUnknownFields - Set to false if unknown field names should be ignored
    • isFailOnUnknownFields

      public boolean isFailOnUnknownFields()
      Returns:
      true if the search should fail by unknown fields.
    • isTypeExclusive

      public boolean isTypeExclusive()
    • getCount

      public int getCount()
      Returns:
      the number of elements in this search range. Default value is -1 which means all elements.
    • getLanguage

      @Deprecated(since="ages", forRemoval=true) public LanguageModel getLanguage()
      Deprecated, for removal: This API element is subject to removal in a future version.
      since ages - usegetLocale() and setLocale(Locale) instead of LanguageModel directly.

      Gets the language which will be used for executing query.

      If the language has not been set then current session language will be used for executing query.

      Returns:
      the used language from the search session context.
    • getLocale

      public Locale getLocale()

      Gets the locale which will be used for executing query.

      If the locale has not been set then current session locale will be used for executing query.

      Returns:
      the locale
    • getSessionSearchRestrictions

      public Collection<SessionSearchRestriction> getSessionSearchRestrictions()
      Gets the session search restrictions will be used for executing query.

      Please notice that any search restrictions are ignored if current logged user is admin or any other user with admin rights.

      Returns:
      the session restrictions
    • getStart

      public int getStart()
      Default value for the start range is 0 (first element).
      Returns:
      the start number of the search range.
    • isNeedTotal

      public boolean isNeedTotal()
      Checks if is need total.

      Attention: For performance reasons the default value for isNeedTotal() is false !
      This means: When using setCount(int) in the SearchResult the SearchResult.getTotalCount() will be equal to the used value in setCount(int). When isNeedTotal() is true then total count will be returned from method SearchResult.getTotalCount(). This parameter is especially important for paging mechanism.

      Returns:
      true, if is need total
    • setCount

      public void setCount(int count)
      Set the number of elements in the search range. Attention with the default value isNeedTotal()= false! The total count of the result will be equal to this value. The default value is -1 which means all elements.
      Parameters:
      count - Sets the number of elements for the search range.
    • setLanguage

      @Deprecated(since="ages", forRemoval=true) public void setLanguage(LanguageModel language)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since ages - usegetLocale() and setLocale(Locale) instead of LanguageModel directly.

      Sets the language to the search session context.

      If the language has not been set then current session language will be used for executing query.

      Parameters:
      language - the language
    • setLocale

      public void setLocale(Locale locale)

      Sets the locale which will be used for executing query.

      If the locale has not been set then current session locale will be used for executing query.

      Please keep in mind that Locale have to be created properly with language code and/or country code and/or variant code as follows:

       Locale loc = new Locale("en", "US", "NY");
       

      Do not create Locale object as follows:

       Locale loc = new Locale("en_US");
       

      It will not split language and country code automatically. To split ISO code string properly use Utilities.parseLocaleCodes(String) method as follows:

       final String[] codes = Utilities.parseLocaleCodes("en_US");
       Locale loc = new Locale(codes[0], codes[1]);
       
      Parameters:
      locale - the new locale
    • setNeedTotal

      public void setNeedTotal(boolean needTotal)

      Sets the isNeedTotal.

      Attention: For performance reasons the default value for isNeedTotal() is false !
      This means: When using setCount(int) in the SearchResult the SearchResult.getTotalCount() will be equal to the used value in setCount(int). When isNeedTotal() is true then total count will be returned from method SearchResult.getTotalCount(). This parameter is especially important for paging mechanism.

      Parameters:
      needTotal - the new need total
    • setSessionSearchRestrictions

      public void setSessionSearchRestrictions(Collection<SessionSearchRestriction> sessionSearchRestrictions)

      Adds the session search restrictions which will be used for executing query.

      Please notice that any search restrictions are ignored if current logged user is admin or any other user with admin rights.

    • setSessionSearchRestrictions

      public void setSessionSearchRestrictions(SessionSearchRestriction... sessionSearchRestrictions)

      Adds the session search restrictions which will be used for executing query.

      Please notice that any search restrictions are ignored if current logged user is admin or any other user with admin rights.

    • setStart

      public void setStart(int start)
      Sets the start number of the search range.
      Parameters:
      start - the start number of the search range
    • getResultClassList

      public <T extends Class> List<T> getResultClassList()
      This list contains the expected types/classes of the result objects. The default result class list returns a singleton list with Item.class
      Returns:
      the expected result class list.
    • setResultClassList

      public <T extends Class> void setResultClassList(List<T> resultClassList)
      Sets the expected result types signature as list. If the search returns a result the result objects has to be from those types. The default result class list contains Item.class
      Parameters:
      resultClassList - the result type list
    • getCatalogVersions

      public Collection<CatalogVersionModel> getCatalogVersions()
      Returns a collection with catalog versions for this FlexibleSearchQuery which were explicitly set by setCatalogVersions(Collection). This collection is used for the search restrictions. If this method returns null the global search restrictions are used for the search (which are stored at the search session using CatalogVersionService.addSessionCatalogVersion(CatalogVersionModel))
      Returns:
      a collection with catalog versions
    • setCatalogVersions

      public void setCatalogVersions(Collection<CatalogVersionModel> catalogVersions)
      Overwrites the global search restrictions for catalog versions. If this method is used the search restrictions for the current user and active catalog versions (stored at the search session using CatalogVersionService.addSessionCatalogVersion(CatalogVersionModel)) are overwritten by the given collection.
      Parameters:
      catalogVersions - a collection with catalog versions which are the new catalog version restriction for the search session context
    • setCatalogVersions

      public void setCatalogVersions(CatalogVersionModel... catalogVersions)
      Overwrites the global search restrictions for catalog versions. If this method is used the search restrictions for the current user and active catalog versions (stored at the search session using CatalogVersionService.addSessionCatalogVersion(CatalogVersionModel)) are overwritten by the given collection.
      Parameters:
      catalogVersions - catalog versions which are the new catalog version restriction for the search session context
    • getUser

      public UserModel getUser()

      Gets the user for which query will be executed.

      If the user has not been set by setUser(UserModel) then the user from the current session is used for executing query.

      Returns:
      the user with which the search is executed. The user is stored in the session context. If no user has been provided then current session user is used for executing query.
    • setUser

      public void setUser(UserModel user)

      Sets the user to the search session context. The search is executed with the restrictions for this user.

      If the user is null or this method was not used at all then the user from the current session is used for executing query.

      Parameters:
      user - the user which will be used for executing query.
    • isDisableSpecificDbLimitSupport

      public Boolean isDisableSpecificDbLimitSupport()
      Checks if specific DB limit support is disabled or enabled for current query.
    • setDisableSpecificDbLimitSupport

      public void setDisableSpecificDbLimitSupport(Boolean disableSpecificDbLimitSupport)
      Sets the specific DB limit support disabled or enabled for current query.
    • isDisableCaching

      public boolean isDisableCaching()
      Checks if caching for current query is disabled.
    • setDisableCaching

      public void setDisableCaching(boolean disableCaching)
      Sets caching of this query disabled or enabled. By default caching is always enabled.