diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ConnectionMode.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ConnectionMode.java index ab421059674c..cefe9935cc9f 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ConnectionMode.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ConnectionMode.java @@ -7,10 +7,6 @@ * Represents the connection mode to be used by the client in the Azure Cosmos DB database service. *

* DIRECT and GATEWAY connectivity modes are supported. DIRECT is the default. - * Refer to <see>http://azure.microsoft.com/documentation/articles/documentdb- - * interactions-with-resources/#connectivity-options</see> for additional - * details. - *

*/ public enum ConnectionMode { diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ConsistencyLevel.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ConsistencyLevel.java index b88edb4f706d..4131d2df7f3c 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ConsistencyLevel.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/ConsistencyLevel.java @@ -11,6 +11,8 @@ *

* 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 { diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ConsistencyPolicy.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ConsistencyPolicy.java similarity index 70% rename from sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ConsistencyPolicy.java rename to sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ConsistencyPolicy.java index 7f41b43f0a35..366e892c8f30 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ConsistencyPolicy.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ConsistencyPolicy.java @@ -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; @@ -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(); } /** @@ -36,8 +32,8 @@ 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); } /** @@ -45,8 +41,8 @@ public ConsistencyPolicy() { * * @param jsonString the json string that represents the consistency policy. */ - ConsistencyPolicy(String jsonString) { - this.jsonSerializable = new JsonSerializable(jsonString); + public ConsistencyPolicy(String jsonString) { + super(jsonString); } /** @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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); } @@ -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; } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DatabaseAccount.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DatabaseAccount.java index f4fbc676efc8..bd8357e5edde 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DatabaseAccount.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DatabaseAccount.java @@ -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; @@ -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); } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/JsonSerializable.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/JsonSerializable.java index c90bdcca9c5c..98eda9509534 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/JsonSerializable.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/JsonSerializable.java @@ -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; @@ -688,7 +687,6 @@ public ObjectNode getPropertyBag() { boolean containsJsonSerializable(Class 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) diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ConflictResolutionPolicy.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ConflictResolutionPolicy.java index d068c8d799d8..5ff66715907d 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ConflictResolutionPolicy.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ConflictResolutionPolicy.java @@ -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); } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ModelBridgeInternal.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ModelBridgeInternal.java index ac3e3e4c206b..fc2cd34bce7a 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ModelBridgeInternal.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/ModelBridgeInternal.java @@ -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; @@ -615,8 +616,6 @@ public static 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) { @@ -652,8 +651,6 @@ public static 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) {