@Override protected void deleteById(final String id) { logger.debug("Delete id: {}", id); try { final InputStream oldDocStream = couchDbConnector.getAsStream(id); final JsonNode oldDoc = objectMapper.readTree(oldDocStream); final String rev = oldDoc.get("_rev").asText(); couchDbConnector.delete(id, rev); } catch (DocumentNotFoundException e) { logger.debug("id {} is not in the database", id); } catch (IOException e) { logger.error("Unexpected IO CouchDB Exception", e); } }
@Override protected void update(final Map<String, Object> attributes) { final String id = (String) attributes.get(COUCH_ID); try { final InputStream oldDocStream = couchDbConnector.getAsStream(id); final Map<String, Object> res = objectMapper.readValue(oldDocStream, typeRef); res.putAll(attributes); couchDbConnector.update(res); logger.debug("Updating id: {} with attributes: {}", id, attributes); } catch (DocumentNotFoundException e) { logger.debug("Insert doc (not found by update(): {}", attributes); couchDbConnector.create(attributes); } catch (IOException e) { logger.error("Unexpected IO CouchDB Exception", e); } }
if (key.equals(COUCH_ID)) { try { final InputStream oldDocStream = couchDbConnector.getAsStream(value); final Map<String, Object> res = objectMapper.readValue(oldDocStream, typeRef); listAttributes.add(populateAttributes(res, names));