
com.azure.cosmos.implementation.routing.PartitionKeyInternal Maven / Gradle / Ivy
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.cosmos.implementation.routing;
import com.azure.cosmos.PartitionKeyDefinition;
import com.azure.cosmos.implementation.Undefined;
import com.azure.cosmos.implementation.RMResources;
import com.azure.cosmos.implementation.Strings;
import com.azure.cosmos.implementation.Utils;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.node.NullNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import static com.azure.cosmos.implementation.Utils.as;
/**
* Used internally to encapsulate internal information of a partition key in the Azure Cosmos DB database service.
*/
@JsonSerialize(using = PartitionKeyInternal.PartitionKeyInternalJsonSerializer.class)
@JsonDeserialize(using = PartitionKeyInternal.PartitionKeyInternalJsonDeserializer.class)
public class PartitionKeyInternal implements Comparable {
private static final String TYPE = "type";
private static final String MIN_NUMBER = "MinNumber";
private static final String MAX_NUMBER = "MaxNumber";
private static final String MIN_STRING = "MinString";
private static final String MAX_STRING = "MaxString";
private static final String INFINITY = "Infinity";
public static final PartitionKeyInternal NonePartitionKey =
new PartitionKeyInternal();
public static final PartitionKeyInternal EmptyPartitionKey =
new PartitionKeyInternal(new ArrayList<>());
@SuppressWarnings("serial")
public static final PartitionKeyInternal InfinityPartitionKey =
new PartitionKeyInternal(new ArrayList() {{
add(new InfinityPartitionKeyComponent());
}});
@SuppressWarnings("serial")
public static final PartitionKeyInternal UndefinedPartitionKey =
new PartitionKeyInternal(new ArrayList() {{
add(new UndefinedPartitionKeyComponent());
}});
public static final PartitionKeyInternal InclusiveMinimum = PartitionKeyInternal.EmptyPartitionKey;
public static final PartitionKeyInternal ExclusiveMaximum = PartitionKeyInternal.InfinityPartitionKey;
public static final PartitionKeyInternal Empty = PartitionKeyInternal.EmptyPartitionKey;
public static final PartitionKeyInternal None = PartitionKeyInternal.NonePartitionKey;
final List components;
public PartitionKeyInternal(List values) {
if (values == null) {
throw new IllegalArgumentException("values");
}
this.components = values;
}
public PartitionKeyInternal() {
this.components = null;
}
public static PartitionKeyInternal fromJsonString(String partitionKey) {
if (Strings.isNullOrEmpty(partitionKey)) {
throw new IllegalArgumentException(String.format(RMResources.UnableToDeserializePartitionKeyValue, partitionKey));
}
try {
return Utils.getSimpleObjectMapper().readValue(partitionKey, PartitionKeyInternal.class);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
public static PartitionKeyInternal fromObjectArray(Object[] values, boolean strict) {
if (values == null) {
throw new IllegalArgumentException("values");
}
return PartitionKeyInternal.fromObjectArray(Arrays.asList(values), strict);
}
public static PartitionKeyInternal fromObjectArray(List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy