setterDocId.set(obj, value.getId()); JsonNode val = value.getValueAsNode(); for (int i = 0; i < setterDoc.size(); i++) { Class<?> type = fieldType.get(i);
public boolean hasNext() { if (closed) { // The BufferedReader is closed. There can't be any more rows. return false; } if (row != null) { // We still already have an 'uncollected' row from last time. return true; } try { JsonNode node; do { String doc = reader.readLine(); if (doc == null || doc.equals("]}")) { reader.close(); closed = true; return false; } if (doc.endsWith(",")) { doc = doc.substring(0, doc.length() -1); } node = objectMapper.readTree(doc); }while(ignoreNotFound && node.has(Row.ERROR_FIELD_NAME)); row = new ViewResult.Row(node); return true; } catch (IOException e) { throw new DbAccessException(e); } }
setterDocId.set(obj, value.getId()); JsonNode val = value.getValueAsNode(); for (int i = 0; i < setterDoc.size(); i++) { Class<?> type = fieldType.get(i);
final ViewResult result = couchDbConnector.queryView(query); for (ViewResult.Row row : result.getRows()) { final String stringValue = row.getValue(); Map<String, Object> res = null; try {
nextPageKey = rows.get(rows.size() - 1).getKey();
nextPageKey = rows.get(rows.size() - 1).getKey();
public ViewResult(JsonNode resultNode, boolean ignoreNotFound) { Assert.notNull(resultNode, "resultNode may not be null"); Assert.isTrue(resultNode.findPath("rows").isArray(), "result must contain 'rows' field of array type"); if (resultNode.get(TOTAL_ROWS_FIELD_NAME) != null) { totalRows = resultNode.get(TOTAL_ROWS_FIELD_NAME).intValue(); } if (resultNode.get(OFFSET_FIELD_NAME) != null) { offset = resultNode.get(OFFSET_FIELD_NAME).intValue(); } if (resultNode.get(UPDATE_SEQ) != null) { updateSeq = resultNode.get(UPDATE_SEQ).textValue(); if(updateSeq == null) { updateSeq = Long.toString(resultNode.get(UPDATE_SEQ).intValue()); } } JsonNode rowsNode = resultNode.get("rows"); rows = new ArrayList<ViewResult.Row>(rowsNode.size()); for (JsonNode n : rowsNode) { if (!(ignoreNotFound && n.has(Row.ERROR_FIELD_NAME))) { rows.add(new Row(n)); } } }
@Override public Set<Ack> removeAcknowledged(final String uaid, final Set<Ack> acked) { final ViewResult viewResult = db.queryView(query(Views.UNACKS.viewName(), uaid)); final List<Row> rows = viewResult.getRows(); final Collection<BulkDeleteDocument> removals = new LinkedHashSet<BulkDeleteDocument>(); for (Iterator<Row> iter = rows.iterator(); iter.hasNext(); ) { final Row row = iter.next(); final JsonNode json = row.getValueAsNode(); final JsonNode doc = json.get(DOC_FIELD); final String channelId = doc.get(CHID_FIELD).asText(); for (Ack ack : acked) { if (ack.getChannelId().equals(channelId)) { removals.add(BulkDeleteDocument.of(doc)); iter.remove(); } } } db.executeBulk(removals); return rowsToAcks(rows); }
@Override public Set<Ack> removeAcknowledged(final String uaid, final Set<Ack> acked) { final ViewResult viewResult = db.queryView(query(Views.UNACKS.viewName(), uaid)); final List<Row> rows = viewResult.getRows(); final Collection<BulkDeleteDocument> removals = new LinkedHashSet<BulkDeleteDocument>(); for (Iterator<Row> iter = rows.iterator(); iter.hasNext(); ) { final Row row = iter.next(); final JsonNode json = row.getValueAsNode(); final JsonNode doc = json.get(DOC_FIELD); final String channelId = doc.get(CHID_FIELD).asText(); for (Ack ack : acked) { if (ack.getChannelId().equals(channelId)) { removals.add(BulkDeleteDocument.of(doc)); iter.remove(); } } } db.executeBulk(removals); return rowsToAcks(rows); }
@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(); }
@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(); }
public String getKey() { return nodeAsString(getKeyAsNode()); }
@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; }
public String getValue() { return nodeAsString(getValueAsNode()); }
@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; }
@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); }
@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); }