classType) {
- this.itemClassType = classType;
- this.responseBodyAsByteArray = response.getBodyAsByteArray();
- this.resourceResponse = response;
- }
-
- /**
- * Gets the resource .
- *
- * @return the resource
- */
- @SuppressWarnings("unchecked") // Casting getProperties() to T is safe given T is of CosmosItemProperties.
- public T getItem() {
- if (item != null) {
- return item;
- }
-
- SerializationDiagnosticsContext serializationDiagnosticsContext = BridgeInternal.getSerializationDiagnosticsContext(this.getDiagnostics());
- if (item == null && this.itemClassType == CosmosItemProperties.class) {
- Instant serializationStartTime = Instant.now();
- item =(T) getProperties();
- Instant serializationEndTime = Instant.now();
- SerializationDiagnosticsContext.SerializationDiagnostics diagnostics = new SerializationDiagnosticsContext.SerializationDiagnostics(
- serializationStartTime,
- serializationEndTime,
- SerializationDiagnosticsContext.SerializationType.ITEM_DESERIALIZATION
- );
- serializationDiagnosticsContext.addSerializationDiagnostics(diagnostics);
- return item;
- }
-
- if (item == null) {
- synchronized (this) {
- if (item == null && !Utils.isEmpty(responseBodyAsByteArray)) {
- Instant serializationStartTime = Instant.now();
- item = Utils.parse(responseBodyAsByteArray, itemClassType);
- Instant serializationEndTime = Instant.now();
- SerializationDiagnosticsContext.SerializationDiagnostics diagnostics = new SerializationDiagnosticsContext.SerializationDiagnostics(
- serializationStartTime,
- serializationEndTime,
- SerializationDiagnosticsContext.SerializationType.ITEM_DESERIALIZATION
- );
- serializationDiagnosticsContext.addSerializationDiagnostics(diagnostics);
- }
- }
- }
-
- return item;
- }
-
- /**
- * Gets the itemProperties
- *
- * @return the itemProperties
- */
- CosmosItemProperties getProperties() {
- ensureCosmosItemPropertiesInitialized();
- return props;
- }
-
- private void ensureCosmosItemPropertiesInitialized() {
- synchronized (this) {
- if (Utils.isEmpty(responseBodyAsByteArray)) {
- props = null;
- } else {
- props = new CosmosItemProperties(responseBodyAsByteArray);
- }
-
- }
- }
-
- /**
- * Gets the maximum size limit for this entity (in megabytes (MB) for server resources and in count for master
- * resources).
- *
- * @return the max resource quota.
- */
- public String getMaxResourceQuota() {
- return resourceResponse.getMaxResourceQuota();
- }
-
- /**
- * Gets the current size of this entity (in megabytes (MB) for server resources and in count for master resources)
- *
- * @return the current resource quota usage.
- */
- public String getCurrentResourceQuotaUsage() {
- return resourceResponse.getCurrentResourceQuotaUsage();
- }
-
- /**
- * Gets the Activity ID for the request.
- *
- * @return the activity getId.
- */
- public String getActivityId() {
- return resourceResponse.getActivityId();
- }
-
- /**
- * Gets the request charge as request units (RU) consumed by the operation.
- *
- * For more information about the RU and factors that can impact the effective charges please visit
- * Request Units in Azure Cosmos DB
- *
- * @return the request charge.
- */
- public double getRequestCharge() {
- return resourceResponse.getRequestCharge();
- }
-
- /**
- * Gets the HTTP status code associated with the response.
- *
- * @return the status code.
- */
- public int getStatusCode() {
- return resourceResponse.getStatusCode();
- }
-
- /**
- * Gets the token used for managing client's consistency requirements.
- *
- * @return the session token.
- */
- public String getSessionToken() {
- return resourceResponse.getSessionToken();
- }
-
- /**
- * Gets the headers associated with the response.
- *
- * @return the response headers.
- */
- public Map getResponseHeaders() {
- return resourceResponse.getResponseHeaders();
- }
-
- /**
- * Gets the diagnostics information for the current request to Azure Cosmos DB service.
- *
- * @return diagnostics information for the current request to Azure Cosmos DB service.
- */
- public CosmosDiagnostics getDiagnostics() {
- return resourceResponse.getDiagnostics();
- }
-
- /**
- * Gets the end-to-end request latency for the current request to Azure Cosmos DB service.
- *
- * @return end-to-end request latency for the current request to Azure Cosmos DB service.
- */
- public Duration getDuration() {
- return resourceResponse.getDuration();
- }
-
- /**
- * Gets the ETag from the response headers.
- * This is only relevant when getting response from the server.
- *
- * Null in case of delete operation.
- *
- * @return ETag
- */
- public String getETag() {
- return resourceResponse.getETag();
- }
-}
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosItemResponse.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosItemResponse.java
index 23c742c6801f..9e50ccfa74fe 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosItemResponse.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosItemResponse.java
@@ -1,42 +1,102 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-
package com.azure.cosmos.models;
+import com.azure.cosmos.BridgeInternal;
import com.azure.cosmos.CosmosDiagnostics;
import com.azure.cosmos.implementation.CosmosItemProperties;
+import com.azure.cosmos.implementation.Document;
+import com.azure.cosmos.implementation.ResourceResponse;
+import com.azure.cosmos.implementation.SerializationDiagnosticsContext;
+import com.azure.cosmos.implementation.Utils;
import java.time.Duration;
+import java.time.Instant;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
import java.util.Map;
/**
- * The synchronous Cosmos item response. Contains methods to access the Item and other response methods
+ * The type Cosmos item response. This contains the item and response methods
*
* @param the type parameter
*/
public class CosmosItemResponse {
- private final CosmosAsyncItemResponse responseWrapper;
-
- CosmosItemResponse(CosmosAsyncItemResponse response) {
- this.responseWrapper = response;
+ private final Class itemClassType;
+ private final byte[] responseBodyAsByteArray;
+ private T item;
+ private final ResourceResponse resourceResponse;
+ private CosmosItemProperties props;
+
+ CosmosItemResponse(ResourceResponse response, Class classType) {
+ this.itemClassType = classType;
+ this.responseBodyAsByteArray = response.getBodyAsByteArray();
+ this.resourceResponse = response;
}
/**
- * Gets resource.
+ * Gets the resource.
*
* @return the resource
*/
+ @SuppressWarnings("unchecked") // Casting getProperties() to T is safe given T is of CosmosItemProperties.
public T getItem() {
- return responseWrapper.getItem();
+ if (item != null) {
+ return item;
+ }
+
+ SerializationDiagnosticsContext serializationDiagnosticsContext = BridgeInternal.getSerializationDiagnosticsContext(this.getDiagnostics());
+ if (item == null && this.itemClassType == CosmosItemProperties.class) {
+ Instant serializationStartTime = Instant.now();
+ item =(T) getProperties();
+ Instant serializationEndTime = Instant.now();
+ SerializationDiagnosticsContext.SerializationDiagnostics diagnostics = new SerializationDiagnosticsContext.SerializationDiagnostics(
+ serializationStartTime,
+ serializationEndTime,
+ SerializationDiagnosticsContext.SerializationType.ITEM_DESERIALIZATION
+ );
+ serializationDiagnosticsContext.addSerializationDiagnostics(diagnostics);
+ return item;
+ }
+
+ if (item == null) {
+ synchronized (this) {
+ if (item == null && !Utils.isEmpty(responseBodyAsByteArray)) {
+ Instant serializationStartTime = Instant.now();
+ item = Utils.parse(responseBodyAsByteArray, itemClassType);
+ Instant serializationEndTime = Instant.now();
+ SerializationDiagnosticsContext.SerializationDiagnostics diagnostics = new SerializationDiagnosticsContext.SerializationDiagnostics(
+ serializationStartTime,
+ serializationEndTime,
+ SerializationDiagnosticsContext.SerializationType.ITEM_DESERIALIZATION
+ );
+ serializationDiagnosticsContext.addSerializationDiagnostics(diagnostics);
+ }
+ }
+ }
+
+ return item;
}
/**
- * Gets the itemSettings
+ * Gets the itemProperties
*
- * @return the itemSettings
+ * @return the itemProperties
*/
CosmosItemProperties getProperties() {
- return responseWrapper.getProperties();
+ ensureCosmosItemPropertiesInitialized();
+ return props;
+ }
+
+ private void ensureCosmosItemPropertiesInitialized() {
+ synchronized (this) {
+ if (Utils.isEmpty(responseBodyAsByteArray)) {
+ props = null;
+ } else {
+ props = new CosmosItemProperties(responseBodyAsByteArray);
+ }
+
+ }
}
/**
@@ -46,7 +106,7 @@ CosmosItemProperties getProperties() {
* @return the max resource quota.
*/
public String getMaxResourceQuota() {
- return responseWrapper.getMaxResourceQuota();
+ return resourceResponse.getMaxResourceQuota();
}
/**
@@ -55,7 +115,7 @@ public String getMaxResourceQuota() {
* @return the current resource quota usage.
*/
public String getCurrentResourceQuotaUsage() {
- return responseWrapper.getCurrentResourceQuotaUsage();
+ return resourceResponse.getCurrentResourceQuotaUsage();
}
/**
@@ -64,7 +124,7 @@ public String getCurrentResourceQuotaUsage() {
* @return the activity getId.
*/
public String getActivityId() {
- return responseWrapper.getActivityId();
+ return resourceResponse.getActivityId();
}
/**
@@ -76,7 +136,7 @@ public String getActivityId() {
* @return the request charge.
*/
public double getRequestCharge() {
- return responseWrapper.getRequestCharge();
+ return resourceResponse.getRequestCharge();
}
/**
@@ -85,7 +145,7 @@ public double getRequestCharge() {
* @return the status code.
*/
public int getStatusCode() {
- return responseWrapper.getStatusCode();
+ return resourceResponse.getStatusCode();
}
/**
@@ -94,7 +154,7 @@ public int getStatusCode() {
* @return the session token.
*/
public String getSessionToken() {
- return responseWrapper.getSessionToken();
+ return resourceResponse.getSessionToken();
}
/**
@@ -103,7 +163,7 @@ public String getSessionToken() {
* @return the response headers.
*/
public Map getResponseHeaders() {
- return responseWrapper.getResponseHeaders();
+ return resourceResponse.getResponseHeaders();
}
/**
@@ -112,7 +172,7 @@ public Map getResponseHeaders() {
* @return diagnostics information for the current request to Azure Cosmos DB service.
*/
public CosmosDiagnostics getDiagnostics() {
- return responseWrapper.getDiagnostics();
+ return resourceResponse.getDiagnostics();
}
/**
@@ -121,7 +181,7 @@ public CosmosDiagnostics getDiagnostics() {
* @return end-to-end request latency for the current request to Azure Cosmos DB service.
*/
public Duration getDuration() {
- return responseWrapper.getDuration();
+ return resourceResponse.getDuration();
}
/**
@@ -133,6 +193,6 @@ public Duration getDuration() {
* @return ETag
*/
public String getETag() {
- return responseWrapper.getETag();
+ return resourceResponse.getETag();
}
}
diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosTriggerResponse.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosTriggerResponse.java
index 5d02c5524315..661083242451 100644
--- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosTriggerResponse.java
+++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/models/CosmosTriggerResponse.java
@@ -7,7 +7,7 @@
import com.azure.cosmos.implementation.apachecommons.lang.StringUtils;
/**
- * The type Cosmos async trigger response.
+ * The type Cosmos trigger response.
*/
public class CosmosTriggerResponse extends CosmosResponse {
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 a9697822cd24..c72caf51a219 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
@@ -77,13 +77,13 @@ public static CosmosDatabaseResponse createCosmosDatabaseResponse(ResourceRespon
}
@Warning(value = INTERNAL_USE_ONLY_WARNING)
- public static CosmosAsyncItemResponse createCosmosAsyncItemResponse(ResourceResponse response, Class classType) {
- return new CosmosAsyncItemResponse<>(response, classType);
+ public static CosmosItemResponse createCosmosAsyncItemResponse(ResourceResponse response, Class classType) {
+ return new CosmosItemResponse<>(response, classType);
}
@Warning(value = INTERNAL_USE_ONLY_WARNING)
- public static CosmosAsyncItemResponse