use of com.azure.cosmos.examples.common.Family in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SamplePatchQuickstart method patchIncrement.
private void patchIncrement(String id, String partitionKey) {
logger.info("Executing Patch with 'increment' operations");
CosmosPatchOperations cosmosPatchOperations = CosmosPatchOperations.create();
cosmosPatchOperations.add("/int", 42).increment("/int", 1).increment("/int", -1).add("/float", 42).increment("/float", 4.2).increment("/float", -4.2);
CosmosPatchItemRequestOptions options = new CosmosPatchItemRequestOptions();
try {
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);
}
}
use of com.azure.cosmos.examples.common.Family in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class QueriesQuickstart method executeQueryWithQuerySpecPrintSingleResult.
private void executeQueryWithQuerySpecPrintSingleResult(SqlQuerySpec querySpec) {
logger.info("Execute query {}", querySpec.getQueryText());
CosmosPagedIterable<Family> filteredFamilies = container.queryItems(querySpec, new CosmosQueryRequestOptions(), Family.class);
// Print
if (filteredFamilies.iterator().hasNext()) {
Family family = filteredFamilies.iterator().next();
logger.info(String.format("First query result: Family with (/id, partition key) = (%s,%s)", family.getId(), family.getLastName()));
}
logger.info("Done.");
}
use of com.azure.cosmos.examples.common.Family in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class QueriesQuickstart method createDocument.
private void createDocument() throws Exception {
logger.info("Create document " + documentId);
// Define a document as a POJO (internally this
// is converted to JSON via custom serialization)
Family family = new Family();
family.setLastName(documentLastName);
family.setId(documentId);
// Insert this item as a document
// Explicitly specifying the /pk value improves performance.
container.createItem(family, new PartitionKey(family.getLastName()), new CosmosItemRequestOptions());
logger.info("Done.");
}
Aggregations