org.ektorp
Class ViewQuery

java.lang.Object
  extended by org.ektorp.ViewQuery

public class ViewQuery
extends Object

Author:
henrik lundgren

Nested Class Summary
static class ViewQuery.Keys
           
 
Constructor Summary
ViewQuery()
           
ViewQuery(org.codehaus.jackson.map.ObjectMapper om)
          Bring your own ObjectMapper.
 
Method Summary
 ViewQuery allDocs()
          Will automatically set the query special _all_docs URI.
 String buildQuery()
           
 ViewQuery cacheOk(boolean b)
          If set to true, the view query result will be cached and subsequent queries (with cacheOk set) may be served from the cache instead of the db.
 ViewQuery dbPath(String s)
           
 ViewQuery descending(boolean b)
          View rows are sorted by the key; specifying descending=true will reverse their order.
 ViewQuery designDocId(String s)
           
 ViewQuery endDocId(String s)
           
 ViewQuery endKey(boolean b)
           
 ViewQuery endKey(double d)
           
 ViewQuery endKey(float f)
           
 ViewQuery endKey(int i)
           
 ViewQuery endKey(long l)
           
 ViewQuery endKey(Object o)
           
 ViewQuery endKey(String s)
           
 boolean equals(Object obj)
           
 String getDbPath()
           
 String getDesignDocId()
           
 String getEndDocId()
           
 Object getEndKey()
           
 int getGroupLevel()
           
 Object getKey()
           
 String getKeysAsJson()
           
 int getLimit()
           
 int getSkip()
           
 String getStartDocId()
           
 Object getStartKey()
           
 String getViewName()
           
 ViewQuery group(boolean b)
          The group option controls whether the reduce function reduces to a set of distinct keys or to a single result row.
 ViewQuery groupLevel(int i)
           
 int hashCode()
           
 boolean hasMultipleKeys()
           
 ViewQuery includeDocs(boolean b)
          The include_docs option will include the associated document.
 ViewQuery inclusiveEnd(boolean b)
          The inclusive_end option controls whether the endkey is included in the result.
 boolean isCacheOk()
           
 boolean isDescending()
           
 boolean isGroup()
           
 boolean isIgnoreNotFound()
           
 boolean isIncludeDocs()
           
 boolean isInclusiveEnd()
           
 boolean isReduce()
           
 boolean isStaleOk()
           
 boolean isUpdateSeq()
           
 ViewQuery key(boolean b)
           
 ViewQuery key(double d)
           
 ViewQuery key(float f)
           
 ViewQuery key(int i)
           
 ViewQuery key(long l)
           
 ViewQuery key(Object o)
           
 ViewQuery key(String s)
           
 ViewQuery keys(Collection<?> keyList)
          For multiple-key queries (as of CouchDB 0.9).
 ViewQuery limit(int i)
          limit=0 you don't get any data, but all meta-data for this View.
 ViewQuery listName(String s)
           
 ViewQuery queryParam(String name, String value)
           
 ViewQuery rawEndKey(String s)
           
 ViewQuery rawKey(String s)
           
 ViewQuery rawStartKey(String s)
           
 ViewQuery reduce(boolean b)
          If a view contains both a map and reduce function, querying that view will by default return the result of the reduce function.
 void reset()
          Resets internal state so this builder can be used again.
 void setIgnoreNotFound(boolean ignoreNotFound)
           
 ViewQuery skip(int i)
          The skip option should only be used with small values, as skipping a large range of documents this way is inefficient (it scans the index from the startkey and then skips N elements, but still needs to read all the index values to do that).
 ViewQuery staleOk(boolean b)
          The stale option can be used for higher performance at the cost of possibly not seeing the all latest data.
 ViewQuery staleOkUpdateAfter()
          Same as staleOk(true) but will also trigger a rebuild of the view index after the results of the view have been retrieved.
 ViewQuery startDocId(String s)
           
 ViewQuery startKey(boolean b)
           
 ViewQuery startKey(double d)
           
 ViewQuery startKey(float f)
           
 ViewQuery startKey(int i)
           
 ViewQuery startKey(long l)
           
 ViewQuery startKey(Object o)
           
 ViewQuery startKey(String s)
           
 ViewQuery updateSeq(boolean b)
          The update_seq option adds a field to the result indicating the update_seq the view reflects.
 ViewQuery viewName(String s)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ViewQuery

public ViewQuery()

ViewQuery

public ViewQuery(org.codehaus.jackson.map.ObjectMapper om)
Bring your own ObjectMapper. The mapper is used when serializing keys when building the query.

Parameters:
om -
Method Detail

getDbPath

public String getDbPath()

getDesignDocId

public String getDesignDocId()

getViewName

public String getViewName()

getStartDocId

public String getStartDocId()

getEndDocId

public String getEndDocId()

getLimit

public int getLimit()

isStaleOk

public boolean isStaleOk()

isDescending

public boolean isDescending()

getSkip

public int getSkip()

isGroup

public boolean isGroup()

getGroupLevel

public int getGroupLevel()

isReduce

public boolean isReduce()

isIncludeDocs

public boolean isIncludeDocs()

isInclusiveEnd

public boolean isInclusiveEnd()

isUpdateSeq

public boolean isUpdateSeq()

dbPath

public ViewQuery dbPath(String s)

designDocId

public ViewQuery designDocId(String s)

allDocs

public ViewQuery allDocs()
Will automatically set the query special _all_docs URI. In this case, setting designDocId will have no effect.

Returns:

viewName

public ViewQuery viewName(String s)

listName

public ViewQuery listName(String s)

cacheOk

public ViewQuery cacheOk(boolean b)
If set to true, the view query result will be cached and subsequent queries (with cacheOk set) may be served from the cache instead of the db. Note that if the view changes, the cache will be invalidated.

