Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,10 +3,9 @@

package com.azure.cosmos.benchmark;

import com.azure.cosmos.BridgeInternal;
import com.azure.cosmos.models.DataType;
import com.azure.cosmos.implementation.DataType;
import com.azure.cosmos.models.IncludedPath;
import com.azure.cosmos.models.Index;
import com.azure.cosmos.implementation.Index;
import com.azure.cosmos.models.IndexingPolicy;
import com.azure.cosmos.models.ModelBridgeInternal;
import com.azure.cosmos.models.PartitionKeyDefinition;
Expand All @@ -29,7 +28,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;
Expand Down Expand Up @@ -170,7 +168,7 @@ DocumentCollection getCollectionDefinitionWithRangeRangeIndex() {
List<Index> indexes = new ArrayList<>();
indexes.add(Index.range(DataType.STRING, -1));
indexes.add(Index.range(DataType.NUMBER, -1));
includedPath.setIndexes(indexes);
ModelBridgeInternal.setIncludedPathIndexes(includedPath, indexes);
includedPaths.add(includedPath);
indexingPolicy.setIncludedPaths(includedPaths);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

package com.azure.cosmos.benchmark;

import com.azure.cosmos.BridgeInternal;
import com.azure.cosmos.models.DataType;
import com.azure.cosmos.implementation.DataType;
import com.azure.cosmos.models.IncludedPath;
import com.azure.cosmos.models.Index;
import com.azure.cosmos.implementation.Index;
import com.azure.cosmos.models.IndexingPolicy;
import com.azure.cosmos.models.ModelBridgeInternal;
import com.azure.cosmos.models.PartitionKeyDefinition;
Expand All @@ -23,7 +22,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;
Expand Down Expand Up @@ -310,7 +308,7 @@ DocumentCollection getCollectionDefinitionWithRangeRangeIndex() {
List<Index> indexes = new ArrayList<>();
indexes.add(Index.range(DataType.STRING, -1));
indexes.add(Index.range(DataType.NUMBER, -1));
includedPath.setIndexes(indexes);
ModelBridgeInternal.setIncludedPathIndexes(includedPath, indexes);
includedPaths.add(includedPath);
indexingPolicy.setIncludedPaths(includedPaths);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
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.implementation.DataType;
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.implementation.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;
Expand Down Expand Up @@ -380,7 +381,7 @@ private DocumentCollection getMultiPartitionCollectionDefinition() {
List<Index> indexes = new ArrayList<>();
indexes.add(Index.range(DataType.STRING, -1));
indexes.add(Index.range(DataType.NUMBER, -1));
includedPath.setIndexes(indexes);
ModelBridgeInternal.setIncludedPathIndexes(includedPath, indexes);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should change this. Since this is in examples module, we should not use *BridgeInternal classes here.

Also please check if you have not un-intentionally made this change in other public surface area (examples sub-module)

@xinlian12 xinlian12 Jun 2, 2020

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I need to change it because I hide the setIndexes method of IncludedPath, should I keep it public? Checked the .net SDK, the setter and getter are both internal. So I changed the setIndexes method to package private

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chatted offline, make sense that do not call this new method here, since it is not accessible publicly. Will remove.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed from all tests.

includedPaths.add(includedPath);
indexingPolicy.setIncludedPaths(includedPaths);
collectionDefinition.setIndexingPolicy(indexingPolicy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@

import com.azure.cosmos.DirectConnectionConfig;
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.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.implementation.Index;
import com.azure.cosmos.models.IndexingPolicy;
import com.azure.cosmos.implementation.Offer;
import com.azure.cosmos.models.ModelBridgeInternal;
Expand All @@ -26,7 +24,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.CountDownLatch;
Expand Down Expand Up @@ -145,7 +142,7 @@ private DocumentCollection getMultiPartitionCollectionDefinition() {
List<Index> indexes = new ArrayList<>();
indexes.add(Index.range(DataType.STRING, -1));
indexes.add(Index.range(DataType.NUMBER, -1));
includedPath.setIndexes(indexes);
ModelBridgeInternal.setIncludedPathIndexes(includedPath, indexes);
includedPaths.add(includedPath);
indexingPolicy.setIncludedPaths(includedPaths);
collectionDefinition.setIndexingPolicy(indexingPolicy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@

import com.azure.cosmos.DirectConnectionConfig;
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.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.implementation.Index;
import com.azure.cosmos.models.IndexingPolicy;
import com.azure.cosmos.models.ModelBridgeInternal;
import com.azure.cosmos.models.PartitionKey;
Expand Down Expand Up @@ -237,7 +235,7 @@ private static DocumentCollection getMultiPartitionCollectionDefinition() {
List<Index> indexes = new ArrayList<Index>();
indexes.add(Index.range(DataType.STRING, -1));
indexes.add(Index.range(DataType.NUMBER, -1));
includedPath.setIndexes(indexes);
ModelBridgeInternal.setIncludedPathIndexes(includedPath, indexes);
includedPaths.add(includedPath);
indexingPolicy.setIncludedPaths(includedPaths);
collectionDefinition.setIndexingPolicy(indexingPolicy);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down Expand Up @@ -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'.");
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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);
}

/**
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
// 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.
*
* @param indexKind the kind of the index
*/
Index(IndexKind indexKind) {
this.jsonSerializable = new JsonSerializable();
super();
this.setKind(indexKind);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand All @@ -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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -692,7 +691,6 @@ <T> boolean containsJsonSerializable(Class<T> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down Expand Up @@ -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'.");
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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);
}

/**
Expand All @@ -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);
}
}
Loading