Class AbsQuery<Resource,​Query extends AbsQuery<Resource,​Query>>

  • Type Parameters:
    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.
    Direct Known Subclasses:
    FetchQuery, ObserveQuery, TransformQuery

    public abstract class AbsQuery<Resource,​Query extends AbsQuery<Resource,​Query>>
    extends java.lang.Object
    Root of all queries.

    This class includes options to query for entries, limit the amount of responses and more.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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 key)
      Order result by the given key.
      Query orderBy​(java.lang.String... keys)
      Order result by the multiple keys.
      Query reverseOrderBy​(java.lang.String key)
      Order result by the given key, reversing the order.
      Query select​(java.lang.String selection)
      Limit response to only selected properties.
      Query select​(java.lang.String... selections)
      Convenient method for chaining several select queries together.
      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.
      Query withLocale​(java.lang.String locale)
      Requesting content with specific locale.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • withContentType

        public Query withContentType​(java.lang.String contentType)
        Requesting a specific content type.

        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.

        Parameters:
        contentType - the content type to be used.
        Returns:
        the calling query for chaining.
        Throws:
        java.lang.IllegalArgumentException - if contentType is null.
        java.lang.IllegalArgumentException - if contentType is empty.
        java.lang.IllegalStateException - if contentType was set before.
      • withLocale

        public Query withLocale​(java.lang.String locale)
        Requesting content with specific locale.
        Parameters:
        locale - the locale to be used.
        Returns:
        the calling query for chaining.
        Throws:
        java.lang.IllegalArgumentException - if locale is null.
        java.lang.IllegalStateException - if locale was set before.
      • select

        public Query select​(java.lang.String selection)
        Limit response to only selected properties.

        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.

        Parameters:
        selection - to be used. Should be 'fields.name' or similar.
        Returns:
        the calling query for chaining.
        Throws:
        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.
      • linksToEntryId

        public Query linksToEntryId​(java.lang.String entryId)
        Request entries that link to given entryId.
        Parameters:
        entryId - to be used.
        Returns:
        the calling query for chaining.
        Throws:
        java.lang.NullPointerException - if entryId is null.
        java.lang.IllegalArgumentException - if entryId is empty.
      • linksToAssetId

        public Query linksToAssetId​(java.lang.String assetId)
        Request entries that link to given entryId.
        Parameters:
        assetId - to be used.
        Returns:
        the calling query for chaining.
        Throws:
        java.lang.NullPointerException - if entryId is null.
        java.lang.IllegalArgumentException - if entryId is empty.
      • select

        public Query select​(java.lang.String... selections)
        Convenient method for chaining several select queries together.

        This method makes it easier to select multiple properties from one method call. It calls select for all of its arguments.

        Parameters:
        selections - field names to be requested.
        Returns:
        the calling query for chaining.
        Throws:
        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.
        See Also:
        select(String)
      • where

        public <T> Query where​(java.lang.String name,
                               QueryOperation<T> queryOperation,
                               T... values)
        Complex where query.

        Use this for a more controlled and versatile way of doing specialized search requests.

        Type Parameters:
        T - value type the operation uses.
        Parameters:
        name - which attribute should be checked?
        queryOperation - specify the queryOperation here.
        values - a list of values to be checked.
        Returns:
        the calling query for chaining.
        Throws:
        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.
        See Also:
        QueryOperation
      • where

        public Query where​(java.lang.String key,
                           java.lang.String value)
        Simple `where` query.

        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.

        Parameters:
        key - the key to be added to the query.
        value - the value to be added.
        Returns:
        the calling query for chaining.
      • orderBy

        public Query orderBy​(java.lang.String key)
        Order result by the given key.

        Please do not forget to include the content type if you are requesting to order by a field.

        Parameters:
        key - the key to be ordered by.
        Returns:
        the calling query for chaining.
        Throws:
        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.
        See Also:
        withContentType(String)
      • orderBy

        public Query orderBy​(java.lang.String... keys)
        Order result by the multiple keys.

        Please do not forget to include the content type if you are requesting to order by a field.

        Parameters:
        keys - the keys to be ordered by.
        Returns:
        the calling query for chaining.
        Throws:
        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.
        See Also:
        withContentType(String), orderBy(String)
      • reverseOrderBy

        public Query reverseOrderBy​(java.lang.String key)
        Order result by the given key, reversing the order.

        Please do not forget to include the content type if you are requesting to order by a field.

        Parameters:
        key - the key to be reversely ordered by.
        Returns:
        the calling query for chaining.
        Throws:
        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.
        See Also:
        withContentType(String)
      • limit

        public Query limit​(int limit)
        Limits the amount of elements to a given number.

        If more then the number given elements are present, you can use skip(int) and this method for pagination.

        Parameters:
        limit - a non negative number less than 1001 to include elements.
        Returns:
        the calling query for chaining.
        See Also:
        skip(int)
      • skip

        public Query skip​(int skip)
        Skips the first elements of a response.

        If more limit(int) elements are present, you can use skip(int) to simulate pagination.

        Parameters:
        skip - a non negative number to exclude the first elements.
        Returns:
        the calling query for chaining.
        See Also:
        limit(int)
      • include

        public Query include​(int level)
        Include references entries and their entries up to the given 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.

        Parameters:
        level - the number of recursion of inclusion to be used.
        Returns:
        the calling query for chaining.