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

Removing AccessCondition, AccessConditionType #11313

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -3,8 +3,6 @@

package com.azure.cosmos.rx.examples.multimaster.samples;

import com.azure.cosmos.models.AccessCondition;
import com.azure.cosmos.models.AccessConditionType;
import com.azure.cosmos.BridgeInternal;
import com.azure.cosmos.models.ConflictResolutionPolicy;
import com.azure.cosmos.CosmosClientException;
Expand Down Expand Up @@ -530,9 +528,7 @@ private Mono<Document> tryUpdateDocument(AsyncDocumentClient client, String coll
BridgeInternal.setProperty(document, "regionEndpoint", client.getReadEndpoint());

RequestOptions options = new RequestOptions();
options.setAccessCondition(new AccessCondition());
options.getAccessCondition().setType(AccessConditionType.IF_MATCH);
options.getAccessCondition().setCondition(document.getETag());
options.setIfMatchETag(document.getETag());


return client.replaceDocument(document.getSelfLink(), document, null).onErrorResume(e -> {
Expand All @@ -552,9 +548,7 @@ private Mono<Document> tryDeleteDocument(AsyncDocumentClient client, String coll
BridgeInternal.setProperty(document, "regionEndpoint", client.getReadEndpoint());

RequestOptions options = new RequestOptions();
options.setAccessCondition(new AccessCondition());
options.getAccessCondition().setType(AccessConditionType.IF_MATCH);
options.getAccessCondition().setCondition(document.getETag());
options.setIfMatchETag(document.getETag());


return client.deleteDocument(document.getSelfLink(), options).onErrorResume(e -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package com.azure.cosmos.implementation;

import com.azure.cosmos.models.AccessCondition;
import com.azure.cosmos.ConsistencyLevel;
import com.azure.cosmos.models.IndexingDirective;
import com.azure.cosmos.models.PartitionKey;
Expand All @@ -20,12 +19,13 @@ public class RequestOptions {
private Map<String, String> customOptions;
private List<String> preTriggerInclude;
private List<String> postTriggerInclude;
private AccessCondition accessCondition;
private IndexingDirective indexingDirective;
private ConsistencyLevel consistencyLevel;
private String sessionToken;
private Integer resourceTokenExpirySeconds;
private String offerType;
private String ifMatchETag;
private String ifNoneMatchETag;
private Integer offerThroughput;
private PartitionKey partitionkey;
private String partitionKeyRangeId;
Expand Down Expand Up @@ -71,21 +71,39 @@ public void setPostTriggerInclude(List<String> postTriggerInclude) {
}

/**
* Gets the conditions associated with the request.
* Gets the If-Match (ETag) associated with the request in the Azure Cosmos DB service.
*
* @return the access condition.
* @return tthe ifMatchETag associated with the request.
*/
public AccessCondition getAccessCondition() {
return this.accessCondition;
public String getIfMatchETag() {
return this.ifMatchETag;
}

/**
* Sets the conditions associated with the request.
* Sets the If-Match (ETag) associated with the request in the Azure Cosmos DB service.
*
* @param accessCondition the access condition.
* @param ifMatchETag the ifMatchETag associated with the request.
*/
public void setAccessCondition(AccessCondition accessCondition) {
this.accessCondition = accessCondition;
public void setIfMatchETag(String ifMatchETag) {
this.ifMatchETag = ifMatchETag;
}

/**
* Gets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service.
*
* @return the ifNoneMatchETag associated with the request.
*/
public String getIfNoneMatchETag() {
return this.ifNoneMatchETag;
}

/**
* Sets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service.
*
* @param ifNoneMatchETag the ifNoneMatchETag associated with the request.
*/
public void setIfNoneMatchETag(String ifNoneMatchETag) {
this.ifNoneMatchETag = ifNoneMatchETag;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.azure.cosmos.implementation.routing.PartitionKeyAndResourceTokenPair;
import com.azure.cosmos.implementation.routing.PartitionKeyInternal;
import com.azure.cosmos.implementation.routing.PartitionKeyInternalHelper;
import com.azure.cosmos.models.AccessConditionType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
Expand Down Expand Up @@ -874,12 +873,12 @@ private Map<String, String> getRequestHeaders(RequestOptions options, ResourceTy
headers.putAll(customOptions);
}

if (options.getAccessCondition() != null) {
if (options.getAccessCondition().getType() == AccessConditionType.IF_MATCH) {
headers.put(HttpConstants.HttpHeaders.IF_MATCH, options.getAccessCondition().getCondition());
} else {
headers.put(HttpConstants.HttpHeaders.IF_NONE_MATCH, options.getAccessCondition().getCondition());
}
if (options.getIfMatchETag() != null) {
headers.put(HttpConstants.HttpHeaders.IF_MATCH, options.getIfMatchETag());
}

if(options.getIfNoneMatchETag() != null) {
headers.put(HttpConstants.HttpHeaders.IF_NONE_MATCH, options.getIfNoneMatchETag());
}

if (options.getConsistencyLevel() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Licensed under the MIT License.
package com.azure.cosmos.implementation.changefeed.implementation;

import com.azure.cosmos.models.AccessCondition;
import com.azure.cosmos.models.AccessConditionType;
import com.azure.cosmos.BridgeInternal;
import com.azure.cosmos.CosmosClientException;
import com.azure.cosmos.implementation.CosmosItemProperties;
Expand Down Expand Up @@ -133,10 +131,7 @@ public Mono<Boolean> releaseInitializationLock() {
requestOptions = new CosmosItemRequestOptions();
}

AccessCondition accessCondition = new AccessCondition();
accessCondition.setType(AccessConditionType.IF_MATCH);
accessCondition.setCondition(this.lockETag);
requestOptions.setAccessCondition(accessCondition);
requestOptions.setIfMatchETag(this.lockETag);

return this.client.deleteItem(lockId, new PartitionKey(lockId), requestOptions)
.map(documentResourceResponse -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Licensed under the MIT License.
package com.azure.cosmos.implementation.changefeed.implementation;

import com.azure.cosmos.models.AccessCondition;
import com.azure.cosmos.models.AccessConditionType;
import com.azure.cosmos.BridgeInternal;
import com.azure.cosmos.CosmosClientException;
import com.azure.cosmos.implementation.CosmosItemProperties;
Expand All @@ -17,7 +15,6 @@
import com.azure.cosmos.implementation.changefeed.exceptions.LeaseLostException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.ZoneId;
Expand Down Expand Up @@ -150,12 +147,8 @@ private Mono<CosmosItemProperties> tryReplaceLease(Lease lease, String itemId, P
}

private CosmosItemRequestOptions getCreateIfMatchOptions(Lease lease) {
AccessCondition ifMatchCondition = new AccessCondition();
ifMatchCondition.setType(AccessConditionType.IF_MATCH);
ifMatchCondition.setCondition(lease.getConcurrencyToken());

CosmosItemRequestOptions createIfMatchOptions = new CosmosItemRequestOptions();
createIfMatchOptions.setAccessCondition(ifMatchCondition);
createIfMatchOptions.setIfMatchETag(lease.getConcurrencyToken());

return createIfMatchOptions;
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,53 @@
* The type Cosmos conflict request options.
*/
public final class CosmosConflictRequestOptions {
private AccessCondition accessCondition;
private String ifMatchETag;
private String ifNoneMatchETag;

/**
* Gets the conditions associated with the request.
* Gets the If-Match (ETag) associated with the request in the Azure Cosmos DB service.
*
* @return the access condition.
* @return ifMatchETag the ifMatchETag associated with the request.
*/
public AccessCondition getAccessCondition() {
return accessCondition;
public String getIfMatchETag() {
return this.ifMatchETag;
}

/**
* Sets the conditions associated with the request.
* Sets the If-Match (ETag) associated with the request in the Azure Cosmos DB service.
*
* @param accessCondition the access condition.
* @param ifMatchETag the ifMatchETag associated with the request.
* @return the current request options
*/
public CosmosConflictRequestOptions setAccessCondition(AccessCondition accessCondition) {
this.accessCondition = accessCondition;
public CosmosConflictRequestOptions setIfMatchETag(String ifMatchETag) {
this.ifMatchETag = ifMatchETag;
return this;
}

/**
* Gets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service.
*
* @return the ifNoneMatchETag associated with the request.
*/
public String getIfNoneMatchETag() {
return this.ifNoneMatchETag;
}

/**
* Sets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service.
*
* @param ifNoneMatchEtag the ifNoneMatchETag associated with the request.
* @return the current request options
*/
public CosmosConflictRequestOptions setIfNoneMatchETag(String ifNoneMatchEtag) {
this.ifNoneMatchETag = ifNoneMatchEtag;
return this;
}

RequestOptions toRequestOptions() {
RequestOptions requestOptions = new RequestOptions();
requestOptions.setAccessCondition(accessCondition);
requestOptions.setIfMatchETag(getIfMatchETag());
requestOptions.setIfNoneMatchETag(getIfNoneMatchETag());
return requestOptions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public final class CosmosContainerRequestOptions {
private boolean populateQuotaInfo;
private ConsistencyLevel consistencyLevel;
private String sessionToken;
private AccessCondition accessCondition;
private String ifMatchETag;
private String ifNoneMatchETag;
private ThroughputProperties throughputProperties;

/**
Expand Down Expand Up @@ -101,22 +102,42 @@ public CosmosContainerRequestOptions setSessionToken(String sessionToken) {
}

/**
* Gets the conditions associated with the request.
* Gets the If-Match (ETag) associated with the request in the Azure Cosmos DB service.
*
* @return the access condition.
* @return the ifMatchETag associated with the request.
*/
public AccessCondition getAccessCondition() {
return accessCondition;
public String getIfMatchETag() {
return this.ifMatchETag;
}

/**
* Sets the conditions associated with the request.
* Sets the If-Match (ETag) associated with the request in the Azure Cosmos DB service.
*
* @param accessCondition the access condition.
* @param ifMatchETag the ifMatchETag associated with the request.
* @return the current request options
*/
public CosmosContainerRequestOptions setAccessCondition(AccessCondition accessCondition) {
this.accessCondition = accessCondition;
public CosmosContainerRequestOptions setIfMatchETag(String ifMatchETag) {
this.ifMatchETag = ifMatchETag;
return this;
}

/**
* Gets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service.
*
* @return the ifNoneMatchETag associated with the request.
*/
public String getIfNoneMatchETag() {
return this.ifNoneMatchETag;
}

/**
* Sets the If-None-Match (ETag) associated with the request in the Azure Cosmos DB service.
*
* @param ifNoneMatchETag the ifNoneMatchETag associated with the request.
* @return the current request options
*/
public CosmosContainerRequestOptions setIfNoneMatchETag(String ifNoneMatchETag) {
this.ifNoneMatchETag = ifNoneMatchETag;
return this;
}

Expand All @@ -127,7 +148,8 @@ CosmosContainerRequestOptions setThroughputProperties(ThroughputProperties throu

RequestOptions toRequestOptions() {
RequestOptions options = new RequestOptions();
options.setAccessCondition(accessCondition);
options.setIfMatchETag(getIfMatchETag());
options.setIfNoneMatchETag(getIfNoneMatchETag());
options.setOfferThroughput(offerThroughput);
options.setPopulateQuotaInfo(populateQuotaInfo);
options.setSessionToken(sessionToken);
Expand Down
Loading