All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.services.dynamodb.model.QueryResponse Maven / Gradle / Ivy

Go to download

A single bundled dependency that includes all service and dependent JARs with third-party libraries relocated to different namespaces.

There is a newer version: 2.5.20
Show newest version
/*
 * 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 software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructMap;
import software.amazon.awssdk.utils.CollectionUtils;
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 Query operation. *

*/ @Generated("software.amazon.awssdk:codegen") public final class QueryResponse extends DynamoDbResponse implements ToCopyableBuilder { private final List> items; private final Integer count; private final Integer scannedCount; private final Map lastEvaluatedKey; private final ConsumedCapacity consumedCapacity; private QueryResponse(BuilderImpl builder) { super(builder); this.items = builder.items; this.count = builder.count; this.scannedCount = builder.scannedCount; this.lastEvaluatedKey = builder.lastEvaluatedKey; this.consumedCapacity = builder.consumedCapacity; } /** *

* An array of item attributes that match the query criteria. Each element in this array consists of an attribute * name and the value for that attribute. *

*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

* * @return An array of item attributes that match the query criteria. Each element in this array consists of an * attribute name and the value for that attribute. */ public List> items() { return items; } /** *

* The number of items in the response. *

*

* If you used a QueryFilter in the request, then Count is the number of items returned * after the filter was applied, and ScannedCount is the number of matching items before the filter was * applied. *

*

* If you did not use a filter in the request, then Count and ScannedCount are the same. *

* * @return The number of items in the response.

*

* If you used a QueryFilter in the request, then Count is the number of items * returned after the filter was applied, and ScannedCount is the number of matching items * before the filter was applied. *

*

* If you did not use a filter in the request, then Count and ScannedCount are the * same. */ public Integer count() { return count; } /** *

* The number of items evaluated, before any QueryFilter is applied. A high ScannedCount * value with few, or no, Count results indicates an inefficient Query operation. For more * information, see Count and * ScannedCount in the Amazon DynamoDB Developer Guide. *

*

* If you did not use a filter in the request, then ScannedCount is the same as Count. *

* * @return The number of items evaluated, before any QueryFilter is applied. A high * ScannedCount value with few, or no, Count results indicates an inefficient * Query operation. For more information, see Count and * ScannedCount in the Amazon DynamoDB Developer Guide.

*

* If you did not use a filter in the request, then ScannedCount is the same as * Count. */ public Integer scannedCount() { return scannedCount; } /** *

* The primary key of the item where the operation stopped, inclusive of the previous result set. Use this value to * start a new operation, excluding this value in the new request. *

*

* If LastEvaluatedKey is empty, then the "last page" of results has been processed and there is no * more data to be retrieved. *

*

* If LastEvaluatedKey is not empty, it does not necessarily mean that there is more data in the result * set. The only way to know when you have reached the end of the result set is when LastEvaluatedKey * is empty. *

*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

* * @return The primary key of the item where the operation stopped, inclusive of the previous result set. Use this * value to start a new operation, excluding this value in the new request.

*

* If LastEvaluatedKey is empty, then the "last page" of results has been processed and there * is no more data to be retrieved. *

*

* If LastEvaluatedKey is not empty, it does not necessarily mean that there is more data in * the result set. The only way to know when you have reached the end of the result set is when * LastEvaluatedKey is empty. */ public Map lastEvaluatedKey() { return lastEvaluatedKey; } /** *

* The capacity units consumed by the Query operation. The data returned includes the total provisioned * throughput consumed, along with statistics for the table and any indexes involved in the operation. * ConsumedCapacity is only returned if the ReturnConsumedCapacity parameter was specified * For more information, see Provisioned Throughput in the Amazon DynamoDB Developer Guide. *

* * @return The capacity units consumed by the Query operation. The data returned includes the total * provisioned throughput consumed, along with statistics for the table and any indexes involved in the * operation. ConsumedCapacity is only returned if the ReturnConsumedCapacity * parameter was specified For more information, see Provisioned Throughput in the Amazon DynamoDB Developer Guide. */ public ConsumedCapacity consumedCapacity() { return consumedCapacity; } @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(items()); hashCode = 31 * hashCode + Objects.hashCode(count()); hashCode = 31 * hashCode + Objects.hashCode(scannedCount()); hashCode = 31 * hashCode + Objects.hashCode(lastEvaluatedKey()); 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 QueryResponse)) { return false; } QueryResponse other = (QueryResponse) obj; return Objects.equals(items(), other.items()) && Objects.equals(count(), other.count()) && Objects.equals(scannedCount(), other.scannedCount()) && Objects.equals(lastEvaluatedKey(), other.lastEvaluatedKey()) && Objects.equals(consumedCapacity(), other.consumedCapacity()); } @Override public String toString() { return ToString.builder("QueryResponse").add("Items", items()).add("Count", count()).add("ScannedCount", scannedCount()) .add("LastEvaluatedKey", lastEvaluatedKey()).add("ConsumedCapacity", consumedCapacity()).build(); } public Optional getValueForField(String fieldName, Class clazz) { switch (fieldName) { case "Items": return Optional.ofNullable(clazz.cast(items())); case "Count": return Optional.ofNullable(clazz.cast(count())); case "ScannedCount": return Optional.ofNullable(clazz.cast(scannedCount())); case "LastEvaluatedKey": return Optional.ofNullable(clazz.cast(lastEvaluatedKey())); case "ConsumedCapacity": return Optional.ofNullable(clazz.cast(consumedCapacity())); default: return Optional.empty(); } } public interface Builder extends DynamoDbResponse.Builder, CopyableBuilder { /** *

* An array of item attributes that match the query criteria. Each element in this array consists of an * attribute name and the value for that attribute. *

* * @param items * An array of item attributes that match the query criteria. Each element in this array consists of an * attribute name and the value for that attribute. * @return Returns a reference to this object so that method calls can be chained together. */ Builder items(Collection> items); /** *

* An array of item attributes that match the query criteria. Each element in this array consists of an * attribute name and the value for that attribute. *

* * @param items * An array of item attributes that match the query criteria. Each element in this array consists of an * attribute name and the value for that attribute. * @return Returns a reference to this object so that method calls can be chained together. */ Builder items(Map... items); /** *

* The number of items in the response. *

*

* If you used a QueryFilter in the request, then Count is the number of items * returned after the filter was applied, and ScannedCount is the number of matching items before * the filter was applied. *

*

* If you did not use a filter in the request, then Count and ScannedCount are the * same. *

* * @param count * The number of items in the response.

*

* If you used a QueryFilter in the request, then Count is the number of items * returned after the filter was applied, and ScannedCount is the number of matching items * before the filter was applied. *

*

* If you did not use a filter in the request, then Count and ScannedCount are * the same. * @return Returns a reference to this object so that method calls can be chained together. */ Builder count(Integer count); /** *

* The number of items evaluated, before any QueryFilter is applied. A high * ScannedCount value with few, or no, Count results indicates an inefficient * Query operation. For more information, see Count and * ScannedCount in the Amazon DynamoDB Developer Guide. *

*

* If you did not use a filter in the request, then ScannedCount is the same as Count. *

* * @param scannedCount * The number of items evaluated, before any QueryFilter is applied. A high * ScannedCount value with few, or no, Count results indicates an inefficient * Query operation. For more information, see Count * and ScannedCount in the Amazon DynamoDB Developer Guide.

*

* If you did not use a filter in the request, then ScannedCount is the same as * Count. * @return Returns a reference to this object so that method calls can be chained together. */ Builder scannedCount(Integer scannedCount); /** *

* The primary key of the item where the operation stopped, inclusive of the previous result set. Use this value * to start a new operation, excluding this value in the new request. *

*

* If LastEvaluatedKey is empty, then the "last page" of results has been processed and there is no * more data to be retrieved. *

*

* If LastEvaluatedKey is not empty, it does not necessarily mean that there is more data in the * result set. The only way to know when you have reached the end of the result set is when * LastEvaluatedKey is empty. *

* * @param lastEvaluatedKey * The primary key of the item where the operation stopped, inclusive of the previous result set. Use * this value to start a new operation, excluding this value in the new request.

*

* If LastEvaluatedKey is empty, then the "last page" of results has been processed and * there is no more data to be retrieved. *

*

* If LastEvaluatedKey is not empty, it does not necessarily mean that there is more data in * the result set. The only way to know when you have reached the end of the result set is when * LastEvaluatedKey is empty. * @return Returns a reference to this object so that method calls can be chained together. */ Builder lastEvaluatedKey(Map lastEvaluatedKey); /** *

* The capacity units consumed by the Query operation. The data returned includes the total * provisioned throughput consumed, along with statistics for the table and any indexes involved in the * operation. ConsumedCapacity is only returned if the ReturnConsumedCapacity * parameter was specified For more information, see Provisioned Throughput in the Amazon DynamoDB Developer Guide. *

* * @param consumedCapacity * The capacity units consumed by the Query operation. The data returned includes the total * provisioned throughput consumed, along with statistics for the table and any indexes involved in the * operation. ConsumedCapacity is only returned if the ReturnConsumedCapacity * parameter was specified For more information, see Provisioned Throughput in the Amazon DynamoDB Developer Guide. * @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 Query operation. The data returned includes the total * provisioned throughput consumed, along with statistics for the table and any indexes involved in the * operation. ConsumedCapacity is only returned if the ReturnConsumedCapacity * parameter was specified For more information, see Provisioned Throughput in the Amazon DynamoDB Developer Guide. *

* This is a convenience that creates an instance of the {@link ConsumedCapacity.Builder} avoiding the need to * create one manually via {@link ConsumedCapacity#builder()}. * * When the {@link Consumer} completes, {@link ConsumedCapacity.Builder#build()} is called immediately and its * result is passed to {@link #consumedCapacity(ConsumedCapacity)}. * * @param consumedCapacity * a consumer that will call methods on {@link ConsumedCapacity.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #consumedCapacity(ConsumedCapacity) */ default Builder consumedCapacity(Consumer consumedCapacity) { return consumedCapacity(ConsumedCapacity.builder().applyMutation(consumedCapacity).build()); } } static final class BuilderImpl extends DynamoDbResponse.BuilderImpl implements Builder { private List> items = DefaultSdkAutoConstructList.getInstance(); private Integer count; private Integer scannedCount; private Map lastEvaluatedKey = DefaultSdkAutoConstructMap.getInstance(); private ConsumedCapacity consumedCapacity; private BuilderImpl() { } private BuilderImpl(QueryResponse model) { super(model); items(model.items); count(model.count); scannedCount(model.scannedCount); lastEvaluatedKey(model.lastEvaluatedKey); consumedCapacity(model.consumedCapacity); } public final Collection> getItems() { return items; } @Override public final Builder items(Collection> items) { this.items = ItemListCopier.copy(items); return this; } @Override @SafeVarargs public final Builder items(Map... items) { items(Arrays.asList(items)); return this; } public final void setItems(Collection> items) { this.items = ItemListCopier.copy(items); } public final Integer getCount() { return count; } @Override public final Builder count(Integer count) { this.count = count; return this; } public final void setCount(Integer count) { this.count = count; } public final Integer getScannedCount() { return scannedCount; } @Override public final Builder scannedCount(Integer scannedCount) { this.scannedCount = scannedCount; return this; } public final void setScannedCount(Integer scannedCount) { this.scannedCount = scannedCount; } public final Map getLastEvaluatedKey() { return lastEvaluatedKey != null ? CollectionUtils.mapValues(lastEvaluatedKey, AttributeValue::toBuilder) : null; } @Override public final Builder lastEvaluatedKey(Map lastEvaluatedKey) { this.lastEvaluatedKey = KeyCopier.copy(lastEvaluatedKey); return this; } public final void setLastEvaluatedKey(Map lastEvaluatedKey) { this.lastEvaluatedKey = KeyCopier.copyFromBuilder(lastEvaluatedKey); } public final ConsumedCapacity.Builder getConsumedCapacity() { return consumedCapacity != null ? consumedCapacity.toBuilder() : null; } @Override public final Builder consumedCapacity(ConsumedCapacity consumedCapacity) { this.consumedCapacity = consumedCapacity; return this; } public final void setConsumedCapacity(ConsumedCapacity.BuilderImpl consumedCapacity) { this.consumedCapacity = consumedCapacity != null ? consumedCapacity.build() : null; } @Override public QueryResponse build() { return new QueryResponse(this); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy