use of com.azure.cosmos.examples.common.Family in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class CosmosDiagnosticsQuickStart method replaceDocument.
private void replaceDocument() throws Exception {
logger.info("Replace document : {}", documentId);
// Replace existing document with new modified document
Family family = new Family();
family.setLastName(documentLastName);
family.setId(documentId);
// Document modification
family.setDistrict("Columbia");
CosmosItemResponse<Family> itemResponse = container.replaceItem(family, family.getId(), new PartitionKey(family.getLastName()), new CosmosItemRequestOptions());
CosmosDiagnostics diagnostics = itemResponse.getDiagnostics();
logger.info("Replace item diagnostics : {}", diagnostics);
logger.info("Request charge of replace operation: {} RU", itemResponse.getRequestCharge());
logger.info("Done.");
}
use of com.azure.cosmos.examples.common.Family in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class CosmosDiagnosticsQuickStart method upsertDocument.
private void upsertDocument() throws Exception {
logger.info("Replace document : {}", documentId);
// Replace existing document with new modified document (contingent on modification).
Family family = new Family();
family.setLastName(documentLastName);
family.setId(documentId);
// Document modification
family.setDistrict("Columbia");
CosmosItemResponse<Family> itemResponse = container.upsertItem(family, new CosmosItemRequestOptions());
CosmosDiagnostics diagnostics = itemResponse.getDiagnostics();
logger.info("Upsert item diagnostics : {}", diagnostics);
logger.info("Done.");
}
use of com.azure.cosmos.examples.common.Family in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SalesOrder method TroubleshootingGuideJavaSDKv4PublishOnSchedulerAsync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/troubleshoot-java-sdk-v4-sql
* Troubleshooting guide - publish on scheduler
* Async only
*/
/**
* Troubleshooting guide - publish on scheduler
*/
public static void TroubleshootingGuideJavaSDKv4PublishOnSchedulerAsync() {
CosmosAsyncContainer container = null;
Scheduler customScheduler = null;
Family family = null;
// <TroubleshootPublishOnSchedulerAsync>
container.createItem(family).publishOn(// Switches the thread.
customScheduler).subscribe();
// </TroubleshootPublishOnSchedulerAsync>
}
use of com.azure.cosmos.examples.common.Family in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleIndexManagement method readItems.
private void readItems(ArrayList<Family> familiesToCreate) {
// Using partition key for point read scenarios.
// This will help fast look up of items because of partition key
familiesToCreate.forEach(family -> {
// <ReadItem>
try {
CosmosItemResponse<Family> item = container.readItem(family.getId(), new PartitionKey(family.getLastName()), Family.class);
double requestCharge = item.getRequestCharge();
Duration requestLatency = item.getDuration();
logger.info(String.format("Item successfully read with id %s with a charge of %.2f and within duration %s", item.getItem().getId(), requestCharge, requestLatency));
} catch (CosmosException e) {
e.printStackTrace();
logger.error(String.format("Read Item failed with %s", e));
}
// </ReadItem>
});
}
use of com.azure.cosmos.examples.common.Family in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SamplePatchQuickstart method patchAddSingleJsonString.
// demonstrates a single patch (add) operation using json String
private void patchAddSingleJsonString(String id, String partitionKey) {
logger.info("Executing Patch with single 'add' operation to add json from String");
String json = "[{\"givenName\": \"Goofy\"},{\"givenName\": \"Shadow\"}]";
ObjectMapper objectMapper = new ObjectMapper();
try {
// Converting json String to JsonNode using Jackson
JsonNode jsonNode = objectMapper.readTree(json);
CosmosPatchOperations cosmosPatchOperations = CosmosPatchOperations.create();
// attribute does not exist, will be added
cosmosPatchOperations.add("/pets", jsonNode);
CosmosPatchItemRequestOptions options = new CosmosPatchItemRequestOptions();
CosmosItemResponse<Family> response = this.container.patchItem(id, new PartitionKey(partitionKey), cosmosPatchOperations, options, Family.class);
logger.info("Item with ID {} has been patched", response.getItem().getId());
} catch (Exception e) {
logger.error("failed", e);
}
}
Aggregations