Resource
- The type of the resource to be returned by this query.Query
- The query type to be returned on chaining to avoid casting on client side.public abstract class AbsQuery<Resource,Query extends AbsQuery<Resource,Query>>
extends java.lang.Object
This class includes options to query for entries, limit the amount of responses and more.
Modifier and Type | Method and Description |
---|---|
Query |
include(int level)
Include references entries and their entries up to the given level.
|
Query |
limit(int limit)
Limits the amount of elements to a given number.
|
Query |
linksToAssetId(java.lang.String assetId)
Request entries that link to given entryId.
|
Query |
linksToEntryId(java.lang.String entryId)
Request entries that link to given entryId.
|
Query |
orderBy(java.lang.String... keys)
Order result by the multiple keys.
|
Query |
orderBy(java.lang.String key)
Order result by the given key.
|
Query |
reverseOrderBy(java.lang.String key)
Order result by the given key, reversing the order.
|
Query |
select(java.lang.String... selections)
Convenient method for chaining several select queries together.
|
Query |
select(java.lang.String selection)
Limit response to only selected properties.
|
Query |
skip(int skip)
Skips the first elements of a response.
|
<T> Query |
where(java.lang.String name,
QueryOperation<T> queryOperation,
T... values)
Complex where query.
|
Query |
where(java.lang.String key,
java.lang.String value)
Simple `where` query.
|
Query |
withContentType(java.lang.String contentType)
Requesting a specific content type.
|
public Query withContentType(java.lang.String contentType)
The content type is especially useful if you want to limit the result of this query to only one content model type.
You must specify a content type before querying a specific field on a query, an exception will be thrown otherwise.
contentType
- the content type to be used.java.lang.IllegalArgumentException
- if contentType is null.java.lang.IllegalArgumentException
- if contentType is empty.java.lang.IllegalStateException
- if contentType was set before.public Query select(java.lang.String selection)
Returns an object in which fields not specified will be null, resulting in potentially smaller response from Contentful.
The complete sys object will always be returned.
selection
- to be used. Should be 'fields.name' or similar.java.lang.NullPointerException
- if selection is null.java.lang.IllegalArgumentException
- if selection is empty.java.lang.IllegalStateException
- if no content type was queried for before.java.lang.IllegalArgumentException
- if tried to request deeper then the name of a selection.public Query linksToEntryId(java.lang.String entryId)
entryId
- to be used.java.lang.NullPointerException
- if entryId is null.java.lang.IllegalArgumentException
- if entryId is empty.public Query linksToAssetId(java.lang.String assetId)
assetId
- to be used.java.lang.NullPointerException
- if entryId is null.java.lang.IllegalArgumentException
- if entryId is empty.public Query select(java.lang.String... selections)
This method makes it easier to select multiple properties from one method call. It calls select for all of its arguments.
selections
- field names to be requested.java.lang.NullPointerException
- if a field is null.java.lang.IllegalArgumentException
- if a field is of zero length, aka empty.java.lang.IllegalStateException
- if no contentType was queried for before.java.lang.IllegalArgumentException
- if tried to request deeper then the name of a field.java.lang.IllegalArgumentException
- if no selections were requested.select(String)
public <T> Query where(java.lang.String name, QueryOperation<T> queryOperation, T... values)
Use this for a more controlled and versatile way of doing specialized search requests.
T
- value type the operation uses.name
- which attribute should be checked?queryOperation
- specify the queryOperation here.values
- a list of values to be checked.java.lang.IllegalArgumentException
- if name is empty or null.java.lang.IllegalArgumentException
- if queryOperation is not set.java.lang.IllegalArgumentException
- if values is not set.java.lang.IllegalArgumentException
- if values does not contain valid values.java.lang.IllegalArgumentException
- if one value was null or empty.java.lang.IllegalStateException
- if no content type was set first, but a field was requested.java.lang.IllegalArgumentException
- if name does not start with either sys or field.QueryOperation
public Query where(java.lang.String key, java.lang.String value)
This query will be used if there are not specialized queries available. Please use the more concrete methods in order to gain type safety and early exceptions, without requesting the API.
key
- the key to be added to the query.value
- the value to be added.public Query orderBy(java.lang.String key)
Please do not forget to include the content type if you are requesting to order by a field.
key
- the key to be ordered by.java.lang.IllegalArgumentException
- if key is null.java.lang.IllegalArgumentException
- if key is empty.java.lang.IllegalStateException
- if key requests a field, but no content type is requested.withContentType(String)
public Query orderBy(java.lang.String... keys)
Please do not forget to include the content type if you are requesting to order by a field.
keys
- the keys to be ordered by.java.lang.IllegalArgumentException
- if keys is null.java.lang.IllegalArgumentException
- if keys is empty.java.lang.IllegalArgumentException
- if one key is null.java.lang.IllegalArgumentException
- if one key is empty.java.lang.IllegalStateException
- if one key requests a field, but no content type is requested.withContentType(String)
,
orderBy(String)
public Query reverseOrderBy(java.lang.String key)
Please do not forget to include the content type if you are requesting to order by a field.
key
- the key to be reversely ordered by.java.lang.IllegalArgumentException
- if key is null.java.lang.IllegalArgumentException
- if key is empty.java.lang.IllegalStateException
- if key requests a field, but no content type is requested.withContentType(String)
public Query limit(int limit)
If more then the number given elements are present, you can use skip(int)
and
this method for pagination.
limit
- a non negative number less than 1001 to include elements.skip(int)
public Query skip(int skip)
If more limit(int) elements are present, you can use skip(int) to simulate pagination.
skip
- a non negative number to exclude the first elements.limit(int)
public Query include(int level)
A level of inclusion of 0 means, do not include references referenced, but not requested. Please note also, that more then 10 include levels cannot be specified.
level
- the number of recursion of inclusion to be used.Copyright © 2019 Contentful, GmbH.. All Rights Reserved.