Class AbstractQuery

  • Direct Known Subclasses:
    FlexibleSearchQuery, GenericSearchQuery

    public abstract class AbstractQuery
    extends java.lang.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 Detail

      • AbstractQuery

        public AbstractQuery()
    • Method Detail

      • 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.
      • 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.
      • getCount

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

        @Deprecated
        public LanguageModel getLanguage()
        Deprecated.
        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 java.util.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 java.util.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.
      • 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
        public void setLanguage​(LanguageModel language)
        Deprecated.
        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​(java.util.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
      • setSessionSearchRestrictions

        public void setSessionSearchRestrictions​(java.util.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 java.lang.Class> java.util.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 java.lang.Class> void setResultClassList​(java.util.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
      • setCatalogVersions

        public void setCatalogVersions​(java.util.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 java.lang.Boolean isDisableSpecificDbLimitSupport()
        Checks if specific DB limit support is disabled or enabled for current query.
      • setDisableSpecificDbLimitSupport

        public void setDisableSpecificDbLimitSupport​(java.lang.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.