K
- the type of key emitted by the viewV
- the type of value emitted by the viewpublic interface ViewRequest<K,V>
Modifier and Type | Method and Description |
---|---|
ViewResponse<K,V> |
getResponse()
Performs the request and returns the response.
|
ViewResponse<K,V> |
getResponse(java.lang.String paginationToken)
Performs view request for the page represented by a pagination token obtained from a
previous request.
|
V |
getSingleValue()
Performs the request and returns a single value.
|
ViewResponse<K,V> getResponse() throws java.io.IOException
Example usage:
ViewResponse<String, String> response = db.getViewRequestBuilder("designDoc","viewName")
.newRequest(Key.Type.STRING, String.class)
.build()
.getResponse();
java.io.IOException
- if there is an error communicating with the serverViewResponse<K,V> getResponse(java.lang.String paginationToken) throws java.io.IOException
Example usage for stateless pagination:
ViewResponse<String, String> responsePage1 = db.getViewRequestBuilder("designDoc","viewName")
.newRequest(Key.Type.STRING, String.class)
.build()
.getResponse();
String tokenForPage2 = responsePage1.getNextPageToken();
// To request the next page:
// 1. Recreate the view request by supplying the same parameters to the builder.
// 2. Execute the request using the pagination token retrieved above.
ViewResponse<String, String> responsePage2 = db.getViewRequestBuilder("designDoc","viewName")
.newRequest(Key.Type.STRING, String.class)
.build()
.getResponse(tokenForPage2);
paginationToken
- obtained from a previous ViewResponse, null
is equivalent to
getResponse()
java.io.IOException
- if there is an error communicating with the serverViewResponse.getNextPageToken()
,
ViewResponse.getPreviousPageToken()
V getSingleValue() throws java.io.IOException
This is primarily intended for retrieving a single result (e.g. count) from a reduced view.
Example usage for a view with a "_count" reduce function:
Integer count = db.getViewRequestBuilder("designDoc","viewWithCount")
.newRequest(Key.Type.STRING, Integer.class)
.reduce(true) //this is the default, but shown for clarity
.build()
.getSingleValue();
null
if there were no rowsjava.io.IOException
- if there is an error communicating with the server