diff --git a/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/ReadMyWritesConsistencyTest.java b/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/ReadMyWritesConsistencyTest.java index 7816baf073f6..66a0aa06cb1a 100644 --- a/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/ReadMyWritesConsistencyTest.java +++ b/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/ReadMyWritesConsistencyTest.java @@ -3,18 +3,14 @@ package com.azure.cosmos.benchmark; -import com.azure.cosmos.BridgeInternal; -import com.azure.cosmos.models.DataType; -import com.azure.cosmos.models.IncludedPath; -import com.azure.cosmos.models.Index; -import com.azure.cosmos.models.IndexingPolicy; -import com.azure.cosmos.models.ModelBridgeInternal; -import com.azure.cosmos.models.PartitionKeyDefinition; import com.azure.cosmos.implementation.AsyncDocumentClient; import com.azure.cosmos.implementation.Database; import com.azure.cosmos.implementation.DocumentCollection; import com.azure.cosmos.implementation.RequestOptions; import com.azure.cosmos.implementation.TestConfigurations; +import com.azure.cosmos.models.IncludedPath; +import com.azure.cosmos.models.IndexingPolicy; +import com.azure.cosmos.models.PartitionKeyDefinition; import com.beust.jcommander.JCommander; import com.google.common.base.Strings; import org.apache.commons.lang3.StringUtils; @@ -29,7 +25,6 @@ import java.time.Duration; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; @@ -167,10 +162,6 @@ DocumentCollection getCollectionDefinitionWithRangeRangeIndex() { IndexingPolicy indexingPolicy = new IndexingPolicy(); List includedPaths = new ArrayList<>(); IncludedPath includedPath = new IncludedPath("/*"); - List indexes = new ArrayList<>(); - indexes.add(Index.range(DataType.STRING, -1)); - indexes.add(Index.range(DataType.NUMBER, -1)); - includedPath.setIndexes(indexes); includedPaths.add(includedPath); indexingPolicy.setIncludedPaths(includedPaths); diff --git a/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/WorkflowTest.java b/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/WorkflowTest.java index 74706117fb62..27bce373d6a0 100644 --- a/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/WorkflowTest.java +++ b/sdk/cosmos/azure-cosmos-benchmark/src/test/java/com/azure/cosmos/benchmark/WorkflowTest.java @@ -3,18 +3,14 @@ package com.azure.cosmos.benchmark; -import com.azure.cosmos.BridgeInternal; -import com.azure.cosmos.models.DataType; -import com.azure.cosmos.models.IncludedPath; -import com.azure.cosmos.models.Index; -import com.azure.cosmos.models.IndexingPolicy; -import com.azure.cosmos.models.ModelBridgeInternal; -import com.azure.cosmos.models.PartitionKeyDefinition; import com.azure.cosmos.implementation.AsyncDocumentClient; import com.azure.cosmos.implementation.Database; import com.azure.cosmos.implementation.DocumentCollection; import com.azure.cosmos.implementation.RequestOptions; import com.azure.cosmos.implementation.TestConfigurations; +import com.azure.cosmos.models.IncludedPath; +import com.azure.cosmos.models.IndexingPolicy; +import com.azure.cosmos.models.PartitionKeyDefinition; import com.beust.jcommander.JCommander; import org.apache.commons.lang3.StringUtils; import org.testng.annotations.AfterClass; @@ -23,7 +19,6 @@ import org.testng.annotations.Test; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; @@ -307,10 +302,6 @@ DocumentCollection getCollectionDefinitionWithRangeRangeIndex() { IndexingPolicy indexingPolicy = new IndexingPolicy(); List includedPaths = new ArrayList<>(); IncludedPath includedPath = new IncludedPath("/*"); - List indexes = new ArrayList<>(); - indexes.add(Index.range(DataType.STRING, -1)); - indexes.add(Index.range(DataType.NUMBER, -1)); - includedPath.setIndexes(indexes); includedPaths.add(includedPath); indexingPolicy.setIncludedPaths(includedPaths); diff --git a/sdk/cosmos/azure-cosmos-examples/src/test/java/com/azure/cosmos/rx/examples/CollectionCRUDAsyncAPITest.java b/sdk/cosmos/azure-cosmos-examples/src/test/java/com/azure/cosmos/rx/examples/CollectionCRUDAsyncAPITest.java index 1d40f78629d6..c3d4769fd140 100644 --- a/sdk/cosmos/azure-cosmos-examples/src/test/java/com/azure/cosmos/rx/examples/CollectionCRUDAsyncAPITest.java +++ b/sdk/cosmos/azure-cosmos-examples/src/test/java/com/azure/cosmos/rx/examples/CollectionCRUDAsyncAPITest.java @@ -2,23 +2,21 @@ // Licensed under the MIT License. package com.azure.cosmos.rx.examples; -import com.azure.cosmos.DirectConnectionConfig; -import com.azure.cosmos.implementation.ConnectionPolicy; import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.CosmosException; -import com.azure.cosmos.models.DataType; +import com.azure.cosmos.DirectConnectionConfig; import com.azure.cosmos.DocumentClientTest; -import com.azure.cosmos.models.FeedResponse; -import com.azure.cosmos.models.IncludedPath; -import com.azure.cosmos.models.Index; -import com.azure.cosmos.models.IndexingPolicy; -import com.azure.cosmos.models.PartitionKeyDefinition; import com.azure.cosmos.implementation.AsyncDocumentClient; +import com.azure.cosmos.implementation.ConnectionPolicy; import com.azure.cosmos.implementation.Database; import com.azure.cosmos.implementation.DocumentCollection; import com.azure.cosmos.implementation.RequestOptions; import com.azure.cosmos.implementation.ResourceResponse; import com.azure.cosmos.implementation.TestConfigurations; +import com.azure.cosmos.models.FeedResponse; +import com.azure.cosmos.models.IncludedPath; +import com.azure.cosmos.models.IndexingPolicy; +import com.azure.cosmos.models.PartitionKeyDefinition; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; @@ -377,10 +375,6 @@ private DocumentCollection getMultiPartitionCollectionDefinition() { IndexingPolicy indexingPolicy = new IndexingPolicy(); List includedPaths = new ArrayList<>(); IncludedPath includedPath = new IncludedPath("/*"); - List indexes = new ArrayList<>(); - indexes.add(Index.range(DataType.STRING, -1)); - indexes.add(Index.range(DataType.NUMBER, -1)); - includedPath.setIndexes(indexes); includedPaths.add(includedPath); indexingPolicy.setIncludedPaths(includedPaths); collectionDefinition.setIndexingPolicy(indexingPolicy); diff --git a/sdk/cosmos/azure-cosmos-examples/src/test/java/com/azure/cosmos/rx/examples/OfferCRUDAsyncAPITest.java b/sdk/cosmos/azure-cosmos-examples/src/test/java/com/azure/cosmos/rx/examples/OfferCRUDAsyncAPITest.java index 6933f3599f68..3395e49de586 100644 --- a/sdk/cosmos/azure-cosmos-examples/src/test/java/com/azure/cosmos/rx/examples/OfferCRUDAsyncAPITest.java +++ b/sdk/cosmos/azure-cosmos-examples/src/test/java/com/azure/cosmos/rx/examples/OfferCRUDAsyncAPITest.java @@ -3,30 +3,24 @@ package com.azure.cosmos.rx.examples; +import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.DirectConnectionConfig; +import com.azure.cosmos.DocumentClientTest; import com.azure.cosmos.implementation.AsyncDocumentClient; -import com.azure.cosmos.BridgeInternal; -import com.azure.cosmos.ConnectionMode; import com.azure.cosmos.implementation.ConnectionPolicy; -import com.azure.cosmos.ConsistencyLevel; -import com.azure.cosmos.models.DataType; import com.azure.cosmos.implementation.Database; -import com.azure.cosmos.DocumentClientTest; import com.azure.cosmos.implementation.DocumentCollection; -import com.azure.cosmos.models.IncludedPath; -import com.azure.cosmos.models.Index; -import com.azure.cosmos.models.IndexingPolicy; import com.azure.cosmos.implementation.Offer; -import com.azure.cosmos.models.ModelBridgeInternal; -import com.azure.cosmos.models.PartitionKeyDefinition; import com.azure.cosmos.implementation.RequestOptions; import com.azure.cosmos.implementation.TestConfigurations; +import com.azure.cosmos.models.IncludedPath; +import com.azure.cosmos.models.IndexingPolicy; +import com.azure.cosmos.models.PartitionKeyDefinition; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.UUID; import java.util.concurrent.CountDownLatch; @@ -142,10 +136,6 @@ private DocumentCollection getMultiPartitionCollectionDefinition() { IndexingPolicy indexingPolicy = new IndexingPolicy(); List includedPaths = new ArrayList<>(); IncludedPath includedPath = new IncludedPath("/*"); - List indexes = new ArrayList<>(); - indexes.add(Index.range(DataType.STRING, -1)); - indexes.add(Index.range(DataType.NUMBER, -1)); - includedPath.setIndexes(indexes); includedPaths.add(includedPath); indexingPolicy.setIncludedPaths(includedPaths); collectionDefinition.setIndexingPolicy(indexingPolicy); diff --git a/sdk/cosmos/azure-cosmos-examples/src/test/java/com/azure/cosmos/rx/examples/StoredProcedureAsyncAPITest.java b/sdk/cosmos/azure-cosmos-examples/src/test/java/com/azure/cosmos/rx/examples/StoredProcedureAsyncAPITest.java index ea8a0ebb0dd7..3e4c289241e3 100644 --- a/sdk/cosmos/azure-cosmos-examples/src/test/java/com/azure/cosmos/rx/examples/StoredProcedureAsyncAPITest.java +++ b/sdk/cosmos/azure-cosmos-examples/src/test/java/com/azure/cosmos/rx/examples/StoredProcedureAsyncAPITest.java @@ -3,26 +3,21 @@ package com.azure.cosmos.rx.examples; +import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.DirectConnectionConfig; +import com.azure.cosmos.DocumentClientTest; import com.azure.cosmos.implementation.AsyncDocumentClient; -import com.azure.cosmos.BridgeInternal; -import com.azure.cosmos.ConnectionMode; import com.azure.cosmos.implementation.ConnectionPolicy; -import com.azure.cosmos.ConsistencyLevel; -import com.azure.cosmos.models.DataType; import com.azure.cosmos.implementation.Database; -import com.azure.cosmos.DocumentClientTest; import com.azure.cosmos.implementation.DocumentCollection; +import com.azure.cosmos.implementation.HttpConstants; +import com.azure.cosmos.implementation.RequestOptions; +import com.azure.cosmos.implementation.StoredProcedure; +import com.azure.cosmos.implementation.TestConfigurations; import com.azure.cosmos.models.IncludedPath; -import com.azure.cosmos.models.Index; import com.azure.cosmos.models.IndexingPolicy; -import com.azure.cosmos.models.ModelBridgeInternal; import com.azure.cosmos.models.PartitionKey; import com.azure.cosmos.models.PartitionKeyDefinition; -import com.azure.cosmos.implementation.RequestOptions; -import com.azure.cosmos.implementation.StoredProcedure; -import com.azure.cosmos.implementation.HttpConstants; -import com.azure.cosmos.implementation.TestConfigurations; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -234,10 +229,6 @@ private static DocumentCollection getMultiPartitionCollectionDefinition() { IndexingPolicy indexingPolicy = new IndexingPolicy(); List includedPaths = new ArrayList(); IncludedPath includedPath = new IncludedPath("/*"); - List indexes = new ArrayList(); - indexes.add(Index.range(DataType.STRING, -1)); - indexes.add(Index.range(DataType.NUMBER, -1)); - includedPath.setIndexes(indexes); includedPaths.add(includedPath); indexingPolicy.setIncludedPaths(includedPaths); collectionDefinition.setIndexingPolicy(indexingPolicy); diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/DataType.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DataType.java similarity index 95% rename from sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/DataType.java rename to sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DataType.java index 8412cb1d7eff..424b38ee9049 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/DataType.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/DataType.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.cosmos.models; +package com.azure.cosmos.implementation; /** * Data types in the Azure Cosmos DB database service. diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/HashIndex.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/HashIndex.java similarity index 78% rename from sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/HashIndex.java rename to sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/HashIndex.java index cf25396292ed..b5994edf61c3 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/HashIndex.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/HashIndex.java @@ -1,11 +1,9 @@ // 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.implementation.Constants; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; -import com.azure.cosmos.implementation.IndexKind; import com.fasterxml.jackson.databind.node.ObjectNode; /** @@ -47,7 +45,7 @@ public final class HashIndex extends Index { * * @param jsonString the json string that represents the index. */ - HashIndex(String jsonString) { + public HashIndex(String jsonString) { super(jsonString, IndexKind.HASH); if (this.getDataType() == null) { throw new IllegalArgumentException("The jsonString doesn't contain a valid 'dataType'."); @@ -74,11 +72,10 @@ public final class HashIndex extends Index { public DataType getDataType() { DataType result = null; try { - result = DataType.valueOf(StringUtils.upperCase(this.jsonSerializable.getString(Constants.Properties.DATA_TYPE))); + result = DataType.valueOf(StringUtils.upperCase(super.getString(Constants.Properties.DATA_TYPE))); } catch (IllegalArgumentException e) { // Ignore exception and let the caller handle null value. - this.jsonSerializable.getLogger().warn("INVALID index dataType value {}.", - this.jsonSerializable.getString(Constants.Properties.DATA_TYPE)); + super.getLogger().warn("INVALID index dataType value {}.", super.getString(Constants.Properties.DATA_TYPE)); } return result; } @@ -90,7 +87,7 @@ public DataType getDataType() { * @return the Hash Index. */ public HashIndex setDataType(DataType dataType) { - this.jsonSerializable.set(Constants.Properties.DATA_TYPE, dataType.toString()); + super.set(Constants.Properties.DATA_TYPE, dataType.toString()); return this; } @@ -100,7 +97,7 @@ public HashIndex setDataType(DataType dataType) { * @return the precision. */ public int getPrecision() { - return this.jsonSerializable.getInt(Constants.Properties.PRECISION); + return super.getInt(Constants.Properties.PRECISION); } /** @@ -110,11 +107,11 @@ public int getPrecision() { * @return the Hash Index. */ public HashIndex setPrecision(int precision) { - this.jsonSerializable.set(Constants.Properties.PRECISION, precision); + super.set(Constants.Properties.PRECISION, precision); return this; } boolean hasPrecision() { - return this.jsonSerializable.has(Constants.Properties.PRECISION); + return super.has(Constants.Properties.PRECISION); } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/Index.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Index.java similarity index 80% rename from sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/Index.java rename to sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Index.java index f09e33167015..3afb7413ad0c 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/Index.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Index.java @@ -1,19 +1,15 @@ // 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.implementation.Constants; -import com.azure.cosmos.implementation.JsonSerializable; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; -import com.azure.cosmos.implementation.IndexKind; import com.fasterxml.jackson.databind.node.ObjectNode; /** * Represents the index of a container in the Azure Cosmos DB database service. */ -public abstract class Index { - JsonSerializable jsonSerializable; +public abstract class Index extends JsonSerializable { /** * Constructor. @@ -21,7 +17,7 @@ public abstract class Index { * @param indexKind the kind of the index */ Index(IndexKind indexKind) { - this.jsonSerializable = new JsonSerializable(); + super(); this.setKind(indexKind); } @@ -32,7 +28,7 @@ public abstract class Index { * @param indexKind the kind of the index */ Index(String jsonString, IndexKind indexKind) { - this.jsonSerializable = new JsonSerializable(jsonString); + super(jsonString); this.setKind(indexKind); } @@ -43,7 +39,7 @@ public abstract class Index { * @param indexKind the kind of the index */ Index(ObjectNode objectNode, IndexKind indexKind) { - this.jsonSerializable = new JsonSerializable(objectNode); + super(objectNode); this.setKind(indexKind); } @@ -125,9 +121,9 @@ public static SpatialIndex spatial(DataType dataType) { IndexKind getKind() { IndexKind result = null; try { - result = IndexKind.valueOf(StringUtils.upperCase(this.jsonSerializable.getString(Constants.Properties.INDEX_KIND))); + result = IndexKind.valueOf(StringUtils.upperCase(super.getString(Constants.Properties.INDEX_KIND))); } catch (IllegalArgumentException e) { - this.jsonSerializable.getLogger().warn("INVALID index kind value %s.", this.jsonSerializable.getString(Constants.Properties.INDEX_KIND)); + super.getLogger().warn("INVALID index kind value %s.", super.getString(Constants.Properties.INDEX_KIND)); } return result; @@ -139,13 +135,7 @@ IndexKind getKind() { * @param indexKind the index kind. */ private Index setKind(IndexKind indexKind) { - this.jsonSerializable.set(Constants.Properties.INDEX_KIND, indexKind.toString()); + super.set(Constants.Properties.INDEX_KIND, indexKind.toString()); 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/JsonSerializable.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/JsonSerializable.java index 1defa62155fe..1ffd9ac12f9c 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 @@ -7,7 +7,6 @@ import com.azure.cosmos.models.ConflictResolutionPolicy; import com.azure.cosmos.models.ExcludedPath; import com.azure.cosmos.models.IncludedPath; -import com.azure.cosmos.models.Index; import com.azure.cosmos.models.IndexingPolicy; import com.azure.cosmos.models.ModelBridgeInternal; import com.azure.cosmos.models.PartitionKeyDefinition; @@ -692,7 +691,6 @@ boolean containsJsonSerializable(Class c) { || SqlParameter.class.equals(c) || SqlQuerySpec.class.equals(c) || UniqueKey.class.equals(c) - || UniqueKeyPolicy.class.equals(c) - || Index.class.isAssignableFrom(c); + || UniqueKeyPolicy.class.equals(c); } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/RangeIndex.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RangeIndex.java similarity index 78% rename from sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/RangeIndex.java rename to sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RangeIndex.java index 76c8cfac35b2..7abc9d353299 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/RangeIndex.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RangeIndex.java @@ -1,11 +1,9 @@ // 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.implementation.Constants; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; -import com.azure.cosmos.implementation.IndexKind; import com.fasterxml.jackson.databind.node.ObjectNode; /** @@ -44,7 +42,7 @@ public final class RangeIndex extends Index { * * @param jsonString the json string that represents the index. */ - RangeIndex(String jsonString) { + public RangeIndex(String jsonString) { super(jsonString, IndexKind.RANGE); if (this.getDataType() == null) { throw new IllegalArgumentException("The jsonString doesn't contain a valid 'dataType'."); @@ -71,10 +69,9 @@ public final class RangeIndex extends Index { public DataType getDataType() { DataType result = null; try { - result = DataType.valueOf(StringUtils.upperCase(this.jsonSerializable.getString(Constants.Properties.DATA_TYPE))); + result = DataType.valueOf(StringUtils.upperCase(super.getString(Constants.Properties.DATA_TYPE))); } catch (IllegalArgumentException e) { - this.jsonSerializable.getLogger().warn("INVALID index dataType value {}.", - this.jsonSerializable.getString(Constants.Properties.DATA_TYPE)); + super.getLogger().warn("INVALID index dataType value {}.", super.getString(Constants.Properties.DATA_TYPE)); } return result; } @@ -86,7 +83,7 @@ public DataType getDataType() { * @return the RangeIndex. */ public RangeIndex setDataType(DataType dataType) { - this.jsonSerializable.set(Constants.Properties.DATA_TYPE, dataType.toString()); + super.set(Constants.Properties.DATA_TYPE, dataType.toString()); return this; } @@ -96,7 +93,7 @@ public RangeIndex setDataType(DataType dataType) { * @return the precision. */ public int getPrecision() { - return this.jsonSerializable.getInt(Constants.Properties.PRECISION); + return super.getInt(Constants.Properties.PRECISION); } /** @@ -106,11 +103,11 @@ public int getPrecision() { * @return the RangeIndex. */ public RangeIndex setPrecision(int precision) { - this.jsonSerializable.set(Constants.Properties.PRECISION, precision); + super.set(Constants.Properties.PRECISION, precision); return this; } boolean hasPrecision() { - return this.jsonSerializable.has(Constants.Properties.PRECISION); + return super.has(Constants.Properties.PRECISION); } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/SpatialIndex.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/SpatialIndex.java similarity index 78% rename from sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/SpatialIndex.java rename to sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/SpatialIndex.java index 468fbebb519b..9243238be30d 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/SpatialIndex.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/SpatialIndex.java @@ -1,11 +1,9 @@ // 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.implementation.Constants; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; -import com.azure.cosmos.implementation.IndexKind; import com.fasterxml.jackson.databind.node.ObjectNode; /** @@ -31,7 +29,7 @@ public final class SpatialIndex extends Index { * * @param jsonString the json string that represents the index. */ - SpatialIndex(String jsonString) { + public SpatialIndex(String jsonString) { super(jsonString, IndexKind.SPATIAL); if (this.getDataType() == null) { throw new IllegalArgumentException("The jsonString doesn't contain a valid 'dataType'."); @@ -58,10 +56,9 @@ public final class SpatialIndex extends Index { public DataType getDataType() { DataType result = null; try { - result = DataType.valueOf(StringUtils.upperCase(this.jsonSerializable.getString(Constants.Properties.DATA_TYPE))); + result = DataType.valueOf(StringUtils.upperCase(super.getString(Constants.Properties.DATA_TYPE))); } catch (IllegalArgumentException e) { - this.jsonSerializable.getLogger().warn("INVALID index dataType value {}.", - this.jsonSerializable.getString(Constants.Properties.DATA_TYPE)); + super.getLogger().warn("INVALID index dataType value {}.", super.getString(Constants.Properties.DATA_TYPE)); } return result; } @@ -73,7 +70,7 @@ public DataType getDataType() { * @return the SpatialIndex. */ public SpatialIndex setDataType(DataType dataType) { - this.jsonSerializable.set(Constants.Properties.DATA_TYPE, dataType.toString()); + super.set(Constants.Properties.DATA_TYPE, dataType.toString()); return this; } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/IncludedPath.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/IncludedPath.java index 81fd8835bd08..da2065816d65 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/IncludedPath.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/IncludedPath.java @@ -4,8 +4,12 @@ package com.azure.cosmos.models; import com.azure.cosmos.implementation.Constants; +import com.azure.cosmos.implementation.HashIndex; +import com.azure.cosmos.implementation.Index; import com.azure.cosmos.implementation.IndexKind; import com.azure.cosmos.implementation.JsonSerializable; +import com.azure.cosmos.implementation.RangeIndex; +import com.azure.cosmos.implementation.SpatialIndex; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; @@ -65,7 +69,7 @@ public IncludedPath setPath(String path) { * * @return the included paths. */ - public List getIndexes() { + List getIndexes() { if (this.indexes == null) { this.indexes = this.getIndexCollection(); @@ -83,7 +87,7 @@ public List getIndexes() { * @param indexes the indexes * @return the indexes */ - public IncludedPath setIndexes(List indexes) { + IncludedPath setIndexes(List indexes) { this.indexes = indexes; return this; } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/IndexingPolicy.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/IndexingPolicy.java index 803659aa70d7..d5bde6ef26a6 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/IndexingPolicy.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/IndexingPolicy.java @@ -4,6 +4,7 @@ package com.azure.cosmos.models; import com.azure.cosmos.implementation.Constants; +import com.azure.cosmos.implementation.Index; import com.azure.cosmos.implementation.JsonSerializable; import com.fasterxml.jackson.databind.node.ArrayNode; import com.azure.cosmos.implementation.apachecommons.lang.StringUtils; @@ -55,7 +56,7 @@ public IndexingPolicy() { * root path. * @throws IllegalArgumentException throws when defaultIndexOverrides is null */ - public IndexingPolicy(Index[] defaultIndexOverrides) { + IndexingPolicy(Index[] defaultIndexOverrides) { this(); if (defaultIndexOverrides == null) { 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 8ffb00fedc1d..861ef378b90a 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.implementation.Document; import com.azure.cosmos.implementation.DocumentCollection; import com.azure.cosmos.implementation.HttpConstants; +import com.azure.cosmos.implementation.Index; import com.azure.cosmos.implementation.JsonSerializable; import com.azure.cosmos.implementation.Offer; import com.azure.cosmos.implementation.PartitionKeyRange; @@ -568,8 +569,6 @@ public static void populatePropertyBag(T t) { ((UniqueKey) t).populatePropertyBag(); } else if (t instanceof UniqueKeyPolicy) { ((UniqueKeyPolicy) t).populatePropertyBag(); - } else if (t instanceof Index) { - ((Index) t).populatePropertyBag(); } else { throw new IllegalArgumentException("populatePropertyBag method does not exists in class " + t.getClass()); } @@ -601,8 +600,6 @@ public static JsonSerializable getJsonSerializable(T t) { return ((UniqueKey) t).getJsonSerializable(); } else if (t instanceof UniqueKeyPolicy) { return ((UniqueKeyPolicy) t).getJsonSerializable(); - } else if (t instanceof Index) { - return ((Index) t).getJsonSerializable(); } else { throw new IllegalArgumentException("getJsonSerializable method does not exists in class " + t.getClass()); } @@ -689,4 +686,9 @@ public static boolean getEmptyPagesAllowedFromQueryRequestOptions(QueryRequestOp public static QueryRequestOptions setQueryRequestOptionsEmptyPagesAllowed(QueryRequestOptions options, boolean emptyPageAllowed) { return options.setEmptyPagesAllowed(emptyPageAllowed); } + + @Warning(value = INTERNAL_USE_ONLY_WARNING) + public static IndexingPolicy createIndexingPolicy(Index[] indexes) { + return new IndexingPolicy(indexes); + } } diff --git a/sdk/cosmos/azure-cosmos/src/samples/java/com/azure/cosmos/IndexPolicyCodeSnippet.java b/sdk/cosmos/azure-cosmos/src/samples/java/com/azure/cosmos/IndexPolicyCodeSnippet.java index 65dd40ec2134..988b96e15f04 100644 --- a/sdk/cosmos/azure-cosmos/src/samples/java/com/azure/cosmos/IndexPolicyCodeSnippet.java +++ b/sdk/cosmos/azure-cosmos/src/samples/java/com/azure/cosmos/IndexPolicyCodeSnippet.java @@ -3,12 +3,13 @@ package com.azure.cosmos; -import com.azure.cosmos.models.DataType; -import com.azure.cosmos.models.HashIndex; -import com.azure.cosmos.models.Index; +import com.azure.cosmos.implementation.DataType; +import com.azure.cosmos.implementation.HashIndex; +import com.azure.cosmos.implementation.Index; import com.azure.cosmos.models.IndexingPolicy; -import com.azure.cosmos.models.RangeIndex; -import com.azure.cosmos.models.SpatialIndex; +import com.azure.cosmos.implementation.RangeIndex; +import com.azure.cosmos.implementation.SpatialIndex; +import com.azure.cosmos.models.ModelBridgeInternal; /** * Code snippets for {@link IndexingPolicy} @@ -21,7 +22,7 @@ public void codeSnippetForIndexPolicyConstructor() { RangeIndex rangeIndexOverride = Index.range(DataType.NUMBER, 2); SpatialIndex spatialIndexOverride = Index.spatial(DataType.POINT); - IndexingPolicy indexingPolicy = new IndexingPolicy(new Index[]{hashIndexOverride, + IndexingPolicy indexingPolicy = ModelBridgeInternal.createIndexingPolicy(new Index[]{hashIndexOverride, rangeIndexOverride, spatialIndexOverride}); // END: com.azure.cosmos.indexingPolicy.defaultOverride } diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java index 06d9ea6096f0..ecf2c13461bf 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java @@ -8,12 +8,10 @@ import com.azure.cosmos.models.CompositePathSortOrder; import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.CosmosException; -import com.azure.cosmos.models.DataType; import com.azure.cosmos.DocumentClientTest; import com.azure.cosmos.models.QueryRequestOptions; import com.azure.cosmos.models.FeedResponse; import com.azure.cosmos.models.IncludedPath; -import com.azure.cosmos.models.Index; import com.azure.cosmos.models.IndexingPolicy; import com.azure.cosmos.models.ModelBridgeInternal; import com.azure.cosmos.models.PartitionKey; @@ -475,10 +473,6 @@ static protected DocumentCollection getCollectionDefinitionWithRangeRangeIndex() IndexingPolicy indexingPolicy = new IndexingPolicy(); List includedPaths = new ArrayList<>(); IncludedPath includedPath = new IncludedPath("/*"); - List indexes = new ArrayList<>(); - indexes.add(Index.range(DataType.STRING, -1)); - indexes.add(Index.range(DataType.NUMBER, -1)); - includedPath.setIndexes(indexes); includedPaths.add(includedPath); indexingPolicy.setIncludedPaths(includedPaths); diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/models/IncludedPathTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/models/IncludedPathTest.java index 181373448327..c93a027249ac 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/models/IncludedPathTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/models/IncludedPathTest.java @@ -2,6 +2,9 @@ // Licensed under the MIT License. package com.azure.cosmos.models; +import com.azure.cosmos.implementation.DataType; +import com.azure.cosmos.implementation.Index; +import com.azure.cosmos.implementation.RangeIndex; import org.testng.annotations.Test; import java.util.ArrayList; diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/BackPressureCrossPartitionTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/BackPressureCrossPartitionTest.java index 7a996e434e7d..913f26592d10 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/BackPressureCrossPartitionTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/BackPressureCrossPartitionTest.java @@ -8,19 +8,17 @@ import com.azure.cosmos.CosmosAsyncDatabase; import com.azure.cosmos.CosmosBridgeInternal; import com.azure.cosmos.CosmosClientBuilder; +import com.azure.cosmos.implementation.CosmosItemProperties; +import com.azure.cosmos.implementation.RxDocumentClientUnderTest; +import com.azure.cosmos.implementation.TestUtils; import com.azure.cosmos.models.CosmosContainerProperties; import com.azure.cosmos.models.CosmosContainerRequestOptions; -import com.azure.cosmos.util.CosmosPagedFlux; -import com.azure.cosmos.implementation.CosmosItemProperties; -import com.azure.cosmos.models.DataType; -import com.azure.cosmos.models.QueryRequestOptions; import com.azure.cosmos.models.FeedResponse; import com.azure.cosmos.models.IncludedPath; -import com.azure.cosmos.models.Index; import com.azure.cosmos.models.IndexingPolicy; import com.azure.cosmos.models.PartitionKeyDefinition; -import com.azure.cosmos.implementation.RxDocumentClientUnderTest; -import com.azure.cosmos.implementation.TestUtils; +import com.azure.cosmos.models.QueryRequestOptions; +import com.azure.cosmos.util.CosmosPagedFlux; import io.reactivex.subscribers.TestSubscriber; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,10 +65,6 @@ static protected CosmosContainerProperties getCollectionDefinition() { IndexingPolicy indexingPolicy = new IndexingPolicy(); List includedPaths = new ArrayList<>(); IncludedPath includedPath = new IncludedPath("/*"); - List indexes = new ArrayList<>(); - indexes.add(Index.range(DataType.STRING, -1)); - indexes.add(Index.range(DataType.NUMBER, -1)); - includedPath.setIndexes(indexes); includedPaths.add(includedPath); indexingPolicy.setIncludedPaths(includedPaths); diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/TestSuiteBase.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/TestSuiteBase.java index 7eb578847ada..3ac411a85c36 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/TestSuiteBase.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/TestSuiteBase.java @@ -13,9 +13,9 @@ import com.azure.cosmos.CosmosBridgeInternal; import com.azure.cosmos.CosmosClient; import com.azure.cosmos.CosmosClientBuilder; -import com.azure.cosmos.CosmosException; import com.azure.cosmos.CosmosDatabase; import com.azure.cosmos.CosmosDatabaseForTest; +import com.azure.cosmos.CosmosException; import com.azure.cosmos.CosmosResponseValidator; import com.azure.cosmos.DirectConnectionConfig; import com.azure.cosmos.GatewayConnectionConfig; @@ -35,24 +35,22 @@ import com.azure.cosmos.implementation.guava25.collect.ImmutableList; import com.azure.cosmos.models.CompositePath; import com.azure.cosmos.models.CompositePathSortOrder; -import com.azure.cosmos.models.CosmosDatabaseResponse; -import com.azure.cosmos.models.CosmosItemResponse; import com.azure.cosmos.models.CosmosContainerProperties; import com.azure.cosmos.models.CosmosContainerRequestOptions; import com.azure.cosmos.models.CosmosDatabaseProperties; +import com.azure.cosmos.models.CosmosDatabaseResponse; +import com.azure.cosmos.models.CosmosItemResponse; import com.azure.cosmos.models.CosmosResponse; import com.azure.cosmos.models.CosmosStoredProcedureRequestOptions; import com.azure.cosmos.models.CosmosUserProperties; import com.azure.cosmos.models.CosmosUserResponse; -import com.azure.cosmos.models.DataType; -import com.azure.cosmos.models.QueryRequestOptions; import com.azure.cosmos.models.FeedResponse; import com.azure.cosmos.models.IncludedPath; -import com.azure.cosmos.models.Index; import com.azure.cosmos.models.IndexingPolicy; import com.azure.cosmos.models.ModelBridgeInternal; import com.azure.cosmos.models.PartitionKey; import com.azure.cosmos.models.PartitionKeyDefinition; +import com.azure.cosmos.models.QueryRequestOptions; import com.azure.cosmos.models.SqlQuerySpec; import com.azure.cosmos.models.ThroughputProperties; import com.azure.cosmos.util.CosmosPagedFlux; @@ -545,10 +543,6 @@ static protected CosmosContainerProperties getCollectionDefinitionWithRangeRange IndexingPolicy indexingPolicy = new IndexingPolicy(); List includedPaths = new ArrayList<>(); IncludedPath includedPath = new IncludedPath("/*"); - List indexes = new ArrayList<>(); - indexes.add(Index.range(DataType.STRING, -1)); - indexes.add(Index.range(DataType.NUMBER, -1)); - includedPath.setIndexes(indexes); includedPaths.add(includedPath); indexingPolicy.setIncludedPaths(includedPaths); diff --git a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/UniqueIndexTest.java b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/UniqueIndexTest.java index 6c2cec868ebb..9212d67d1132 100644 --- a/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/UniqueIndexTest.java +++ b/sdk/cosmos/azure-cosmos/src/test/java/com/azure/cosmos/rx/UniqueIndexTest.java @@ -8,16 +8,19 @@ import com.azure.cosmos.CosmosAsyncContainer; import com.azure.cosmos.CosmosAsyncDatabase; import com.azure.cosmos.CosmosClientBuilder; +import com.azure.cosmos.CosmosDatabaseForTest; import com.azure.cosmos.CosmosException; import com.azure.cosmos.DirectConnectionConfig; -import com.azure.cosmos.models.CosmosContainerProperties; -import com.azure.cosmos.CosmosDatabaseForTest; import com.azure.cosmos.implementation.CosmosItemProperties; +import com.azure.cosmos.implementation.HttpConstants; +import com.azure.cosmos.implementation.TestConfigurations; +import com.azure.cosmos.implementation.Utils; +import com.azure.cosmos.implementation.guava25.collect.ImmutableList; +import com.azure.cosmos.implementation.guava25.collect.Lists; +import com.azure.cosmos.models.CosmosContainerProperties; import com.azure.cosmos.models.CosmosItemRequestOptions; -import com.azure.cosmos.models.DataType; import com.azure.cosmos.models.ExcludedPath; import com.azure.cosmos.models.IncludedPath; -import com.azure.cosmos.models.Index; import com.azure.cosmos.models.IndexingMode; import com.azure.cosmos.models.IndexingPolicy; import com.azure.cosmos.models.ModelBridgeInternal; @@ -25,14 +28,9 @@ import com.azure.cosmos.models.PartitionKeyDefinition; import com.azure.cosmos.models.UniqueKey; import com.azure.cosmos.models.UniqueKeyPolicy; -import com.azure.cosmos.implementation.HttpConstants; -import com.azure.cosmos.implementation.TestConfigurations; -import com.azure.cosmos.implementation.Utils; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.azure.cosmos.implementation.guava25.collect.ImmutableList; -import com.azure.cosmos.implementation.guava25.collect.Lists; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -75,11 +73,8 @@ public void insertWithUniqueIndex() throws Exception { indexingPolicy.setExcludedPaths(Collections.singletonList(excludedPath)); IncludedPath includedPath1 = new IncludedPath("/name/?"); - includedPath1.setIndexes(Collections.singletonList(Index.hash(DataType.STRING, 7))); - includedPath1.setIndexes(Collections.singletonList(Index.hash(DataType.STRING, 7))); IncludedPath includedPath2 = new IncludedPath("/description/?"); - includedPath2.setIndexes(Collections.singletonList(Index.hash(DataType.STRING, 7))); indexingPolicy.setIncludedPaths(ImmutableList.of(includedPath1, includedPath2)); collectionDefinition.setIndexingPolicy(indexingPolicy); @@ -181,10 +176,8 @@ public void uniqueKeySerializationDeserialization() { indexingPolicy.setExcludedPaths(Collections.singletonList(excludedPath)); IncludedPath includedPath1 = new IncludedPath("/name/?"); - includedPath1.setIndexes(Collections.singletonList(Index.hash(DataType.STRING, 7))); IncludedPath includedPath2 = new IncludedPath("/description/?"); - includedPath2.setIndexes(Collections.singletonList(Index.hash(DataType.STRING, 7))); indexingPolicy.setIncludedPaths(ImmutableList.of(includedPath1, includedPath2)); collectionDefinition.setIndexingPolicy(indexingPolicy);