Class AbstractQuery
- java.lang.Object
-
- de.hybris.platform.servicelayer.search.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()
isfalse
!
This means: When usingsetCount(int)
in the SearchResult theSearchResult.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 Constructor Description AbstractQuery()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.util.Collection<CatalogVersionModel>
getCatalogVersions()
Returns a collection with catalog versions for this FlexibleSearchQuery which were explicitly set bysetCatalogVersions(Collection)
.int
getCount()
LanguageModel
getLanguage()
Deprecated.java.util.Locale
getLocale()
Gets the locale which will be used for executing query.<T extends java.lang.Class>
java.util.List<T>getResultClassList()
This list contains the expected types/classes of the result objects.java.util.Collection<SessionSearchRestriction>
getSessionSearchRestrictions()
Gets the session search restrictions will be used for executing query.int
getStart()
Default value for the start range is 0 (first element).UserModel
getUser()
Gets the user for which query will be executed.boolean
isDisableCaching()
Checks if caching for current query is disabled.boolean
isDisableSearchRestrictions()
java.lang.Boolean
isDisableSpecificDbLimitSupport()
Checks if specific DB limit support is disabled or enabled for current query.boolean
isFailOnUnknownFields()
boolean
isNeedTotal()
Checks if is need total.void
setCatalogVersions(CatalogVersionModel... catalogVersions)
Overwrites the global search restrictions for catalog versions.void
setCatalogVersions(java.util.Collection<CatalogVersionModel> catalogVersions)
Overwrites the global search restrictions for catalog versions.void
setCount(int count)
Set the number of elements in the search range.void
setDisableCaching(boolean disableCaching)
Sets caching of this query disabled or enabled.void
setDisableSearchRestrictions(boolean disableSearchRestrictions)
Set this value totrue
if you want to disable search restrictions.void
setDisableSpecificDbLimitSupport(java.lang.Boolean disableSpecificDbLimitSupport)
Sets the specific DB limit support disabled or enabled for current query.void
setFailOnUnknownFields(boolean isFailOnUnknownFields)
Set this value totrue
(default value) and it causes an error when using an unknown field name.void
setLanguage(LanguageModel language)
Deprecated.void
setLocale(java.util.Locale locale)
Sets the locale which will be used for executing query.void
setNeedTotal(boolean needTotal)
Sets theisNeedTotal
.<T extends java.lang.Class>
voidsetResultClassList(java.util.List<T> resultClassList)
Sets the expected result types signature as list.void
setSessionSearchRestrictions(SessionSearchRestriction... sessionSearchRestrictions)
Adds the session search restrictions which will be used for executing query.void
setSessionSearchRestrictions(java.util.Collection<SessionSearchRestriction> sessionSearchRestrictions)
Adds the session search restrictions which will be used for executing query.void
setStart(int start)
Sets the start number of the search range.void
setUser(UserModel user)
Sets the user to the search session context.
-
-
-
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 totrue
if you want to disable search restrictions.
-
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 tofalse
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.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.
-
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()
istrue
then 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 public void setLanguage(LanguageModel language)
Deprecated.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
-
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()
istrue
then 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(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
-
getCatalogVersions
public java.util.Collection<CatalogVersionModel> 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 returnsnull
the 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
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 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
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 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
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.
-
-