requestHeaders.put(HttpConstants.HttpHeaders.ACCEPT, RuntimeConstants.MediaTypes.JSON); if (options != null) { if (options.getPartitionKey() != null) { requestHeaders.put(HttpConstants.HttpHeaders.PARTITION_KEY, options.getPartitionKey().toString());
void addPartitionKeyInformation(AbstractDocumentServiceRequest request, Document document, RequestOptions options) { PartitionKeyInternal partitionKeyInternal; if (options != null && options.getPartitionKey() != null) { partitionKeyInternal = options.getPartitionKey().getInternalPartitionKey(); } else { // Resolve collection only when it's needed DocumentCollection collection = this.collectionCache.resolveCollection(request); PartitionKeyDefinition partitionKeyDefinition = collection.getPartitionKey(); if (partitionKeyDefinition == null || partitionKeyDefinition.getPaths().size() == 0) { // For backward compatibility, if collection doesn't have partition key defined, we assume all documents // have empty value for it and user doesn't need to specify it explicitly. partitionKeyInternal = PartitionKeyInternal.getEmpty(); } else if (document != null) { partitionKeyInternal = extractPartitionKeyValueFromDocument(document, partitionKeyDefinition); } else { throw new UnsupportedOperationException("PartitionKey value must be supplied for this operation."); } } request.getHeaders().put(HttpConstants.HttpHeaders.PARTITION_KEY, escapeNonAscii(partitionKeyInternal.toJson())); }
final RequestOptions optionsLocal = options; final boolean disableAutomaticIdGenerationLocal = disableAutomaticIdGeneration; final boolean shouldRetry = options == null || options.getPartitionKey() == null;
final RequestOptions optionsLocal = options; final boolean disableAutomaticIdGenerationLocal = disableAutomaticIdGeneration; final boolean shouldRetry = options == null || options.getPartitionKey() == null;
final RequestOptions optionsLocal = options; final boolean disableAutomaticIdGenerationLocal = disableAutomaticIdGeneration; final boolean shouldRetry = options == null || options.getPartitionKey() == null; Observable<ResourceResponse<Document>> createObservable = Observable.defer(() -> {
final RequestOptions optionsLocal = options; final boolean disableAutomaticIdGenerationLocal = disableAutomaticIdGeneration; final boolean shouldRetry = options == null || options.getPartitionKey() == null;
if (options.getPartitionKey() != null) { headers.put(HttpConstants.HttpHeaders.PARTITION_KEY, options.getPartitionKey().toString());
private ResourceResponse<Document> replaceDocumentInternal(String documentLink, Document document, RequestOptions options) throws DocumentClientException { if (document == null) { throw new IllegalArgumentException("document"); } logger.debug("Replacing a Document. documentLink: [{}]", documentLink); final String documentCollectionName = Utils.getCollectionName(documentLink); final String documentCollectionLink = this.getTargetDocumentCollectionLink(documentCollectionName, document); final String path = Utils.joinPath(documentLink, null); final Map<String, String> requestHeaders = getRequestHeaders(options); final DocumentServiceRequest request = DocumentServiceRequest.create(OperationType.Replace, ResourceType.Document, path, document, requestHeaders); this.addPartitionKeyInformation(request, document, options); final boolean shouldRetry = options == null || options.getPartitionKey() == null; DocumentClient.validateResource(document); RetryCreateDocumentDelegate replaceDelegate = new RetryCreateDocumentDelegate() { @Override public ResourceResponse<Document> apply() throws DocumentClientException { return new ResourceResponse<Document>(doReplace(request), Document.class); } }; return shouldRetry ? RetryUtility.executeCreateDocument(replaceDelegate, this.collectionCache, documentCollectionLink) : replaceDelegate.apply(); }
private Observable<ResourceResponse<Document>> replaceDocumentInternal(String documentLink, Document document, RequestOptions options) throws DocumentClientException { if (document == null) { throw new IllegalArgumentException("document"); } logger.debug("Replacing a Document. documentLink: [{}]", documentLink); final String documentCollectionName = Utils.getCollectionName(documentLink); final String documentCollectionLink = this.getTargetDocumentCollectionLink(documentCollectionName, document); final String path = Utils.joinPath(documentLink, null); final Map<String, String> requestHeaders = getRequestHeaders(options); final RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Replace, ResourceType.Document, path, document, requestHeaders); final boolean shouldRetry = options == null || options.getPartitionKey() == null; // NOTE: if the collection is not cached this will block till collection // is retrieved DocumentCollection collection = this.collectionCache.resolveCollection(request); this.addPartitionKeyInformation(request, document, options, collection); validateResource(document); Observable<ResourceResponse<Document>> resourceResponseObs = this.doReplace(request) .map(resp -> toResourceResponse(resp, Document.class)); if (shouldRetry) { CreateDocumentRetryHandler createDocumentRetryHandler = new CreateDocumentRetryHandler(null, documentCollectionLink); return resourceResponseObs.retryWhen(RetryFunctionFactory.from(createDocumentRetryHandler)); } else { return resourceResponseObs; } }