Class AbstractQuery
- Direct Known Subclasses:
FlexibleSearchQuery,GenericSearchQuery
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a collection with catalog versions for this FlexibleSearchQuery which were explicitly set bysetCatalogVersions(Collection).intgetCount()Deprecated, for removal: This API element is subject to removal in a future version.Gets the locale which will be used for executing query.This list contains the expected types/classes of the result objects.Gets the session search restrictions will be used for executing query.intgetStart()Default value for the start range is 0 (first element).getUser()Gets the user for which query will be executed.booleanChecks if caching for current query is disabled.booleanChecks if specific DB limit support is disabled or enabled for current query.booleanbooleanChecks if is need total.booleanvoidsetCatalogVersions(CatalogVersionModel... catalogVersions) Overwrites the global search restrictions for catalog versions.voidsetCatalogVersions(Collection<CatalogVersionModel> catalogVersions) Overwrites the global search restrictions for catalog versions.voidsetCount(int count) Set the number of elements in the search range.voidsetDisableCaching(boolean disableCaching) Sets caching of this query disabled or enabled.voidsetDisableSearchRestrictions(boolean disableSearchRestrictions) Set this value totrueif you want to disable search restrictions.voidsetDisableSpecificDbLimitSupport(Boolean disableSpecificDbLimitSupport) Sets the specific DB limit support disabled or enabled for current query.voidsetFailOnUnknownFields(boolean isFailOnUnknownFields) Set this value totrue(default value) and it causes an error when using an unknown field name.voidsetLanguage(LanguageModel language) Deprecated, for removal: This API element is subject to removal in a future version.voidSets the locale which will be used for executing query.voidsetNeedTotal(boolean needTotal) Sets theisNeedTotal.<T extends Class>
voidsetResultClassList(List<T> resultClassList) Sets the expected result types signature as list.voidsetSessionSearchRestrictions(SessionSearchRestriction... sessionSearchRestrictions) Adds the session search restrictions which will be used for executing query.voidsetSessionSearchRestrictions(Collection<SessionSearchRestriction> sessionSearchRestrictions) Adds the session search restrictions which will be used for executing query.voidsetStart(int start) Sets the start number of the search range.voidsetTypeExclusive(boolean typeExclusive) voidSets the user to the search session context.
-
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 totrueif you want to disable search restrictions. -
setTypeExclusive
public void setTypeExclusive(boolean typeExclusive) -
setFailOnUnknownFields
public void setFailOnUnknownFields(boolean isFailOnUnknownFields) Set this value totrue(default value) and it causes an error when using an unknown field name.- Parameters:
isFailOnUnknownFields- Set tofalseif unknown field names should be ignored
-
isFailOnUnknownFields
public boolean isFailOnUnknownFields()- Returns:
trueif 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, for removal: This API element is subject to removal in a future version.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
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
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()isfalse!
This means: When usingsetCount(int)in the SearchResult theSearchResult.getTotalCount()will be equal to the used value insetCount(int). WhenisNeedTotal()istruethen total count will be returned from methodSearchResult.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 valueisNeedTotal()=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, for removal: This API element is subject to removal in a future version.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
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
Localehave 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
Localeobject 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()isfalse!
This means: When usingsetCount(int)in the SearchResult theSearchResult.getTotalCount()will be equal to the used value insetCount(int). WhenisNeedTotal()istruethen total count will be returned from methodSearchResult.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
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
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
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
Returns a collection with catalog versions for this FlexibleSearchQuery which were explicitly set bysetCatalogVersions(Collection). This collection is used for the search restrictions. If this method returnsnullthe global search restrictions are used for the search (which are stored at the search session usingCatalogVersionService.addSessionCatalogVersion(CatalogVersionModel))- Returns:
- a collection with catalog versions
-
setCatalogVersions
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 usingCatalogVersionService.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
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 usingCatalogVersionService.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
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
Sets the user to the search session context. The search is executed with the restrictions for this user.
If the user is
nullor 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
Checks if specific DB limit support is disabled or enabled for current query. -
setDisableSpecificDbLimitSupport
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.
-
getLocale()andsetLocale(Locale)instead ofLanguageModeldirectly.