ComplexKey keys = ComplexKey.of(“93”,”23”); ViewQuery q = createQuery("getProfileInfo").descending(true).key(keys).includeDocs(true); ViewResult vr = db.queryView(q); List<Row> rows = vr.getRows(); for (Row row : rows) { System.out.println("Key--->"+row.getKey()); System.out.println("Value--->"+row.getValue()); }
@Override public byte[] getPrivateKeySalt() { final ViewQuery viewQuery = new ViewQuery().dbPath(db.path()).viewName(Views.SERVER.viewName()).designDocId(designDocument.getId()); final ViewResult viewResult = db.queryView(viewQuery); if (viewResult.isEmpty()) { return new byte[]{}; } final Row row = viewResult.getRows().get(0); return row.getKeyAsNode().get("salt").asText().getBytes(UTF_8); }
@View(name = "maxCallDuration", map = "function(doc){ emit(null, doc.duration);}", reduce = "function (key, values) {" + " var max = 0;" + " for(var i = 0; i < values.length; i++) {" + " max = Math.max(values[i], max);" + " }" + " return max;" + "}") public long findMaxCallDuration() { ViewResult result = db.queryView(createQuery("maxCallDuration").reduce(true)); if (!result.isEmpty() && result.iterator().hasNext()) { return Integer.valueOf(result.iterator().next().getValue()); } return 0; }
protected void onSuccess() { if(viewResult != null) { lastUpdateView = viewResult.getUpdateSeq(); listRows = viewResult.getRows(); notifyDataSetChanged(); } updateListItemsTask = null; //we want to start our changes feed AFTER //getting our first copy of the view if(couchChangesAsyncTask == null && followChanges) { //create an ansyc task to get updates ChangesCommand changesCmd = new ChangesCommand.Builder().since(lastUpdateView) .includeDocs(false) .continuous(true) .heartbeat(5000) .build(); couchChangesAsyncTask = new CouchbaseListChangesAsyncTask(couchDbConnector, changesCmd); executeTask(couchChangesAsyncTask); } if(lastUpdateChangesFeed > lastUpdateView) { LOG.debug("Finished, but still behind {} > {}", lastUpdateChangesFeed, lastUpdateView); updateListItems(); } }
@Override public ViewResult success(HttpResponse hr) throws Exception { return new ViewResult(objectMapper.readTree(hr.getContent()), query.isIgnoreNotFound()); }
public static int getTotalDocuments() { return connector.queryView(createAndFetchViewQuery()).getTotalRows(); }
protected void onSuccess() { if(viewResult != null) { lastUpdateView = viewResult.getUpdateSeq(); listRows = viewResult.getRows(); notifyDataSetChanged(); } updateListItemsTask = null; //we want to start our changes feed AFTER //getting our first copy of the view if(couchChangesAsyncTask == null && followChanges) { //create an ansyc task to get updates ChangesCommand changesCmd = new ChangesCommand.Builder().since(lastUpdateView) .includeDocs(false) .continuous(true) .heartbeat(5000) .build(); couchChangesAsyncTask = new CouchbaseListChangesAsyncTask(couchDbConnector, changesCmd); executeTask(couchChangesAsyncTask); } if(lastUpdateChangesFeed > lastUpdateView) { LOG.debug("Finished, but still behind {} > {}", lastUpdateChangesFeed, lastUpdateView); updateListItems(); } }
@Override public Set<String> getChannelIds(final String uaid) { final ViewResult viewResult = db.queryView(query(Views.UAID.viewName(), uaid)); final List<Row> rows = viewResult.getRows(); if (rows.isEmpty()) { return Collections.emptySet(); } final Set<String> channelIds = new HashSet<String> (rows.size()); for (Row row : rows) { channelIds.add(row.getValueAsNode().get(DOC_FIELD).get(CHID_FIELD).asText()); } return channelIds; }
@Override public byte[] getPrivateKeySalt() { final ViewQuery viewQuery = new ViewQuery().dbPath(db.path()).viewName(Views.SERVER.viewName()).designDocId(designDocument.getId()); final ViewResult viewResult = db.queryView(viewQuery); if (viewResult.isEmpty()) { return new byte[]{}; } final Row row = viewResult.getRows().get(0); return row.getKeyAsNode().get("salt").asText().getBytes(UTF_8); }
@View(name = "maxCallDuration", map = "function(doc){ emit(null, doc.duration);}", reduce = "function (key, values) {" + " var max = 0;" + " for(var i = 0; i < values.length; i++) {" + " max = Math.max(values[i], max);" + " }" + " return max;" + "}") public long findMaxCallDuration() { ViewResult result = db.queryView(createQuery("maxCallDuration").reduce(true)); if (!result.isEmpty() && result.iterator().hasNext()) { return Integer.valueOf(result.iterator().next().getValue()); } return 0; }
@Override public Set<String> getChannelIds(final String uaid) { final ViewResult viewResult = db.queryView(query(Views.UAID.viewName(), uaid)); final List<Row> rows = viewResult.getRows(); if (rows.isEmpty()) { return Collections.emptySet(); } final Set<String> channelIds = new HashSet<String> (rows.size()); for (Row row : rows) { channelIds.add(row.getValueAsNode().get(DOC_FIELD).get(CHID_FIELD).asText()); } return channelIds; }
@Override public void removeChannels(final String uaid) { final ViewResult viewResult = db.queryView(query(Views.UAID.viewName(), uaid)); final List<Row> rows = viewResult.getRows(); final Set<String> channelIds = new HashSet<String>(rows.size()); for (Row row : rows) { final JsonNode json = row.getValueAsNode().get(DOC_FIELD); channelIds.add(json.get(CHID_FIELD).asText()); } removeChannels(channelIds); }
public List<String> getCalendarNames() { final ViewResult result = db.queryView(createQuery("by_calendarName")); List<String> calendarNames = new ArrayList<String>(); for (ViewResult.Row row : result.getRows()) { calendarNames.add(row.getKey()); } return calendarNames; }
@Override public void removeChannels(final String uaid) { final ViewResult viewResult = db.queryView(query(Views.UAID.viewName(), uaid)); final List<Row> rows = viewResult.getRows(); final Set<String> channelIds = new HashSet<String>(rows.size()); for (Row row : rows) { final JsonNode json = row.getValueAsNode().get(DOC_FIELD); channelIds.add(json.get(CHID_FIELD).asText()); } removeChannels(channelIds); }
private JsonNode getChannelJson(final String channelId) throws ChannelNotFoundException { final ViewResult viewResult = db.queryView(query(Views.CHANNEL.viewName(), channelId)); final List<Row> rows = viewResult.getRows(); if (rows.isEmpty()) { throw new ChannelNotFoundException("Cound not find channel", channelId); } if (rows.size() > 1) { throw new IllegalStateException("There should not be multiple channelId with the same id"); } return rows.get(0).getValueAsNode(); }
@Override public String updateVersion(final String endpointToken, final long version) throws VersionException, ChannelNotFoundException { final ViewResult viewResult = db.queryView(query(Views.TOKEN.viewName(), endpointToken)); final List<Row> rows = viewResult.getRows(); if (rows.isEmpty()) { throw new ChannelNotFoundException("Cound not find channel for endpointToken", endpointToken); } final ObjectNode node = (ObjectNode) rows.get(0).getValueAsNode().get(DOC_FIELD); final long currentVersion = node.get(VERSION_FIELD).asLong(); if (version <= currentVersion) { throw new VersionException("version [" + version + "] must be greater than the current version [" + currentVersion + "]"); } node.put(VERSION_FIELD, String.valueOf(version)); db.update(node); return node.get(CHID_FIELD).asText(); }
private JsonNode getChannelJson(final String channelId) throws ChannelNotFoundException { final ViewResult viewResult = db.queryView(query(Views.CHANNEL.viewName(), channelId)); final List<Row> rows = viewResult.getRows(); if (rows.isEmpty()) { throw new ChannelNotFoundException("Cound not find channel", channelId); } if (rows.size() > 1) { throw new IllegalStateException("There should not be multiple channelId with the same id"); } return rows.get(0).getValueAsNode(); }
@Override public void removeChannels(final Set<String> channelIds) { final ViewResult viewResult = db.queryView(channelsQuery(channelIds)); final List<Row> rows = viewResult.getRows(); final Collection<BulkDeleteDocument> removals = new LinkedHashSet<BulkDeleteDocument>(); for (Row row : rows) { final JsonNode json = row.getValueAsNode(); removals.add(BulkDeleteDocument.of(json.get(DOC_FIELD))); } db.executeBulk(removals); }
@Override @View(name = "find_by_observation_id", map = "function (doc) { if (doc.type === 'Encounter') for each(item in doc.observations) { emit(item.observationId, item); recursiveDescent(item); } function recursiveDescent(obsNode) { for each(item in obsNode.dependantObservations) { emit(item.observationId, item); recursiveDescent(item) }}}") public MRSObservation findByObservationId(String observationId) { ViewQuery viewQuery = createQuery("find_by_observation_id").key(observationId).includeDocs(false); ViewResult viewResult = db.queryView(viewQuery); MRSObservation obs = null; if (viewResult.getRows() != null && viewResult.getRows().size() > 0) { Row row = viewResult.getRows().get(0); JsonNode value = row.getValueAsNode(); String text = value.toString(); obs = (CouchObservation) CouchJsonUtils.readJson(text, CouchObservation.class); } return obs; }
@Override public String updateVersion(final String endpointToken, final long version) throws VersionException, ChannelNotFoundException { final ViewResult viewResult = db.queryView(query(Views.TOKEN.viewName(), endpointToken)); final List<Row> rows = viewResult.getRows(); if (rows.isEmpty()) { throw new ChannelNotFoundException("Cound not find channel for endpointToken", endpointToken); } final ObjectNode node = (ObjectNode) rows.get(0).getValueAsNode().get(DOC_FIELD); final long currentVersion = node.get(VERSION_FIELD).asLong(); if (version <= currentVersion) { throw new VersionException("version [" + version + "] must be greater than the current version [" + currentVersion + "]"); } node.put(VERSION_FIELD, String.valueOf(version)); db.update(node); return node.get(CHID_FIELD).asText(); }