Skip to content
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 @@ -7,10 +7,6 @@
* Represents the connection mode to be used by the client in the Azure Cosmos DB database service.
* <p>
* DIRECT and GATEWAY connectivity modes are supported. DIRECT is the default.
* Refer to &lt;see&gt;http://azure.microsoft.com/documentation/articles/documentdb-
* interactions-with-resources/#connectivity-options&lt;/see&gt; for additional
* details.
* </p>
*/
public enum ConnectionMode {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* <p>
* The requested ConsistencyLevel must match or be weaker than that provisioned for the database account. Consistency
* levels by order of strength are STRONG, BOUNDED_STALENESS, SESSION and EVENTUAL.
*
* Refer to consistency level documentation for additional details: https://docs.microsoft.com/en-us/azure/cosmos-db/consistency-levels
*/
public enum ConsistencyLevel {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.models;
package com.azure.cosmos.implementation;


import com.azure.cosmos.ConsistencyLevel;
import com.azure.cosmos.implementation.Constants;
import com.azure.cosmos.implementation.JsonSerializable;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.azure.cosmos.implementation.guava25.base.CaseFormat;

Expand All @@ -15,19 +13,17 @@
/**
* Encapsulates the properties for consistency policy in the Azure Cosmos DB database service.
*/
public final class ConsistencyPolicy {
public final class ConsistencyPolicy extends JsonSerializable {
private static final ConsistencyLevel DEFAULT_DEFAULT_CONSISTENCY_LEVEL =
ConsistencyLevel.SESSION;

private static final int DEFAULT_MAX_STALENESS_INTERVAL = 5;
private static final int DEFAULT_MAX_STALENESS_PREFIX = 100;
private JsonSerializable jsonSerializable;

/**
* Constructor.
*/
public ConsistencyPolicy() {
this.jsonSerializable = new JsonSerializable();
}

/**
Expand All @@ -36,17 +32,17 @@ public ConsistencyPolicy() {
* @param objectNode the {@link ObjectNode} that represent the
* {@link JsonSerializable}
*/
ConsistencyPolicy(ObjectNode objectNode) {
this.jsonSerializable = new JsonSerializable(objectNode);
public ConsistencyPolicy(ObjectNode objectNode) {
super(objectNode);
}

/**
* Constructor.
*
* @param jsonString the json string that represents the consistency policy.
*/
ConsistencyPolicy(String jsonString) {
this.jsonSerializable = new JsonSerializable(jsonString);
public ConsistencyPolicy(String jsonString) {
super(jsonString);
}

/**
Expand All @@ -57,13 +53,13 @@ public ConsistencyPolicy() {
public ConsistencyLevel getDefaultConsistencyLevel() {

ConsistencyLevel result = ConsistencyPolicy.DEFAULT_DEFAULT_CONSISTENCY_LEVEL;
String consistencyLevelString = this.jsonSerializable.getString(Constants.Properties.DEFAULT_CONSISTENCY_LEVEL);
String consistencyLevelString = super.getString(Constants.Properties.DEFAULT_CONSISTENCY_LEVEL);
try {
result = ConsistencyLevel
.valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, consistencyLevelString));
} catch (IllegalArgumentException e) {
// ignore the exception and return the default
this.jsonSerializable.getLogger().warn("Unknown consistency level {}, value ignored.", consistencyLevelString);
this.getLogger().warn("Unknown consistency level {}, value ignored.", consistencyLevelString);
}
return result;
}
Expand All @@ -75,7 +71,7 @@ public ConsistencyLevel getDefaultConsistencyLevel() {
* @return the ConsistencyPolicy.
*/
public ConsistencyPolicy setDefaultConsistencyLevel(ConsistencyLevel level) {
this.jsonSerializable.set(Constants.Properties.DEFAULT_CONSISTENCY_LEVEL, level.toString());
super.set(Constants.Properties.DEFAULT_CONSISTENCY_LEVEL, level.toString());
return this;
}

Expand All @@ -86,7 +82,7 @@ public ConsistencyPolicy setDefaultConsistencyLevel(ConsistencyLevel level) {
* @return the max staleness prefix.
*/
public int getMaxStalenessPrefix() {
Integer value = this.jsonSerializable.getInt(Constants.Properties.MAX_STALENESS_PREFIX);
Integer value = super.getInt(Constants.Properties.MAX_STALENESS_PREFIX);
if (value == null) {
return ConsistencyPolicy.DEFAULT_MAX_STALENESS_PREFIX;
}
Expand All @@ -101,7 +97,7 @@ public int getMaxStalenessPrefix() {
* @return the ConsistencyPolicy.
*/
public ConsistencyPolicy setMaxStalenessPrefix(int maxStalenessPrefix) {
this.jsonSerializable.set(Constants.Properties.MAX_STALENESS_PREFIX, maxStalenessPrefix);
super.set(Constants.Properties.MAX_STALENESS_PREFIX, maxStalenessPrefix);
return this;
}

Expand All @@ -112,7 +108,7 @@ public ConsistencyPolicy setMaxStalenessPrefix(int maxStalenessPrefix) {
* @return the max staleness prefix.
*/
public Duration getMaxStalenessInterval() {
Integer value = this.jsonSerializable.getInt(Constants.Properties.MAX_STALENESS_INTERVAL_IN_SECONDS);
Integer value = super.getInt(Constants.Properties.MAX_STALENESS_INTERVAL_IN_SECONDS);
if (value == null) {
return Duration.ofSeconds(ConsistencyPolicy.DEFAULT_MAX_STALENESS_INTERVAL);
}
Expand All @@ -130,13 +126,7 @@ public ConsistencyPolicy setMaxStalenessInterval(Duration maxStalenessInterval)
if (maxStalenessInterval == null) {
throw new IllegalArgumentException("maxStalenessInterval should not be null");
}
this.jsonSerializable.set(Constants.Properties.MAX_STALENESS_INTERVAL_IN_SECONDS, maxStalenessInterval.getSeconds());
super.set(Constants.Properties.MAX_STALENESS_INTERVAL_IN_SECONDS, maxStalenessInterval.getSeconds());
return this;
}

void populatePropertyBag() {
this.jsonSerializable.populatePropertyBag();
}

JsonSerializable getJsonSerializable() { return this.jsonSerializable; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
package com.azure.cosmos.implementation;

import com.azure.cosmos.BridgeInternal;
import com.azure.cosmos.models.ConsistencyPolicy;
import com.azure.cosmos.models.DatabaseAccountLocation;
import com.azure.cosmos.models.ModelBridgeInternal;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.azure.cosmos.implementation.apachecommons.lang.ObjectUtils;
Expand Down Expand Up @@ -273,7 +271,7 @@ public void setEnableMultipleWriteLocations(boolean value) {
public void populatePropertyBag() {
super.populatePropertyBag();
if (this.consistencyPolicy != null) {
ModelBridgeInternal.populatePropertyBag(this.consistencyPolicy);
this.consistencyPolicy.populatePropertyBag();
BridgeInternal.setProperty(this, Constants.Properties.USER_CONSISTENCY_POLICY, this.consistencyPolicy);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import com.azure.cosmos.models.CompositePath;
import com.azure.cosmos.models.ConflictResolutionPolicy;
import com.azure.cosmos.models.ConsistencyPolicy;
import com.azure.cosmos.models.CosmosError;
import com.azure.cosmos.models.DatabaseAccountLocation;
import com.azure.cosmos.models.ExcludedPath;
Expand Down Expand Up @@ -688,7 +687,6 @@ public ObjectNode getPropertyBag() {
<T> boolean containsJsonSerializable(Class<T> c) {
return CompositePath.class.equals(c)
|| ConflictResolutionPolicy.class.equals(c)
|| ConsistencyPolicy.class.equals(c)
|| DatabaseAccountLocation.class.equals(c)
|| ExcludedPath.class.equals(c)
|| IncludedPath.class.equals(c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static ConflictResolutionPolicy createCustomPolicy() {
*
* @param jsonString the json string
*/
public ConflictResolutionPolicy(String jsonString) {
ConflictResolutionPolicy(String jsonString) {
this.jsonSerializable = new JsonSerializable(jsonString);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.azure.cosmos.CosmosTrigger;
import com.azure.cosmos.CosmosUserDefinedFunction;
import com.azure.cosmos.implementation.Conflict;
import com.azure.cosmos.implementation.ConsistencyPolicy;
import com.azure.cosmos.implementation.CosmosItemProperties;
import com.azure.cosmos.implementation.CosmosResourceType;
import com.azure.cosmos.implementation.Database;
Expand Down Expand Up @@ -615,8 +616,6 @@ public static <T> void populatePropertyBag(T t) {
((CompositePath) t).populatePropertyBag();
} else if (t instanceof ConflictResolutionPolicy) {
((ConflictResolutionPolicy) t).populatePropertyBag();
} else if (t instanceof ConsistencyPolicy) {
((ConsistencyPolicy) t).populatePropertyBag();
} else if (t instanceof DatabaseAccountLocation) {
((DatabaseAccountLocation) t).populatePropertyBag();
} else if (t instanceof ExcludedPath) {
Expand Down Expand Up @@ -652,8 +651,6 @@ public static <T> JsonSerializable getJsonSerializable(T t) {
return ((CompositePath) t).getJsonSerializable();
} else if (t instanceof ConflictResolutionPolicy) {
return ((ConflictResolutionPolicy) t).getJsonSerializable();
} else if (t instanceof ConsistencyPolicy) {
return ((ConsistencyPolicy) t).getJsonSerializable();
} else if (t instanceof DatabaseAccountLocation) {
return ((DatabaseAccountLocation) t).getJsonSerializable();
} else if (t instanceof ExcludedPath) {
Expand Down