@Override public Status delete(String table, String key) { Document record = getDocumentById(table, key); try { // Delete the document by self link. documentClient.deleteDocument(record.getSelfLink(), null); } catch (DocumentClientException e) { e.printStackTrace(); return Status.ERROR; } return Status.OK; }
/** * Replaces a document with the passed in document. * * @param document the document to replace (containing the document id). * @param options the request options. * @return the resource response with the replaced document. * @throws DocumentClientException the document client exception. */ public ResourceResponse<Document> replaceDocument(Document document, RequestOptions options) throws DocumentClientException { if (document == null) { throw new IllegalArgumentException("document"); } return this.replaceDocumentInternal(document.getSelfLink(), document, options); }
@Override public Observable<ResourceResponse<Document>> replaceDocument(Document document, RequestOptions options) { return Observable.defer(() -> { try { if (document == null) { throw new IllegalArgumentException("document"); } return this.replaceDocumentInternal(document.getSelfLink(), document, options); } catch (Exception e) { logger.debug("Failure in replacing a database due to [{}]", e.getMessage()); return Observable.error(e); } }); }
private void deleteDocument(@NonNull Document document, @NonNull List<String> partitionKeyNames) { try { final RequestOptions options = new RequestOptions(); Assert.isTrue(partitionKeyNames.size() <= 1, "Only one Partition is supported."); if (!partitionKeyNames.isEmpty() && StringUtils.hasText(partitionKeyNames.get(0))) { options.setPartitionKey(new PartitionKey(document.get(partitionKeyNames.get(0)))); } getDocumentClient().deleteDocument(document.getSelfLink(), options); } catch (DocumentClientException e) { throw new DocumentDBAccessException("Failed to delete document: " + document.getSelfLink(), e); } }
originalDoc.getSelfLink(), originalDoc, null);
@Override public <T> List<T> delete(Query query, Class<T> entityClass, String collectionName) { final SqlQuerySpec sqlQuerySpec = createSqlQuerySpec(query, entityClass); final Optional<Object> partitionKeyValue = getPartitionKeyValue(query, entityClass); final DocumentCollection collection = getDocCollection(collectionName); final FeedOptions feedOptions = new FeedOptions(); if (!partitionKeyValue.isPresent()) { feedOptions.setEnableCrossPartitionQuery(true); } final List<Document> results = documentDbFactory.getDocumentClient() .queryDocuments(collection.getSelfLink(), sqlQuerySpec, feedOptions).getQueryIterable().toList(); final RequestOptions options = new RequestOptions(); if (partitionKeyValue.isPresent()) { options.setPartitionKey(new PartitionKey(partitionKeyValue.get())); } final List<T> deletedResult = new ArrayList<>(); for (final Document document : results) { try { documentDbFactory.getDocumentClient().deleteDocument((document).getSelfLink(), options); deletedResult.add(getConverter().read(entityClass, document)); } catch (DocumentClientException e) { throw new DocumentDBAccessException( String.format("Failed to delete document [%s]", (document).getSelfLink()), e); } } return deletedResult; }