Exemple #1
0
  private URI buildViewPath() {
    assertHasText(dbPath, "dbPath");
    assertHasText(viewName, "viewName");

    URI uri = URI.of(dbPath);
    if (isNotEmpty(listName)) {
      uri.append(designDocId).append("_list").append(listName).append(viewName);
    } else if (ALL_DOCS_VIEW_NAME.equals(viewName)) {
      uri.append(viewName);
    } else {
      assertHasText(designDocId, "designDocId");
      uri.append(designDocId).append("_view").append(viewName);
    }
    return uri;
  }
Exemple #2
0
 private void appendQueryParams(URI query) {
   for (Map.Entry<String, String> param : queryParams.entrySet()) {
     query.param(param.getKey(), param.getValue());
   }
 }
Exemple #3
0
  public String buildQuery() {
    if (cachedQuery != null) {
      return cachedQuery;
    }

    URI query = buildViewPath();

    if (isNotEmpty(key)) {
      query.param("key", key);
    }

    if (isNotEmpty(startKey)) {
      query.param("startkey", startKey);
    }

    if (isNotEmpty(endKey)) {
      query.param("endkey", endKey);
    }

    if (isNotEmpty(startDocId)) {
      query.param("startkey_docid", startDocId);
    }

    if (isNotEmpty(endDocId)) {
      query.param("endkey_docid", endDocId);
    }

    if (hasValue(limit)) {
      query.param("limit", limit);
    }

    if (staleOk != null) {
      query.param("stale", staleOk);
    }

    if (descending) {
      query.param("descending", "true");
    }

    if (!inclusiveEnd) {
      query.param("inclusive_end", "false");
    }

    if (!reduce) {
      query.param("reduce", "false");
    }

    if (hasValue(skip)) {
      query.param("skip", skip);
    }

    if (includeDocs) {
      query.param("include_docs", "true");
    }

    if (group) {
      query.param("group", "true");
    }

    if (hasValue(groupLevel)) {
      query.param("group_level", groupLevel);
    }

    if (queryParams != null && !queryParams.isEmpty()) {
      appendQueryParams(query);
    }

    cachedQuery = query.toString();
    return cachedQuery;
  }