Class View


  • public class View
    extends java.lang.Object
    This class provides access to the View APIs.

    Usage Example:

     
      List<Foo> list = dbClient.view("example/foo")
    	.startKey("start-key")
    	.endKey("end-key")
    	.limit(10)
    	.includeDocs(true)
    	.query(Foo.class);
      
      // scalar values
      int count = dbClient.view("example/by_tag")
     	.key("couchdb")
     	.queryForInt(); 
     
     // pagination
     Page<Foo> page = dbClient.view("example/foo").queryPage(...);
     
     
    Since:
    0.0.2
    See Also:
    CouchDbClientBase.view(String), ViewResult
    • Constructor Summary

      Constructors 
      Constructor Description
      View​(CouchDbClientBase dbc, java.lang.String viewId)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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)  
      private java.lang.String getKeyAsJson​(java.lang.Object... key)  
      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<?> keys)
      Supplies a key list when calling _all_docs View.
      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()  
      private <T> Page<T> queryNextPage​(int rowsPerPage, java.lang.String currentStartKey, java.lang.String currentStartKeyDocId, java.lang.String startKey, java.lang.String startKeyDocId, java.lang.Class<T> classOfT)  
      <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.
      private <T> Page<T> queryPreviousPage​(int rowsPerPage, java.lang.String currentStartKey, java.lang.String currentStartKeyDocId, java.lang.String startKey, java.lang.String startKeyDocId, java.lang.Class<T> classOfT)  
      private <V> V queryValue​(java.lang.Class<V> classOfV)
      Queries for scalar values.
      <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 updateSeq​(java.lang.Boolean updateSeq)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • log

        private static final org.apache.commons.logging.Log log
      • START_KEY_DOC_ID

        private static final java.lang.String START_KEY_DOC_ID
        See Also:
        Constant Field Values
      • CURRENT_START_KEY

        private static final java.lang.String CURRENT_START_KEY
        See Also:
        Constant Field Values
      • CURRENT_START_KEY_DOC_ID

        private static final java.lang.String CURRENT_START_KEY_DOC_ID
        See Also:
        Constant Field Values
      • key

        private java.lang.String key
      • startKey

        private java.lang.String startKey
      • startKeyDocId

        private java.lang.String startKeyDocId
      • endKey

        private java.lang.String endKey
      • endKeyDocId

        private java.lang.String endKeyDocId
      • limit

        private java.lang.Integer limit
      • stale

        private java.lang.String stale
      • descending

        private java.lang.Boolean descending
      • skip

        private java.lang.Integer skip
      • group

        private java.lang.Boolean group
      • groupLevel

        private java.lang.Integer groupLevel
      • reduce

        private java.lang.Boolean reduce
      • includeDocs

        private java.lang.Boolean includeDocs
      • inclusiveEnd

        private java.lang.Boolean inclusiveEnd
      • updateSeq

        private java.lang.Boolean updateSeq
      • gson

        private com.google.gson.Gson gson
      • allDocsKeys

        private java.lang.String allDocsKeys
    • Method Detail

      • queryForStream

        public java.io.InputStream queryForStream()
        Queries a view as an InputStream

        The stream should be properly closed after usage, as to avoid connection leaks.

        Returns:
        The result as an InputStream.
      • query

        public <T> java.util.List<T> query​(java.lang.Class<T> classOfT)
        Queries a view.
        Type Parameters:
        T - Object type T
        Parameters:
        classOfT - The class of type T
        Returns:
        The result of the view query as a List<T>
      • queryView

        public <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.
        Type Parameters:
        K - Object type K (key)
        V - Object type V (value)
        T - The class type
        Parameters:
        classOfK - The class of type K.
        classOfV - The class of type V.
        classOfT - The class of type T.
        Returns:
        The View result entries.
      • queryForString

        public java.lang.String queryForString()
        Returns:
        The result of the view as String.
      • queryForInt

        public int queryForInt()
        Returns:
        The result of the view as int.
      • queryForLong

        public long queryForLong()
        Returns:
        The result of the view as long.
      • queryForBoolean

        public boolean queryForBoolean()
        Returns:
        The result of the view as boolean.
      • queryValue

        private <V> V queryValue​(java.lang.Class<V> classOfV)
        Queries for scalar values. Internal use.
      • queryPage

        public <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.
        Type Parameters:
        T - Object type T
        Parameters:
        rowsPerPage - 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.
        Returns:
        Page
      • queryNextPage

        private <T> Page<T> queryNextPage​(int rowsPerPage,
                                          java.lang.String currentStartKey,
                                          java.lang.String currentStartKeyDocId,
                                          java.lang.String startKey,
                                          java.lang.String startKeyDocId,
                                          java.lang.Class<T> classOfT)
        Returns:
        The next page.
      • queryPreviousPage

        private <T> Page<T> queryPreviousPage​(int rowsPerPage,
                                              java.lang.String currentStartKey,
                                              java.lang.String currentStartKeyDocId,
                                              java.lang.String startKey,
                                              java.lang.String startKeyDocId,
                                              java.lang.Class<T> classOfT)
        Returns:
        The previous page.
      • key

        public View key​(java.lang.Object... key)
        Parameters:
        key - The key value, accepts a single value or multiple values for complex keys.
        Returns:
        View
      • startKey

        public View startKey​(java.lang.Object... startKey)
        Parameters:
        startKey - The start key value, accepts a single value or multiple values for complex keys.
        Returns:
        View
      • startKeyDocId

        public View startKeyDocId​(java.lang.String startKeyDocId)
        Parameters:
        startKeyDocId - The start key document id.
        Returns:
        View
      • endKey

        public View endKey​(java.lang.Object... endKey)
        Parameters:
        endKey - The end key value, accepts a single value or multiple values for complex keys.
        Returns:
        View
      • endKeyDocId

        public View endKeyDocId​(java.lang.String endKeyDocId)
        Parameters:
        endKeyDocId - The end key document id.
        Returns:
        View
      • limit

        public View limit​(java.lang.Integer limit)
        Parameters:
        limit - The limit value.
        Returns:
        View
      • stale

        public View stale​(java.lang.String stale)
        Parameters:
        stale - Accept values: ok | update_after (update_after as of CouchDB 1.1.0)
        Returns:
        View
      • descending

        public View descending​(java.lang.Boolean descending)
        Reverses the reading direction, not the sort order.
        Parameters:
        descending - The descending value true | false
        Returns:
        View
      • skip

        public View skip​(java.lang.Integer skip)
        Parameters:
        skip - Skips n number of documents.
        Returns:
        View
      • group

        public View group​(java.lang.Boolean group)
        Parameters:
        group - Specifies whether the reduce function reduces the result to a set of keys, or to a single result. Defaults to false (single result).
        Returns:
        View
      • groupLevel

        public View groupLevel​(java.lang.Integer groupLevel)
        Parameters:
        groupLevel - The group level
        Returns:
        View
      • reduce

        public View reduce​(java.lang.Boolean reduce)
        Parameters:
        reduce - Indicates whether to use the reduce function of the view, defaults to true if the reduce function is defined.
        Returns:
        View
      • includeDocs

        public View includeDocs​(java.lang.Boolean includeDocs)
        Parameters:
        includeDocs - Indicates whether to include documents
        Returns:
        View
      • inclusiveEnd

        public View inclusiveEnd​(java.lang.Boolean inclusiveEnd)
        Parameters:
        inclusiveEnd - Indicates whether the endkey is included in the result, defaults to true.
        Returns:
        View
      • updateSeq

        public View updateSeq​(java.lang.Boolean updateSeq)
        Parameters:
        updateSeq - Indicates whether to include sequence id of the view
        Returns:
        View
      • keys

        public View keys​(java.util.List<?> keys)
        Supplies a key list when calling _all_docs View.
        Parameters:
        keys - The list of keys
        Returns:
        View
      • getKeyAsJson

        private java.lang.String getKeyAsJson​(java.lang.Object... key)