Package com.couchbase.client.java.view
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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ViewQuerydebug()Enabled debugging on view queries.ViewQuerydebug(boolean debug)ViewQuerydescending()Return the documents in descending by key order.ViewQuerydescending(boolean desc)ViewQuerydevelopment()ViewQuerydevelopment(boolean development)protected Stringencode(String source)Helper method to properly encode a string.ViewQueryendKey(boolean key)ViewQueryendKey(double key)ViewQueryendKey(int key)ViewQueryendKey(long key)ViewQueryendKey(JsonArray key)ViewQueryendKey(JsonObject key)ViewQueryendKey(String key)ViewQueryendKeyDocId(String id)booleanequals(Object o)static ViewQueryfrom(String design, String view)Creates an newViewQuery.StringgetDesign()StringgetKeys()StringgetView()ViewQuerygroup()Group the results using the reduce function to a group or single row.ViewQuerygroup(boolean group)ViewQuerygroupLevel(int grouplevel)Specify the group level to be used.inthashCode()ViewQueryincludeDocs()Proactively load the full document for the row returned.ViewQueryincludeDocs(boolean includeDocs)Proactively load the full document for the row returned.ViewQueryincludeDocs(boolean includeDocs, Class<? extends Document<?>> target)Proactively load the full document for the row returned.ViewQueryincludeDocs(Class<? extends Document<?>> target)Proactively load the full document for the row returned.ViewQueryincludeDocsOrdered()Proactively load the full document for the row returned, while strictly retaining view row order.ViewQueryincludeDocsOrdered(boolean includeDocs)Proactively load the full document for the row returned, while strictly retaining view row order.ViewQueryincludeDocsOrdered(boolean includeDocs, Class<? extends Document<?>> target)Proactively load the full document for the row returned, while strictly retaining view row order.ViewQueryincludeDocsOrdered(Class<? extends Document<?>> target)Proactively load the full document for the row returned, while strictly retaining view row order.Class<? extends Document<?>>includeDocsTarget()ViewQueryinclusiveEnd()Specifies whether the specified end key should be included in the result.ViewQueryinclusiveEnd(boolean inclusive)booleanisDevelopment()booleanisIncludeDocs()booleanisOrderRetained()ViewQuerykey(boolean key)ViewQuerykey(double key)ViewQuerykey(int key)ViewQuerykey(long key)ViewQuerykey(JsonArray key)ViewQuerykey(JsonObject key)ViewQuerykey(String key)ViewQuerykeys(JsonArray keys)ViewQuerylimit(int limit)Limit the number of the returned documents to the specified number.ViewQueryonError(OnError onError)Sets the response in the event of an error.ViewQueryreduce()ViewQueryreduce(boolean reduce)Explicitly enable/disable the reduce function on the query.ViewQueryskip(int skip)Skip this number of records before starting to return the results.ViewQuerystale(Stale stale)Allow the results from a stale view to be used.ViewQuerystartKey(boolean key)ViewQuerystartKey(double key)ViewQuerystartKey(int key)ViewQuerystartKey(long key)ViewQuerystartKey(JsonArray key)ViewQuerystartKey(JsonObject key)ViewQuerystartKey(String key)ViewQuerystartKeyDocId(String id)StringtoQueryString()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.StringtoString()A string representation of this ViewQuery, suitable for logging and other human consumption.
-
-
-
Method Detail
-
from
public static ViewQuery from(String design, String view)
Creates an newViewQuery.- Parameters:
design- the name of the design document.view- the name of the view.- Returns:
- a
ViewQueryDSL.
-
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
ViewQueryDSL.
-
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
ViewQueryDSL.
-
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
ViewQueryDSL.
-
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
ViewQueryDSL.
-
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 (seeincludeDocsOrdered())} if you want to enforce the row order).- Returns:
- the
ViewQueryDSL.
-
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 (seeincludeDocsOrdered(Class))} if you want to enforce the row order).- Parameters:
target- the custom document type target.- Returns:
- the
ViewQueryDSL.
-
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 (seeincludeDocsOrdered(boolean)if you want to enforce the row order).- Parameters:
includeDocs- if it should be enabled or not.- Returns:
- the
ViewQueryDSL.
-
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 (seeincludeDocsOrdered(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
ViewQueryDSL.
-
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
ViewQueryobject 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
ViewQueryobject for proper chaining.
-
group
public ViewQuery group()
Group the results using the reduce function to a group or single row. Important: this setter andgroupLevel(int)should not be used together in the sameViewQuery. 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
ViewQueryobject 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 sameViewQuery. It is sufficient to only use this setter and usegroup()in cases where you always want the highest group level implictly.- Parameters:
grouplevel- How deep the grouping level should be.- Returns:
- the
ViewQueryobject for proper chaining.
-
inclusiveEnd
public ViewQuery inclusiveEnd()
Specifies whether the specified end key should be included in the result.- Returns:
- the
ViewQueryobject 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
ViewQueryobject 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
ViewQueryobject 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
ViewQueryobject for proper chaining.
-
debug
public ViewQuery debug()
Enabled debugging on view queries.- Returns:
- the
ViewQueryobject for proper chaining.
-
debug
public ViewQuery debug(boolean debug)
-
descending
public ViewQuery descending()
Return the documents in descending by key order.- Returns:
- the
ViewQueryobject for proper chaining.
-
descending
public ViewQuery descending(boolean desc)
-
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)
-
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)
-
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)
-
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 thatkeysis 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 thekeys(JsonArray)parameter is too large, it is truncated in this dump. see thetoQueryString()for the parameter representation of the ViewQuery execution URL.
-
getDesign
public String getDesign()
-
getView
public String getView()
-
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()
-
-