
software.amazon.awssdk.services.dynamodb.model.BatchWriteItemResponse Maven / Gradle / Ivy
/*
* 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.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructMap;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* Represents the output of a BatchWriteItem
operation.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class BatchWriteItemResponse extends DynamoDbResponse implements
ToCopyableBuilder {
private final Map> unprocessedItems;
private final Map> itemCollectionMetrics;
private final List consumedCapacity;
private BatchWriteItemResponse(BuilderImpl builder) {
super(builder);
this.unprocessedItems = builder.unprocessedItems;
this.itemCollectionMetrics = builder.itemCollectionMetrics;
this.consumedCapacity = builder.consumedCapacity;
}
/**
*
* A map of tables and requests against those tables that were not processed. The UnprocessedItems
* value is in the same form as RequestItems
, so you can provide this value directly to a subsequent
* BatchGetItem
operation. For more information, see RequestItems
in the Request
* Parameters section.
*
*
* Each UnprocessedItems
entry consists of a table name and, for that table, a list of operations to
* perform (DeleteRequest
or PutRequest
).
*
*
* -
*
* DeleteRequest
- Perform a DeleteItem
operation on the specified item. The item to be
* deleted is identified by a Key
subelement:
*
*
* -
*
* Key
- A map of primary key attribute values that uniquely identify the item. Each entry in this map
* consists of an attribute name and an attribute value.
*
*
*
*
* -
*
* PutRequest
- Perform a PutItem
operation on the specified item. The item to be put is
* identified by an Item
subelement:
*
*
* -
*
* Item
- A map of attributes and their values. Each entry in this map consists of an attribute name
* and an attribute value. Attribute values must not be null; string and binary type attributes must have lengths
* greater than zero; and set type attributes must not be empty. Requests that contain empty values will be rejected
* with a ValidationException
exception.
*
*
* If you specify any attributes that are part of an index key, then the data types for those attributes must match
* those of the schema in the table's attribute definition.
*
*
*
*
*
*
* If there are no unprocessed items remaining, the response contains an empty UnprocessedItems
map.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* @return A map of tables and requests against those tables that were not processed. The
* UnprocessedItems
value is in the same form as RequestItems
, so you can provide
* this value directly to a subsequent BatchGetItem
operation. For more information, see
* RequestItems
in the Request Parameters section.
*
* Each UnprocessedItems
entry consists of a table name and, for that table, a list of
* operations to perform (DeleteRequest
or PutRequest
).
*
*
* -
*
* DeleteRequest
- Perform a DeleteItem
operation on the specified item. The item
* to be deleted is identified by a Key
subelement:
*
*
* -
*
* Key
- A map of primary key attribute values that uniquely identify the item. Each entry in
* this map consists of an attribute name and an attribute value.
*
*
*
*
* -
*
* PutRequest
- Perform a PutItem
operation on the specified item. The item to be
* put is identified by an Item
subelement:
*
*
* -
*
* Item
- A map of attributes and their values. Each entry in this map consists of an attribute
* name and an attribute value. Attribute values must not be null; string and binary type attributes must
* have lengths greater than zero; and set type attributes must not be empty. Requests that contain empty
* values will be rejected with a ValidationException
exception.
*
*
* If you specify any attributes that are part of an index key, then the data types for those attributes
* must match those of the schema in the table's attribute definition.
*
*
*
*
*
*
* If there are no unprocessed items remaining, the response contains an empty UnprocessedItems
* map.
*/
public Map> unprocessedItems() {
return unprocessedItems;
}
/**
*
* A list of tables that were processed by BatchWriteItem
and, for each table, information about any
* item collections that were affected by individual DeleteItem
or PutItem
operations.
*
*
* Each entry consists of the following subelements:
*
*
* -
*
* ItemCollectionKey
- The partition key value of the item collection. This is the same as the
* partition key value of the item.
*
*
* -
*
* SizeEstimateRangeGB
- An estimate of item collection size, expressed in GB. This is a two-element
* array containing a lower bound and an upper bound for the estimate. The estimate includes the size of all the
* items in the table, plus the size of all attributes projected into all of the local secondary indexes on the
* table. Use this estimate to measure whether a local secondary index is approaching its size limit.
*
*
* The estimate is subject to change over time; therefore, do not rely on the precision or accuracy of the estimate.
*
*
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* @return A list of tables that were processed by BatchWriteItem
and, for each table, information
* about any item collections that were affected by individual DeleteItem
or
* PutItem
operations.
*
* Each entry consists of the following subelements:
*
*
* -
*
* ItemCollectionKey
- The partition key value of the item collection. This is the same as the
* partition key value of the item.
*
*
* -
*
* SizeEstimateRangeGB
- An estimate of item collection size, expressed in GB. This is a
* two-element array containing a lower bound and an upper bound for the estimate. The estimate includes the
* size of all the items in the table, plus the size of all attributes projected into all of the local
* secondary indexes on the table. Use this estimate to measure whether a local secondary index is
* approaching its size limit.
*
*
* The estimate is subject to change over time; therefore, do not rely on the precision or accuracy of the
* estimate.
*
*
*/
public Map> itemCollectionMetrics() {
return itemCollectionMetrics;
}
/**
*
* The capacity units consumed by the entire BatchWriteItem
operation.
*
*
* Each element consists of:
*
*
* -
*
* TableName
- The table that consumed the provisioned throughput.
*
*
* -
*
* CapacityUnits
- The total number of capacity units consumed.
*
*
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* @return The capacity units consumed by the entire BatchWriteItem
operation.
*
* Each element consists of:
*
*
* -
*
* TableName
- The table that consumed the provisioned throughput.
*
*
* -
*
* CapacityUnits
- The total number of capacity units consumed.
*
*
*/
public List consumedCapacity() {
return consumedCapacity;
}
@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 int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(unprocessedItems());
hashCode = 31 * hashCode + Objects.hashCode(itemCollectionMetrics());
hashCode = 31 * hashCode + Objects.hashCode(consumedCapacity());
return hashCode;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof BatchWriteItemResponse)) {
return false;
}
BatchWriteItemResponse other = (BatchWriteItemResponse) obj;
return Objects.equals(unprocessedItems(), other.unprocessedItems())
&& Objects.equals(itemCollectionMetrics(), other.itemCollectionMetrics())
&& Objects.equals(consumedCapacity(), other.consumedCapacity());
}
@Override
public String toString() {
return ToString.builder("BatchWriteItemResponse").add("UnprocessedItems", unprocessedItems())
.add("ItemCollectionMetrics", itemCollectionMetrics()).add("ConsumedCapacity", consumedCapacity()).build();
}
public Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "UnprocessedItems":
return Optional.ofNullable(clazz.cast(unprocessedItems()));
case "ItemCollectionMetrics":
return Optional.ofNullable(clazz.cast(itemCollectionMetrics()));
case "ConsumedCapacity":
return Optional.ofNullable(clazz.cast(consumedCapacity()));
default:
return Optional.empty();
}
}
public interface Builder extends DynamoDbResponse.Builder, CopyableBuilder {
/**
*
* A map of tables and requests against those tables that were not processed. The UnprocessedItems
* value is in the same form as RequestItems
, so you can provide this value directly to a
* subsequent BatchGetItem
operation. For more information, see RequestItems
in the
* Request Parameters section.
*
*
* Each UnprocessedItems
entry consists of a table name and, for that table, a list of operations
* to perform (DeleteRequest
or PutRequest
).
*
*
* -
*
* DeleteRequest
- Perform a DeleteItem
operation on the specified item. The item to
* be deleted is identified by a Key
subelement:
*
*
* -
*
* Key
- A map of primary key attribute values that uniquely identify the item. Each entry in this
* map consists of an attribute name and an attribute value.
*
*
*
*
* -
*
* PutRequest
- Perform a PutItem
operation on the specified item. The item to be put
* is identified by an Item
subelement:
*
*
* -
*
* Item
- A map of attributes and their values. Each entry in this map consists of an attribute
* name and an attribute value. Attribute values must not be null; string and binary type attributes must have
* lengths greater than zero; and set type attributes must not be empty. Requests that contain empty values will
* be rejected with a ValidationException
exception.
*
*
* If you specify any attributes that are part of an index key, then the data types for those attributes must
* match those of the schema in the table's attribute definition.
*
*
*
*
*
*
* If there are no unprocessed items remaining, the response contains an empty UnprocessedItems
* map.
*
*
* @param unprocessedItems
* A map of tables and requests against those tables that were not processed. The
* UnprocessedItems
value is in the same form as RequestItems
, so you can
* provide this value directly to a subsequent BatchGetItem
operation. For more information,
* see RequestItems
in the Request Parameters section.
*
* Each UnprocessedItems
entry consists of a table name and, for that table, a list of
* operations to perform (DeleteRequest
or PutRequest
).
*
*
* -
*
* DeleteRequest
- Perform a DeleteItem
operation on the specified item. The
* item to be deleted is identified by a Key
subelement:
*
*
* -
*
* Key
- A map of primary key attribute values that uniquely identify the item. Each entry
* in this map consists of an attribute name and an attribute value.
*
*
*
*
* -
*
* PutRequest
- Perform a PutItem
operation on the specified item. The item to
* be put is identified by an Item
subelement:
*
*
* -
*
* Item
- A map of attributes and their values. Each entry in this map consists of an
* attribute name and an attribute value. Attribute values must not be null; string and binary type
* attributes must have lengths greater than zero; and set type attributes must not be empty. Requests
* that contain empty values will be rejected with a ValidationException
exception.
*
*
* If you specify any attributes that are part of an index key, then the data types for those attributes
* must match those of the schema in the table's attribute definition.
*
*
*
*
*
*
* If there are no unprocessed items remaining, the response contains an empty
* UnprocessedItems
map.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder unprocessedItems(Map> unprocessedItems);
/**
*
* A list of tables that were processed by BatchWriteItem
and, for each table, information about
* any item collections that were affected by individual DeleteItem
or PutItem
* operations.
*
*
* Each entry consists of the following subelements:
*
*
* -
*
* ItemCollectionKey
- The partition key value of the item collection. This is the same as the
* partition key value of the item.
*
*
* -
*
* SizeEstimateRangeGB
- An estimate of item collection size, expressed in GB. This is a
* two-element array containing a lower bound and an upper bound for the estimate. The estimate includes the
* size of all the items in the table, plus the size of all attributes projected into all of the local secondary
* indexes on the table. Use this estimate to measure whether a local secondary index is approaching its size
* limit.
*
*
* The estimate is subject to change over time; therefore, do not rely on the precision or accuracy of the
* estimate.
*
*
*
*
* @param itemCollectionMetrics
* A list of tables that were processed by BatchWriteItem
and, for each table, information
* about any item collections that were affected by individual DeleteItem
or
* PutItem
operations.
*
* Each entry consists of the following subelements:
*
*
* -
*
* ItemCollectionKey
- The partition key value of the item collection. This is the same as
* the partition key value of the item.
*
*
* -
*
* SizeEstimateRangeGB
- An estimate of item collection size, expressed in GB. This is a
* two-element array containing a lower bound and an upper bound for the estimate. The estimate includes
* the size of all the items in the table, plus the size of all attributes projected into all of the
* local secondary indexes on the table. Use this estimate to measure whether a local secondary index is
* approaching its size limit.
*
*
* The estimate is subject to change over time; therefore, do not rely on the precision or accuracy of
* the estimate.
*
*
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder itemCollectionMetrics(Map> itemCollectionMetrics);
/**
*
* The capacity units consumed by the entire BatchWriteItem
operation.
*
*
* Each element consists of:
*
*
* -
*
* TableName
- The table that consumed the provisioned throughput.
*
*
* -
*
* CapacityUnits
- The total number of capacity units consumed.
*
*
*
*
* @param consumedCapacity
* The capacity units consumed by the entire BatchWriteItem
operation.
*
* Each element consists of:
*
*
* -
*
* TableName
- The table that consumed the provisioned throughput.
*
*
* -
*
* CapacityUnits
- The total number of capacity units consumed.
*
*
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder consumedCapacity(Collection consumedCapacity);
/**
*
* The capacity units consumed by the entire BatchWriteItem
operation.
*
*
* Each element consists of:
*
*
* -
*
* TableName
- The table that consumed the provisioned throughput.
*
*
* -
*
* CapacityUnits
- The total number of capacity units consumed.
*
*
*
*
* @param consumedCapacity
* The capacity units consumed by the entire BatchWriteItem
operation.
*
* Each element consists of:
*
*
* -
*
* TableName
- The table that consumed the provisioned throughput.
*
*
* -
*
* CapacityUnits
- The total number of capacity units consumed.
*
*
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder consumedCapacity(ConsumedCapacity... consumedCapacity);
/**
*
* The capacity units consumed by the entire BatchWriteItem
operation.
*
*
* Each element consists of:
*
*
* -
*
* TableName
- The table that consumed the provisioned throughput.
*
*
* -
*
* CapacityUnits
- The total number of capacity units consumed.
*
*
*
* This is a convenience that creates an instance of the {@link List.Builder} avoiding the
* need to create one manually via {@link List#builder()}.
*
* When the {@link Consumer} completes, {@link List.Builder#build()} is called immediately and
* its result is passed to {@link #consumedCapacity(List)}.
*
* @param consumedCapacity
* a consumer that will call methods on {@link List.Builder}
* @return Returns a reference to this object so that method calls can be chained together.
* @see #consumedCapacity(List)
*/
Builder consumedCapacity(Consumer... consumedCapacity);
}
static final class BuilderImpl extends DynamoDbResponse.BuilderImpl implements Builder {
private Map> unprocessedItems = DefaultSdkAutoConstructMap.getInstance();
private Map> itemCollectionMetrics = DefaultSdkAutoConstructMap.getInstance();
private List consumedCapacity = DefaultSdkAutoConstructList.getInstance();
private BuilderImpl() {
}
private BuilderImpl(BatchWriteItemResponse model) {
super(model);
unprocessedItems(model.unprocessedItems);
itemCollectionMetrics(model.itemCollectionMetrics);
consumedCapacity(model.consumedCapacity);
}
public final Map> getUnprocessedItems() {
return unprocessedItems;
}
@Override
public final Builder unprocessedItems(Map> unprocessedItems) {
this.unprocessedItems = BatchWriteItemRequestMapCopier.copy(unprocessedItems);
return this;
}
public final void setUnprocessedItems(Map> unprocessedItems) {
this.unprocessedItems = BatchWriteItemRequestMapCopier.copy(unprocessedItems);
}
public final Map> getItemCollectionMetrics() {
return itemCollectionMetrics;
}
@Override
public final Builder itemCollectionMetrics(Map> itemCollectionMetrics) {
this.itemCollectionMetrics = ItemCollectionMetricsPerTableCopier.copy(itemCollectionMetrics);
return this;
}
public final void setItemCollectionMetrics(Map> itemCollectionMetrics) {
this.itemCollectionMetrics = ItemCollectionMetricsPerTableCopier.copy(itemCollectionMetrics);
}
public final Collection getConsumedCapacity() {
return consumedCapacity != null ? consumedCapacity.stream().map(ConsumedCapacity::toBuilder)
.collect(Collectors.toList()) : null;
}
@Override
public final Builder consumedCapacity(Collection consumedCapacity) {
this.consumedCapacity = ConsumedCapacityMultipleCopier.copy(consumedCapacity);
return this;
}
@Override
@SafeVarargs
public final Builder consumedCapacity(ConsumedCapacity... consumedCapacity) {
consumedCapacity(Arrays.asList(consumedCapacity));
return this;
}
@Override
@SafeVarargs
public final Builder consumedCapacity(Consumer... consumedCapacity) {
consumedCapacity(Stream.of(consumedCapacity).map(c -> ConsumedCapacity.builder().applyMutation(c).build())
.collect(Collectors.toList()));
return this;
}
public final void setConsumedCapacity(Collection consumedCapacity) {
this.consumedCapacity = ConsumedCapacityMultipleCopier.copyFromBuilder(consumedCapacity);
}
@Override
public BatchWriteItemResponse build() {
return new BatchWriteItemResponse(this);
}
}
}