Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional Patch SDK #19307

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3b37725
Draft 1 for Conditional Patch SDK
deparash Feb 18, 2021
f09cd50
Draft 2 for Conditional Patch SDK
deparash Feb 22, 2021
91b2b4e
Adding test cases to Conditional Patch Java SDK
deparash Feb 24, 2021
746b2ca
Merge branch 'master' into users/deparsh/conditional-patch
deparash Feb 24, 2021
5e28808
fixing the inheritance.
deparash Feb 25, 2021
0919c3c
importing patch spec
deparash Feb 25, 2021
1cd6a2c
remove blank
deparash Feb 25, 2021
f48681b
Adding Assert that Request fail
deparash Feb 26, 2021
24f68c4
Fixing inheritance in bulkoptions
deparash Mar 2, 2021
b0d44e9
Fixing inheritance in Batch options
deparash Mar 2, 2021
d438497
Fixing NIT's
deparash Mar 2, 2021
7066b3e
NIT Format.
deparash Mar 2, 2021
7f02c7f
NIT Format.
deparash Mar 2, 2021
50b2789
Removing unused import.
deparash Mar 2, 2021
25ab7a1
minor warnings removed.
deparash Mar 2, 2021
df42138
Nit Remove extra space.
deparash Mar 2, 2021
c2fa6e8
Fixing test case.
deparash Mar 2, 2021
4d63afc
removing constructor of abstract classes.
deparash Mar 2, 2021
66f0def
pull from master.
deparash Mar 3, 2021
902cc79
Removing Extra Line.
deparash Mar 3, 2021
6d2e5f9
Altering inheritance.
deparash Mar 3, 2021
00da1f9
minor updates to the inheritance flow.
deparash Mar 3, 2021
6b294f3
NIT Update.
deparash Mar 3, 2021
d9fed4c
making classes package private.
deparash Mar 3, 2021
80cae2b
removing return from doc.
deparash Mar 3, 2021
862e7b7
Nit Updates.
deparash Mar 4, 2021
cfdf2c5
remove println from tests.
deparash Mar 4, 2021
6e422b5
remove beta from patch spec.
deparash Mar 4, 2021
5b0d6d6
remove patch spec.
deparash Mar 4, 2021
95b3ccf
No need for typecasting.
deparash Mar 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,11 @@ public static List<PatchOperation> getPatchOperationsFromCosmosPatch(CosmosPatch
return cosmosPatchOperations.getPatchOperations();
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
public static int getPayloadLength(TransactionalBatchResponse transactionalBatchResponse) {
return transactionalBatchResponse.getResponseLength();
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
public static SqlQuerySpec getOfferQuerySpecFromResourceId(CosmosAsyncContainer container, String resourceId) {
return container.getDatabase().getOfferQuerySpecFromResourceId(resourceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,15 @@

package com.azure.cosmos;

import com.azure.cosmos.implementation.RequestOptions;
import com.azure.cosmos.util.Beta;

/**
* Encapsulates options that can be specified for an operation used in Bulk execution. It can be passed while
* creating bulk request using {@link BulkOperations}.
*/
@Beta(value = Beta.SinceVersion.V4_9_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public final class BulkItemRequestOptions {

private String ifMatchETag;
private String ifNoneMatchETag;
private Boolean contentResponseOnWriteEnabled;

/**
* Gets the If-Match (ETag) associated with the operation in {@link CosmosItemOperation}.
*
* @return ifMatchETag the ifMatchETag associated with the request.
*/
@Beta(value = Beta.SinceVersion.V4_9_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public String getIfMatchETag() {
return this.ifMatchETag;
}
public final class BulkItemRequestOptions
extends BulkItemRequestOptionsBase {

/**
* Sets the If-Match (ETag) associated with the operation in {@link CosmosItemOperation}.
Expand All @@ -35,20 +21,10 @@ public String getIfMatchETag() {
*/
@Beta(value = Beta.SinceVersion.V4_9_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public BulkItemRequestOptions setIfMatchETag(final String ifMatchETag) {
this.ifMatchETag = ifMatchETag;
super.setIfMatchETagCore(ifMatchETag);
return this;
}

/**
* Gets the If-None-Match (ETag) associated with the request in operation in {@link CosmosItemOperation}.
*
* @return the ifNoneMatchETag associated with the request.
*/
@Beta(value = Beta.SinceVersion.V4_9_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public String getIfNoneMatchETag() {
return this.ifNoneMatchETag;
}

/**
* Sets the If-None-Match (ETag) associated with the request in operation in {@link CosmosItemOperation}.
*
Expand All @@ -57,28 +33,10 @@ public String getIfNoneMatchETag() {
*/
@Beta(value = Beta.SinceVersion.V4_9_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public BulkItemRequestOptions setIfNoneMatchETag(final String ifNoneMatchEtag) {
this.ifNoneMatchETag = ifNoneMatchEtag;
super.setIfNoneMatchETagCore(ifNoneMatchEtag);
return this;
}

/**
* Gets the boolean to only return the headers and status code in Cosmos DB response
* in case of Create, Update and Delete operations in {@link CosmosItemOperation}.
*
* If set to false, service doesn't return payload in the response. It reduces networking
* and CPU load by not sending the payload back over the network and serializing it on the client.
*
* This feature does not impact RU usage for read or write operations.
*
* By-default, this is null.
*
* @return a boolean indicating whether payload will be included in the response or not for this operation.
*/
@Beta(value = Beta.SinceVersion.V4_9_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public Boolean isContentResponseOnWriteEnabled() {
return contentResponseOnWriteEnabled;
}

/**
* Sets the boolean to only return the headers and status code in Cosmos DB response
* in case of Create, Update and Delete operations in {@link CosmosItemOperation}.
Expand All @@ -100,15 +58,7 @@ public Boolean isContentResponseOnWriteEnabled() {
*/
@Beta(value = Beta.SinceVersion.V4_9_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public BulkItemRequestOptions setContentResponseOnWriteEnabled(Boolean contentResponseOnWriteEnabled) {
this.contentResponseOnWriteEnabled = contentResponseOnWriteEnabled;
super.setContentResponseOnWriteEnabledCore(contentResponseOnWriteEnabled);
return this;
}

RequestOptions toRequestOptions() {
final RequestOptions requestOptions = new RequestOptions();
requestOptions.setIfMatchETag(getIfMatchETag());
requestOptions.setIfNoneMatchETag(getIfNoneMatchETag());
requestOptions.setContentResponseOnWriteEnabled(isContentResponseOnWriteEnabled());
return requestOptions;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos;

import com.azure.cosmos.implementation.RequestOptions;
import com.azure.cosmos.util.Beta;

/**
* Encapsulates options that can be specified for an operation used in Bulk execution. It can be passed while
* creating bulk request using {@link BulkOperations}.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
class BulkItemRequestOptionsBase {

private String ifMatchETag;
private String ifNoneMatchETag;
private Boolean contentResponseOnWriteEnabled;

protected BulkItemRequestOptionsBase(){
}

/**
* Gets the If-Match (ETag) associated with the operation in {@link CosmosItemOperation}.
*
* @return ifMatchETag the ifMatchETag associated with the request.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public String getIfMatchETag() {
return this.ifMatchETag;
}

/**
* Sets the If-Match (ETag) associated with the operation in {@link CosmosItemOperation}.
*
* @param ifMatchETag the ifMatchETag associated with the request.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public void setIfMatchETagCore(final String ifMatchETag){
this.ifMatchETag = ifMatchETag;
return;
}

/**
* Gets the If-None-Match (ETag) associated with the request in operation in {@link CosmosItemOperation}.
*
* @return the ifNoneMatchETag associated with the request.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public String getIfNoneMatchETag() {
return this.ifNoneMatchETag;
}

/**
* Sets the If-None-Match (ETag) associated with the request in operation in {@link CosmosItemOperation}.
*
* @param ifNoneMatchEtag the ifNoneMatchETag associated with the request.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public void setIfNoneMatchETagCore(final String ifNoneMatchEtag){
this.ifNoneMatchETag = ifNoneMatchEtag;
return;
}

/**
* Gets the boolean to only return the headers and status code in Cosmos DB response
* in case of Create, Update and Delete operations in {@link CosmosItemOperation}.
*
* If set to false, service doesn't return payload in the response. It reduces networking
* and CPU load by not sending the payload back over the network and serializing it on the client.
*
* This feature does not impact RU usage for read or write operations.
*
* By-default, this is null.
*
* @return a boolean indicating whether payload will be included in the response or not for this operation.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public Boolean isContentResponseOnWriteEnabled() {
return contentResponseOnWriteEnabled;
}

/**
* Sets the boolean to only return the headers and status code in Cosmos DB response
* in case of Create, Update and Delete operations in {@link CosmosItemOperation}.
*
* If set to false, service doesn't return payload in the response. It reduces networking
* and CPU load by not sending the payload back over the network and serializing it on the client.
*
* This feature does not impact RU usage for read or write operations.
*
* By-default, this is null.
*
* NOTE: This flag is also present on {@link com.azure.cosmos.CosmosClientBuilder}, however if specified
* here, it will override the value specified in {@link com.azure.cosmos.CosmosClientBuilder} for this request.
*
* @param contentResponseOnWriteEnabled a boolean indicating whether payload will be included
* in the response or not for this operation.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public void setContentResponseOnWriteEnabledCore(Boolean contentResponseOnWriteEnabled){
this.contentResponseOnWriteEnabled = contentResponseOnWriteEnabled;
return;
}

RequestOptions toRequestOptions() {
final RequestOptions requestOptions = new RequestOptions();
requestOptions.setIfMatchETag(getIfMatchETag());
requestOptions.setIfNoneMatchETag(getIfNoneMatchETag());
requestOptions.setContentResponseOnWriteEnabled(isContentResponseOnWriteEnabled());
return requestOptions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public static <T> CosmosItemOperation getUpsertItemOperation(

checkNotNull(item, "expected non-null item");
checkNotNull(partitionKey, "expected non-null partitionKey");

if (requestOptions == null) {
requestOptions = new BulkItemRequestOptions();
}
Expand Down Expand Up @@ -292,7 +292,7 @@ public static CosmosItemOperation getPatchItemOperation(
checkNotNull(partitionKey, "expected non-null partitionKey");
checkNotNull(cosmosPatchOperations, "expected non-null cosmosPatchOperations");

return getPatchItemOperation(id, partitionKey, cosmosPatchOperations, new BulkItemRequestOptions());
return getPatchItemOperation(id, partitionKey, cosmosPatchOperations, new BulkPatchItemRequestOptions());
}

/**
Expand All @@ -310,14 +310,14 @@ public static CosmosItemOperation getPatchItemOperation(
String id,
PartitionKey partitionKey,
CosmosPatchOperations cosmosPatchOperations,
BulkItemRequestOptions requestOptions) {
BulkPatchItemRequestOptions requestOptions) {

checkNotNull(id, "expected non-null id");
checkNotNull(partitionKey, "expected non-null partitionKey");
checkNotNull(cosmosPatchOperations, "expected non-null cosmosPatchOperations");

if (requestOptions == null) {
requestOptions = new BulkItemRequestOptions();
requestOptions = new BulkPatchItemRequestOptions();
}

return new ItemBulkOperation<>(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos;

import com.azure.cosmos.implementation.RequestOptions;
import com.azure.cosmos.util.Beta;

/**
* Encapsulates options that can be specified for an patch operation used in Bulk execution. It can be passed while
* creating bulk patch request using {@link BulkOperations}.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public final class BulkPatchItemRequestOptions
extends BulkItemRequestOptionsBase {
private String filterPredicate;

/**
* Gets the FilterPredicate associated with the request in the Azure Cosmos DB service.
*
* @return the FilterPredicate associated with the request.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public String getFilterPredicate() {
return this.filterPredicate;
}

/**
* Sets the FilterPredicate associated with the request in the Azure Cosmos DB service. for example: {@code setFilterPredicate("from c where c.taskNum = 3")}.
*
* @param filterPredicate the filterPredicate associated with the request.
* @return the current request options
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public BulkPatchItemRequestOptions setFilterPredicate(String filterPredicate) {
this.filterPredicate = filterPredicate;
return this;
}

/**
* Sets the boolean to only return the headers and status code in Cosmos DB response
* in case of Create, Update and Delete operations in {@link CosmosItemOperation}.
*
* If set to false, service doesn't return payload in the response. It reduces networking
* and CPU load by not sending the payload back over the network and serializing it on the client.
*
* This feature does not impact RU usage for read or write operations.
*
* By-default, this is null.
*
* NOTE: This flag is also present on {@link com.azure.cosmos.CosmosClientBuilder}, however if specified
* here, it will override the value specified in {@link com.azure.cosmos.CosmosClientBuilder} for this request.
*
* @param contentResponseOnWriteEnabled a boolean indicating whether payload will be included
* in the response or not for this operation.
*
* @return the current request options.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public BulkPatchItemRequestOptions setContentResponseOnWriteEnabled(Boolean contentResponseOnWriteEnabled) {
super.setContentResponseOnWriteEnabledCore(contentResponseOnWriteEnabled);
return this;
}

/**
* Sets the If-None-Match (ETag) associated with the request in operation in {@link CosmosItemOperation}.
*
* @param ifNoneMatchEtag the ifNoneMatchETag associated with the request.
* @return the current request options.
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public BulkPatchItemRequestOptions setIfNoneMatchETag(final String ifNoneMatchEtag) {
super.setIfNoneMatchETagCore(ifNoneMatchEtag);
return this;
}

/**
* Sets the If-Match (ETag) associated with the operation in {@link CosmosItemOperation}.
*
* @param ifMatchETag the ifMatchETag associated with the request.
* @return the current request options
*/
@Beta(value = Beta.SinceVersion.V4_13_0, warningText = Beta.PREVIEW_SUBJECT_TO_CHANGE_WARNING)
public BulkPatchItemRequestOptions setIfMatchETag(final String ifMatchETag) {
super.setIfMatchETagCore(ifMatchETag);
return this;
}

RequestOptions toRequestOptions() {
final RequestOptions requestOptions = super.toRequestOptions();
requestOptions.setFilterPredicate(getFilterPredicate());
return requestOptions;
}
}
Loading