Class ViewQuery

java.lang.Object
com.couchbase.client.java.view.ViewQuery
All Implemented Interfaces:
Serializable

public class ViewQuery
extends Object
implements Serializable
Fluent DSL for a View Query.
Since:
2.0.0
Author:
Michael Nitschinger
See Also:
Serialized Form
  • Method Details

    • from

      public static ViewQuery from​(String design, String view)
      Creates an new ViewQuery.
      Parameters:
      design - the name of the design document.
      view - the name of the view.
      Returns:
      a ViewQuery DSL.
    • development

      public ViewQuery development()
    • development

      public ViewQuery development​(boolean development)
    • includeDocsOrdered

      public ViewQuery includeDocsOrdered()
      Proactively load the full document for the row returned, while strictly retaining view row order. This only works if reduce is false, since with reduce the original document ID is not included anymore.
      Returns:
      the ViewQuery DSL.
    • includeDocsOrdered

      public ViewQuery includeDocsOrdered​(Class<? extends Document<?>> target)
      Proactively load the full document for the row returned, while strictly retaining view row order. This only works if reduce is false, since with reduce the original document ID is not included anymore.
      Parameters:
      target - the custom document type target.
      Returns:
      the ViewQuery DSL.
    • includeDocsOrdered

      public ViewQuery includeDocsOrdered​(boolean includeDocs)
      Proactively load the full document for the row returned, while strictly retaining view row order. This only works if reduce is false, since with reduce the original document ID is not included anymore.
      Parameters:
      includeDocs - if it should be enabled or not.
      Returns:
      the ViewQuery DSL.
    • includeDocsOrdered

      public ViewQuery includeDocsOrdered​(boolean includeDocs, Class<? extends Document<?>> target)
      Proactively load the full document for the row returned, while strictly retaining view row order. This only works if reduce is false, since with reduce the original document ID is not included anymore.
      Parameters:
      includeDocs - if it should be enabled or not.
      target - the custom document type target.
      Returns:
      the ViewQuery DSL.
    • includeDocs

      public ViewQuery includeDocs()
      Proactively load the full document for the row returned. This only works if reduce is false, since with reduce the original document ID is not included anymore. The order could be changed if one of the document takes longer to load than the others (see includeDocsOrdered() )} if you want to enforce the row order).
      Returns:
      the ViewQuery DSL.
    • includeDocs

      public ViewQuery includeDocs​(Class<? extends Document<?>> target)
      Proactively load the full document for the row returned. This only works if reduce is false, since with reduce the original document ID is not included anymore. The order could be changed if one of the document takes longer to load than the others (see includeDocsOrdered(Class) )} if you want to enforce the row order).
      Parameters:
      target - the custom document type target.
      Returns:
      the ViewQuery DSL.
    • includeDocs

      public ViewQuery includeDocs​(boolean includeDocs)
      Proactively load the full document for the row returned. This only works if reduce is false, since with reduce the original document ID is not included anymore. The order could be changed if one of the document takes longer to load than the others (see includeDocsOrdered(boolean) if you want to enforce the row order).
      Parameters:
      includeDocs - if it should be enabled or not.
      Returns:
      the ViewQuery DSL.
    • includeDocs

      public ViewQuery includeDocs​(boolean includeDocs, Class<? extends Document<?>> target)
      Proactively load the full document for the row returned. This only works if reduce is false, since with reduce the original document ID is not included anymore. The order could be changed if one of the document takes longer to load than the others (see includeDocsOrdered(boolean, Class) if you want to enforce the row order).
      Parameters:
      includeDocs - if it should be enabled or not.
      target - the custom document type target.
      Returns:
      the ViewQuery DSL.
    • reduce

      public ViewQuery reduce​(boolean reduce)
      Explicitly enable/disable the reduce function on the query.
      Parameters:
      reduce - if reduce should be enabled or not.
      Returns:
      the ViewQuery object for proper chaining.
    • reduce

      public ViewQuery reduce()
    • limit

      public ViewQuery limit​(int limit)
      Limit the number of the returned documents to the specified number.
      Parameters:
      limit - the number of documents to return.
      Returns:
      the ViewQuery object for proper chaining.
    • group

      public ViewQuery group()
      Group the results using the reduce function to a group or single row. Important: this setter and groupLevel(int) should not be used together in the same ViewQuery. It is sufficient to only set the grouping level only and use this setter in cases where you always want the highest group level implictly.
      Returns:
      the ViewQuery object for proper chaining.
    • group

      public ViewQuery group​(boolean group)
    • groupLevel

      public ViewQuery groupLevel​(int grouplevel)
      Specify the group level to be used. Important: group() and this setter should not be used together in the same ViewQuery. It is sufficient to only use this setter and use group() in cases where you always want the highest group level implictly.
      Parameters:
      grouplevel - How deep the grouping level should be.
      Returns:
      the ViewQuery object for proper chaining.
    • inclusiveEnd

      public ViewQuery inclusiveEnd()
      Specifies whether the specified end key should be included in the result.
      Returns:
      the ViewQuery object for proper chaining.
    • inclusiveEnd

      public ViewQuery inclusiveEnd​(boolean inclusive)
    • skip

      public ViewQuery skip​(int skip)
      Skip this number of records before starting to return the results.
      Parameters:
      skip - The number of records to skip.
      Returns:
      the ViewQuery object for proper chaining.
    • stale

      public ViewQuery stale​(Stale stale)
      Allow the results from a stale view to be used. See the "Stale" enum for more information on the possible options. The default setting is "update_after"!
      Parameters:
      stale - Which stale mode should be used.
      Returns:
      the ViewQuery object for proper chaining.
    • onError

      public ViewQuery onError​(OnError onError)
      Sets the response in the event of an error. See the "OnError" enum for more details on the available options.
      Parameters:
      onError - The appropriate error handling type.
      Returns:
      the ViewQuery object for proper chaining.
    • debug

      public ViewQuery debug()
      Enabled debugging on view queries.
      Returns:
      the ViewQuery object for proper chaining.
    • debug

      public ViewQuery debug​(boolean debug)
    • descending

      public ViewQuery descending()
      Return the documents in descending by key order.
      Returns:
      the ViewQuery object for proper chaining.
    • descending

      public ViewQuery descending​(boolean desc)
    • key

      public ViewQuery key​(String key)
    • key

      public ViewQuery key​(int key)
    • key

      public ViewQuery key​(long key)
    • key

      public ViewQuery key​(double key)
    • key

      public ViewQuery key​(boolean key)
    • key

      public ViewQuery key​(JsonObject key)
    • key

      public ViewQuery key​(JsonArray key)
    • keys

      public ViewQuery keys​(JsonArray keys)
    • startKeyDocId

      public ViewQuery startKeyDocId​(String id)
    • endKeyDocId

      public ViewQuery endKeyDocId​(String id)
    • endKey

      public ViewQuery endKey​(String key)
    • endKey

      public ViewQuery endKey​(int key)
    • endKey

      public ViewQuery endKey​(long key)
    • endKey

      public ViewQuery endKey​(double key)
    • endKey

      public ViewQuery endKey​(boolean key)
    • endKey

      public ViewQuery endKey​(JsonObject key)
    • endKey

      public ViewQuery endKey​(JsonArray key)
    • startKey

      public ViewQuery startKey​(String key)
    • startKey

      public ViewQuery startKey​(int key)
    • startKey

      public ViewQuery startKey​(long key)
    • startKey

      public ViewQuery startKey​(double key)
    • startKey

      public ViewQuery startKey​(boolean key)
    • startKey

      public ViewQuery startKey​(JsonObject key)
    • startKey

      public ViewQuery startKey​(JsonArray key)
    • encode

      protected String encode​(String source)
      Helper method to properly encode a string. This method can be overridden if a different encoding logic needs to be used. If so, note that keys is not encoded via this method, but by the core.
      Parameters:
      source - source string.
      Returns:
      encoded target string.
    • toQueryString

      public String toQueryString()
      Returns the query string for this ViewQuery, containing all the key/value pairs for parameters that will be part of this ViewQuery's execution URL for the view service.
    • toString

      public String toString()
      A string representation of this ViewQuery, suitable for logging and other human consumption. If the keys(JsonArray) parameter is too large, it is truncated in this dump. see the toQueryString() for the parameter representation of the ViewQuery execution URL.
      Overrides:
      toString in class Object
    • getDesign

      public String getDesign()
    • getView

      public String getView()
    • getKeys

      public String getKeys()
      Returns:
      the String JSON representation of the keys parameter.
    • isOrderRetained

      public boolean isOrderRetained()
      Returns:
      true if row order, as returned by the view, should be kept while also including docs.
    • isDevelopment

      public boolean isDevelopment()
    • isIncludeDocs

      public boolean isIncludeDocs()
    • includeDocsTarget

      public Class<? extends Document<?>> includeDocsTarget()
    • equals

      public boolean equals​(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object