Parameters:
b -
Returns:

isCacheOk

public boolean isCacheOk()

key

public ViewQuery key(String s)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

rawKey

public ViewQuery rawKey(String s)
Parameters:
Will - be parsed as JSON.
Returns:
the view query for chained calls

key

public ViewQuery key(int i)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

key

public ViewQuery key(long l)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

key

public ViewQuery key(float f)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

key

public ViewQuery key(double d)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

key

public ViewQuery key(boolean b)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

key

public ViewQuery key(Object o)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

keys

public ViewQuery keys(Collection<?> keyList)
For multiple-key queries (as of CouchDB 0.9). Keys will be JSON-encoded.

Parameters:
keyList - a list of Object, will be JSON encoded according to each element's type.
Returns:
the view query for chained calls

startKey

public ViewQuery startKey(String s)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

rawStartKey

public ViewQuery rawStartKey(String s)
Parameters:
Will - be parsed as json
Returns:
the view query for chained calls

startKey

public ViewQuery startKey(int i)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

startKey

public ViewQuery startKey(long l)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

startKey

public ViewQuery startKey(float f)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

startKey

public ViewQuery startKey(double d)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

startKey

public ViewQuery startKey(boolean b)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

startKey

public ViewQuery startKey(Object o)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

startDocId

public ViewQuery startDocId(String s)

endKey

public ViewQuery endKey(String s)
Parameters:
will - be JSON-encoded.
Returns:
the view query for chained calls

rawEndKey

public ViewQuery rawEndKey(String s)
Parameters:
will - be parsed as JSON.
Returns:
the view query for chained calls

endKey

public ViewQuery endKey(int i)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

endKey

public ViewQuery endKey(long l)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

endKey

public ViewQuery endKey(float f)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

endKey

public ViewQuery endKey(double d)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

endKey

public ViewQuery endKey(boolean b)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

endKey

public ViewQuery endKey(Object o)
Parameters:
Will - be JSON-encoded.
Returns:
the view query for chained calls

endDocId

public ViewQuery endDocId(String s)

limit

public ViewQuery limit(int i)
limit=0 you don't get any data, but all meta-data for this View. The number of documents in this View for example.

Parameters:
i - the limit
Returns:
the view query for chained calls

staleOk

public ViewQuery staleOk(boolean b)
The stale option can be used for higher performance at the cost of possibly not seeing the all latest data. If you set the stale option to ok, CouchDB may not perform any refreshing on the view that may be necessary.

Parameters:
b - the staleOk flag
Returns:
the view query for chained calls

staleOkUpdateAfter

public ViewQuery staleOkUpdateAfter()
Same as staleOk(true) but will also trigger a rebuild of the view index after the results of the view have been retrieved. (since CouchDB 1.1.0)

Returns:

descending

public ViewQuery descending(boolean b)
View rows are sorted by the key; specifying descending=true will reverse their order. Note that the descending option is applied before any key filtering, so you may need to swap the values of the startkey and endkey options to get the expected results.

Parameters:
b - the descending flag
Returns:
the view query for chained calls

skip

public ViewQuery skip(int i)
The skip option should only be used with small values, as skipping a large range of documents this way is inefficient (it scans the index from the startkey and then skips N elements, but still needs to read all the index values to do that). For efficient paging you'll need to use startkey and limit. If you expect to have multiple documents emit identical keys, you'll need to use startkey_docid in addition to startkey to paginate correctly. The reason is that startkey alone will no longer be sufficient to uniquely identify a row.

Parameters:
i - the skip count
Returns:
the view query for chained calls

group

public ViewQuery group(boolean b)
The group option controls whether the reduce function reduces to a set of distinct keys or to a single result row.

Parameters:
b - the group flag
Returns:
the view query for chained calls

groupLevel

public ViewQuery groupLevel(int i)

reduce

public ViewQuery reduce(boolean b)
If a view contains both a map and reduce function, querying that view will by default return the result of the reduce function. The result of the map function only may be retrieved by passing reduce=false as a query parameter.

Parameters:
b - the reduce flag
Returns:
the view query for chained calls

includeDocs

public ViewQuery includeDocs(boolean b)
The include_docs option will include the associated document. Although, the user should keep in mind that there is a race condition when using this option. It is possible that between reading the view data and fetching the corresponding document that the document has changed. If you want to alleviate such concerns you should emit an object with a _rev attribute as in emit(key, {"_rev": doc._rev}). This alleviates the race condition but leaves the possiblity that the returned document has been deleted (in which case, it includes the "_deleted": true attribute).

Parameters:
b - the includeDocs flag
Returns:
the view query for chained calls

inclusiveEnd

public ViewQuery inclusiveEnd(boolean b)
The inclusive_end option controls whether the endkey is included in the result. It defaults to true.

Parameters:
b - the inclusiveEnd flag
Returns:
the view query for chained calls

updateSeq

public ViewQuery updateSeq(boolean b)
The update_seq option adds a field to the result indicating the update_seq the view reflects. It defaults to false.

Parameters:
b - the updateSeq flag
Returns:
the view query for chained calls

queryParam

public ViewQuery queryParam(String name,
                            String value)

reset

public void reset()
Resets internal state so this builder can be used again.


getKey

public Object getKey()

hasMultipleKeys

public boolean hasMultipleKeys()

getKeysAsJson

public String getKeysAsJson()

getStartKey

public Object getStartKey()

getEndKey

public Object getEndKey()

buildQuery

public String buildQuery()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

setIgnoreNotFound

public void setIgnoreNotFound(boolean ignoreNotFound)

isIgnoreNotFound

public boolean isIgnoreNotFound()


Copyright © 2011. All Rights Reserved.