@Override public Status delete(String table, String key) { ResourceResponse<Document> deletedResource = null; long startTime = System.nanoTime(); try { deletedResource = AzureCosmosClient.client.deleteDocument(getDocumentLink(this.databaseName, table, key), getRequestOptions(key)); } catch (DocumentClientException e) { if (!this.includeExceptionStackInLog) { e = null; } LOGGER.error("Failed to delete key {} in collection {} in database {}", key, table, this.databaseName, e); return Status.ERROR; } finally { long elapsed = (System.nanoTime() - startTime) / NS_IN_US; LOGGER.debug("Deleted key {} in {}us - ActivityID: {}", key, elapsed, deletedResource != null ? deletedResource.getActivityId() : NA_STRING); } return Status.OK; }
@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; }
@Override public ResourceResponse<Document> invoke() throws Exception { return client.deleteDocument(documentLink, options); } });
public void deleteById(String collectionName, Object id) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("execute deleteById in database {} collection {}", this.databaseName, collectionName); } try { documentDbFactory.getDocumentClient().deleteDocument( getDocumentLink(this.databaseName, collectionName, id.toString()), null); } catch (DocumentClientException ex) { throw new RuntimeException("deleteById exception", ex); } }
public void deleteById(String collectionName, Object id, PartitionKey partitionKey) { Assert.hasText(collectionName, "collectionName should not be null, empty or only whitespaces"); assertValidId(id); log.debug("execute deleteById in database {} collection {}", this.databaseName, collectionName); try { getDocumentClient().deleteDocument(getDocumentLink(this.databaseName, collectionName, id.toString()), getRequestOptions(partitionKey, null)); } catch (DocumentClientException ex) { throw new DocumentDBAccessException("deleteById exception", ex); } }
public <T> void deleteById(String collectionName, Object id, Class<T> domainClass, PartitionKey partitionKey) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("execute deleteById in database {} collection {}", this.databaseName, collectionName); } try { documentDbFactory.getDocumentClient().deleteDocument( getDocumentLink(this.databaseName, collectionName, id.toString()), getRequestOptions(partitionKey, null)); } catch (DocumentClientException ex) { throw new DocumentDBAccessException("deleteById exception", ex); } }
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); } }
@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; }