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); } }
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)); } } }