
software.amazon.awssdk.services.dynamodb.model.TransactWriteItemsRequest 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.util.Arrays;
import java.util.Collection;
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.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
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.DefaultValueTrait;
import software.amazon.awssdk.core.traits.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*/
@Generated("software.amazon.awssdk:codegen")
public final class TransactWriteItemsRequest extends DynamoDbRequest implements
ToCopyableBuilder {
private static final SdkField> TRANSACT_ITEMS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("TransactItems")
.getter(getter(TransactWriteItemsRequest::transactItems))
.setter(setter(Builder::transactItems))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("TransactItems").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(TransactWriteItem::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField RETURN_CONSUMED_CAPACITY_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("ReturnConsumedCapacity").getter(getter(TransactWriteItemsRequest::returnConsumedCapacityAsString))
.setter(setter(Builder::returnConsumedCapacity))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ReturnConsumedCapacity").build())
.build();
private static final SdkField RETURN_ITEM_COLLECTION_METRICS_FIELD = SdkField
. builder(MarshallingType.STRING)
.memberName("ReturnItemCollectionMetrics")
.getter(getter(TransactWriteItemsRequest::returnItemCollectionMetricsAsString))
.setter(setter(Builder::returnItemCollectionMetrics))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ReturnItemCollectionMetrics")
.build()).build();
private static final SdkField CLIENT_REQUEST_TOKEN_FIELD = SdkField
. builder(MarshallingType.STRING)
.memberName("ClientRequestToken")
.getter(getter(TransactWriteItemsRequest::clientRequestToken))
.setter(setter(Builder::clientRequestToken))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ClientRequestToken").build(),
DefaultValueTrait.idempotencyToken()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(TRANSACT_ITEMS_FIELD,
RETURN_CONSUMED_CAPACITY_FIELD, RETURN_ITEM_COLLECTION_METRICS_FIELD, CLIENT_REQUEST_TOKEN_FIELD));
private final List transactItems;
private final String returnConsumedCapacity;
private final String returnItemCollectionMetrics;
private final String clientRequestToken;
private TransactWriteItemsRequest(BuilderImpl builder) {
super(builder);
this.transactItems = builder.transactItems;
this.returnConsumedCapacity = builder.returnConsumedCapacity;
this.returnItemCollectionMetrics = builder.returnItemCollectionMetrics;
this.clientRequestToken = builder.clientRequestToken;
}
/**
* Returns true if the TransactItems property was specified by the sender (it may be empty), or false if the sender
* did not specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS service.
*/
public final boolean hasTransactItems() {
return transactItems != null && !(transactItems instanceof SdkAutoConstructList);
}
/**
*
* An ordered array of up to 25 TransactWriteItem
objects, each of which contains a
* ConditionCheck
, Put
, Update
, or Delete
object. These can
* operate on items in different tables, but the tables must reside in the same AWS account and Region, and no two
* of them can operate on the same item.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* You can use {@link #hasTransactItems()} to see if a value was sent in this field.
*
*
* @return An ordered array of up to 25 TransactWriteItem
objects, each of which contains a
* ConditionCheck
, Put
, Update
, or Delete
object. These
* can operate on items in different tables, but the tables must reside in the same AWS account and Region,
* and no two of them can operate on the same item.
*/
public final List transactItems() {
return transactItems;
}
/**
* Returns the value of the ReturnConsumedCapacity property for this object.
*
* If the service returns an enum value that is not available in the current SDK version,
* {@link #returnConsumedCapacity} will return {@link ReturnConsumedCapacity#UNKNOWN_TO_SDK_VERSION}. The raw value
* returned by the service is available from {@link #returnConsumedCapacityAsString}.
*
*
* @return The value of the ReturnConsumedCapacity property for this object.
* @see ReturnConsumedCapacity
*/
public final ReturnConsumedCapacity returnConsumedCapacity() {
return ReturnConsumedCapacity.fromValue(returnConsumedCapacity);
}
/**
* Returns the value of the ReturnConsumedCapacity property for this object.
*
* If the service returns an enum value that is not available in the current SDK version,
* {@link #returnConsumedCapacity} will return {@link ReturnConsumedCapacity#UNKNOWN_TO_SDK_VERSION}. The raw value
* returned by the service is available from {@link #returnConsumedCapacityAsString}.
*
*
* @return The value of the ReturnConsumedCapacity property for this object.
* @see ReturnConsumedCapacity
*/
public final String returnConsumedCapacityAsString() {
return returnConsumedCapacity;
}
/**
*
* Determines whether item collection metrics are returned. If set to SIZE
, the response includes
* statistics about item collections (if any), that were modified during the operation and are returned in the
* response. If set to NONE
(the default), no statistics are returned.
*
*
* If the service returns an enum value that is not available in the current SDK version,
* {@link #returnItemCollectionMetrics} will return {@link ReturnItemCollectionMetrics#UNKNOWN_TO_SDK_VERSION}. The
* raw value returned by the service is available from {@link #returnItemCollectionMetricsAsString}.
*
*
* @return Determines whether item collection metrics are returned. If set to SIZE
, the response
* includes statistics about item collections (if any), that were modified during the operation and are
* returned in the response. If set to NONE
(the default), no statistics are returned.
* @see ReturnItemCollectionMetrics
*/
public final ReturnItemCollectionMetrics returnItemCollectionMetrics() {
return ReturnItemCollectionMetrics.fromValue(returnItemCollectionMetrics);
}
/**
*
* Determines whether item collection metrics are returned. If set to SIZE
, the response includes
* statistics about item collections (if any), that were modified during the operation and are returned in the
* response. If set to NONE
(the default), no statistics are returned.
*
*
* If the service returns an enum value that is not available in the current SDK version,
* {@link #returnItemCollectionMetrics} will return {@link ReturnItemCollectionMetrics#UNKNOWN_TO_SDK_VERSION}. The
* raw value returned by the service is available from {@link #returnItemCollectionMetricsAsString}.
*
*
* @return Determines whether item collection metrics are returned. If set to SIZE
, the response
* includes statistics about item collections (if any), that were modified during the operation and are
* returned in the response. If set to NONE
(the default), no statistics are returned.
* @see ReturnItemCollectionMetrics
*/
public final String returnItemCollectionMetricsAsString() {
return returnItemCollectionMetrics;
}
/**
*
* Providing a ClientRequestToken
makes the call to TransactWriteItems
idempotent, meaning
* that multiple identical calls have the same effect as one single call.
*
*
* Although multiple identical calls using the same client request token produce the same result on the server (no
* side effects), the responses to the calls might not be the same. If the ReturnConsumedCapacity>
* parameter is set, then the initial TransactWriteItems
call returns the amount of write capacity
* units consumed in making the changes. Subsequent TransactWriteItems
calls with the same client token
* return the number of read capacity units consumed in reading the item.
*
*
* A client request token is valid for 10 minutes after the first request that uses it is completed. After 10
* minutes, any request with the same client token is treated as a new request. Do not resubmit the same request
* with the same client token for more than 10 minutes, or the result might not be idempotent.
*
*
* If you submit a request with the same client token but a change in other parameters within the 10-minute
* idempotency window, DynamoDB returns an IdempotentParameterMismatch
exception.
*
*
* @return Providing a ClientRequestToken
makes the call to TransactWriteItems
idempotent,
* meaning that multiple identical calls have the same effect as one single call.
*
* Although multiple identical calls using the same client request token produce the same result on the
* server (no side effects), the responses to the calls might not be the same. If the
* ReturnConsumedCapacity>
parameter is set, then the initial
* TransactWriteItems
call returns the amount of write capacity units consumed in making the
* changes. Subsequent TransactWriteItems
calls with the same client token return the number of
* read capacity units consumed in reading the item.
*
*
* A client request token is valid for 10 minutes after the first request that uses it is completed. After
* 10 minutes, any request with the same client token is treated as a new request. Do not resubmit the same
* request with the same client token for more than 10 minutes, or the result might not be idempotent.
*
*
* If you submit a request with the same client token but a change in other parameters within the 10-minute
* idempotency window, DynamoDB returns an IdempotentParameterMismatch
exception.
*/
public final String clientRequestToken() {
return clientRequestToken;
}
@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 + super.hashCode();
hashCode = 31 * hashCode + Objects.hashCode(hasTransactItems() ? transactItems() : null);
hashCode = 31 * hashCode + Objects.hashCode(returnConsumedCapacityAsString());
hashCode = 31 * hashCode + Objects.hashCode(returnItemCollectionMetricsAsString());
hashCode = 31 * hashCode + Objects.hashCode(clientRequestToken());
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return super.equals(obj) && equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof TransactWriteItemsRequest)) {
return false;
}
TransactWriteItemsRequest other = (TransactWriteItemsRequest) obj;
return hasTransactItems() == other.hasTransactItems() && Objects.equals(transactItems(), other.transactItems())
&& Objects.equals(returnConsumedCapacityAsString(), other.returnConsumedCapacityAsString())
&& Objects.equals(returnItemCollectionMetricsAsString(), other.returnItemCollectionMetricsAsString())
&& Objects.equals(clientRequestToken(), other.clientRequestToken());
}
/**
* 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("TransactWriteItemsRequest").add("TransactItems", hasTransactItems() ? transactItems() : null)
.add("ReturnConsumedCapacity", returnConsumedCapacityAsString())
.add("ReturnItemCollectionMetrics", returnItemCollectionMetricsAsString())
.add("ClientRequestToken", clientRequestToken()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "TransactItems":
return Optional.ofNullable(clazz.cast(transactItems()));
case "ReturnConsumedCapacity":
return Optional.ofNullable(clazz.cast(returnConsumedCapacityAsString()));
case "ReturnItemCollectionMetrics":
return Optional.ofNullable(clazz.cast(returnItemCollectionMetricsAsString()));
case "ClientRequestToken":
return Optional.ofNullable(clazz.cast(clientRequestToken()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function
*
* Although multiple identical calls using the same client request token produce the same result on the
* server (no side effects), the responses to the calls might not be the same. If the
* ReturnConsumedCapacity>
parameter is set, then the initial
* TransactWriteItems
call returns the amount of write capacity units consumed in making the
* changes. Subsequent TransactWriteItems
calls with the same client token return the number
* of read capacity units consumed in reading the item.
*
*
* A client request token is valid for 10 minutes after the first request that uses it is completed.
* After 10 minutes, any request with the same client token is treated as a new request. Do not resubmit
* the same request with the same client token for more than 10 minutes, or the result might not be
* idempotent.
*
*
* If you submit a request with the same client token but a change in other parameters within the
* 10-minute idempotency window, DynamoDB returns an IdempotentParameterMismatch
exception.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder clientRequestToken(String clientRequestToken);
@Override
Builder overrideConfiguration(AwsRequestOverrideConfiguration overrideConfiguration);
@Override
Builder overrideConfiguration(Consumer builderConsumer);
}
static final class BuilderImpl extends DynamoDbRequest.BuilderImpl implements Builder {
private List transactItems = DefaultSdkAutoConstructList.getInstance();
private String returnConsumedCapacity;
private String returnItemCollectionMetrics;
private String clientRequestToken;
private BuilderImpl() {
}
private BuilderImpl(TransactWriteItemsRequest model) {
super(model);
transactItems(model.transactItems);
returnConsumedCapacity(model.returnConsumedCapacity);
returnItemCollectionMetrics(model.returnItemCollectionMetrics);
clientRequestToken(model.clientRequestToken);
}
public final List getTransactItems() {
List result = TransactWriteItemListCopier.copyToBuilder(this.transactItems);
if (result instanceof SdkAutoConstructList) {
return null;
}
return result;
}
@Override
public final Builder transactItems(Collection transactItems) {
this.transactItems = TransactWriteItemListCopier.copy(transactItems);
return this;
}
@Override
@SafeVarargs
public final Builder transactItems(TransactWriteItem... transactItems) {
transactItems(Arrays.asList(transactItems));
return this;
}
@Override
@SafeVarargs
public final Builder transactItems(Consumer... transactItems) {
transactItems(Stream.of(transactItems).map(c -> TransactWriteItem.builder().applyMutation(c).build())
.collect(Collectors.toList()));
return this;
}
public final void setTransactItems(Collection transactItems) {
this.transactItems = TransactWriteItemListCopier.copyFromBuilder(transactItems);
}
public final String getReturnConsumedCapacity() {
return returnConsumedCapacity;
}
@Override
public final Builder returnConsumedCapacity(String returnConsumedCapacity) {
this.returnConsumedCapacity = returnConsumedCapacity;
return this;
}
@Override
public final Builder returnConsumedCapacity(ReturnConsumedCapacity returnConsumedCapacity) {
this.returnConsumedCapacity(returnConsumedCapacity == null ? null : returnConsumedCapacity.toString());
return this;
}
public final void setReturnConsumedCapacity(String returnConsumedCapacity) {
this.returnConsumedCapacity = returnConsumedCapacity;
}
public final String getReturnItemCollectionMetrics() {
return returnItemCollectionMetrics;
}
@Override
public final Builder returnItemCollectionMetrics(String returnItemCollectionMetrics) {
this.returnItemCollectionMetrics = returnItemCollectionMetrics;
return this;
}
@Override
public final Builder returnItemCollectionMetrics(ReturnItemCollectionMetrics returnItemCollectionMetrics) {
this.returnItemCollectionMetrics(returnItemCollectionMetrics == null ? null : returnItemCollectionMetrics.toString());
return this;
}
public final void setReturnItemCollectionMetrics(String returnItemCollectionMetrics) {
this.returnItemCollectionMetrics = returnItemCollectionMetrics;
}
public final String getClientRequestToken() {
return clientRequestToken;
}
@Override
public final Builder clientRequestToken(String clientRequestToken) {
this.clientRequestToken = clientRequestToken;
return this;
}
public final void setClientRequestToken(String clientRequestToken) {
this.clientRequestToken = clientRequestToken;
}
@Override
public Builder overrideConfiguration(AwsRequestOverrideConfiguration overrideConfiguration) {
super.overrideConfiguration(overrideConfiguration);
return this;
}
@Override
public Builder overrideConfiguration(Consumer builderConsumer) {
super.overrideConfiguration(builderConsumer);
return this;
}
@Override
public TransactWriteItemsRequest build() {
return new TransactWriteItemsRequest(this);
}
@Override
public List> sdkFields() {
return SDK_FIELDS;
}
}
}