Skip to content

Commit

Permalink
Hiding Json Serializable set and remove methods and object mapper and…
Browse files Browse the repository at this point in the history
… object node return types (Azure#204)
  • Loading branch information
kushagraThapar authored and Christopher Anderson committed Jun 25, 2019
1 parent 7b0dc3c commit 87aafe7
Show file tree
Hide file tree
Showing 37 changed files with 168 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package com.azure.data.cosmos.benchmark;

import com.azure.data.cosmos.AsyncDocumentClient;
import com.azure.data.cosmos.BridgeInternal;
import com.azure.data.cosmos.Database;
import com.azure.data.cosmos.Document;
import com.azure.data.cosmos.DocumentCollection;
Expand Down Expand Up @@ -100,12 +101,12 @@ abstract class AsyncBenchmark<T> {
String uuid = UUID.randomUUID().toString();
Document newDoc = new Document();
newDoc.id(uuid);
newDoc.set(partitionKey, uuid);
newDoc.set("dataField1", dataFieldValue);
newDoc.set("dataField2", dataFieldValue);
newDoc.set("dataField3", dataFieldValue);
newDoc.set("dataField4", dataFieldValue);
newDoc.set("dataField5", dataFieldValue);
BridgeInternal.setProperty(newDoc, partitionKey, uuid);
BridgeInternal.setProperty(newDoc, "dataField1", dataFieldValue);
BridgeInternal.setProperty(newDoc, "dataField2", dataFieldValue);
BridgeInternal.setProperty(newDoc, "dataField3", dataFieldValue);
BridgeInternal.setProperty(newDoc, "dataField4", dataFieldValue);
BridgeInternal.setProperty(newDoc, "dataField5", dataFieldValue);
Flux<Document> obs = client.createDocument(collection.selfLink(), newDoc, null, false)
.map(ResourceResponse::getResource);
createDocumentObservables.add(obs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package com.azure.data.cosmos.benchmark;

import com.azure.data.cosmos.BridgeInternal;
import com.azure.data.cosmos.Document;
import com.azure.data.cosmos.FeedOptions;
import com.azure.data.cosmos.PartitionKey;
Expand Down Expand Up @@ -57,12 +58,12 @@ protected void performWorkload(BaseSubscriber<Document> documentBaseSubscriber,
String idString = uuid + i;
Document newDoc = new Document();
newDoc.id(idString);
newDoc.set(partitionKey, idString);
newDoc.set("dataField1", dataFieldValue);
newDoc.set("dataField2", dataFieldValue);
newDoc.set("dataField3", dataFieldValue);
newDoc.set("dataField4", dataFieldValue);
newDoc.set("dataField5", dataFieldValue);
BridgeInternal.setProperty(newDoc, partitionKey, idString);
BridgeInternal.setProperty(newDoc, "dataField1", dataFieldValue);
BridgeInternal.setProperty(newDoc, "dataField2", dataFieldValue);
BridgeInternal.setProperty(newDoc, "dataField3", dataFieldValue);
BridgeInternal.setProperty(newDoc, "dataField4", dataFieldValue);
BridgeInternal.setProperty(newDoc, "dataField5", dataFieldValue);
obs = client.createDocument(getCollectionLink(), newDoc, null, false).map(ResourceResponse::getResource);

} else if (i % 100 == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package com.azure.data.cosmos.benchmark;

import com.azure.data.cosmos.BridgeInternal;
import com.azure.data.cosmos.Document;
import com.azure.data.cosmos.ResourceResponse;
import com.codahale.metrics.Timer;
Expand Down Expand Up @@ -82,12 +83,12 @@ protected void performWorkload(BaseSubscriber<ResourceResponse<Document>> baseSu
String idString = uuid + i;
Document newDoc = new Document();
newDoc.id(idString);
newDoc.set(partitionKey, idString);
newDoc.set("dataField1", dataFieldValue);
newDoc.set("dataField2", dataFieldValue);
newDoc.set("dataField3", dataFieldValue);
newDoc.set("dataField4", dataFieldValue);
newDoc.set("dataField5", dataFieldValue);
BridgeInternal.setProperty(newDoc, partitionKey, idString);
BridgeInternal.setProperty(newDoc, "dataField1", dataFieldValue);
BridgeInternal.setProperty(newDoc, "dataField2", dataFieldValue);
BridgeInternal.setProperty(newDoc, "dataField3", dataFieldValue);
BridgeInternal.setProperty(newDoc, "dataField4", dataFieldValue);
BridgeInternal.setProperty(newDoc, "dataField5", dataFieldValue);
Flux<ResourceResponse<Document>> obs = client.createDocument(getCollectionLink(), newDoc, null,
false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package com.azure.data.cosmos.benchmark;

import com.azure.data.cosmos.BridgeInternal;
import com.azure.data.cosmos.Document;
import com.azure.data.cosmos.FeedOptions;
import com.azure.data.cosmos.PartitionKey;
Expand Down Expand Up @@ -178,12 +179,12 @@ private Flux<Document> writeDocument(Integer i) {
String randomVal = Utils.randomUUID().toString();
Document document = new Document();
document.id(idString);
document.set(partitionKey, idString);
document.set(QUERY_FIELD_NAME, randomVal);
document.set("dataField1", randomVal);
document.set("dataField2", randomVal);
document.set("dataField3", randomVal);
document.set("dataField4", randomVal);
BridgeInternal.setProperty(document, partitionKey, idString);
BridgeInternal.setProperty(document, QUERY_FIELD_NAME, randomVal);
BridgeInternal.setProperty(document, "dataField1", randomVal);
BridgeInternal.setProperty(document, "dataField2", randomVal);
BridgeInternal.setProperty(document, "dataField3", randomVal);
BridgeInternal.setProperty(document, "dataField4", randomVal);

Integer key = i == null ? cacheKey() : i;
return client.createDocument(getCollectionLink(), document, null, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package com.azure.data.cosmos.benchmark;

import com.azure.data.cosmos.AsyncDocumentClient;
import com.azure.data.cosmos.BridgeInternal;
import com.azure.data.cosmos.DataType;
import com.azure.data.cosmos.Database;
import com.azure.data.cosmos.DocumentCollection;
Expand Down Expand Up @@ -176,11 +177,11 @@ DocumentCollection getCollectionDefinitionWithRangeRangeIndex() {
includedPath.path("/*");
Collection<Index> indexes = new ArrayList<>();
Index stringIndex = Index.Range(DataType.STRING);
stringIndex.set("precision", -1);
BridgeInternal.setProperty(stringIndex, "precision", -1);
indexes.add(stringIndex);

Index numberIndex = Index.Range(DataType.NUMBER);
numberIndex.set("precision", -1);
BridgeInternal.setProperty(numberIndex, "precision", -1);
indexes.add(numberIndex);
includedPath.indexes(indexes);
includedPaths.add(includedPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package com.azure.data.cosmos.benchmark;

import com.azure.data.cosmos.AsyncDocumentClient;
import com.azure.data.cosmos.BridgeInternal;
import com.azure.data.cosmos.DataType;
import com.azure.data.cosmos.Database;
import com.azure.data.cosmos.DocumentCollection;
Expand Down Expand Up @@ -328,11 +329,11 @@ DocumentCollection getCollectionDefinitionWithRangeRangeIndex() {
includedPath.path("/*");
Collection<Index> indexes = new ArrayList<>();
Index stringIndex = Index.Range(DataType.STRING);
stringIndex.set("precision", -1);
BridgeInternal.setProperty(stringIndex, "precision", -1);
indexes.add(stringIndex);

Index numberIndex = Index.Range(DataType.NUMBER);
numberIndex.set("precision", -1);
BridgeInternal.setProperty(numberIndex, "precision", -1);
indexes.add(numberIndex);
includedPath.indexes(indexes);
includedPaths.add(includedPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,12 @@ public static PartitionKeyInternal getNonePartitionKey(PartitionKeyDefinition pa
public static PartitionKey getPartitionKey(PartitionKeyInternal partitionKeyInternal) {
return new PartitionKey(partitionKeyInternal);
}

public static <T> void setProperty(JsonSerializable jsonSerializable, String propertyName, T value) {
jsonSerializable.set(propertyName, value);
}

public static void remove(JsonSerializable jsonSerializable, String propertyName) {
jsonSerializable.remove(propertyName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected JsonSerializable(String jsonString) {
this.propertyBag = objectNode;
}

ObjectMapper getMapper() {
private ObjectMapper getMapper() {
// TODO: Made package private due to #153. #171 adding custom serialization options back.
if (this.om != null) { return this.om; }
return OBJECT_MAPPER;
Expand All @@ -103,7 +103,7 @@ private static void checkForValidPOJO(Class<?> c) {
}
}

protected Logger getLogger() {
Logger getLogger() {
return logger;
}

Expand Down Expand Up @@ -134,7 +134,7 @@ public boolean has(String propertyName) {
*
* @param propertyName the property to remove.
*/
public void remove(String propertyName) {
void remove(String propertyName) {
this.propertyBag.remove(propertyName);
}

Expand All @@ -146,7 +146,7 @@ public void remove(String propertyName) {
* @param value the value of the property.
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public <T> void set(String propertyName, T value) {
<T> void set(String propertyName, T value) {
if (value == null) {
// Sets null.
this.propertyBag.putNull(propertyName);
Expand Down Expand Up @@ -416,7 +416,7 @@ public <T> Collection<T> getCollection(String propertyName, Class<T> c, boolean
* @param propertyName the property to get.
* @return the JSONObject.
*/
public ObjectNode getObject(String propertyName) {
ObjectNode getObject(String propertyName) {
if (this.propertyBag.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) {
ObjectNode jsonObj = (ObjectNode) this.propertyBag.get(propertyName);
return jsonObj;
Expand All @@ -430,7 +430,7 @@ public ObjectNode getObject(String propertyName) {
* @param propertyName the property to get.
* @return the JSONObject collection.
*/
public Collection<ObjectNode> getCollection(String propertyName) {
Collection<ObjectNode> getCollection(String propertyName) {
Collection<ObjectNode> result = null;
if (this.propertyBag.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) {
result = new ArrayList<ObjectNode>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package com.azure.data.cosmos.directconnectivity;

import com.azure.data.cosmos.BridgeInternal;
import com.azure.data.cosmos.Resource;
import com.azure.data.cosmos.internal.Constants;

Expand Down Expand Up @@ -51,46 +52,46 @@ public boolean IsPrimary() {
}

void setIsPrimary(boolean isPrimary) {
super.set(Constants.Properties.IS_PRIMARY, isPrimary);
BridgeInternal.setProperty(this, Constants.Properties.IS_PRIMARY, isPrimary);
}

public String getProtocolScheme() {
return super.getString(Constants.Properties.PROTOCOL);
}

void setProtocol(String protocol) {
super.set(Constants.Properties.PROTOCOL, protocol);
BridgeInternal.setProperty(this, Constants.Properties.PROTOCOL, protocol);
}

public String getLogicalUri() {
return super.getString(Constants.Properties.LOGICAL_URI);
}

void setLogicalUri(String logicalUri) {
super.set(Constants.Properties.LOGICAL_URI, logicalUri);
BridgeInternal.setProperty(this, Constants.Properties.LOGICAL_URI, logicalUri);
}

public String getPhyicalUri() {
return super.getString(Constants.Properties.PHYISCAL_URI);
}

void setPhysicalUri(String phyicalUri) {
super.set(Constants.Properties.PHYISCAL_URI, phyicalUri);
BridgeInternal.setProperty(this, Constants.Properties.PHYISCAL_URI, phyicalUri);
}

public String getPartitionIndex() {
return super.getString(Constants.Properties.PARTITION_INDEX);
}

void setPartitionIndex(String partitionIndex) {
super.set(Constants.Properties.PARTITION_INDEX, partitionIndex);
BridgeInternal.setProperty(this, Constants.Properties.PARTITION_INDEX, partitionIndex);
}

public String getParitionKeyRangeId() {
return super.getString(Constants.Properties.PARTITION_KEY_RANGE_ID);
}

public void setPartitionKeyRangeId(String partitionKeyRangeId) {
super.set(Constants.Properties.PARTITION_KEY_RANGE_ID, partitionKeyRangeId);
BridgeInternal.setProperty(this, Constants.Properties.PARTITION_KEY_RANGE_ID, partitionKeyRangeId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package com.azure.data.cosmos.internal.routing;

import com.azure.data.cosmos.BridgeInternal;
import com.azure.data.cosmos.JsonSerializable;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -89,7 +90,7 @@ public T getMin() {

public void setMin(T min) {
this.minValue = min;
super.set(Range.MIN_PROPERTY, min);
BridgeInternal.setProperty(this, Range.MIN_PROPERTY, min);
}

@SuppressWarnings("unchecked")
Expand All @@ -103,7 +104,7 @@ public T getMax() {

public void setMax(T max) {
this.maxValue = max;
super.set(Range.MAX_PROPERTY, max);
BridgeInternal.setProperty(this, Range.MAX_PROPERTY, max);
}

@JsonProperty("isMinInclusive")
Expand All @@ -112,7 +113,7 @@ public boolean isMinInclusive() {
}

public void setMinInclusive(boolean isMinInclusive) {
super.set(Range.IS_MIN_INCLUSIVE_PROPERTY, isMinInclusive);
BridgeInternal.setProperty(this, Range.IS_MIN_INCLUSIVE_PROPERTY, isMinInclusive);
}

@JsonProperty("isMaxInclusive")
Expand All @@ -121,7 +122,7 @@ public boolean isMaxInclusive() {
}

public void setMaxInclusive(boolean isMaxInclusive) {
super.set(Range.IS_MAX_INCLUSIVE_PROPERTY, isMaxInclusive);
BridgeInternal.setProperty(this, Range.IS_MAX_INCLUSIVE_PROPERTY, isMaxInclusive);
}

public boolean isSingleValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.azure.data.cosmos.AccessCondition;
import com.azure.data.cosmos.AccessConditionType;
import com.azure.data.cosmos.AsyncDocumentClient;
import com.azure.data.cosmos.BridgeInternal;
import com.azure.data.cosmos.Conflict;
import com.azure.data.cosmos.ConflictResolutionPolicy;
import com.azure.data.cosmos.CosmosClientException;
Expand Down Expand Up @@ -498,8 +499,8 @@ public void runDeleteConflictOnUdp() throws Exception {
private Flux<Document> tryInsertDocument(AsyncDocumentClient client, String collectionUri, Document document, int index) {

logger.debug("region: {}", client.getWriteEndpoint());
document.set("regionId", index);
document.set("regionEndpoint", client.getReadEndpoint());
BridgeInternal.setProperty(document, "regionId", index);
BridgeInternal.setProperty(document, "regionEndpoint", client.getReadEndpoint());
return client.createDocument(collectionUri, document, null, false)
.onErrorResume(e -> {
if (hasDocumentClientException(e, 409)) {
Expand Down Expand Up @@ -544,8 +545,8 @@ private boolean hasDocumentClientExceptionCause(Throwable e, int statusCode) {
}

private Flux<Document> tryUpdateDocument(AsyncDocumentClient client, String collectionUri, Document document, int index) {
document.set("regionId", index);
document.set("regionEndpoint", client.getReadEndpoint());
BridgeInternal.setProperty(document, "regionId", index);
BridgeInternal.setProperty(document, "regionEndpoint", client.getReadEndpoint());

RequestOptions options = new RequestOptions();
options.setAccessCondition(new AccessCondition());
Expand All @@ -566,8 +567,8 @@ private Flux<Document> tryUpdateDocument(AsyncDocumentClient client, String coll
}

private Flux<Document> tryDeleteDocument(AsyncDocumentClient client, String collectionUri, Document document, int index) {
document.set("regionId", index);
document.set("regionEndpoint", client.getReadEndpoint());
BridgeInternal.setProperty(document, "regionId", index);
BridgeInternal.setProperty(document, "regionEndpoint", client.getReadEndpoint());

RequestOptions options = new RequestOptions();
options.setAccessCondition(new AccessCondition());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package com.azure.data.cosmos.rx.examples;

import com.azure.data.cosmos.AsyncDocumentClient;
import com.azure.data.cosmos.BridgeInternal;
import com.azure.data.cosmos.ConnectionMode;
import com.azure.data.cosmos.ConnectionPolicy;
import com.azure.data.cosmos.ConsistencyLevel;
Expand Down Expand Up @@ -398,11 +399,11 @@ private DocumentCollection getMultiPartitionCollectionDefinition() {
includedPath.path("/*");
Collection<Index> indexes = new ArrayList<>();
Index stringIndex = Index.Range(DataType.STRING);
stringIndex.set("precision", -1);
BridgeInternal.setProperty(stringIndex, "precision", -1);
indexes.add(stringIndex);

Index numberIndex = Index.Range(DataType.NUMBER);
numberIndex.set("precision", -1);
BridgeInternal.setProperty(numberIndex, "precision", -1);
indexes.add(numberIndex);
includedPath.indexes(indexes);
includedPaths.add(includedPath);
Expand Down
Loading

0 comments on commit 87aafe7

Please sign in to comment.