public InputStreamBulkEntityBulkExecutor(URI dbURI, RestTemplate restTemplate, ObjectMapper objectMapper) { this.restTemplate = restTemplate; this.objectMapper = objectMapper; this.bulkDocsUri = dbURI.append("_bulk_docs").toString(); }
private URI buildUpdateHandlerRequestPath() { Assert.hasText(dbPath, "dbPath"); Assert.hasText(functionName, "functionName"); Assert.hasText(designDocId, "designDocId"); Assert.hasText(docId, "docId"); URI uri = URI.of(dbPath); uri.append(designDocId) .append("_update") .append(functionName) .append(docId); return uri; }
@Override public void setRevisionLimit(int limit) { restTemplate.put(dbURI.append("_revs_limit").toString(), Integer.toString(limit), VOID_RESPONSE_HANDLER); }
@Override public List<String> getAllDocIds() { return restTemplate.get(dbURI.append("_all_docs").toString(), docIdResponseHandler); }
@Override public int getRevisionLimit() { return restTemplate.get(dbURI.append("_revs_limit").toString(), new StdResponseHandler<Integer>() { @Override public Integer success(HttpResponse hr) throws Exception { JsonNode rlimit = objectMapper.readTree(hr.getContent()); return rlimit.asInt(); } }); }
public InputStreamWrapperBulkExecutor(URI dbURI, RestTemplate restTemplate, ObjectMapper objectMapper) { this.restTemplate = restTemplate; this.objectMapper = objectMapper; this.writer = new BulkDocumentWriter(objectMapper); this.bulkDocsUri = dbURI.append("_bulk_docs").toString(); }
@Override public void compact() { restTemplate.post(dbURI.append("_compact").toString(), "not_used", VOID_RESPONSE_HANDLER); }
@Override public PurgeResult purge(Map<String, List<String>> revisionsToPurge) { return restTemplate.post(dbURI.append("_purge").toString(), serializeToJson(revisionsToPurge), new StdResponseHandler<PurgeResult>() { @Override public PurgeResult success(HttpResponse hr) throws Exception { return objectMapper.readValue(hr.getContent(), PurgeResult.class); } }); }
@Override public PurgeResult purge(Map<String, List<String>> revisionsToPurge) { HttpEntity entity = createHttpEntity(revisionsToPurge); return restTemplate.post(dbURI.append("_purge").toString(), entity, new StdResponseHandler<PurgeResult>() { @Override public PurgeResult success(HttpResponse hr) throws Exception { return objectMapper.readValue(hr.getContent(), PurgeResult.class); } }); }
@Override public String copy(String sourceDocId, String targetDocId, String targetRevision) { String destinationUri = targetRevision != null ? targetDocId + "?rev=" + targetRevision : targetDocId; return restTemplate.copy(dbURI.append(sourceDocId).toString(), destinationUri, revisionHandler).getRevision(); }
@Override public String getCurrentRevision(String id) { assertDocIdHasValue(id); return restTemplate.head(dbURI.append(id).toString(), new StdResponseHandler<String>(){ @Override public String success(HttpResponse hr) throws Exception { return hr.getETag(); } }); }
@Override public void updateMultipart(String id, InputStream stream, String boundary, long length, Options options) { assertDocIdHasValue(id); Assert.hasText(boundary); URI uri = dbURI.append(id); applyOptions(options, uri); String contentType = String.format("multipart/related; boundary=\"%s\"", boundary); restTemplate.put(uri.toString(), stream, contentType, length); }
@Override public String createAttachment(String docId, String revision, AttachmentInputStream data) { assertDocIdHasValue(docId); URI uri = dbURI.append(docId).append(data.getId()); if (revision != null) { uri.param("rev", revision); } return restTemplate.put(uri.toString(), data, data.getContentType(), data.getContentLength(), revisionHandler).getRevision(); }
@Override public InputStream getAsStream(String id, Options options) { URI uri = dbURI.append(id); applyOptions(options, uri); HttpResponse r = restTemplate.get(uri.toString()); return r.getContent(); }
private InputStream fetchChangesAsStream(ChangesCommand cmd) { HttpResponse r = restTemplate.get(dbURI.append(cmd.toString()) .toString()); return r.getContent(); }
@Override public void update(String id, InputStream document, long length, Options options) { assertDocIdHasValue(id); URI uri = dbURI.append(id); applyOptions(options, uri); restTemplate.put(uri.toString(), document, "application/json", length); }
@Override public List<DocumentOperationResult> executeBulk(Collection<?> objects, boolean allOrNothing) { BulkDocumentBean<?> bulkDocumentBean = new BulkDocumentBean(objects, allOrNothing); return restTemplate.post( dbURI.append("_bulk_docs").toString(), createHttpEntity(bulkDocumentBean), new BulkOperationResponseHandler(objects, objectMapper)); }
@Override public String delete(String id, String revision) { assertDocIdHasValue(id); return restTemplate.delete( dbURI.append(id).param("rev", revision).toString(), revisionHandler).getRevision(); }
@Override public ChangesFeed changesFeed(ChangesCommand cmd) { int heartbeat = cmd.heartbeat > 0 ? cmd.heartbeat : DEFAULT_HEARTBEAT_INTERVAL; String since = cmd.since != null ? cmd.since : getDbInfo().getUpdateSeqAsString(); ChangesCommand actualCmd = new ChangesCommand.Builder().merge(cmd) .continuous(true).heartbeat(heartbeat).since(since).build(); return new ContinuousChangesFeed(dbName, restTemplate.getUncached(dbURI.append(actualCmd.toString()).toString())); }