private void endKey(Iterator<Object> iterator) { if (!iterator.hasNext()) { throw new IllegalArgumentException("Not enough parameters for endKey"); } Object next = iterator.next(); if (next instanceof String) { query.endKey((String) next); } else if (next instanceof Boolean) { query.endKey((Boolean) next); } else if (next instanceof Double) { query.endKey((Double) next); } else if (next instanceof Integer) { query.endKey((Integer) next); } else if (next instanceof Long) { query.endKey((Long) next); } else if (next instanceof Collection) { // when creating a JsonArray, the from(List) method is preferred because it will convert // internal // Lists and Maps to JsonObject and JsonArray respectively List<Object> arrayContent = new ArrayList<Object>((Collection) next); query.endKey(JsonArray.from(arrayContent)); } else if (next.getClass().isArray()) { List<Object> arrayContent = Arrays.asList((Object[]) next); query.endKey(JsonArray.from(arrayContent)); } else if (next instanceof JsonArray) { // discouraged, since it's leaking store-specifics in the method signature query.endKey((JsonArray) next); } else if (next instanceof JsonObject) { // discouraged, since it's leaking store-specifics in the method signature query.endKey((JsonObject) next); } else { throw new IllegalArgumentException( "Unsupported parameter type for endKey: " + next.getClass()); } }
/** * Queries all documents of a view with an optional range parameter * * @param designDocName * @param viewName * @param startKey * @param endKey * @return */ public static ViewResult query( String designDocName, String viewName, String startKey, String endKey) { ViewResult result; // Perform the query ViewQuery query = ViewQuery.from(designDocName, viewName).inclusiveEnd(true).stale(Stale.FALSE); if (startKey != null) { query = query.startKey(startKey); } if (endKey != null) { query = query.endKey(endKey); } result = client.query(query); return result; }