software.amazon.awssdk.services.dynamodb.model.KeySchemaElement Maven / Gradle / Ivy
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.dynamodb.model;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Function;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* Represents a single element of a key schema. A key schema specifies the attributes that make up the primary
* key of a table, or the key attributes of an index.
*
*
* A KeySchemaElement
represents exactly one attribute of the primary key. For example, a simple primary
* key would be represented by one KeySchemaElement
(for the partition key). A composite primary key would
* require one KeySchemaElement
for the partition key, and another KeySchemaElement
for the
* sort key.
*
*
* A KeySchemaElement
must be a scalar, top-level attribute (not a nested attribute). The data type must be
* one of String, Number, or Binary. The attribute cannot be nested within a List or a Map.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class KeySchemaElement implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField ATTRIBUTE_NAME_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("AttributeName").getter(getter(KeySchemaElement::attributeName)).setter(setter(Builder::attributeName))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("AttributeName").build()).build();
private static final SdkField KEY_TYPE_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("KeyType").getter(getter(KeySchemaElement::keyTypeAsString)).setter(setter(Builder::keyType))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("KeyType").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(ATTRIBUTE_NAME_FIELD,
KEY_TYPE_FIELD));
private static final long serialVersionUID = 1L;
private final String attributeName;
private final String keyType;
private KeySchemaElement(BuilderImpl builder) {
this.attributeName = builder.attributeName;
this.keyType = builder.keyType;
}
/**
*
* The name of a key attribute.
*
*
* @return The name of a key attribute.
*/
public final String attributeName() {
return attributeName;
}
/**
*
* The role that this key attribute will assume:
*
*
* -
*
* HASH
- partition key
*
*
* -
*
* RANGE
- sort key
*
*
*
*
*
* The partition key of an item is also known as its hash attribute. The term "hash attribute" derives from
* DynamoDB's usage of an internal hash function to evenly distribute data items across partitions, based on their
* partition key values.
*
*
* The sort key of an item is also known as its range attribute. The term "range attribute" derives from the
* way DynamoDB stores items with the same partition key physically close together, in sorted order by the sort key
* value.
*
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #keyType} will
* return {@link KeyType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #keyTypeAsString}.
*
*
* @return The role that this key attribute will assume:
*
* -
*
* HASH
- partition key
*
*
* -
*
* RANGE
- sort key
*
*
*
*
*
* The partition key of an item is also known as its hash attribute. The term "hash attribute"
* derives from DynamoDB's usage of an internal hash function to evenly distribute data items across
* partitions, based on their partition key values.
*
*
* The sort key of an item is also known as its range attribute. The term "range attribute" derives
* from the way DynamoDB stores items with the same partition key physically close together, in sorted order
* by the sort key value.
*
* @see KeyType
*/
public final KeyType keyType() {
return KeyType.fromValue(keyType);
}
/**
*
* The role that this key attribute will assume:
*
*
* -
*
* HASH
- partition key
*
*
* -
*
* RANGE
- sort key
*
*
*
*
*
* The partition key of an item is also known as its hash attribute. The term "hash attribute" derives from
* DynamoDB's usage of an internal hash function to evenly distribute data items across partitions, based on their
* partition key values.
*
*
* The sort key of an item is also known as its range attribute. The term "range attribute" derives from the
* way DynamoDB stores items with the same partition key physically close together, in sorted order by the sort key
* value.
*
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #keyType} will
* return {@link KeyType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #keyTypeAsString}.
*
*
* @return The role that this key attribute will assume:
*
* -
*
* HASH
- partition key
*
*
* -
*
* RANGE
- sort key
*
*
*
*
*
* The partition key of an item is also known as its hash attribute. The term "hash attribute"
* derives from DynamoDB's usage of an internal hash function to evenly distribute data items across
* partitions, based on their partition key values.
*
*
* The sort key of an item is also known as its range attribute. The term "range attribute" derives
* from the way DynamoDB stores items with the same partition key physically close together, in sorted order
* by the sort key value.
*
* @see KeyType
*/
public final String keyTypeAsString() {
return keyType;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(attributeName());
hashCode = 31 * hashCode + Objects.hashCode(keyTypeAsString());
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof KeySchemaElement)) {
return false;
}
KeySchemaElement other = (KeySchemaElement) obj;
return Objects.equals(attributeName(), other.attributeName())
&& Objects.equals(keyTypeAsString(), other.keyTypeAsString());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public final String toString() {
return ToString.builder("KeySchemaElement").add("AttributeName", attributeName()).add("KeyType", keyTypeAsString())
.build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "AttributeName":
return Optional.ofNullable(clazz.cast(attributeName()));
case "KeyType":
return Optional.ofNullable(clazz.cast(keyTypeAsString()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function