software.amazon.awssdk.services.dynamodb.model.Projection Maven / Gradle / Ivy
Show all versions of bundle Show documentation
/*
* Copyright 2013-2018 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.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.core.protocol.ProtocolMarshaller;
import software.amazon.awssdk.core.protocol.StructuredPojo;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.services.dynamodb.transform.ProjectionMarshaller;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* Represents attributes that are copied (projected) from the table into an index. These are in addition to the primary
* key attributes and index key attributes, which are automatically projected.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class Projection implements StructuredPojo, ToCopyableBuilder {
private final String projectionType;
private final List nonKeyAttributes;
private Projection(BuilderImpl builder) {
this.projectionType = builder.projectionType;
this.nonKeyAttributes = builder.nonKeyAttributes;
}
/**
*
* The set of attributes that are projected into the index:
*
*
* -
*
* KEYS_ONLY
- Only the index and primary keys are projected into the index.
*
*
* -
*
* INCLUDE
- Only the specified table attributes are projected into the index. The list of projected
* attributes are in NonKeyAttributes
.
*
*
* -
*
* ALL
- All of the table attributes are projected into the index.
*
*
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #projectionType}
* will return {@link ProjectionType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available
* from {@link #projectionTypeAsString}.
*
*
* @return The set of attributes that are projected into the index:
*
* -
*
* KEYS_ONLY
- Only the index and primary keys are projected into the index.
*
*
* -
*
* INCLUDE
- Only the specified table attributes are projected into the index. The list of
* projected attributes are in NonKeyAttributes
.
*
*
* -
*
* ALL
- All of the table attributes are projected into the index.
*
*
* @see ProjectionType
*/
public ProjectionType projectionType() {
return ProjectionType.fromValue(projectionType);
}
/**
*
* The set of attributes that are projected into the index:
*
*
* -
*
* KEYS_ONLY
- Only the index and primary keys are projected into the index.
*
*
* -
*
* INCLUDE
- Only the specified table attributes are projected into the index. The list of projected
* attributes are in NonKeyAttributes
.
*
*
* -
*
* ALL
- All of the table attributes are projected into the index.
*
*
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #projectionType}
* will return {@link ProjectionType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available
* from {@link #projectionTypeAsString}.
*
*
* @return The set of attributes that are projected into the index:
*
* -
*
* KEYS_ONLY
- Only the index and primary keys are projected into the index.
*
*
* -
*
* INCLUDE
- Only the specified table attributes are projected into the index. The list of
* projected attributes are in NonKeyAttributes
.
*
*
* -
*
* ALL
- All of the table attributes are projected into the index.
*
*
* @see ProjectionType
*/
public String projectionTypeAsString() {
return projectionType;
}
/**
*
* Represents the non-key attribute names which will be projected into the index.
*
*
* For local secondary indexes, the total count of NonKeyAttributes
summed across all of the local
* secondary indexes, must not exceed 20. If you project the same attribute into two different indexes, this counts
* as two distinct attributes when determining the total.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* @return Represents the non-key attribute names which will be projected into the index.
*
* For local secondary indexes, the total count of NonKeyAttributes
summed across all of the
* local secondary indexes, must not exceed 20. If you project the same attribute into two different
* indexes, this counts as two distinct attributes when determining the total.
*/
public List nonKeyAttributes() {
return nonKeyAttributes;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(projectionTypeAsString());
hashCode = 31 * hashCode + Objects.hashCode(nonKeyAttributes());
return hashCode;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Projection)) {
return false;
}
Projection other = (Projection) obj;
return Objects.equals(projectionTypeAsString(), other.projectionTypeAsString())
&& Objects.equals(nonKeyAttributes(), other.nonKeyAttributes());
}
@Override
public String toString() {
return ToString.builder("Projection").add("ProjectionType", projectionTypeAsString())
.add("NonKeyAttributes", nonKeyAttributes()).build();
}
public Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "ProjectionType":
return Optional.ofNullable(clazz.cast(projectionTypeAsString()));
case "NonKeyAttributes":
return Optional.ofNullable(clazz.cast(nonKeyAttributes()));
default:
return Optional.empty();
}
}
@SdkInternalApi
@Override
public void marshall(ProtocolMarshaller protocolMarshaller) {
ProjectionMarshaller.getInstance().marshall(this, protocolMarshaller);
}
public interface Builder extends CopyableBuilder {
/**
*
* The set of attributes that are projected into the index:
*
*
* -
*
* KEYS_ONLY
- Only the index and primary keys are projected into the index.
*
*
* -
*
* INCLUDE
- Only the specified table attributes are projected into the index. The list of
* projected attributes are in NonKeyAttributes
.
*
*
* -
*
* ALL
- All of the table attributes are projected into the index.
*
*
*
*
* @param projectionType
* The set of attributes that are projected into the index:
*
* -
*
* KEYS_ONLY
- Only the index and primary keys are projected into the index.
*
*
* -
*
* INCLUDE
- Only the specified table attributes are projected into the index. The list of
* projected attributes are in NonKeyAttributes
.
*
*
* -
*
* ALL
- All of the table attributes are projected into the index.
*
*
* @see ProjectionType
* @return Returns a reference to this object so that method calls can be chained together.
* @see ProjectionType
*/
Builder projectionType(String projectionType);
/**
*
* The set of attributes that are projected into the index:
*
*
* -
*
* KEYS_ONLY
- Only the index and primary keys are projected into the index.
*
*
* -
*
* INCLUDE
- Only the specified table attributes are projected into the index. The list of
* projected attributes are in NonKeyAttributes
.
*
*
* -
*
* ALL
- All of the table attributes are projected into the index.
*
*
*
*
* @param projectionType
* The set of attributes that are projected into the index:
*
* -
*
* KEYS_ONLY
- Only the index and primary keys are projected into the index.
*
*
* -
*
* INCLUDE
- Only the specified table attributes are projected into the index. The list of
* projected attributes are in NonKeyAttributes
.
*
*
* -
*
* ALL
- All of the table attributes are projected into the index.
*
*
* @see ProjectionType
* @return Returns a reference to this object so that method calls can be chained together.
* @see ProjectionType
*/
Builder projectionType(ProjectionType projectionType);
/**
*
* Represents the non-key attribute names which will be projected into the index.
*
*
* For local secondary indexes, the total count of NonKeyAttributes
summed across all of the local
* secondary indexes, must not exceed 20. If you project the same attribute into two different indexes, this
* counts as two distinct attributes when determining the total.
*
*
* @param nonKeyAttributes
* Represents the non-key attribute names which will be projected into the index.
*
* For local secondary indexes, the total count of NonKeyAttributes
summed across all of the
* local secondary indexes, must not exceed 20. If you project the same attribute into two different
* indexes, this counts as two distinct attributes when determining the total.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder nonKeyAttributes(Collection nonKeyAttributes);
/**
*
* Represents the non-key attribute names which will be projected into the index.
*
*
* For local secondary indexes, the total count of NonKeyAttributes
summed across all of the local
* secondary indexes, must not exceed 20. If you project the same attribute into two different indexes, this
* counts as two distinct attributes when determining the total.
*
*
* @param nonKeyAttributes
* Represents the non-key attribute names which will be projected into the index.
*
* For local secondary indexes, the total count of NonKeyAttributes
summed across all of the
* local secondary indexes, must not exceed 20. If you project the same attribute into two different
* indexes, this counts as two distinct attributes when determining the total.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder nonKeyAttributes(String... nonKeyAttributes);
}
static final class BuilderImpl implements Builder {
private String projectionType;
private List nonKeyAttributes = DefaultSdkAutoConstructList.getInstance();
private BuilderImpl() {
}
private BuilderImpl(Projection model) {
projectionType(model.projectionType);
nonKeyAttributes(model.nonKeyAttributes);
}
public final String getProjectionType() {
return projectionType;
}
@Override
public final Builder projectionType(String projectionType) {
this.projectionType = projectionType;
return this;
}
@Override
public final Builder projectionType(ProjectionType projectionType) {
this.projectionType(projectionType.toString());
return this;
}
public final void setProjectionType(String projectionType) {
this.projectionType = projectionType;
}
public final Collection getNonKeyAttributes() {
return nonKeyAttributes;
}
@Override
public final Builder nonKeyAttributes(Collection nonKeyAttributes) {
this.nonKeyAttributes = NonKeyAttributeNameListCopier.copy(nonKeyAttributes);
return this;
}
@Override
@SafeVarargs
public final Builder nonKeyAttributes(String... nonKeyAttributes) {
nonKeyAttributes(Arrays.asList(nonKeyAttributes));
return this;
}
public final void setNonKeyAttributes(Collection nonKeyAttributes) {
this.nonKeyAttributes = NonKeyAttributeNameListCopier.copy(nonKeyAttributes);
}
@Override
public Projection build() {
return new Projection(this);
}
}
}