com.azure.cosmos.models.ComputedProperty Maven / Gradle / Ivy
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.cosmos.models;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Represents a computed property definition for a Cosmos DB container.
*
* Below is an example of how to use {@link ComputedProperty} in the context of creating a container.
*
*
* List<ComputedProperty> computedProperties = new ArrayList<>(
* Arrays.asList(
* new ComputedProperty("lowerName", "SELECT VALUE LOWER(c.name) FROM c")
* )
* );
* containerProperties.setComputedProperties(computedProperties);
* database.createContainer(containerProperties).subscribe();
*
*
*
* Below is an example of how to use {@link ComputedProperty} in the context of replacing a container.
*
*
* CosmosContainerProperties containerProperties = getCollectionDefinition(containerName);
* List<ComputedProperty> computedProperties = new ArrayList<>(
* Arrays.asList(
* new ComputedProperty("upperName", "SELECT VALUE UPPER(c.name) FROM c")
* )
* );
* containerProperties.setComputedProperties(computedProperties);
* container = database.getContainer(containerName);
* container.replace(containerProperties).subscribe();
*
*
*/
public final class ComputedProperty {
private final String name;
private final String query;
/**
* Instantiates a new Computed properties with name and query.
* @param name the name of the computed property.
* @param query the query used to evaluate the value for the computed property.
*/
@JsonCreator
public ComputedProperty(@JsonProperty("name") String name, @JsonProperty("query") String query) {
this.name = name;
this.query = query;
}
/**
* Gets the name of the computed property.
*
* @return the name of the computed property.
*/
public String getName() {
return name;
}
/**
* Gets the query used to evaluate the value for the computed property.
*
* @return the query for the computed property.
*/
public String getQuery() {
return query;
}
}