public class View
extends java.lang.Object
This class allows construction and sending of View query requests. The API supports view queries for various data type results, and for pagination.
List<Foo> list = dbClient.view("example/foo")
.includeDocs(true).startKey("start-key").endKey("end-key").limit(10).query(Foo.class);
int count = dbClient.view("example/by_tag").key("couchdb").queryForInt(); // query for scalar values
// query for view entries
View view = dbClient.view("example/by_date")
.key(2011, 10, 15) // complex key example
.reduce(false)
.includeDocs(true);
ViewResult<int[], String, Foo> result =
view.queryView(int[].class, String.class, Foo.class);
// pagination
Page<Foo> page = dbClient.view("example/foo").queryPage(15, param, Foo.class);
// page.get*Param() contains the param to query subsequent pages, {@code null} param queries the first page
| Modifier and Type | Method and Description |
|---|---|
View |
descending(java.lang.Boolean descending)
Reverses the reading direction, not the sort order.
|
View |
endKey(java.lang.Object... endKey) |
View |
endKeyDocId(java.lang.String endKeyDocId) |
View |
group(java.lang.Boolean group) |
View |
groupLevel(java.lang.Integer groupLevel) |
View |
includeDocs(java.lang.Boolean includeDocs) |
View |
inclusiveEnd(java.lang.Boolean inclusiveEnd) |
View |
key(java.lang.Object... key) |
View |
keys(java.util.List<java.lang.String> keys) |
View |
limit(java.lang.Integer limit) |
<T> java.util.List<T> |
query(java.lang.Class<T> classOfT)
Queries a view.
|
boolean |
queryForBoolean() |
int |
queryForInt() |
long |
queryForLong() |
java.io.InputStream |
queryForStream()
Queries a view as an
InputStream |
java.lang.String |
queryForString() |
<T> Page<T> |
queryPage(int rowsPerPage,
java.lang.String param,
java.lang.Class<T> classOfT)
Queries a view for pagination, returns a next or a previous page, this method
figures out which page to return based on the given param that is generated by an
earlier call to this method, quering the first page is done by passing a
null param. |
<K,V,T> ViewResult<K,V,T> |
queryView(java.lang.Class<K> classOfK,
java.lang.Class<V> classOfV,
java.lang.Class<T> classOfT)
Queries a view.
|
View |
reduce(java.lang.Boolean reduce) |
View |
skip(java.lang.Integer skip) |
View |
stale(java.lang.String stale) |
View |
startKey(java.lang.Object... startKey) |
View |
startKeyDocId(java.lang.String startKeyDocId) |
View |
tempView(DesignDocument.MapReduce mapReduce) |
View |
tempView(java.lang.String id) |
View |
updateSeq(java.lang.Boolean updateSeq) |
public java.io.InputStream queryForStream()
InputStream
The stream should be properly closed after usage, as to avoid connection leaks.
InputStream.public <T> java.util.List<T> query(java.lang.Class<T> classOfT)
T - Object type TclassOfT - The class of type TList<T> public <K,V,T> ViewResult<K,V,T> queryView(java.lang.Class<K> classOfK, java.lang.Class<V> classOfV, java.lang.Class<T> classOfT)
K - Object type K (key)V - Object type V (value)classOfK - The class of type K.classOfV - The class of type V.classOfT - The class of type T.public java.lang.String queryForString()
public int queryForInt()
public long queryForLong()
public boolean queryForBoolean()
public <T> Page<T> queryPage(int rowsPerPage, java.lang.String param, java.lang.Class<T> classOfT)
null param.T - Object type TrowsPerPage - The number of rows per page.param - The request parameter to use to query a page, or null to return the first page.classOfT - The class of type T.Pagepublic View key(java.lang.Object... key)
key - The key value, accepts a single value or multiple values for complex keys.public View startKey(java.lang.Object... startKey)
startKey - The start key value, accepts a single value or multiple values for complex keys.public View startKeyDocId(java.lang.String startKeyDocId)
public View endKey(java.lang.Object... endKey)
endKey - The end key value, accepts a single value or multiple values for complex keys.public View endKeyDocId(java.lang.String endKeyDocId)
public View limit(java.lang.Integer limit)
public View stale(java.lang.String stale)
stale - Accept values: ok | update_after (update_after as of CouchDB 1.1.0)public View descending(java.lang.Boolean descending)
public View skip(java.lang.Integer skip)
skip - Skips n number of documents.public View group(java.lang.Boolean group)
group - Specifies whether the reduce function reduces the result to a set of keys,
or to a single result. Defaults to false (single result).public View groupLevel(java.lang.Integer groupLevel)
public View reduce(java.lang.Boolean reduce)
reduce - Indicates whether to use the reduce function of the view,
defaults to true if the reduce function is defined.public View includeDocs(java.lang.Boolean includeDocs)
public View inclusiveEnd(java.lang.Boolean inclusiveEnd)
inclusiveEnd - Indicates whether the endkey is included in the result,
defaults to true.public View updateSeq(java.lang.Boolean updateSeq)
public View keys(java.util.List<java.lang.String> keys)
public View tempView(java.lang.String id)
public View tempView(DesignDocument.MapReduce mapReduce)