index
int64
0
0
repo_id
stringlengths
26
205
file_path
stringlengths
51
246
content
stringlengths
8
433k
__index_level_0__
int64
0
10k
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/attribute/JsonItemAttributeConverter.java
/* * 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.enhanced.dynamodb.internal.converter.attribute; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.core.SdkBytes; import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.AttributeValueType; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.TypeConvertingVisitor; import software.amazon.awssdk.protocols.jsoncore.JsonNode; import software.amazon.awssdk.protocols.jsoncore.internal.ArrayJsonNode; import software.amazon.awssdk.protocols.jsoncore.internal.BooleanJsonNode; import software.amazon.awssdk.protocols.jsoncore.internal.NullJsonNode; import software.amazon.awssdk.protocols.jsoncore.internal.NumberJsonNode; import software.amazon.awssdk.protocols.jsoncore.internal.ObjectJsonNode; import software.amazon.awssdk.protocols.jsoncore.internal.StringJsonNode; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import software.amazon.awssdk.utils.BinaryUtils; /** * An Internal converter between JsonNode and {@link AttributeValue}. * * <p> * This converts the Attribute Value read from the DDB to JsonNode. */ @SdkInternalApi @ThreadSafe @Immutable public final class JsonItemAttributeConverter implements AttributeConverter<JsonNode> { private static final Visitor VISITOR = new Visitor(); private JsonItemAttributeConverter() { } public static JsonItemAttributeConverter create() { return new JsonItemAttributeConverter(); } @Override public EnhancedType<JsonNode> type() { return EnhancedType.of(JsonNode.class); } @Override public AttributeValueType attributeValueType() { return AttributeValueType.M; } @Override public AttributeValue transformFrom(JsonNode input) { JsonNodeToAttributeValueMapConverter attributeValueMapConverter = JsonNodeToAttributeValueMapConverter.instance(); return input.visit(attributeValueMapConverter); } @Override public JsonNode transformTo(AttributeValue input) { if (AttributeValue.fromNul(true).equals(input)) { return NullJsonNode.instance(); } return EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR); } private static final class Visitor extends TypeConvertingVisitor<JsonNode> { private Visitor() { super(JsonNode.class, JsonItemAttributeConverter.class); } @Override public JsonNode convertMap(Map<String, AttributeValue> value) { if (value == null) { return null; } Map<String, JsonNode> jsonNodeMap = new LinkedHashMap<>(); value.entrySet().forEach( k -> { JsonNode jsonNode = this.convert(EnhancedAttributeValue.fromAttributeValue(k.getValue())); jsonNodeMap.put(k.getKey(), jsonNode == null ? NullJsonNode.instance() : jsonNode); }); return new ObjectJsonNode(jsonNodeMap); } @Override public JsonNode convertString(String value) { if (value == null) { return null; } return new StringJsonNode(value); } @Override public JsonNode convertNumber(String value) { if (value == null) { return null; } return new NumberJsonNode(value); } @Override public JsonNode convertBytes(SdkBytes value) { if (value == null) { return null; } return new StringJsonNode(BinaryUtils.toBase64(value.asByteArray())); } @Override public JsonNode convertBoolean(Boolean value) { if (value == null) { return null; } return new BooleanJsonNode(value); } @Override public JsonNode convertSetOfStrings(List<String> value) { if (value == null) { return null; } return new ArrayJsonNode(value.stream().map(StringJsonNode::new).collect(Collectors.toList())); } @Override public JsonNode convertSetOfNumbers(List<String> value) { if (value == null) { return null; } return new ArrayJsonNode(value.stream().map(NumberJsonNode::new).collect(Collectors.toList())); } @Override public JsonNode convertSetOfBytes(List<SdkBytes> value) { if (value == null) { return null; } return new ArrayJsonNode(value.stream().map( sdkByte -> new StringJsonNode(BinaryUtils.toBase64(sdkByte.asByteArray())) ).collect(Collectors.toList())); } @Override public JsonNode convertListOfAttributeValues(List<AttributeValue> value) { if (value == null) { return null; } return new ArrayJsonNode(value.stream().map( attributeValue -> { EnhancedAttributeValue enhancedAttributeValue = EnhancedAttributeValue.fromAttributeValue(attributeValue); return enhancedAttributeValue.isNull() ? NullJsonNode.instance() : enhancedAttributeValue.convert(VISITOR); }).collect(Collectors.toList())); } } }
4,200
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/attribute/LocalTimeAttributeConverter.java
/* * 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.enhanced.dynamodb.internal.converter.attribute; import java.time.DateTimeException; import java.time.LocalTime; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.AttributeValueType; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.TypeConvertingVisitor; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; /** * A converter between {@link LocalTime} and {@link AttributeValue}. * * <p> * This stores and reads values in DynamoDB as a String. * * <p> * LocalTimes are stored in the official {@link LocalTime} format "HH:II:SS[.NNNNNNNNN]", where: * <ol> * <li>H is a 2-character, zero-prefixed hour between 00 and 23</li> * <li>I is a 2-character, zero-prefixed minute between 00 and 59</li> * <li>S is a 2-character, zero-prefixed second between 00 and 59</li> * <li>N is a 9-character, zero-prefixed nanosecond between 000,000,000 and 999,999,999. * The . and N may be excluded if N is 0.</li> * </ol> * See {@link LocalTime} for more details on the serialization format. * * <p> * This serialization is lexicographically orderable. * <p> * * Examples: * <ul> * <li>{@code LocalTime.of(5, 30, 0)} is stored as an AttributeValue with the String "05:30"</li> * <li>{@code LocalTime.of(5, 30, 0, 1)} is stored as an AttributeValue with the String "05:30:00.000000001"</li> * </ul> * * <p> * This can be created via {@link #create()}. */ @SdkInternalApi @ThreadSafe @Immutable public final class LocalTimeAttributeConverter implements AttributeConverter<LocalTime> { private static final Visitor VISITOR = new Visitor(); private LocalTimeAttributeConverter() { } public static LocalTimeAttributeConverter create() { return new LocalTimeAttributeConverter(); } @Override public EnhancedType<LocalTime> type() { return EnhancedType.of(LocalTime.class); } @Override public AttributeValueType attributeValueType() { return AttributeValueType.S; } @Override public AttributeValue transformFrom(LocalTime input) { return AttributeValue.builder().s(input.toString()).build(); } @Override public LocalTime transformTo(AttributeValue input) { if (input.s() != null) { return EnhancedAttributeValue.fromString(input.s()).convert(VISITOR); } return EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR); } private static final class Visitor extends TypeConvertingVisitor<LocalTime> { private Visitor() { super(LocalTime.class, InstantAsStringAttributeConverter.class); } @Override public LocalTime convertString(String value) { try { return LocalTime.parse(value); } catch (DateTimeException e) { throw new IllegalArgumentException(e); } } } }
4,201
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/attribute/OptionalAttributeConverter.java
/* * 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.enhanced.dynamodb.internal.converter.attribute; import java.util.Optional; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.AttributeValueType; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.AttributeValues; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; /** * A converter between {@link Optional} and {@link EnhancedAttributeValue}. */ @SdkInternalApi @ThreadSafe @Immutable public class OptionalAttributeConverter<T> implements AttributeConverter<Optional<T>> { private final AttributeConverter delegate; private OptionalAttributeConverter(AttributeConverter delegate) { this.delegate = delegate; } public static OptionalAttributeConverter create(AttributeConverter delegate) { return new OptionalAttributeConverter(delegate); } @Override public EnhancedType<Optional<T>> type() { return EnhancedType.optionalOf(delegate.type().rawClass()); } @Override public AttributeValueType attributeValueType() { return AttributeValueType.S; } @Override public AttributeValue transformFrom(Optional<T> input) { if (!input.isPresent()) { return AttributeValues.nullAttributeValue(); } return delegate.transformFrom(input.get()); } @SuppressWarnings("unchecked") @Override public Optional<T> transformTo(AttributeValue input) { Optional<T> result; if (Boolean.TRUE.equals(input.nul())) { // This is safe - An Optional.empty() can be used for any Optional<?> subtype. result = Optional.empty(); } else { result = (Optional<T>) Optional.ofNullable(delegate.transformTo(input)); } return result; } }
4,202
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/attribute/OffsetDateTimeAsStringAttributeConverter.java
/* * 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.enhanced.dynamodb.internal.converter.attribute; import java.time.OffsetDateTime; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.AttributeValueType; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.TypeConvertingVisitor; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; /** * A converter between {@link OffsetDateTime} and {@link AttributeValue}. * * <p> * This stores values in DynamoDB as a string. * * <p> * Values are stored in ISO-8601 format, with nanosecond precision. If the offset has seconds then they will also be included, * even though this is not part of the ISO-8601 standard. For full ISO-8601 compliance, ensure your {@code OffsetDateTime}s do * not have offsets at the precision level of seconds. * * <p> * Examples: * <ul> * <li>{@code OffsetDateTime.MIN} is stored as * an AttributeValue with the String "-999999999-01-01T00:00+18:00"</li> * <li>{@code OffsetDateTime.MAX} is stored as * an AttributeValue with the String "+999999999-12-31T23:59:59.999999999-18:00"</li> * <li>{@code Instant.EPOCH.atOffset(ZoneOffset.UTC).plusSeconds(1)} is stored as * an AttributeValue with the String "1970-01-01T00:00:01Z"</li> * <li>{@code Instant.EPOCH.atOffset(ZoneOffset.UTC).minusSeconds(1)} is stored as * an AttributeValue with the String "1969-12-31T23:59:59Z"</li> * <li>{@code Instant.EPOCH.atOffset(ZoneOffset.UTC).plusMillis(1)} is stored as * an AttributeValue with the String "1970-01-01T00:00:00.001Z"</li> * <li>{@code Instant.EPOCH.atOffset(ZoneOffset.UTC).minusMillis(1)} is stored as * an AttributeValue with the String "1969-12-31T23:59:59.999Z"</li> * <li>{@code Instant.EPOCH.atOffset(ZoneOffset.UTC).plusNanos(1)} is stored as * an AttributeValue with the String "1970-01-01T00:00:00.000000001Z"</li> * <li>{@code Instant.EPOCH.atOffset(ZoneOffset.UTC).minusNanos(1)} is stored as * an AttributeValue with the String "1969-12-31T23:59:59.999999999Z"</li> * </ul> * See {@link OffsetDateTime} for more details on the serialization format. * <p> * This converter can read any values written by itself or {@link InstantAsStringAttributeConverter}, * and values without a time zone named written by{@link ZonedDateTimeAsStringAttributeConverter}. * Values written by {@code Instant} converters are treated as if they are in the UTC time zone * (and an offset of 0 seconds will be returned). * * <p> * This serialization is lexicographically orderable when the year is not negative. * <p> * This can be created via {@link #create()}. */ @SdkInternalApi @ThreadSafe @Immutable public final class OffsetDateTimeAsStringAttributeConverter implements AttributeConverter<OffsetDateTime> { private static final Visitor VISITOR = new Visitor(); public static OffsetDateTimeAsStringAttributeConverter create() { return new OffsetDateTimeAsStringAttributeConverter(); } @Override public EnhancedType<OffsetDateTime> type() { return EnhancedType.of(OffsetDateTime.class); } @Override public AttributeValueType attributeValueType() { return AttributeValueType.S; } @Override public AttributeValue transformFrom(OffsetDateTime input) { return AttributeValue.builder().s(input.toString()).build(); } @Override public OffsetDateTime transformTo(AttributeValue input) { try { if (input.s() != null) { return EnhancedAttributeValue.fromString(input.s()).convert(VISITOR); } return EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR); } catch (RuntimeException e) { throw new IllegalArgumentException(e); } } private static final class Visitor extends TypeConvertingVisitor<OffsetDateTime> { private Visitor() { super(OffsetDateTime.class, InstantAsStringAttributeConverter.class); } @Override public OffsetDateTime convertString(String value) { return OffsetDateTime.parse(value); } } }
4,203
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/attribute/CharacterAttributeConverter.java
/* * 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.enhanced.dynamodb.internal.converter.attribute; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.AttributeValueType; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.PrimitiveConverter; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.TypeConvertingVisitor; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.string.CharacterStringConverter; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; /** * A converter between {@link Character} and {@link AttributeValue}. * * <p> * This stores values in DynamoDB as a single-character string. * * <p> * This only supports reading a single character from DynamoDB. Any string longer than 1 character will cause a RuntimeException * during conversion. * * <p> * This can be created via {@link #create()}. */ @SdkInternalApi @ThreadSafe @Immutable public final class CharacterAttributeConverter implements AttributeConverter<Character>, PrimitiveConverter<Character> { private static final Visitor VISITOR = new Visitor(); private static final CharacterStringConverter STRING_CONVERTER = CharacterStringConverter.create(); private CharacterAttributeConverter() { } public static CharacterAttributeConverter create() { return new CharacterAttributeConverter(); } @Override public EnhancedType<Character> type() { return EnhancedType.of(Character.class); } @Override public AttributeValueType attributeValueType() { return AttributeValueType.S; } @Override public AttributeValue transformFrom(Character input) { return AttributeValue.builder().s(STRING_CONVERTER.toString(input)).build(); } @Override public Character transformTo(AttributeValue input) { if (input.s() != null) { return EnhancedAttributeValue.fromString(input.s()).convert(VISITOR); } return EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR); } @Override public EnhancedType<Character> primitiveType() { return EnhancedType.of(char.class); } private static final class Visitor extends TypeConvertingVisitor<Character> { private Visitor() { super(Character.class, CharacterAttributeConverter.class); } @Override public Character convertString(String value) { return STRING_CONVERTER.fromString(value); } } }
4,204
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/attribute/JsonNodeToAttributeValueMapConverter.java
/* * 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.enhanced.dynamodb.internal.converter.attribute; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.protocols.jsoncore.JsonNode; import software.amazon.awssdk.protocols.jsoncore.JsonNodeVisitor; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; @SdkInternalApi public class JsonNodeToAttributeValueMapConverter implements JsonNodeVisitor<AttributeValue> { private static final JsonNodeToAttributeValueMapConverter INSTANCE = new JsonNodeToAttributeValueMapConverter(); private JsonNodeToAttributeValueMapConverter() { } public static JsonNodeToAttributeValueMapConverter instance() { return INSTANCE; } @Override public AttributeValue visitNull() { return AttributeValue.fromNul(true); } @Override public AttributeValue visitBoolean(boolean bool) { return AttributeValue.builder().bool(bool).build(); } @Override public AttributeValue visitNumber(String number) { return AttributeValue.builder().n(number).build(); } @Override public AttributeValue visitString(String string) { return AttributeValue.builder().s(string).build(); } @Override public AttributeValue visitArray(List<JsonNode> array) { return AttributeValue.builder().l(array.stream() .map(node -> node.visit(this)) .collect(Collectors.toList())) .build(); } @Override public AttributeValue visitObject(Map<String, JsonNode> object) { return AttributeValue.builder().m(object.entrySet().stream() .collect(Collectors.toMap( Map.Entry::getKey, entry -> entry.getValue().visit(this), (left, right) -> left, LinkedHashMap::new))) .build(); } @Override public AttributeValue visitEmbeddedObject(Object embeddedObject) { throw new UnsupportedOperationException("Embedded objects are not supported within Document types."); } }
4,205
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/attribute/UuidAttributeConverter.java
/* * 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.enhanced.dynamodb.internal.converter.attribute; import java.util.UUID; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.AttributeValueType; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.TypeConvertingVisitor; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.string.UuidStringConverter; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; /** * A converter between {@link UUID} and {@link AttributeValue}. * * <p> * This supports storing and reading values in DynamoDB as a string. */ @SdkInternalApi @ThreadSafe @Immutable public final class UuidAttributeConverter implements AttributeConverter<UUID> { public static final UuidStringConverter STRING_CONVERTER = UuidStringConverter.create(); public static UuidAttributeConverter create() { return new UuidAttributeConverter(); } @Override public EnhancedType<UUID> type() { return EnhancedType.of(UUID.class); } @Override public AttributeValueType attributeValueType() { return AttributeValueType.S; } @Override public AttributeValue transformFrom(UUID input) { return AttributeValue.builder().s(STRING_CONVERTER.toString(input)).build(); } @Override public UUID transformTo(AttributeValue input) { return EnhancedAttributeValue.fromAttributeValue(input).convert(Visitor.INSTANCE); } private static final class Visitor extends TypeConvertingVisitor<UUID> { private static final Visitor INSTANCE = new Visitor(); private Visitor() { super(UUID.class, UuidAttributeConverter.class); } @Override public UUID convertString(String value) { return STRING_CONVERTER.fromString(value); } } }
4,206
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/attribute/IntegerAttributeConverter.java
/* * 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.enhanced.dynamodb.internal.converter.attribute; import java.time.Instant; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.AttributeValueType; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.PrimitiveConverter; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.TypeConvertingVisitor; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.string.IntegerStringConverter; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; /** * A converter between {@link Integer} and {@link AttributeValue}. * * <p> * This stores values in DynamoDB as a number. * * <p> * This supports reading numbers between {@link Integer#MIN_VALUE} and {@link Integer#MAX_VALUE} from DynamoDB. For smaller * numbers, consider using {@link ShortAttributeConverter}. For larger numbers, consider using {@link LongAttributeConverter} * or {@link BigIntegerAttributeConverter}. Numbers outside of the supported range will cause a {@link NumberFormatException} * on conversion. * * <p> * This does not support reading decimal numbers. For decimal numbers, consider using {@link FloatAttributeConverter}, * {@link DoubleAttributeConverter} or {@link BigDecimalAttributeConverter}. Decimal numbers will cause a * {@link NumberFormatException} on conversion. */ @SdkInternalApi @ThreadSafe @Immutable public final class IntegerAttributeConverter implements AttributeConverter<Integer>, PrimitiveConverter<Integer> { public static final IntegerStringConverter INTEGER_STRING_CONVERTER = IntegerStringConverter.create(); private IntegerAttributeConverter() { } public static IntegerAttributeConverter create() { return new IntegerAttributeConverter(); } @Override public EnhancedType<Integer> type() { return EnhancedType.of(Integer.class); } @Override public AttributeValueType attributeValueType() { return AttributeValueType.N; } @Override public AttributeValue transformFrom(Integer input) { return AttributeValue.builder().n(INTEGER_STRING_CONVERTER.toString(input)).build(); } @Override public Integer transformTo(AttributeValue input) { if (input.n() != null) { return EnhancedAttributeValue.fromNumber(input.n()).convert(Visitor.INSTANCE); } return EnhancedAttributeValue.fromAttributeValue(input).convert(Visitor.INSTANCE); } @Override public EnhancedType<Integer> primitiveType() { return EnhancedType.of(int.class); } private static final class Visitor extends TypeConvertingVisitor<Integer> { private static final Visitor INSTANCE = new Visitor(); private Visitor() { super(Instant.class, IntegerAttributeConverter.class); } @Override public Integer convertString(String value) { return INTEGER_STRING_CONVERTER.fromString(value); } @Override public Integer convertNumber(String value) { return INTEGER_STRING_CONVERTER.fromString(value); } } }
4,207
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/attribute/MonthDayAttributeConverter.java
/* * 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.enhanced.dynamodb.internal.converter.attribute; import java.time.MonthDay; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.AttributeValueType; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.TypeConvertingVisitor; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; /** * A converter between {@link MonthDay} and {@link AttributeValue}. * * <p> * This stores and reads values in DynamoDB as a String. * * <p> * MonthDays are stored in the official {@link MonthDay} format "--MM-DD", where: * <ol> * <li>M is a 2-character, zero-prefixed month between 01 and 12</li> * <li>D is a 2-character, zero-prefixed day between 01 and 31</li> * </ol> * See {@link MonthDay} for more details on the serialization format. * * <p> * This serialization is lexicographically orderable. * <p> * * Examples: * <ul> * <li>{@code MonthDay.of(5, 21)} is stored as as an AttributeValue with the String "--05-21"</li> * <li>{@code MonthDay.of(12, 1)} is stored as as an AttributeValue with the String "--12-01"</li> * </ul> * * <p> * This can be created via {@link #create()}. */ @SdkInternalApi @ThreadSafe @Immutable public final class MonthDayAttributeConverter implements AttributeConverter<MonthDay> { private static final Visitor VISITOR = new Visitor(); private MonthDayAttributeConverter() { } public static MonthDayAttributeConverter create() { return new MonthDayAttributeConverter(); } @Override public EnhancedType<MonthDay> type() { return EnhancedType.of(MonthDay.class); } @Override public AttributeValueType attributeValueType() { return AttributeValueType.S; } @Override public AttributeValue transformFrom(MonthDay input) { return AttributeValue.builder().s(input.toString()).build(); } @Override public MonthDay transformTo(AttributeValue input) { try { if (input.s() != null) { return EnhancedAttributeValue.fromString(input.s()).convert(VISITOR); } return EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR); } catch (RuntimeException e) { throw new IllegalArgumentException(e); } } private static final class Visitor extends TypeConvertingVisitor<MonthDay> { private Visitor() { super(MonthDay.class, MonthDayAttributeConverter.class); } @Override public MonthDay convertString(String value) { return MonthDay.parse(value); } } }
4,208
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/attribute/SetAttributeConverter.java
/* * 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.enhanced.dynamodb.internal.converter.attribute; import static java.util.stream.Collectors.toList; import java.util.Collection; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.NotThreadSafe; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.core.SdkBytes; import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.AttributeValueType; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.TypeConvertingVisitor; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import software.amazon.awssdk.utils.Validate; /** * A converter between a specific {@link Collection} type and {@link EnhancedAttributeValue}. * * <p> * This stores values in DynamoDB as a list of attribute values. This uses a configured {@link AttributeConverter} to convert * the collection contents to an attribute value. * * <p> * This supports reading a list of attribute values. This uses a configured {@link AttributeConverter} to convert * the collection contents. * * <p> * A builder is exposed to allow defining how the collection and element types are created and converted: * <code> * {@literal AttributeConverter<List<Integer>> listConverter = * CollectionAttributeConverter.builder(EnhancedType.listOf(Integer.class)) * .collectionConstructor(ArrayList::new) * .elementConverter(IntegerAttributeConverter.create()) * .build()} * </code> * * <p> * For frequently-used types, static methods are exposed to reduce the amount of boilerplate involved in creation: * <code> * {@literal AttributeConverter<List<Integer>> listConverter = * CollectionAttributeConverter.listConverter(IntegerAttributeConverter.create());} * </code> * <p> * <code> * {@literal AttributeConverter<Collection<Integer>> collectionConverer = * CollectionAttributeConverter.collectionConverter(IntegerAttributeConverter.create());} * </code> * <p> * <code> * {@literal AttributeConverter<Set<Integer>> setConverter = * CollectionAttributeConverter.setConverter(IntegerAttributeConverter.create());} * </code> * <p> * <code> * {@literal AttributeConverter<SortedSet<Integer>> sortedSetConverter = * CollectionAttributeConverter.sortedSetConverter(IntegerAttributeConverter.create());} * </code> * * @see MapAttributeConverter */ @SdkInternalApi @ThreadSafe @Immutable public class SetAttributeConverter<T extends Collection<?>> implements AttributeConverter<T> { private final Delegate<T, ?> delegate; private SetAttributeConverter(Delegate<T, ?> delegate) { this.delegate = delegate; } public static <U> SetAttributeConverter<Set<U>> setConverter(AttributeConverter<U> elementConverter) { return builder(EnhancedType.setOf(elementConverter.type())) .collectionConstructor(LinkedHashSet::new) .elementConverter(elementConverter) .build(); } public static <T extends Collection<U>, U> SetAttributeConverter.Builder<T, U> builder(EnhancedType<T> collectionType) { return new Builder<>(collectionType); } @Override public EnhancedType<T> type() { return delegate.type(); } @Override public AttributeValueType attributeValueType() { return delegate.attributeValueType(); } @Override public AttributeValue transformFrom(T input) { return delegate.transformFrom(input); } @Override public T transformTo(AttributeValue input) { return delegate.transformTo(input); } private static final class Delegate<T extends Collection<U>, U> implements AttributeConverter<T> { private final EnhancedType<T> type; private final Supplier<? extends T> collectionConstructor; private final AttributeConverter<U> elementConverter; private final AttributeValueType attributeValueType; private Delegate(Builder<T, U> builder) { this.type = builder.collectionType; this.collectionConstructor = builder.collectionConstructor; this.elementConverter = builder.elementConverter; this.attributeValueType = attributeValueTypeForSet(this.elementConverter); } @Override public EnhancedType<T> type() { return type; } @Override public AttributeValueType attributeValueType() { return attributeValueType; } @Override public AttributeValue transformFrom(T input) { return flatten(input.stream() .map(elementConverter::transformFrom) .collect(toList())); } @Override public T transformTo(AttributeValue input) { return EnhancedAttributeValue.fromAttributeValue(input) .convert(new TypeConvertingVisitor<T>(type.rawClass(), SetAttributeConverter.class) { @Override public T convertSetOfStrings(List<String> value) { return convertCollection(value, v -> AttributeValue.builder().s(v).build()); } @Override public T convertSetOfNumbers(List<String> value) { return convertCollection(value, v -> AttributeValue.builder().n(v).build()); } @Override public T convertSetOfBytes(List<SdkBytes> value) { return convertCollection(value, v -> AttributeValue.builder().b(v).build()); } @Override public T convertListOfAttributeValues(List<AttributeValue> value) { return convertCollection(value, Function.identity()); } private <V> T convertCollection(Collection<V> collection, Function<V, AttributeValue> transformFrom) { Collection<Object> result = (Collection<Object>) collectionConstructor.get(); collection.stream() .map(transformFrom) .map(elementConverter::transformTo) .forEach(result::add); // This is a safe cast - We know the values we added to the list // match the type that the customer requested. return (T) result; } }); } private AttributeValueType attributeValueTypeForSet(AttributeConverter<U> innerType) { switch (innerType.attributeValueType()) { case N: return AttributeValueType.NS; case S: return AttributeValueType.SS; case B: return AttributeValueType.BS; default: throw new IllegalArgumentException( String.format("SetAttributeConverter cannot be created with a parameterized type of '%s'. " + "Supported parameterized types must convert to B, S or N DynamoDB " + "AttributeValues.", innerType.type().rawClass())); } } /** * Takes a list of {@link AttributeValue}s and flattens into a resulting * single {@link AttributeValue} set of the corresponding type. */ public AttributeValue flatten(List<AttributeValue> listOfAttributeValues) { Validate.paramNotNull(listOfAttributeValues, "listOfAttributeValues"); Validate.noNullElements(listOfAttributeValues, "List must not have null values."); switch (attributeValueType) { case NS: return AttributeValue.builder() .ns(listOfAttributeValues.stream() .peek(av -> Validate.isTrue(av.n() != null, "Attribute value must be N.")) .map(AttributeValue::n) .collect(Collectors.toList())) .build(); case SS: return AttributeValue.builder() .ss(listOfAttributeValues.stream() .peek(av -> Validate.isTrue(av.s() != null, "Attribute value must be S.")) .map(AttributeValue::s) .collect(Collectors.toList())) .build(); case BS: return AttributeValue.builder() .bs(listOfAttributeValues.stream() .peek(av -> Validate.isTrue(av.b() != null, "Attribute value must be B.")) .map(AttributeValue::b) .collect(Collectors.toList())) .build(); default: throw new IllegalStateException("Unsupported set attribute value type: " + attributeValueType); } } } @NotThreadSafe public static final class Builder<T extends Collection<U>, U> { private final EnhancedType<T> collectionType; private Supplier<? extends T> collectionConstructor; private AttributeConverter<U> elementConverter; private Builder(EnhancedType<T> collectionType) { this.collectionType = collectionType; } public Builder<T, U> collectionConstructor(Supplier<? extends T> collectionConstructor) { this.collectionConstructor = collectionConstructor; return this; } public Builder<T, U> elementConverter(AttributeConverter<U> elementConverter) { this.elementConverter = elementConverter; return this; } public SetAttributeConverter<T> build() { return new SetAttributeConverter<>(new Delegate<>(this)); } } }
4,209
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/attribute/StringBuilderAttributeConverter.java
/* * 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.enhanced.dynamodb.internal.converter.attribute; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.AttributeValueType; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; /** * A converter between {@link StringBuffer} and {@link AttributeValue}. * * <p> * This stores values in DynamoDB as a string. * * <p> * This supports reading any DynamoDB attribute type into a string builder. */ @SdkInternalApi @ThreadSafe @Immutable public final class StringBuilderAttributeConverter implements AttributeConverter<StringBuilder> { public static final StringAttributeConverter STRING_CONVERTER = StringAttributeConverter.create(); public static StringBuilderAttributeConverter create() { return new StringBuilderAttributeConverter(); } @Override public EnhancedType<StringBuilder> type() { return EnhancedType.of(StringBuilder.class); } @Override public AttributeValueType attributeValueType() { return AttributeValueType.S; } @Override public AttributeValue transformFrom(StringBuilder input) { return STRING_CONVERTER.transformFrom(input.toString()); } @Override public StringBuilder transformTo(AttributeValue input) { return new StringBuilder(STRING_CONVERTER.transformTo(input)); } }
4,210
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/BigDecimalStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.math.BigDecimal; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link BigDecimal} and {@link String}. * * <p> * This converts values using {@link BigDecimal#toString()} and {@link BigDecimal#BigDecimal(String)}. */ @SdkInternalApi @ThreadSafe @Immutable public class BigDecimalStringConverter implements StringConverter<BigDecimal> { private BigDecimalStringConverter() { } public static BigDecimalStringConverter create() { return new BigDecimalStringConverter(); } @Override public EnhancedType<BigDecimal> type() { return EnhancedType.of(BigDecimal.class); } @Override public BigDecimal fromString(String string) { return new BigDecimal(string); } }
4,211
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/DefaultStringConverterProvider.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.concurrent.ConcurrentHashMap; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.NotThreadSafe; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.PrimitiveConverter; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverterProvider; import software.amazon.awssdk.utils.Validate; /** * <p> * Included converters: * <ul> * <li>{@link AtomicIntegerStringConverter}</li> * <li>{@link AtomicLongStringConverter}</li> * <li>{@link BigDecimalStringConverter}</li> * <li>{@link BigIntegerStringConverter}</li> * <li>{@link DoubleStringConverter}</li> * <li>{@link DurationStringConverter}</li> * <li>{@link FloatStringConverter}</li> * <li>{@link InstantStringConverter}</li> * <li>{@link IntegerStringConverter}</li> * <li>{@link LocalDateStringConverter}</li> * <li>{@link LocalDateTimeStringConverter}</li> * <li>{@link LocalTimeStringConverter}</li> * <li>{@link LocaleStringConverter}</li> * <li>{@link LongStringConverter}</li> * <li>{@link MonthDayStringConverter}</li> * <li>{@link OptionalDoubleStringConverter}</li> * <li>{@link OptionalIntStringConverter}</li> * <li>{@link OptionalLongStringConverter}</li> * <li>{@link ShortStringConverter}</li> * <li>{@link CharacterArrayStringConverter}</li> * <li>{@link CharacterStringConverter}</li> * <li>{@link CharSequenceStringConverter}</li> * <li>{@link OffsetDateTimeStringConverter}</li> * <li>{@link PeriodStringConverter}</li> * <li>{@link StringStringConverter}</li> * <li>{@link StringBufferStringConverter}</li> * <li>{@link StringBuilderStringConverter}</li> * <li>{@link UriStringConverter}</li> * <li>{@link UrlStringConverter}</li> * <li>{@link UuidStringConverter}</li> * <li>{@link ZonedDateTimeStringConverter}</li> * <li>{@link ZoneIdStringConverter}</li> * <li>{@link ZoneOffsetStringConverter}</li> * <li>{@link ByteArrayStringConverter}</li> * <li>{@link ByteStringConverter}</li> * <li>{@link SdkBytesStringConverter}</li> * <li>{@link AtomicBooleanStringConverter}</li> * <li>{@link BooleanStringConverter}</li> * </ul> * * <p> * This can be created via {@link #create()}. */ @SdkInternalApi @ThreadSafe @Immutable public class DefaultStringConverterProvider implements StringConverterProvider { private final ConcurrentHashMap<EnhancedType<?>, StringConverter<?>> converterCache = new ConcurrentHashMap<>(); private DefaultStringConverterProvider(Builder builder) { // Converters are used in the REVERSE order of how they were added to the builder. for (int i = builder.converters.size() - 1; i >= 0; i--) { StringConverter<?> converter = builder.converters.get(i); converterCache.put(converter.type(), converter); if (converter instanceof PrimitiveConverter) { PrimitiveConverter primitiveConverter = (PrimitiveConverter) converter; converterCache.put(primitiveConverter.primitiveType(), converter); } } } /** * Create a builder for a {@link DefaultStringConverterProvider}. */ public static Builder builder() { return new Builder(); } public static DefaultStringConverterProvider create() { return DefaultStringConverterProvider.builder() .addConverter(ByteArrayStringConverter.create()) .addConverter(CharacterArrayStringConverter.create()) .addConverter(BooleanStringConverter.create()) .addConverter(ShortStringConverter.create()) .addConverter(IntegerStringConverter.create()) .addConverter(LongStringConverter.create()) .addConverter(FloatStringConverter.create()) .addConverter(DoubleStringConverter.create()) .addConverter(CharacterStringConverter.create()) .addConverter(ByteStringConverter.create()) .addConverter(StringStringConverter.create()) .addConverter(CharSequenceStringConverter.create()) .addConverter(StringBufferStringConverter.create()) .addConverter(StringBuilderStringConverter.create()) .addConverter(BigIntegerStringConverter.create()) .addConverter(BigDecimalStringConverter.create()) .addConverter(AtomicLongStringConverter.create()) .addConverter(AtomicIntegerStringConverter.create()) .addConverter(AtomicBooleanStringConverter.create()) .addConverter(OptionalIntStringConverter.create()) .addConverter(OptionalLongStringConverter.create()) .addConverter(OptionalDoubleStringConverter.create()) .addConverter(InstantStringConverter.create()) .addConverter(DurationStringConverter.create()) .addConverter(LocalDateStringConverter.create()) .addConverter(LocalTimeStringConverter.create()) .addConverter(LocalDateTimeStringConverter.create()) .addConverter(LocaleStringConverter.create()) .addConverter(OffsetTimeStringConverter.create()) .addConverter(OffsetDateTimeStringConverter.create()) .addConverter(ZonedDateTimeStringConverter.create()) .addConverter(YearStringConverter.create()) .addConverter(YearMonthStringConverter.create()) .addConverter(MonthDayStringConverter.create()) .addConverter(PeriodStringConverter.create()) .addConverter(ZoneOffsetStringConverter.create()) .addConverter(ZoneIdStringConverter.create()) .addConverter(UuidStringConverter.create()) .addConverter(UrlStringConverter.create()) .addConverter(UriStringConverter.create()) .build(); } @Override public <T> StringConverter converterFor(EnhancedType<T> enhancedType) { @SuppressWarnings("unchecked") // We initialized correctly, so this is safe. StringConverter<T> converter = (StringConverter<T>) converterCache.get(enhancedType); if (converter == null) { throw new IllegalArgumentException("No string converter exists for " + enhancedType.rawClass()); } return converter; } /** * A builder for configuring and creating {@link DefaultStringConverterProvider}s. */ @NotThreadSafe public static class Builder { private List<StringConverter<?>> converters = new ArrayList<>(); private Builder() { } public Builder addConverters(Collection<? extends StringConverter<?>> converters) { Validate.paramNotNull(converters, "converters"); Validate.noNullElements(converters, "Converters must not contain null members."); this.converters.addAll(converters); return this; } public Builder addConverter(StringConverter<?> converter) { Validate.paramNotNull(converter, "converter"); this.converters.add(converter); return this; } public Builder clearConverters() { this.converters.clear(); return this; } public DefaultStringConverterProvider build() { return new DefaultStringConverterProvider(this); } } }
4,212
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/MonthDayStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.time.MonthDay; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link MonthDay} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class MonthDayStringConverter implements StringConverter<MonthDay> { private MonthDayStringConverter() { } public static MonthDayStringConverter create() { return new MonthDayStringConverter(); } @Override public EnhancedType<MonthDay> type() { return EnhancedType.of(MonthDay.class); } @Override public MonthDay fromString(String string) { return MonthDay.parse(string); } }
4,213
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/SdkNumberStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.core.SdkNumber; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link SdkNumber} and {@link String}. * * <p> * This converts values using {@link SdkNumber#toString()} and {@link SdkNumber#fromString(String)}}. */ @SdkInternalApi @ThreadSafe @Immutable public class SdkNumberStringConverter implements StringConverter<SdkNumber> { private SdkNumberStringConverter() { } public static SdkNumberStringConverter create() { return new SdkNumberStringConverter(); } @Override public EnhancedType<SdkNumber> type() { return EnhancedType.of(SdkNumber.class); } @Override public SdkNumber fromString(String string) { return SdkNumber.fromString(string); } }
4,214
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/AtomicBooleanStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.util.concurrent.atomic.AtomicBoolean; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link AtomicBoolean} and {@link String}. * * <p> * This converts values using {@link BooleanStringConverter}. */ @SdkInternalApi @ThreadSafe @Immutable public class AtomicBooleanStringConverter implements StringConverter<AtomicBoolean> { private static BooleanStringConverter BOOLEAN_CONVERTER = BooleanStringConverter.create(); private AtomicBooleanStringConverter() { } public static AtomicBooleanStringConverter create() { return new AtomicBooleanStringConverter(); } @Override public EnhancedType<AtomicBoolean> type() { return EnhancedType.of(AtomicBoolean.class); } @Override public String toString(AtomicBoolean object) { return BOOLEAN_CONVERTER.toString(object.get()); } @Override public AtomicBoolean fromString(String string) { return new AtomicBoolean(BOOLEAN_CONVERTER.fromString(string)); } }
4,215
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/CharSequenceStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link CharSequence} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class CharSequenceStringConverter implements StringConverter<CharSequence> { private CharSequenceStringConverter() { } public static CharSequenceStringConverter create() { return new CharSequenceStringConverter(); } @Override public EnhancedType<CharSequence> type() { return EnhancedType.of(CharSequence.class); } @Override public CharSequence fromString(String string) { return string; } }
4,216
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/OffsetDateTimeStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.time.OffsetDateTime; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link OffsetDateTime} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class OffsetDateTimeStringConverter implements StringConverter<OffsetDateTime> { private OffsetDateTimeStringConverter() { } public static OffsetDateTimeStringConverter create() { return new OffsetDateTimeStringConverter(); } @Override public EnhancedType<OffsetDateTime> type() { return EnhancedType.of(OffsetDateTime.class); } @Override public OffsetDateTime fromString(String string) { return OffsetDateTime.parse(string); } }
4,217
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/StringStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link String} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class StringStringConverter implements StringConverter<String> { private StringStringConverter() { } public static StringStringConverter create() { return new StringStringConverter(); } @Override public EnhancedType<String> type() { return EnhancedType.of(String.class); } @Override public String toString(String object) { return object; } @Override public String fromString(String string) { return string; } }
4,218
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/DoubleStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.PrimitiveConverter; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link Double} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class DoubleStringConverter implements StringConverter<Double>, PrimitiveConverter<Double> { private DoubleStringConverter() { } public static DoubleStringConverter create() { return new DoubleStringConverter(); } @Override public EnhancedType<Double> type() { return EnhancedType.of(Double.class); } @Override public EnhancedType<Double> primitiveType() { return EnhancedType.of(double.class); } @Override public Double fromString(String string) { return Double.valueOf(string); } }
4,219
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/SdkBytesStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.core.SdkBytes; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; import software.amazon.awssdk.utils.BinaryUtils; /** * A converter between {@link SdkBytes} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class SdkBytesStringConverter implements StringConverter<SdkBytes> { private SdkBytesStringConverter() { } public static SdkBytesStringConverter create() { return new SdkBytesStringConverter(); } @Override public EnhancedType<SdkBytes> type() { return EnhancedType.of(SdkBytes.class); } @Override public String toString(SdkBytes object) { return BinaryUtils.toBase64(object.asByteArray()); } @Override public SdkBytes fromString(String string) { return SdkBytes.fromByteArray(BinaryUtils.fromBase64(string)); } }
4,220
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/OptionalIntStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.util.OptionalInt; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link OptionalInt} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class OptionalIntStringConverter implements StringConverter<OptionalInt> { private static IntegerStringConverter INTEGER_CONVERTER = IntegerStringConverter.create(); private OptionalIntStringConverter() { } public static OptionalIntStringConverter create() { return new OptionalIntStringConverter(); } @Override public EnhancedType<OptionalInt> type() { return EnhancedType.of(OptionalInt.class); } @Override public String toString(OptionalInt object) { if (!object.isPresent()) { return null; } return INTEGER_CONVERTER.toString(object.getAsInt()); } @Override public OptionalInt fromString(String string) { if (string == null) { return OptionalInt.empty(); } return OptionalInt.of(INTEGER_CONVERTER.fromString(string)); } }
4,221
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/YearStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.time.Year; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link Year} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class YearStringConverter implements StringConverter<Year> { private YearStringConverter() { } public static YearStringConverter create() { return new YearStringConverter(); } @Override public EnhancedType<Year> type() { return EnhancedType.of(Year.class); } @Override public Year fromString(String string) { return Year.parse(string); } }
4,222
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/LocaleStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.util.Locale; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link Locale} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class LocaleStringConverter implements StringConverter<Locale> { private LocaleStringConverter() { } public static LocaleStringConverter create() { return new LocaleStringConverter(); } @Override public EnhancedType<Locale> type() { return EnhancedType.of(Locale.class); } @Override public Locale fromString(String string) { return Locale.forLanguageTag(string); } @Override public String toString(Locale locale) { return locale.toLanguageTag(); } }
4,223
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/ByteStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.math.BigInteger; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.PrimitiveConverter; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link BigInteger} and {@link String}. * * <p> * This converts values using {@link Byte#toString()} and {@link Byte#valueOf(String)}. */ @SdkInternalApi @ThreadSafe @Immutable public class ByteStringConverter implements StringConverter<Byte>, PrimitiveConverter<Byte> { private ByteStringConverter() { } public static ByteStringConverter create() { return new ByteStringConverter(); } @Override public EnhancedType<Byte> type() { return EnhancedType.of(Byte.class); } @Override public EnhancedType<Byte> primitiveType() { return EnhancedType.of(byte.class); } @Override public Byte fromString(String string) { return Byte.valueOf(string); } }
4,224
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/DurationStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.time.Duration; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link Duration} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class DurationStringConverter implements StringConverter<Duration> { private DurationStringConverter() { } public static DurationStringConverter create() { return new DurationStringConverter(); } @Override public EnhancedType<Duration> type() { return EnhancedType.of(Duration.class); } @Override public Duration fromString(String string) { return Duration.parse(string); } }
4,225
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/UuidStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.util.UUID; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link UUID} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class UuidStringConverter implements StringConverter<UUID> { private UuidStringConverter() { } public static UuidStringConverter create() { return new UuidStringConverter(); } @Override public EnhancedType<UUID> type() { return EnhancedType.of(UUID.class); } @Override public UUID fromString(String string) { return UUID.fromString(string); } }
4,226
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/ZonedDateTimeStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.time.ZonedDateTime; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link ZonedDateTime} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class ZonedDateTimeStringConverter implements StringConverter<ZonedDateTime> { private ZonedDateTimeStringConverter() { } public static ZonedDateTimeStringConverter create() { return new ZonedDateTimeStringConverter(); } @Override public EnhancedType<ZonedDateTime> type() { return EnhancedType.of(ZonedDateTime.class); } @Override public ZonedDateTime fromString(String string) { return ZonedDateTime.parse(string); } }
4,227
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/BigIntegerStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.math.BigInteger; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link BigInteger} and {@link String}. * * <p> * This converts values using {@link BigInteger#toString()} and {@link BigInteger#BigInteger(String)}. */ @SdkInternalApi @ThreadSafe @Immutable public class BigIntegerStringConverter implements StringConverter<BigInteger> { private BigIntegerStringConverter() { } public static BigIntegerStringConverter create() { return new BigIntegerStringConverter(); } @Override public EnhancedType<BigInteger> type() { return EnhancedType.of(BigInteger.class); } @Override public BigInteger fromString(String string) { return new BigInteger(string); } }
4,228
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/ByteArrayStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.math.BigInteger; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; import software.amazon.awssdk.utils.BinaryUtils; /** * A converter between {@link BigInteger} and {@link String}. * * <p> * This converts bytes to a base 64 string. */ @SdkInternalApi @ThreadSafe @Immutable public class ByteArrayStringConverter implements StringConverter<byte[]> { private ByteArrayStringConverter() { } public static ByteArrayStringConverter create() { return new ByteArrayStringConverter(); } @Override public EnhancedType<byte[]> type() { return EnhancedType.of(byte[].class); } @Override public String toString(byte[] object) { return BinaryUtils.toBase64(object); } @Override public byte[] fromString(String string) { return BinaryUtils.fromBase64(string); } }
4,229
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/UriStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.net.URI; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link URI} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class UriStringConverter implements StringConverter<URI> { private UriStringConverter() { } public static UriStringConverter create() { return new UriStringConverter(); } @Override public EnhancedType<URI> type() { return EnhancedType.of(URI.class); } @Override public URI fromString(String string) { return URI.create(string); } }
4,230
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/AtomicLongStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.util.concurrent.atomic.AtomicLong; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link AtomicLong} and {@link String}. * * <p> * This converts values using {@link LongStringConverter}. */ @SdkInternalApi @ThreadSafe @Immutable public class AtomicLongStringConverter implements StringConverter<AtomicLong> { private static LongStringConverter LONG_CONVERTER = LongStringConverter.create(); private AtomicLongStringConverter() { } public static AtomicLongStringConverter create() { return new AtomicLongStringConverter(); } @Override public EnhancedType<AtomicLong> type() { return EnhancedType.of(AtomicLong.class); } @Override public String toString(AtomicLong object) { return LONG_CONVERTER.toString(object.get()); } @Override public AtomicLong fromString(String string) { return new AtomicLong(LONG_CONVERTER.fromString(string)); } }
4,231
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/ShortStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.PrimitiveConverter; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link Short} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class ShortStringConverter implements StringConverter<Short>, PrimitiveConverter<Short> { private ShortStringConverter() { } public static ShortStringConverter create() { return new ShortStringConverter(); } @Override public EnhancedType<Short> type() { return EnhancedType.of(Short.class); } @Override public EnhancedType<Short> primitiveType() { return EnhancedType.of(short.class); } @Override public Short fromString(String string) { return Short.valueOf(string); } }
4,232
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/InstantStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.time.Instant; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link Instant} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class InstantStringConverter implements StringConverter<Instant> { private InstantStringConverter() { } public static InstantStringConverter create() { return new InstantStringConverter(); } @Override public EnhancedType<Instant> type() { return EnhancedType.of(Instant.class); } @Override public Instant fromString(String string) { return Instant.parse(string); } }
4,233
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/CharacterArrayStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@code char[]} and {@link String}. * * <p> * This converts values using {@link String#String(char[])} and {@link String#toCharArray()}. */ @SdkInternalApi @ThreadSafe @Immutable public class CharacterArrayStringConverter implements StringConverter<char[]> { private CharacterArrayStringConverter() { } public static CharacterArrayStringConverter create() { return new CharacterArrayStringConverter(); } @Override public EnhancedType<char[]> type() { return EnhancedType.of(char[].class); } @Override public String toString(char[] object) { return new String(object); } @Override public char[] fromString(String string) { return string.toCharArray(); } }
4,234
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/OptionalLongStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.util.OptionalLong; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link OptionalLong} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class OptionalLongStringConverter implements StringConverter<OptionalLong> { private static LongStringConverter LONG_CONVERTER = LongStringConverter.create(); private OptionalLongStringConverter() { } public static OptionalLongStringConverter create() { return new OptionalLongStringConverter(); } @Override public EnhancedType<OptionalLong> type() { return EnhancedType.of(OptionalLong.class); } @Override public String toString(OptionalLong object) { if (!object.isPresent()) { return null; } return LONG_CONVERTER.toString(object.getAsLong()); } @Override public OptionalLong fromString(String string) { if (string == null) { return OptionalLong.empty(); } return OptionalLong.of(LONG_CONVERTER.fromString(string)); } }
4,235
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/OptionalDoubleStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.util.OptionalDouble; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link OptionalDouble} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class OptionalDoubleStringConverter implements StringConverter<OptionalDouble> { private static DoubleStringConverter DOUBLE_CONVERTER = DoubleStringConverter.create(); private OptionalDoubleStringConverter() { } public static OptionalDoubleStringConverter create() { return new OptionalDoubleStringConverter(); } @Override public EnhancedType<OptionalDouble> type() { return EnhancedType.of(OptionalDouble.class); } @Override public String toString(OptionalDouble object) { if (!object.isPresent()) { return null; } return DOUBLE_CONVERTER.toString(object.getAsDouble()); } @Override public OptionalDouble fromString(String string) { if (string == null) { return OptionalDouble.empty(); } return OptionalDouble.of(DOUBLE_CONVERTER.fromString(string)); } }
4,236
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/AtomicIntegerStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.util.concurrent.atomic.AtomicInteger; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link AtomicInteger} and {@link String}. * * <p> * This converts values using {@link IntegerStringConverter}. */ @SdkInternalApi @ThreadSafe @Immutable public class AtomicIntegerStringConverter implements StringConverter<AtomicInteger> { private static IntegerStringConverter INTEGER_CONVERTER = IntegerStringConverter.create(); private AtomicIntegerStringConverter() { } public static AtomicIntegerStringConverter create() { return new AtomicIntegerStringConverter(); } @Override public EnhancedType<AtomicInteger> type() { return EnhancedType.of(AtomicInteger.class); } @Override public String toString(AtomicInteger object) { return INTEGER_CONVERTER.toString(object.get()); } @Override public AtomicInteger fromString(String string) { return new AtomicInteger(INTEGER_CONVERTER.fromString(string)); } }
4,237
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/OffsetTimeStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.time.OffsetTime; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link OffsetTime} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class OffsetTimeStringConverter implements StringConverter<OffsetTime> { private OffsetTimeStringConverter() { } public static OffsetTimeStringConverter create() { return new OffsetTimeStringConverter(); } @Override public EnhancedType<OffsetTime> type() { return EnhancedType.of(OffsetTime.class); } @Override public OffsetTime fromString(String string) { return OffsetTime.parse(string); } }
4,238
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/StringBufferStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link StringBuffer} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class StringBufferStringConverter implements StringConverter<StringBuffer> { private StringBufferStringConverter() { } public static StringBufferStringConverter create() { return new StringBufferStringConverter(); } @Override public EnhancedType<StringBuffer> type() { return EnhancedType.of(StringBuffer.class); } @Override public StringBuffer fromString(String string) { return new StringBuffer(string); } }
4,239
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/UrlStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.net.MalformedURLException; import java.net.URL; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link URL} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class UrlStringConverter implements StringConverter<URL> { private UrlStringConverter() { } public static UrlStringConverter create() { return new UrlStringConverter(); } @Override public EnhancedType<URL> type() { return EnhancedType.of(URL.class); } @Override public URL fromString(String string) { try { return new URL(string); } catch (MalformedURLException e) { throw new IllegalArgumentException("URL format was incorrect: " + string, e); } } }
4,240
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/BooleanStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.math.BigInteger; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.PrimitiveConverter; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link BigInteger} and {@link String}. * * <p> * This converts values to strings using {@link Boolean#toString()}. This converts the literal string values "true" and "false" * to a boolean. Any other string values will result in an exception. */ @SdkInternalApi @ThreadSafe @Immutable public class BooleanStringConverter implements StringConverter<Boolean>, PrimitiveConverter<Boolean> { private BooleanStringConverter() { } public static BooleanStringConverter create() { return new BooleanStringConverter(); } @Override public EnhancedType<Boolean> type() { return EnhancedType.of(Boolean.class); } @Override public EnhancedType<Boolean> primitiveType() { return EnhancedType.of(boolean.class); } @Override public Boolean fromString(String string) { switch (string) { case "true": return true; case "false": return false; default: throw new IllegalArgumentException("Boolean string was not 'true' or 'false': " + string); } } }
4,241
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/CharacterStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.PrimitiveConverter; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; import software.amazon.awssdk.utils.Validate; /** * A converter between {@link Character} and {@link String}. * * <p> * This converts values using {@link Character#toString()} and {@link String#charAt(int)}. If the string value is longer * than 1 character, an exception will be raised. */ @SdkInternalApi @ThreadSafe @Immutable public class CharacterStringConverter implements StringConverter<Character>, PrimitiveConverter<Character> { private CharacterStringConverter() { } public static CharacterStringConverter create() { return new CharacterStringConverter(); } @Override public EnhancedType<Character> type() { return EnhancedType.of(Character.class); } @Override public EnhancedType<Character> primitiveType() { return EnhancedType.of(char.class); } @Override public Character fromString(String string) { Validate.isTrue(string.length() == 1, "Character string was not of length 1: %s", string); return string.charAt(0); } }
4,242
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/YearMonthStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.time.YearMonth; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link YearMonth} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class YearMonthStringConverter implements StringConverter<YearMonth> { private YearMonthStringConverter() { } public static YearMonthStringConverter create() { return new YearMonthStringConverter(); } @Override public EnhancedType<YearMonth> type() { return EnhancedType.of(YearMonth.class); } @Override public YearMonth fromString(String string) { return YearMonth.parse(string); } }
4,243
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/ZoneOffsetStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.time.ZoneOffset; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link ZoneOffset} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class ZoneOffsetStringConverter implements StringConverter<ZoneOffset> { private ZoneOffsetStringConverter() { } public static ZoneOffsetStringConverter create() { return new ZoneOffsetStringConverter(); } @Override public EnhancedType<ZoneOffset> type() { return EnhancedType.of(ZoneOffset.class); } @Override public ZoneOffset fromString(String string) { return ZoneOffset.of(string); } }
4,244
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/StringBuilderStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link StringBuilder} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class StringBuilderStringConverter implements StringConverter<StringBuilder> { private StringBuilderStringConverter() { } public static StringBuilderStringConverter create() { return new StringBuilderStringConverter(); } @Override public EnhancedType<StringBuilder> type() { return EnhancedType.of(StringBuilder.class); } @Override public StringBuilder fromString(String string) { return new StringBuilder(string); } }
4,245
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/FloatStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.PrimitiveConverter; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link Float} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class FloatStringConverter implements StringConverter<Float>, PrimitiveConverter<Float> { private FloatStringConverter() { } public static FloatStringConverter create() { return new FloatStringConverter(); } @Override public EnhancedType<Float> type() { return EnhancedType.of(Float.class); } @Override public EnhancedType<Float> primitiveType() { return EnhancedType.of(float.class); } @Override public Float fromString(String string) { return Float.valueOf(string); } }
4,246
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/LocalTimeStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.time.LocalTime; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link LocalTime} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class LocalTimeStringConverter implements StringConverter<LocalTime> { private LocalTimeStringConverter() { } public static LocalTimeStringConverter create() { return new LocalTimeStringConverter(); } @Override public EnhancedType<LocalTime> type() { return EnhancedType.of(LocalTime.class); } @Override public LocalTime fromString(String string) { return LocalTime.parse(string); } }
4,247
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/LocalDateStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.time.LocalDate; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link LocalDate} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class LocalDateStringConverter implements StringConverter<LocalDate> { private LocalDateStringConverter() { } public static LocalDateStringConverter create() { return new LocalDateStringConverter(); } @Override public EnhancedType<LocalDate> type() { return EnhancedType.of(LocalDate.class); } @Override public LocalDate fromString(String string) { return LocalDate.parse(string); } }
4,248
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/LocalDateTimeStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.time.LocalDateTime; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link LocalDateTime} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class LocalDateTimeStringConverter implements StringConverter<LocalDateTime> { private LocalDateTimeStringConverter() { } public static LocalDateTimeStringConverter create() { return new LocalDateTimeStringConverter(); } @Override public EnhancedType<LocalDateTime> type() { return EnhancedType.of(LocalDateTime.class); } @Override public LocalDateTime fromString(String string) { return LocalDateTime.parse(string); } }
4,249
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/IntegerStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.PrimitiveConverter; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link Integer} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class IntegerStringConverter implements StringConverter<Integer>, PrimitiveConverter<Integer> { private IntegerStringConverter() { } public static IntegerStringConverter create() { return new IntegerStringConverter(); } @Override public EnhancedType<Integer> type() { return EnhancedType.of(Integer.class); } @Override public EnhancedType<Integer> primitiveType() { return EnhancedType.of(int.class); } @Override public Integer fromString(String string) { return Integer.valueOf(string); } }
4,250
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/PeriodStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.time.Period; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link Period} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class PeriodStringConverter implements StringConverter<Period> { private PeriodStringConverter() { } public static PeriodStringConverter create() { return new PeriodStringConverter(); } @Override public EnhancedType<Period> type() { return EnhancedType.of(Period.class); } @Override public Period fromString(String string) { return Period.parse(string); } }
4,251
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/ZoneIdStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import java.time.ZoneId; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link ZoneId} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class ZoneIdStringConverter implements StringConverter<ZoneId> { private ZoneIdStringConverter() { } public static ZoneIdStringConverter create() { return new ZoneIdStringConverter(); } @Override public EnhancedType<ZoneId> type() { return EnhancedType.of(ZoneId.class); } @Override public ZoneId fromString(String string) { return ZoneId.of(string); } }
4,252
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/string/LongStringConverter.java
/* * 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.enhanced.dynamodb.internal.converter.string; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.PrimitiveConverter; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverter; /** * A converter between {@link Long} and {@link String}. */ @SdkInternalApi @ThreadSafe @Immutable public class LongStringConverter implements StringConverter<Long>, PrimitiveConverter<Long> { private LongStringConverter() { } public static LongStringConverter create() { return new LongStringConverter(); } @Override public EnhancedType<Long> type() { return EnhancedType.of(Long.class); } @Override public EnhancedType<Long> primitiveType() { return EnhancedType.of(long.class); } @Override public Long fromString(String string) { return Long.valueOf(string); } }
4,253
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/MetaTableSchemaCache.java
/* * 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.enhanced.dynamodb.internal.mapper; import java.util.HashMap; import java.util.Map; import java.util.Optional; import software.amazon.awssdk.annotations.SdkInternalApi; /** * A cache that can store lazily initialized MetaTableSchema objects used by the TableSchema creation classes to * facilitate self-referencing recursive builds. */ @SdkInternalApi @SuppressWarnings("unchecked") public class MetaTableSchemaCache { private final Map<Class<?>, MetaTableSchema<?>> cacheMap = new HashMap<>(); public <T> MetaTableSchema<T> getOrCreate(Class<T> mappedClass) { return (MetaTableSchema<T>) cacheMap().computeIfAbsent( mappedClass, ignored -> MetaTableSchema.create(mappedClass)); } public <T> Optional<MetaTableSchema<T>> get(Class<T> mappedClass) { return Optional.ofNullable((MetaTableSchema<T>) cacheMap().get(mappedClass)); } private Map<Class<?>, MetaTableSchema<?>> cacheMap() { return this.cacheMap; } }
4,254
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/DefaultParameterizedType.java
/* * 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.enhanced.dynamodb.internal.mapper; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.utils.Validate; /** * An implementation of {@link ParameterizedType} that guarantees its raw type is always a {@link Class}. */ @SdkInternalApi @ThreadSafe public final class DefaultParameterizedType implements ParameterizedType { private final Class<?> rawType; private final Type[] arguments; private DefaultParameterizedType(Class<?> rawType, Type... arguments) { Validate.notEmpty(arguments, "Arguments must not be empty."); Validate.noNullElements(arguments, "Arguments cannot contain null values."); this.rawType = Validate.paramNotNull(rawType, "rawType"); this.arguments = arguments; } public static ParameterizedType parameterizedType(Class<?> rawType, Type... arguments) { return new DefaultParameterizedType(rawType, arguments); } @Override public Class<?> getRawType() { return rawType; } @Override public Type[] getActualTypeArguments() { return arguments.clone(); } @Override public Type getOwnerType() { return null; } }
4,255
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/BeanAttributeGetter.java
/* * 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.enhanced.dynamodb.internal.mapper; import java.lang.reflect.Method; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.utils.Validate; @FunctionalInterface @SdkInternalApi @SuppressWarnings("unchecked") public interface BeanAttributeGetter<BeanT, GetterT> extends Function<BeanT, GetterT> { static <BeanT, GetterT> BeanAttributeGetter<BeanT, GetterT> create(Class<BeanT> beanClass, Method getter) { Validate.isTrue(getter.getParameterCount() == 0, "%s.%s has parameters, despite being named like a getter.", beanClass, getter.getName()); return LambdaToMethodBridgeBuilder.create(BeanAttributeGetter.class) .lambdaMethodName("apply") .runtimeLambdaSignature(Object.class, Object.class) .compileTimeLambdaSignature(getter.getReturnType(), beanClass) .targetMethod(getter) .build(); } }
4,256
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/MetaTableSchema.java
/* * 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.enhanced.dynamodb.internal.mapper; import java.util.Collection; import java.util.List; import java.util.Map; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.TableMetadata; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; /** * An implementation of {@link TableSchema} that can be instantiated as an uninitialized reference and then lazily * initialized later with a concrete {@link TableSchema} at which point it will behave as the real object. * <p> * This allows an immutable {@link TableSchema} to be declared and used in a self-referential recursive way within its * builder/definition path. Any attempt to use the {@link MetaTableSchema} as a concrete {@link TableSchema} before * calling {@link #initialize(TableSchema)} will cause an exception to be thrown. */ @SdkInternalApi public class MetaTableSchema<T> implements TableSchema<T> { private TableSchema<T> concreteTableSchema; private MetaTableSchema() { } public static <T> MetaTableSchema<T> create(Class<T> itemClass) { return new MetaTableSchema<>(); } @Override public T mapToItem(Map<String, AttributeValue> attributeMap) { return concreteTableSchema().mapToItem(attributeMap); } @Override public Map<String, AttributeValue> itemToMap(T item, boolean ignoreNulls) { return concreteTableSchema().itemToMap(item, ignoreNulls); } @Override public Map<String, AttributeValue> itemToMap(T item, Collection<String> attributes) { return concreteTableSchema().itemToMap(item, attributes); } @Override public AttributeValue attributeValue(T item, String attributeName) { return concreteTableSchema().attributeValue(item, attributeName); } @Override public TableMetadata tableMetadata() { return concreteTableSchema().tableMetadata(); } @Override public EnhancedType<T> itemType() { return concreteTableSchema().itemType(); } @Override public List<String> attributeNames() { return concreteTableSchema().attributeNames(); } @Override public boolean isAbstract() { return concreteTableSchema().isAbstract(); } @Override public AttributeConverter<T> converterForAttribute(Object key) { return concreteTableSchema.converterForAttribute(key); } public void initialize(TableSchema<T> realTableSchema) { if (this.concreteTableSchema != null) { throw new IllegalStateException("A MetaTableSchema can only be initialized with a concrete TableSchema " + "instance once."); } this.concreteTableSchema = realTableSchema; } public TableSchema<T> concreteTableSchema() { if (this.concreteTableSchema == null) { throw new IllegalStateException("A MetaTableSchema must be initialized with a concrete TableSchema " + "instance by calling 'initialize' before it can be used as a " + "TableSchema itself"); } return this.concreteTableSchema; } public boolean isInitialized() { return this.concreteTableSchema != null; } }
4,257
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/ObjectConstructor.java
/* * 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.enhanced.dynamodb.internal.mapper; import java.lang.reflect.Constructor; import java.util.function.Supplier; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.utils.Validate; @FunctionalInterface @SdkInternalApi @SuppressWarnings("unchecked") public interface ObjectConstructor<BeanT> extends Supplier<BeanT> { static <BeanT> ObjectConstructor<BeanT> create(Class<BeanT> beanClass, Constructor<BeanT> noArgsConstructor) { Validate.isTrue(noArgsConstructor.getParameterCount() == 0, "%s has no default constructor.", beanClass); return LambdaToMethodBridgeBuilder.create(ObjectConstructor.class) .lambdaMethodName("get") .runtimeLambdaSignature(Object.class) .compileTimeLambdaSignature(beanClass) .targetMethod(noArgsConstructor) .build(); } }
4,258
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/ObjectGetterMethod.java
/* * 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.enhanced.dynamodb.internal.mapper; import java.lang.reflect.Method; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; @FunctionalInterface @SdkInternalApi @SuppressWarnings("unchecked") public interface ObjectGetterMethod<BeanT, GetterT> extends Function<BeanT, GetterT> { static <BeanT, GetterT> ObjectGetterMethod<BeanT, GetterT> create(Class<BeanT> beanClass, Method buildMethod) { return LambdaToMethodBridgeBuilder.create(ObjectGetterMethod.class) .lambdaMethodName("apply") .runtimeLambdaSignature(Object.class, Object.class) .compileTimeLambdaSignature(buildMethod.getReturnType(), beanClass) .targetMethod(buildMethod) .build(); } }
4,259
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/AtomicCounter.java
/* * 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.enhanced.dynamodb.internal.mapper; import java.util.Objects; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.attribute.LongAttributeConverter; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; @SdkInternalApi public final class AtomicCounter { public static final String KEY_PREFIX = "_"; private static final String DELTA_ATTRIBUTE_NAME = KEY_PREFIX + "Delta"; private static final String STARTVALUE_ATTRIBUTE_NAME = KEY_PREFIX + "Start"; private final CounterAttribute delta; private final CounterAttribute startValue; private AtomicCounter(Builder builder) { this.delta = new CounterAttribute(builder.delta, DELTA_ATTRIBUTE_NAME); this.startValue = new CounterAttribute(builder.startValue, STARTVALUE_ATTRIBUTE_NAME); } public static Builder builder() { return new Builder(); } public CounterAttribute delta() { return delta; } public CounterAttribute startValue() { return startValue; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } AtomicCounter that = (AtomicCounter) o; if (!Objects.equals(delta, that.delta)) { return false; } return Objects.equals(startValue, that.startValue); } @Override public int hashCode() { int result = Objects.hashCode(delta); result = 31 * result + Objects.hashCode(startValue); return result; } public static final class Builder { private Long delta; private Long startValue; private Builder() { } public Builder delta(Long delta) { this.delta = delta; return this; } public Builder startValue(Long startValue) { this.startValue = startValue; return this; } public AtomicCounter build() { return new AtomicCounter(this); } } public static class CounterAttribute { private static final AttributeConverter<Long> CONVERTER = LongAttributeConverter.create(); private final Long value; private final String name; CounterAttribute(Long value, String name) { this.value = value; this.name = name; } public Long value() { return value; } public String name() { return name; } public static AttributeValue resolvedValue(Long value) { return CONVERTER.transformFrom(value); } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } CounterAttribute that = (CounterAttribute) o; if (!Objects.equals(value, that.value)) { return false; } return Objects.equals(name, that.name); } @Override public int hashCode() { int result = Objects.hashCode(value); result = 31 * result + Objects.hashCode(name); return result; } } }
4,260
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/LambdaToMethodBridgeBuilder.java
/* * 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.enhanced.dynamodb.internal.mapper; import static software.amazon.awssdk.utils.FunctionalUtils.invokeSafely; import java.lang.invoke.LambdaMetafactory; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.utils.Either; @SdkInternalApi public class LambdaToMethodBridgeBuilder<T> { private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); private final Class<T> lambdaType; private String lambdaMethodName; private Class<?> postEraseLambdaReturnType; private Class<?>[] postEraseLambdaParameters; private Class<?> preEraseLambdaReturnType; private Class<?>[] preEraseLambdaParameters; private Either<Method, Constructor<?>> targetMethod; private LambdaToMethodBridgeBuilder(Class<T> lambdaType) { this.lambdaType = lambdaType; } public static <T> LambdaToMethodBridgeBuilder<T> create(Class<T> lambdaType) { return new LambdaToMethodBridgeBuilder<>(lambdaType); } public LambdaToMethodBridgeBuilder<T> lambdaMethodName(String lambdaMethodName) { this.lambdaMethodName = lambdaMethodName; return this; } public LambdaToMethodBridgeBuilder<T> runtimeLambdaSignature(Class<?> returnType, Class<?>... parameters) { this.postEraseLambdaReturnType = returnType; this.postEraseLambdaParameters = parameters.clone(); return this; } public LambdaToMethodBridgeBuilder<T> compileTimeLambdaSignature(Class<?> returnType, Class<?>... parameters) { this.preEraseLambdaReturnType = returnType; this.preEraseLambdaParameters = parameters.clone(); return this; } public LambdaToMethodBridgeBuilder<T> targetMethod(Method method) { this.targetMethod = Either.left(method); return this; } public LambdaToMethodBridgeBuilder<T> targetMethod(Constructor<?> method) { this.targetMethod = Either.right(method); return this; } public T build() { try { MethodHandle targetMethodHandle = targetMethod.map( m -> invokeSafely(() -> LOOKUP.unreflect(m)), c -> invokeSafely(() -> LOOKUP.unreflectConstructor(c))); return lambdaType.cast( LambdaMetafactory.metafactory(LOOKUP, lambdaMethodName, MethodType.methodType(lambdaType), MethodType.methodType(postEraseLambdaReturnType, postEraseLambdaParameters), targetMethodHandle, MethodType.methodType(preEraseLambdaReturnType, preEraseLambdaParameters)) .getTarget() .invoke()); } catch (Throwable e) { throw new IllegalArgumentException("Failed to generate method handle.", e); } } }
4,261
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/BeanAttributeSetter.java
/* * 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.enhanced.dynamodb.internal.mapper; import java.lang.reflect.Method; import java.util.function.BiConsumer; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.utils.Validate; import software.amazon.awssdk.utils.internal.ReflectionUtils; @FunctionalInterface @SdkInternalApi public interface BeanAttributeSetter<BeanT, GetterT> extends BiConsumer<BeanT, GetterT> { @SuppressWarnings("unchecked") static <BeanT, SetterT> BeanAttributeSetter<BeanT, SetterT> create(Class<BeanT> beanClass, Method setter) { Validate.isTrue(setter.getParameterCount() == 1, "%s.%s doesn't have just 1 parameter, despite being named like a setter.", beanClass, setter.getName()); Class<?> setterInputClass = setter.getParameters()[0].getType(); Class<?> boxedInputClass = ReflectionUtils.getWrappedClass(setterInputClass); return LambdaToMethodBridgeBuilder.create(BeanAttributeSetter.class) .lambdaMethodName("accept") .runtimeLambdaSignature(void.class, Object.class, Object.class) .compileTimeLambdaSignature(void.class, beanClass, boxedInputClass) .targetMethod(setter) .build(); } }
4,262
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/StaticGetterMethod.java
/* * 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.enhanced.dynamodb.internal.mapper; import java.lang.reflect.Method; import java.util.function.Supplier; import software.amazon.awssdk.annotations.SdkInternalApi; @FunctionalInterface @SdkInternalApi @SuppressWarnings("unchecked") public interface StaticGetterMethod<GetterT> extends Supplier<GetterT> { static <GetterT> StaticGetterMethod<GetterT> create(Method buildMethod) { return LambdaToMethodBridgeBuilder.create(StaticGetterMethod.class) .lambdaMethodName("get") .runtimeLambdaSignature(Object.class) .compileTimeLambdaSignature(buildMethod.getReturnType()) .targetMethod(buildMethod) .build(); } }
4,263
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/AttributeType.java
/* * 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.enhanced.dynamodb.internal.mapper; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.AttributeValueType; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; @SdkInternalApi public interface AttributeType<T> { AttributeValue objectToAttributeValue(T object); T attributeValueToObject(AttributeValue attributeValue); AttributeValueType attributeValueType(); }
4,264
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/StaticIndexMetadata.java
/* * 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.enhanced.dynamodb.internal.mapper; import java.util.Optional; import software.amazon.awssdk.annotations.NotThreadSafe; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.IndexMetadata; import software.amazon.awssdk.enhanced.dynamodb.KeyAttributeMetadata; @SdkInternalApi public class StaticIndexMetadata implements IndexMetadata { private final String name; private final KeyAttributeMetadata partitionKey; private final KeyAttributeMetadata sortKey; private StaticIndexMetadata(Builder b) { this.name = b.name; this.partitionKey = b.partitionKey; this.sortKey = b.sortKey; } public static Builder builder() { return new Builder(); } public static Builder builderFrom(IndexMetadata index) { return index == null ? builder() : builder().name(index.name()) .partitionKey(index.partitionKey().orElse(null)) .sortKey(index.sortKey().orElse(null)); } @Override public String name() { return this.name; } @Override public Optional<KeyAttributeMetadata> partitionKey() { return Optional.ofNullable(this.partitionKey); } @Override public Optional<KeyAttributeMetadata> sortKey() { return Optional.ofNullable(this.sortKey); } @NotThreadSafe public static class Builder { private String name; private KeyAttributeMetadata partitionKey; private KeyAttributeMetadata sortKey; private Builder() { } public Builder name(String name) { this.name = name; return this; } public Builder partitionKey(KeyAttributeMetadata partitionKey) { this.partitionKey = partitionKey; return this; } public Builder sortKey(KeyAttributeMetadata sortKey) { this.sortKey = sortKey; return this; } public StaticIndexMetadata build() { return new StaticIndexMetadata(this); } } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } StaticIndexMetadata that = (StaticIndexMetadata) o; if (name != null ? !name.equals(that.name) : that.name != null) { return false; } if (partitionKey != null ? !partitionKey.equals(that.partitionKey) : that.partitionKey != null) { return false; } return sortKey != null ? sortKey.equals(that.sortKey) : that.sortKey == null; } @Override public int hashCode() { int result = name != null ? name.hashCode() : 0; result = 31 * result + (partitionKey != null ? partitionKey.hashCode() : 0); result = 31 * result + (sortKey != null ? sortKey.hashCode() : 0); return result; } }
4,265
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/StaticKeyAttributeMetadata.java
/* * 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.enhanced.dynamodb.internal.mapper; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.AttributeValueType; import software.amazon.awssdk.enhanced.dynamodb.KeyAttributeMetadata; @SdkInternalApi public class StaticKeyAttributeMetadata implements KeyAttributeMetadata { private final String name; private final AttributeValueType attributeValueType; private StaticKeyAttributeMetadata(String name, AttributeValueType attributeValueType) { this.name = name; this.attributeValueType = attributeValueType; } public static StaticKeyAttributeMetadata create(String name, AttributeValueType attributeValueType) { return new StaticKeyAttributeMetadata(name, attributeValueType); } @Override public String name() { return this.name; } @Override public AttributeValueType attributeValueType() { return this.attributeValueType; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } StaticKeyAttributeMetadata staticKey = (StaticKeyAttributeMetadata) o; if (name != null ? !name.equals(staticKey.name) : staticKey.name != null) { return false; } return attributeValueType == staticKey.attributeValueType; } @Override public int hashCode() { int result = name != null ? name.hashCode() : 0; result = 31 * result + (attributeValueType != null ? attributeValueType.hashCode() : 0); return result; } }
4,266
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/ResolvedImmutableAttribute.java
/* * 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.enhanced.dynamodb.internal.mapper; import static software.amazon.awssdk.enhanced.dynamodb.internal.AttributeValues.nullAttributeValue; import static software.amazon.awssdk.enhanced.dynamodb.internal.EnhancedClientUtils.isNullAttributeValue; import java.util.function.BiConsumer; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.mapper.ImmutableAttribute; import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableMetadata; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; @SdkInternalApi public final class ResolvedImmutableAttribute<T, B> { private final String attributeName; private final Function<T, AttributeValue> getAttributeMethod; private final BiConsumer<B, AttributeValue> updateBuilderMethod; private final StaticTableMetadata tableMetadata; private final AttributeConverter attributeConverter; private ResolvedImmutableAttribute(String attributeName, Function<T, AttributeValue> getAttributeMethod, BiConsumer<B, AttributeValue> updateBuilderMethod, StaticTableMetadata tableMetadata, AttributeConverter attributeConverter) { this.attributeName = attributeName; this.getAttributeMethod = getAttributeMethod; this.updateBuilderMethod = updateBuilderMethod; this.tableMetadata = tableMetadata; this.attributeConverter = attributeConverter; } public static <T, B, R> ResolvedImmutableAttribute<T, B> create(ImmutableAttribute<T, B, R> immutableAttribute, AttributeConverter<R> attributeConverter) { AttributeType<R> attributeType = StaticAttributeType.create(attributeConverter); Function<T, AttributeValue> getAttributeValueWithTransform = item -> { R value = immutableAttribute.getter().apply(item); return value == null ? nullAttributeValue() : attributeType.objectToAttributeValue(value); }; // When setting a value on the java object, do not explicitly set nulls as this can cause an NPE to be thrown // if the target attribute type is a primitive. BiConsumer<B, AttributeValue> updateBuilderWithTransform = (builder, attributeValue) -> { // If the attributeValue is null, do not attempt to marshal if (isNullAttributeValue(attributeValue)) { return; } R value = attributeType.attributeValueToObject(attributeValue); if (value != null) { immutableAttribute.setter().accept(builder, value); } }; StaticTableMetadata.Builder tableMetadataBuilder = StaticTableMetadata.builder(); immutableAttribute.tags().forEach(tag -> { tag.validateType(immutableAttribute.name(), immutableAttribute.type(), attributeType.attributeValueType()); tag.modifyMetadata(immutableAttribute.name(), attributeType.attributeValueType()).accept(tableMetadataBuilder); }); return new ResolvedImmutableAttribute<>(immutableAttribute.name(), getAttributeValueWithTransform, updateBuilderWithTransform, tableMetadataBuilder.build(), attributeConverter); } public <T1, B1> ResolvedImmutableAttribute<T1, B1> transform( Function<T1, T> transformItem, Function<B1, B> transformBuilder) { return new ResolvedImmutableAttribute<>( attributeName, item -> { T otherItem = transformItem.apply(item); // If the containing object is null don't attempt to read attributes from it return otherItem == null ? nullAttributeValue() : getAttributeMethod.apply(otherItem); }, (item, value) -> updateBuilderMethod.accept(transformBuilder.apply(item), value), tableMetadata, attributeConverter); } public String attributeName() { return attributeName; } public Function<T, AttributeValue> attributeGetterMethod() { return getAttributeMethod; } public BiConsumer<B, AttributeValue> updateItemMethod() { return updateBuilderMethod; } public StaticTableMetadata tableMetadata() { return tableMetadata; } public AttributeConverter attributeConverter() { return attributeConverter; } }
4,267
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/UpdateBehaviorTag.java
/* * 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.enhanced.dynamodb.internal.mapper; import java.util.function.Consumer; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.AttributeValueType; import software.amazon.awssdk.enhanced.dynamodb.TableMetadata; import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticAttributeTag; import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableMetadata; import software.amazon.awssdk.enhanced.dynamodb.mapper.UpdateBehavior; @SdkInternalApi public class UpdateBehaviorTag implements StaticAttributeTag { private static final String CUSTOM_METADATA_KEY_PREFIX = "UpdateBehavior:"; private static final UpdateBehavior DEFAULT_UPDATE_BEHAVIOR = UpdateBehavior.WRITE_ALWAYS; private static final UpdateBehaviorTag WRITE_ALWAYS_TAG = new UpdateBehaviorTag(UpdateBehavior.WRITE_ALWAYS); private static final UpdateBehaviorTag WRITE_IF_NOT_EXISTS_TAG = new UpdateBehaviorTag(UpdateBehavior.WRITE_IF_NOT_EXISTS); private final UpdateBehavior updateBehavior; private UpdateBehaviorTag(UpdateBehavior updateBehavior) { this.updateBehavior = updateBehavior; } public static UpdateBehaviorTag fromUpdateBehavior(UpdateBehavior updateBehavior) { switch (updateBehavior) { case WRITE_ALWAYS: return WRITE_ALWAYS_TAG; case WRITE_IF_NOT_EXISTS: return WRITE_IF_NOT_EXISTS_TAG; default: throw new IllegalArgumentException("Update behavior '" + updateBehavior + "' not supported"); } } public static UpdateBehavior resolveForAttribute(String attributeName, TableMetadata tableMetadata) { String metadataKey = CUSTOM_METADATA_KEY_PREFIX + attributeName; return tableMetadata.customMetadataObject(metadataKey, UpdateBehavior.class).orElse(DEFAULT_UPDATE_BEHAVIOR); } @Override public Consumer<StaticTableMetadata.Builder> modifyMetadata(String attributeName, AttributeValueType attributeValueType) { return metadata -> metadata.addCustomMetadataObject(CUSTOM_METADATA_KEY_PREFIX + attributeName, this.updateBehavior); } }
4,268
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/StaticAttributeType.java
/* * 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.enhanced.dynamodb.internal.mapper; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.AttributeValueType; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; @SdkInternalApi public final class StaticAttributeType<T> implements AttributeType<T> { private final AttributeConverter<T> attributeConverter; private final AttributeValueType attributeValueType; private StaticAttributeType(AttributeConverter<T> attributeConverter) { this.attributeConverter = attributeConverter; this.attributeValueType = attributeConverter.attributeValueType(); } public static <T> AttributeType<T> create( AttributeConverter<T> attributeConverter) { return new StaticAttributeType<>(attributeConverter); } @Override public AttributeValue objectToAttributeValue(T object) { return this.attributeConverter.transformFrom(object); } @Override public T attributeValueToObject(AttributeValue attributeValue) { return this.attributeConverter.transformTo(attributeValue); } @Override public AttributeValueType attributeValueType() { return attributeValueType; } }
4,269
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/mapper/BeanTableSchemaAttributeTags.java
/* * 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.enhanced.dynamodb.internal.mapper; import java.util.Arrays; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.extensions.annotations.DynamoDbAtomicCounter; import software.amazon.awssdk.enhanced.dynamodb.mapper.BeanTableSchema; import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticAttributeTag; import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticAttributeTags; import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.BeanTableSchemaAttributeTag; import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbPartitionKey; import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbSecondaryPartitionKey; import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbSecondarySortKey; import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbSortKey; import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbUpdateBehavior; /** * Static provider class for core {@link BeanTableSchema} attribute tags. Each of the implemented annotations has a * corresponding reference to this class in a * {@link BeanTableSchemaAttributeTag} * meta-annotation. */ @SdkInternalApi public final class BeanTableSchemaAttributeTags { private BeanTableSchemaAttributeTags() { } public static StaticAttributeTag attributeTagFor(DynamoDbPartitionKey annotation) { return StaticAttributeTags.primaryPartitionKey(); } public static StaticAttributeTag attributeTagFor(DynamoDbSortKey annotation) { return StaticAttributeTags.primarySortKey(); } public static StaticAttributeTag attributeTagFor(DynamoDbSecondaryPartitionKey annotation) { return StaticAttributeTags.secondaryPartitionKey(Arrays.asList(annotation.indexNames())); } public static StaticAttributeTag attributeTagFor(DynamoDbSecondarySortKey annotation) { return StaticAttributeTags.secondarySortKey(Arrays.asList(annotation.indexNames())); } public static StaticAttributeTag attributeTagFor(DynamoDbUpdateBehavior annotation) { return StaticAttributeTags.updateBehavior(annotation.value()); } public static StaticAttributeTag attributeTagFor(DynamoDbAtomicCounter annotation) { return StaticAttributeTags.atomicCounter(annotation.delta(), annotation.startValue()); } }
4,270
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/document/DefaultEnhancedDocument.java
/* * 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.enhanced.dynamodb.internal.document; import static java.util.Collections.unmodifiableList; import static java.util.Collections.unmodifiableMap; import static software.amazon.awssdk.enhanced.dynamodb.internal.document.JsonStringFormatHelper.addEscapeCharacters; import static software.amazon.awssdk.enhanced.dynamodb.internal.document.JsonStringFormatHelper.stringValue; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import software.amazon.awssdk.annotations.Immutable; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.core.SdkBytes; import software.amazon.awssdk.core.SdkNumber; import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.AttributeConverterProvider; import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; import software.amazon.awssdk.enhanced.dynamodb.document.EnhancedDocument; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.ChainConverterProvider; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.StringConverterProvider; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.attribute.JsonItemAttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.attribute.ListAttributeConverter; import software.amazon.awssdk.enhanced.dynamodb.internal.converter.attribute.MapAttributeConverter; import software.amazon.awssdk.protocols.jsoncore.JsonNode; import software.amazon.awssdk.protocols.jsoncore.JsonNodeParser; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import software.amazon.awssdk.utils.Lazy; import software.amazon.awssdk.utils.StringUtils; import software.amazon.awssdk.utils.Validate; /** * Default implementation of {@link EnhancedDocument} used by the SDK to create Enhanced Documents. Attributes are initially saved * as a String-Object Map when documents are created using the builder. Conversion to an AttributeValueMap is done lazily when * values are accessed. When the document is retrieved from DynamoDB, the AttributeValueMap is internally saved as the attribute * value map. Custom objects or collections are saved in the enhancedTypeMap to preserve the generic class information. Note that * no default ConverterProviders are assigned, so ConverterProviders must be passed in the builder when creating enhanced * documents. */ @Immutable @SdkInternalApi public class DefaultEnhancedDocument implements EnhancedDocument { private static final Lazy<IllegalStateException> NULL_SET_ERROR = new Lazy<>( () -> new IllegalStateException("Set must not have null values.")); private static final JsonItemAttributeConverter JSON_ATTRIBUTE_CONVERTER = JsonItemAttributeConverter.create(); private static final String VALIDATE_TYPE_ERROR = "Values of type %s are not supported by this API, please use the " + "%s%s API instead"; private static final AttributeValue NULL_ATTRIBUTE_VALUE = AttributeValue.fromNul(true); private final Map<String, Object> nonAttributeValueMap; private final Map<String, EnhancedType> enhancedTypeMap; private final List<AttributeConverterProvider> attributeConverterProviders; private final ChainConverterProvider attributeConverterChain; private final Lazy<Map<String, AttributeValue>> attributeValueMap = new Lazy<>(this::initializeAttributeValueMap); public DefaultEnhancedDocument(DefaultBuilder builder) { this.nonAttributeValueMap = unmodifiableMap(new LinkedHashMap<>(builder.nonAttributeValueMap)); this.attributeConverterProviders = unmodifiableList(new ArrayList<>(builder.attributeConverterProviders)); this.attributeConverterChain = ChainConverterProvider.create(attributeConverterProviders); this.enhancedTypeMap = unmodifiableMap(builder.enhancedTypeMap); } public static Builder builder() { return new DefaultBuilder(); } public static <T> AttributeConverter<T> converterForClass(EnhancedType<T> type, ChainConverterProvider chainConverterProvider) { if (type.rawClass().isAssignableFrom(List.class)) { return (AttributeConverter<T>) ListAttributeConverter .create(converterForClass(type.rawClassParameters().get(0), chainConverterProvider)); } if (type.rawClass().isAssignableFrom(Map.class)) { return (AttributeConverter<T>) MapAttributeConverter.mapConverter( StringConverterProvider.defaultProvider().converterFor(type.rawClassParameters().get(0)), converterForClass(type.rawClassParameters().get(1), chainConverterProvider)); } return Optional.ofNullable(chainConverterProvider.converterFor(type)) .orElseThrow(() -> new IllegalStateException( "AttributeConverter not found for class " + type + ". Please add an AttributeConverterProvider for this type. If it is a default type, add the " + "DefaultAttributeConverterProvider to the builder.")); } @Override public Builder toBuilder() { return new DefaultBuilder(this); } @Override public List<AttributeConverterProvider> attributeConverterProviders() { return attributeConverterProviders; } @Override public boolean isNull(String attributeName) { if (!isPresent(attributeName)) { return false; } Object attributeValue = nonAttributeValueMap.get(attributeName); return attributeValue == null || NULL_ATTRIBUTE_VALUE.equals(attributeValue); } @Override public boolean isPresent(String attributeName) { return nonAttributeValueMap.containsKey(attributeName); } @Override public <T> T get(String attributeName, EnhancedType<T> type) { AttributeValue attributeValue = attributeValueMap.getValue().get(attributeName); if (attributeValue == null) { return null; } return fromAttributeValue(attributeValue, type); } @Override public String getString(String attributeName) { return get(attributeName, String.class); } @Override public SdkNumber getNumber(String attributeName) { return get(attributeName, SdkNumber.class); } @Override public <T> T get(String attributeName, Class<T> clazz) { checkAndValidateClass(clazz, false); return get(attributeName, EnhancedType.of(clazz)); } @Override public SdkBytes getBytes(String attributeName) { return get(attributeName, SdkBytes.class); } @Override public Set<String> getStringSet(String attributeName) { return get(attributeName, EnhancedType.setOf(String.class)); } @Override public Set<SdkNumber> getNumberSet(String attributeName) { return get(attributeName, EnhancedType.setOf(SdkNumber.class)); } @Override public Set<SdkBytes> getBytesSet(String attributeName) { return get(attributeName, EnhancedType.setOf(SdkBytes.class)); } @Override public <T> List<T> getList(String attributeName, EnhancedType<T> type) { return get(attributeName, EnhancedType.listOf(type)); } @Override public <K, V> Map<K, V> getMap(String attributeName, EnhancedType<K> keyType, EnhancedType<V> valueType) { return get(attributeName, EnhancedType.mapOf(keyType, valueType)); } @Override public String getJson(String attributeName) { AttributeValue attributeValue = attributeValueMap.getValue().get(attributeName); if (attributeValue == null) { return null; } return stringValue(JSON_ATTRIBUTE_CONVERTER.transformTo(attributeValue)); } @Override public Boolean getBoolean(String attributeName) { return get(attributeName, Boolean.class); } @Override public List<AttributeValue> getListOfUnknownType(String attributeName) { AttributeValue attributeValue = attributeValueMap.getValue().get(attributeName); if (attributeValue == null) { return null; } if (!attributeValue.hasL()) { throw new IllegalStateException("Cannot get a List from attribute value of Type " + attributeValue.type()); } return attributeValue.l(); } @Override public Map<String, AttributeValue> getMapOfUnknownType(String attributeName) { AttributeValue attributeValue = attributeValueMap.getValue().get(attributeName); if (attributeValue == null) { return null; } if (!attributeValue.hasM()) { throw new IllegalStateException("Cannot get a Map from attribute value of Type " + attributeValue.type()); } return attributeValue.m(); } @Override public String toJson() { if (nonAttributeValueMap.isEmpty()) { return "{}"; } return attributeValueMap.getValue().entrySet().stream() .map(entry -> "\"" + addEscapeCharacters(entry.getKey()) + "\":" + stringValue(JSON_ATTRIBUTE_CONVERTER.transformTo(entry.getValue()))) .collect(Collectors.joining(",", "{", "}")); } @Override public Map<String, AttributeValue> toMap() { return attributeValueMap.getValue(); } private Map<String, AttributeValue> initializeAttributeValueMap() { Map<String, AttributeValue> result = new LinkedHashMap<>(this.nonAttributeValueMap.size()); this.nonAttributeValueMap.forEach((k, v) -> { if (v == null) { result.put(k, NULL_ATTRIBUTE_VALUE); } else { result.put(k, toAttributeValue(v, enhancedTypeMap.getOrDefault(k, EnhancedType.of(v.getClass())))); } }); return result; } private <T> AttributeValue toAttributeValue(T value, EnhancedType<T> enhancedType) { if (value instanceof AttributeValue) { return (AttributeValue) value; } return converterForClass(enhancedType, attributeConverterChain).transformFrom(value); } private <T> T fromAttributeValue(AttributeValue attributeValue, EnhancedType<T> type) { if (type.rawClass().equals(AttributeValue.class)) { return (T) attributeValue; } return converterForClass(type, attributeConverterChain).transformTo(attributeValue); } public static class DefaultBuilder implements EnhancedDocument.Builder { Map<String, Object> nonAttributeValueMap = new LinkedHashMap<>(); Map<String, EnhancedType> enhancedTypeMap = new HashMap<>(); List<AttributeConverterProvider> attributeConverterProviders = new ArrayList<>(); private DefaultBuilder() { } public DefaultBuilder(DefaultEnhancedDocument enhancedDocument) { this.nonAttributeValueMap = new LinkedHashMap<>(enhancedDocument.nonAttributeValueMap); this.attributeConverterProviders = new ArrayList<>(enhancedDocument.attributeConverterProviders); this.enhancedTypeMap = new HashMap<>(enhancedDocument.enhancedTypeMap); } public Builder putObject(String attributeName, Object value) { putObject(attributeName, value, false); return this; } private Builder putObject(String attributeName, Object value, boolean ignoreNullValue) { if (!ignoreNullValue) { checkInvalidAttribute(attributeName, value); } else { validateAttributeName(attributeName); } enhancedTypeMap.remove(attributeName); nonAttributeValueMap.remove(attributeName); nonAttributeValueMap.put(attributeName, value); return this; } @Override public Builder putString(String attributeName, String value) { return putObject(attributeName, value); } @Override public Builder putNumber(String attributeName, Number value) { return putObject(attributeName, value); } @Override public Builder putBytes(String attributeName, SdkBytes value) { return putObject(attributeName, value); } @Override public Builder putBoolean(String attributeName, boolean value) { return putObject(attributeName, Boolean.valueOf(value)); } @Override public Builder putNull(String attributeName) { return putObject(attributeName, null, true); } @Override public Builder putStringSet(String attributeName, Set<String> values) { checkInvalidAttribute(attributeName, values); if (values.stream().anyMatch(Objects::isNull)) { throw NULL_SET_ERROR.getValue(); } return put(attributeName, values, EnhancedType.setOf(String.class)); } @Override public Builder putNumberSet(String attributeName, Set<Number> values) { checkInvalidAttribute(attributeName, values); Set<SdkNumber> sdkNumberSet = values.stream().map(number -> { if (number == null) { throw NULL_SET_ERROR.getValue(); } return SdkNumber.fromString(number.toString()); }).collect(Collectors.toCollection(LinkedHashSet::new)); return put(attributeName, sdkNumberSet, EnhancedType.setOf(SdkNumber.class)); } @Override public Builder putBytesSet(String attributeName, Set<SdkBytes> values) { checkInvalidAttribute(attributeName, values); if (values.stream().anyMatch(Objects::isNull)) { throw NULL_SET_ERROR.getValue(); } return put(attributeName, values, EnhancedType.setOf(SdkBytes.class)); } @Override public <T> Builder putList(String attributeName, List<T> value, EnhancedType<T> type) { checkInvalidAttribute(attributeName, value); Validate.paramNotNull(type, "type"); return put(attributeName, value, EnhancedType.listOf(type)); } @Override public <T> Builder put(String attributeName, T value, EnhancedType<T> type) { checkInvalidAttribute(attributeName, value); Validate.notNull(attributeName, "attributeName cannot be null."); enhancedTypeMap.put(attributeName, type); nonAttributeValueMap.remove(attributeName); nonAttributeValueMap.put(attributeName, value); return this; } @Override public <T> Builder put(String attributeName, T value, Class<T> type) { checkAndValidateClass(type, true); put(attributeName, value, EnhancedType.of(type)); return this; } @Override public <K, V> Builder putMap(String attributeName, Map<K, V> value, EnhancedType<K> keyType, EnhancedType<V> valueType) { checkInvalidAttribute(attributeName, value); Validate.notNull(attributeName, "attributeName cannot be null."); Validate.paramNotNull(keyType, "keyType"); Validate.paramNotNull(valueType, "valueType"); return put(attributeName, value, EnhancedType.mapOf(keyType, valueType)); } @Override public Builder putJson(String attributeName, String json) { checkInvalidAttribute(attributeName, json); return putObject(attributeName, getAttributeValueFromJson(json)); } @Override public Builder remove(String attributeName) { Validate.isTrue(!StringUtils.isEmpty(attributeName), "Attribute name must not be null or empty"); nonAttributeValueMap.remove(attributeName); return this; } @Override public Builder addAttributeConverterProvider(AttributeConverterProvider attributeConverterProvider) { Validate.paramNotNull(attributeConverterProvider, "attributeConverterProvider"); attributeConverterProviders.add(attributeConverterProvider); return this; } @Override public Builder attributeConverterProviders(List<AttributeConverterProvider> attributeConverterProviders) { Validate.paramNotNull(attributeConverterProviders, "attributeConverterProviders"); this.attributeConverterProviders.clear(); this.attributeConverterProviders.addAll(attributeConverterProviders); return this; } @Override public Builder attributeConverterProviders(AttributeConverterProvider... attributeConverterProviders) { Validate.paramNotNull(attributeConverterProviders, "attributeConverterProviders"); return attributeConverterProviders(Arrays.asList(attributeConverterProviders)); } @Override public Builder json(String json) { Validate.paramNotNull(json, "json"); AttributeValue attributeValue = getAttributeValueFromJson(json); if (attributeValue != null && attributeValue.hasM()) { nonAttributeValueMap = new LinkedHashMap<>(attributeValue.m()); } return this; } @Override public Builder attributeValueMap(Map<String, AttributeValue> attributeValueMap) { Validate.paramNotNull(attributeConverterProviders, "attributeValueMap"); nonAttributeValueMap.clear(); attributeValueMap.forEach(this::putObject); return this; } @Override public EnhancedDocument build() { return new DefaultEnhancedDocument(this); } private static AttributeValue getAttributeValueFromJson(String json) { JsonNodeParser build = JsonNodeParser.builder().build(); JsonNode jsonNode = build.parse(json); if (jsonNode == null) { throw new IllegalArgumentException("Could not parse argument json " + json); } return JSON_ATTRIBUTE_CONVERTER.transformFrom(jsonNode); } private static void checkInvalidAttribute(String attributeName, Object value) { validateAttributeName(attributeName); Validate.notNull(value, "Value for %s must not be null. Use putNull API to insert a Null value", attributeName); } private static void validateAttributeName(String attributeName) { Validate.isTrue(attributeName != null && !attributeName.trim().isEmpty(), "Attribute name must not be null or empty."); } } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } DefaultEnhancedDocument that = (DefaultEnhancedDocument) o; return nonAttributeValueMap.equals(that.nonAttributeValueMap) && Objects.equals(enhancedTypeMap, that.enhancedTypeMap) && Objects.equals(attributeValueMap, that.attributeValueMap) && Objects.equals(attributeConverterProviders, that.attributeConverterProviders) && attributeConverterChain.equals(that.attributeConverterChain); } @Override public int hashCode() { int result = nonAttributeValueMap != null ? nonAttributeValueMap.hashCode() : 0; result = 31 * result + (attributeConverterProviders != null ? attributeConverterProviders.hashCode() : 0); return result; } private static void checkAndValidateClass(Class<?> type, boolean isPut) { Validate.paramNotNull(type, "type"); Validate.isTrue(!type.isAssignableFrom(List.class), String.format(VALIDATE_TYPE_ERROR, "List", isPut ? "put" : "get", "List")); Validate.isTrue(!type.isAssignableFrom(Map.class), String.format(VALIDATE_TYPE_ERROR, "Map", isPut ? "put" : "get", "Map")); } }
4,271
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/document/JsonStringFormatHelper.java
/* * 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.enhanced.dynamodb.internal.document; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.StreamSupport; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.protocols.jsoncore.JsonNode; @SdkInternalApi public final class JsonStringFormatHelper { private JsonStringFormatHelper() { } /** * Helper function to convert a JsonNode to Json String representation * * @param jsonNode The JsonNode that needs to be converted to Json String. * @return Json String of Json Node. */ public static String stringValue(JsonNode jsonNode) { if (jsonNode.isArray()) { return StreamSupport.stream(jsonNode.asArray().spliterator(), false) .map(JsonStringFormatHelper::stringValue) .collect(Collectors.joining(",", "[", "]")); } if (jsonNode.isObject()) { return mapToString(jsonNode); } return jsonNode.isString() ? "\"" + addEscapeCharacters(jsonNode.text()) + "\"" : jsonNode.toString(); } /** * Escapes characters for a give given string * * @param input Input string * @return String with escaped characters. */ public static String addEscapeCharacters(String input) { StringBuilder output = new StringBuilder(); for (int i = 0; i < input.length(); i++) { char ch = input.charAt(i); switch (ch) { case '\\': output.append("\\\\"); // escape backslash with a backslash break; case '\n': output.append("\\n"); // newline character break; case '\r': output.append("\\r"); // carriage return character break; case '\t': output.append("\\t"); // tab character break; case '\f': output.append("\\f"); // form feed break; case '\"': output.append("\\\""); // double-quote character break; default: output.append(ch); break; } } return output.toString(); } private static String mapToString(JsonNode jsonNode) { Map<String, JsonNode> value = jsonNode.asObject(); if (value.isEmpty()) { return "{}"; } StringBuilder output = new StringBuilder(); output.append("{"); value.forEach((k, v) -> output.append("\"").append(k).append("\":") .append(stringValue(v)).append(",")); output.setCharAt(output.length() - 1, '}'); return output.toString(); } }
4,272
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/ScanOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.Map; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.core.async.SdkPublisher; import software.amazon.awssdk.core.pagination.sync.SdkIterable; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.Expression; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableMetadata; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.enhanced.dynamodb.internal.EnhancedClientUtils; import software.amazon.awssdk.enhanced.dynamodb.internal.ProjectionExpression; import software.amazon.awssdk.enhanced.dynamodb.model.Page; import software.amazon.awssdk.enhanced.dynamodb.model.ScanEnhancedRequest; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import software.amazon.awssdk.services.dynamodb.model.ScanRequest; import software.amazon.awssdk.services.dynamodb.model.ScanResponse; @SdkInternalApi public class ScanOperation<T> implements PaginatedTableOperation<T, ScanRequest, ScanResponse>, PaginatedIndexOperation<T, ScanRequest, ScanResponse> { private final ScanEnhancedRequest request; private ScanOperation(ScanEnhancedRequest request) { this.request = request; } public static <T> ScanOperation<T> create(ScanEnhancedRequest request) { return new ScanOperation<>(request); } @Override public OperationName operationName() { return OperationName.SCAN; } @Override public ScanRequest generateRequest(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { Map<String, AttributeValue> expressionValues = null; Map<String, String> expressionNames = null; if (this.request.filterExpression() != null) { expressionValues = this.request.filterExpression().expressionValues(); expressionNames = this.request.filterExpression().expressionNames(); } String projectionExpressionAsString = null; if (this.request.attributesToProject() != null) { ProjectionExpression attributesToProject = ProjectionExpression.create(this.request.nestedAttributesToProject()); projectionExpressionAsString = attributesToProject.projectionExpressionAsString().orElse(null); expressionNames = Expression.joinNames(expressionNames, attributesToProject.expressionAttributeNames()); } ScanRequest.Builder scanRequest = ScanRequest.builder() .tableName(operationContext.tableName()) .limit(this.request.limit()) .segment(this.request.segment()) .totalSegments(this.request.totalSegments()) .exclusiveStartKey(this.request.exclusiveStartKey()) .consistentRead(this.request.consistentRead()) .returnConsumedCapacity(this.request.returnConsumedCapacity()) .expressionAttributeValues(expressionValues) .expressionAttributeNames(expressionNames) .projectionExpression(projectionExpressionAsString); if (!TableMetadata.primaryIndexName().equals(operationContext.indexName())) { scanRequest = scanRequest.indexName(operationContext.indexName()); } if (this.request.filterExpression() != null) { scanRequest = scanRequest.filterExpression(this.request.filterExpression().expression()); } return scanRequest.build(); } @Override public Page<T> transformResponse(ScanResponse response, TableSchema<T> tableSchema, OperationContext context, DynamoDbEnhancedClientExtension dynamoDbEnhancedClientExtension) { return EnhancedClientUtils.readAndTransformPaginatedItems(response, tableSchema, context, dynamoDbEnhancedClientExtension, ScanResponse::items, ScanResponse::lastEvaluatedKey, ScanResponse::count, ScanResponse::scannedCount, ScanResponse::consumedCapacity); } @Override public Function<ScanRequest, SdkIterable<ScanResponse>> serviceCall(DynamoDbClient dynamoDbClient) { return dynamoDbClient::scanPaginator; } @Override public Function<ScanRequest, SdkPublisher<ScanResponse>> asyncServiceCall(DynamoDbAsyncClient dynamoDbAsyncClient) { return dynamoDbAsyncClient::scanPaginator; } }
4,273
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/TransactableWriteOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.services.dynamodb.model.TransactWriteItem; @SdkInternalApi public interface TransactableWriteOperation<T> { TransactWriteItem generateTransactWriteItem(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension dynamoDbEnhancedClientExtension); }
4,274
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/PutItemOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.Map; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.Expression; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableMetadata; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.enhanced.dynamodb.extensions.WriteModification; import software.amazon.awssdk.enhanced.dynamodb.internal.EnhancedClientUtils; import software.amazon.awssdk.enhanced.dynamodb.internal.extensions.DefaultDynamoDbExtensionContext; import software.amazon.awssdk.enhanced.dynamodb.model.PutItemEnhancedRequest; import software.amazon.awssdk.enhanced.dynamodb.model.PutItemEnhancedResponse; import software.amazon.awssdk.enhanced.dynamodb.model.TransactPutItemEnhancedRequest; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import software.amazon.awssdk.services.dynamodb.model.Put; import software.amazon.awssdk.services.dynamodb.model.PutItemRequest; import software.amazon.awssdk.services.dynamodb.model.PutItemResponse; import software.amazon.awssdk.services.dynamodb.model.PutRequest; import software.amazon.awssdk.services.dynamodb.model.TransactWriteItem; import software.amazon.awssdk.services.dynamodb.model.WriteRequest; import software.amazon.awssdk.utils.Either; @SdkInternalApi public class PutItemOperation<T> implements BatchableWriteOperation<T>, TransactableWriteOperation<T>, TableOperation<T, PutItemRequest, PutItemResponse, PutItemEnhancedResponse<T>> { private final Either<PutItemEnhancedRequest<T>, TransactPutItemEnhancedRequest<T>> request; private PutItemOperation(PutItemEnhancedRequest<T> request) { this.request = Either.left(request); } private PutItemOperation(TransactPutItemEnhancedRequest<T> request) { this.request = Either.right(request); } public static <T> PutItemOperation<T> create(PutItemEnhancedRequest<T> request) { return new PutItemOperation<>(request); } public static <T> PutItemOperation<T> create(TransactPutItemEnhancedRequest<T> request) { return new PutItemOperation<>(request); } @Override public OperationName operationName() { return OperationName.PUT_ITEM; } @Override public PutItemRequest generateRequest(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { if (!TableMetadata.primaryIndexName().equals(operationContext.indexName())) { throw new IllegalArgumentException("PutItem cannot be executed against a secondary index."); } TableMetadata tableMetadata = tableSchema.tableMetadata(); // Fail fast if required primary partition key does not exist and avoid the call to DynamoDb tableMetadata.primaryPartitionKey(); boolean alwaysIgnoreNulls = true; T item = request.map(PutItemEnhancedRequest::item, TransactPutItemEnhancedRequest::item); Map<String, AttributeValue> itemMap = tableSchema.itemToMap(item, alwaysIgnoreNulls); WriteModification transformation = extension != null ? extension.beforeWrite( DefaultDynamoDbExtensionContext.builder() .items(itemMap) .operationContext(operationContext) .tableMetadata(tableMetadata) .tableSchema(tableSchema) .operationName(operationName()) .build()) : null; if (transformation != null && transformation.transformedItem() != null) { itemMap = transformation.transformedItem(); } PutItemRequest.Builder requestBuilder = PutItemRequest.builder() .tableName(operationContext.tableName()) .item(itemMap); if (request.left().isPresent()) { requestBuilder = addPlainPutItemParameters(requestBuilder, request.left().get()); } requestBuilder = addExpressionsIfExist(requestBuilder, transformation); return requestBuilder.build(); } @Override public PutItemEnhancedResponse<T> transformResponse(PutItemResponse response, TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { T attributes = null; if (response.hasAttributes()) { attributes = EnhancedClientUtils.readAndTransformSingleItem(response.attributes(), tableSchema, operationContext, extension); } return PutItemEnhancedResponse.<T>builder(null) .attributes(attributes) .consumedCapacity(response.consumedCapacity()) .itemCollectionMetrics(response.itemCollectionMetrics()) .build(); } @Override public Function<PutItemRequest, PutItemResponse> serviceCall(DynamoDbClient dynamoDbClient) { return dynamoDbClient::putItem; } @Override public Function<PutItemRequest, CompletableFuture<PutItemResponse>> asyncServiceCall( DynamoDbAsyncClient dynamoDbAsyncClient) { return dynamoDbAsyncClient::putItem; } @Override public WriteRequest generateWriteRequest(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { PutItemRequest putItemRequest = generateRequest(tableSchema, operationContext, extension); if (putItemRequest.conditionExpression() != null) { throw new IllegalArgumentException("A mapper extension inserted a conditionExpression in a PutItem " + "request as part of a BatchWriteItemRequest. This is not supported by " + "DynamoDb. An extension known to do this is the " + "VersionedRecordExtension which is loaded by default unless overridden. " + "To fix this use a table schema that does not " + "have a versioned attribute in it or do not load the offending extension."); } return WriteRequest.builder().putRequest(PutRequest.builder().item(putItemRequest.item()).build()).build(); } @Override public TransactWriteItem generateTransactWriteItem(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension dynamoDbEnhancedClientExtension) { PutItemRequest putItemRequest = generateRequest(tableSchema, operationContext, dynamoDbEnhancedClientExtension); Put.Builder builder = Put.builder() .item(putItemRequest.item()) .tableName(putItemRequest.tableName()) .conditionExpression(putItemRequest.conditionExpression()) .expressionAttributeValues(putItemRequest.expressionAttributeValues()) .expressionAttributeNames(putItemRequest.expressionAttributeNames()); request.right() .map(TransactPutItemEnhancedRequest::returnValuesOnConditionCheckFailureAsString) .ifPresent(builder::returnValuesOnConditionCheckFailure); return TransactWriteItem.builder() .put(builder.build()) .build(); } private PutItemRequest.Builder addExpressionsIfExist(PutItemRequest.Builder requestBuilder, WriteModification transformation) { Expression originalConditionExpression = request.map(r -> Optional.ofNullable(r.conditionExpression()), r -> Optional.ofNullable(r.conditionExpression())) .orElse(null); Expression mergedConditionExpression; if (transformation != null && transformation.additionalConditionalExpression() != null) { mergedConditionExpression = Expression.join(originalConditionExpression, transformation.additionalConditionalExpression(), " AND "); } else { mergedConditionExpression = originalConditionExpression; } if (mergedConditionExpression != null) { requestBuilder = requestBuilder.conditionExpression(mergedConditionExpression.expression()); // Avoiding adding empty collections that the low level SDK will propagate to DynamoDb where it causes error. if (mergedConditionExpression.expressionValues() != null && !mergedConditionExpression.expressionValues().isEmpty()) { requestBuilder = requestBuilder.expressionAttributeValues(mergedConditionExpression.expressionValues()); } if (mergedConditionExpression.expressionNames() != null && !mergedConditionExpression.expressionNames().isEmpty()) { requestBuilder = requestBuilder.expressionAttributeNames(mergedConditionExpression.expressionNames()); } } return requestBuilder; } private PutItemRequest.Builder addPlainPutItemParameters(PutItemRequest.Builder requestBuilder, PutItemEnhancedRequest<?> enhancedRequest) { requestBuilder = requestBuilder.returnValues(enhancedRequest.returnValuesAsString()); requestBuilder = requestBuilder.returnConsumedCapacity(enhancedRequest.returnConsumedCapacityAsString()); requestBuilder = requestBuilder.returnItemCollectionMetrics(enhancedRequest.returnItemCollectionMetricsAsString()); return requestBuilder; } }
4,275
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/PaginatedTableOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableMetadata; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.enhanced.dynamodb.model.PageIterable; import software.amazon.awssdk.enhanced.dynamodb.model.PagePublisher; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; /** * Interface for an operation that can be executed against a mapped database table and is expected to return a * paginated list of results. These operations will be executed against the primary index of the table. Typically, * each page of results that is served will automatically perform an additional service call to DynamoDb to retrieve * the next set of results. * <p> * A concrete implementation of this interface should also implement {@link PaginatedIndexOperation} with the same * types if the operation supports being executed against both the primary index and secondary indices. * * @param <ItemT> The modelled object that this table maps records to. * @param <RequestT> The type of the request object for the DynamoDb call in the low level {@link DynamoDbClient}. * @param <ResponseT> The type of the response object for the DynamoDb call in the low level {@link DynamoDbClient}. */ @SdkInternalApi public interface PaginatedTableOperation<ItemT, RequestT, ResponseT> extends PaginatedOperation<ItemT, RequestT, ResponseT> { /** * Default implementation of a complete synchronous execution of this operation against the primary index. It will * construct a context based on the given table name and then call execute() on the {@link PaginatedOperation} * interface to perform the operation. * * @param tableSchema A {@link TableSchema} that maps the table to a modelled object. * @param tableName The physical name of the table to execute the operation against. * @param dynamoDbClient A {@link DynamoDbClient} to make the call against. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request or result of this operation. A * null value here will result in no modifications. * @return A high level result object as specified by the implementation of this operation. */ default PageIterable<ItemT> executeOnPrimaryIndex(TableSchema<ItemT> tableSchema, String tableName, DynamoDbEnhancedClientExtension extension, DynamoDbClient dynamoDbClient) { OperationContext context = DefaultOperationContext.create(tableName, TableMetadata.primaryIndexName()); return execute(tableSchema, context, extension, dynamoDbClient); } /** * Default implementation of a complete non-blocking asynchronous execution of this operation against the primary * index. It will construct a context based on the given table name and then call executeAsync() on the * {@link PaginatedOperation} interface to perform the operation. * * @param tableSchema A {@link TableSchema} that maps the table to a modelled object. * @param tableName The physical name of the table to execute the operation against. * @param dynamoDbAsyncClient A {@link DynamoDbAsyncClient} to make the call against. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request or result of this operation. A * null value here will result in no modifications. * @return A high level result object as specified by the implementation of this operation. */ default PagePublisher<ItemT> executeOnPrimaryIndexAsync(TableSchema<ItemT> tableSchema, String tableName, DynamoDbEnhancedClientExtension extension, DynamoDbAsyncClient dynamoDbAsyncClient) { OperationContext context = DefaultOperationContext.create(tableName, TableMetadata.primaryIndexName()); return executeAsync(tableSchema, context, extension, dynamoDbAsyncClient); } /** * The type, or name, of the operation. */ OperationName operationName(); }
4,276
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/PaginatedOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.core.async.SdkPublisher; import software.amazon.awssdk.core.pagination.sync.SdkIterable; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncIndex; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncTable; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbIndex; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.enhanced.dynamodb.internal.TransformIterable; import software.amazon.awssdk.enhanced.dynamodb.model.Page; import software.amazon.awssdk.enhanced.dynamodb.model.PageIterable; import software.amazon.awssdk.enhanced.dynamodb.model.PagePublisher; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; /** * Common interface for an operation that can be executed in a synchronous or non-blocking asynchronous fashion * against a mapped database table and is expected to return a paginated list of results. These operations can be made * against either the primary index of a table or a secondary index, although some implementations of this interface * do not support secondary indices and will throw an exception when executed against one. Typically, each page of * results that is served will automatically perform an additional service call to DynamoDb to retrieve the next set * of results. * <p> * This interface is extended by {@link PaginatedTableOperation} and {@link PaginatedIndexOperation} which contain * implementations of the behavior to actually execute the operation in the context of a table or secondary index and * are used by {@link DynamoDbTable} or {@link DynamoDbAsyncTable} and {@link DynamoDbIndex} or {@link DynamoDbAsyncIndex} * respectively. By sharing this common interface operations are able to re-use code regardless of whether they are * executed in the context of a primary or secondary index or whether they are being executed in a synchronous or * non-blocking asynchronous fashion. * * @param <ItemT> The modelled object that this table maps records to. * @param <RequestT> The type of the request object for the DynamoDb call in the low level {@link DynamoDbClient} or * {@link DynamoDbAsyncClient}. * @param <ResponseT> The type of the response object for the DynamoDb call in the low level {@link DynamoDbClient} * or {@link DynamoDbAsyncClient}. */ @SdkInternalApi public interface PaginatedOperation<ItemT, RequestT, ResponseT> { /** * This method generates the request that needs to be sent to a low level {@link DynamoDbClient}. * @param tableSchema A {@link TableSchema} that maps the table to a modelled object. * @param context An object containing the context, or target, of the command execution. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request of this operation. A null * value here will result in no modifications. * @return A request that can be used as an argument to a {@link DynamoDbClient} call to perform the operation. */ RequestT generateRequest(TableSchema<ItemT> tableSchema, OperationContext context, DynamoDbEnhancedClientExtension extension); /** * Provides a function for making the low level synchronous SDK call to DynamoDb. * @param dynamoDbClient A low level {@link DynamoDbClient} to make the call against. * @return A function that calls a paginated DynamoDb operation with a provided request object and returns the * response object. */ Function<RequestT, SdkIterable<ResponseT>> serviceCall(DynamoDbClient dynamoDbClient); /** * Provides a function for making the low level non-blocking asynchronous SDK call to DynamoDb. * @param dynamoDbAsyncClient A low level {@link DynamoDbAsyncClient} to make the call against. * @return A function that calls a paginated DynamoDb operation with a provided request object and returns the * response object. */ Function<RequestT, SdkPublisher<ResponseT>> asyncServiceCall(DynamoDbAsyncClient dynamoDbAsyncClient); /** * Takes the response object returned by the actual DynamoDb call and maps it into a higher level abstracted * result object. * @param response The response object returned by the DynamoDb call for this operation. * @param tableSchema A {@link TableSchema} that maps the table to a modelled object. * @param context An object containing the context, or target, of the command execution. * @param dynamoDbEnhancedClientExtension A {@link DynamoDbEnhancedClientExtension} that may modify the result of * this operation. A null value here will result in no modifications. * @return A high level result object as specified by the implementation of this operation. */ Page<ItemT> transformResponse(ResponseT response, TableSchema<ItemT> tableSchema, OperationContext context, DynamoDbEnhancedClientExtension dynamoDbEnhancedClientExtension); /** * Default implementation of a complete synchronous execution of this operation against either the primary or a * secondary index. * <p> * It performs three steps: * <ol> * <li> Call {@link #generateRequest} to get the request object.</li> * <li> Call {@link #asyncServiceCall} and call it using the request object generated in the previous step.</li> * <li> Wraps the {@link SdkIterable} that was returned by the previous step with a transformation that turns each * object returned to a high level result.</li> * </ol> * * @param tableSchema A {@link TableSchema} that maps the table to a modelled object. * @param context An object containing the context, or target, of the command execution. * @param dynamoDbClient A {@link DynamoDbClient} to make the call against. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request or result of this * operation. A null value here will result in no modifications. * @return A high level result object as specified by the implementation of this operation. */ default PageIterable<ItemT> execute(TableSchema<ItemT> tableSchema, OperationContext context, DynamoDbEnhancedClientExtension extension, DynamoDbClient dynamoDbClient) { RequestT request = generateRequest(tableSchema, context, extension); SdkIterable<ResponseT> response = serviceCall(dynamoDbClient).apply(request); SdkIterable<Page<ItemT>> pageIterables = TransformIterable.of(response, r -> transformResponse(r, tableSchema, context, extension)); return PageIterable.create(pageIterables); } /** * Default implementation of a complete non-blocking asynchronous execution of this operation against either the * primary or a secondary index. * <p> * It performs three steps: * <ol> * <li> Call {@link #generateRequest} to get the request object. * <li> Call {@link #asyncServiceCall} and call it using the request object generated in the previous step. * <li> Wraps the {@link SdkPublisher} returned by the SDK in a new one that calls transformResponse() to * convert the response objects published to a high level result. * </ol> * * @param tableSchema A {@link TableSchema} that maps the table to a modelled object. * @param context An object containing the context, or target, of the command execution. * @param dynamoDbAsyncClient A {@link DynamoDbAsyncClient} to make the call against. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request or result of this * operation. A null value here will result in no modifications. * @return An {@link SdkPublisher} that will publish pages of the high level result object as specified by the * implementation of this operation. */ default PagePublisher<ItemT> executeAsync(TableSchema<ItemT> tableSchema, OperationContext context, DynamoDbEnhancedClientExtension extension, DynamoDbAsyncClient dynamoDbAsyncClient) { RequestT request = generateRequest(tableSchema, context, extension); SdkPublisher<ResponseT> response = asyncServiceCall(dynamoDbAsyncClient).apply(request); return PagePublisher.create(response.map(r -> transformResponse(r, tableSchema, context, extension))); } }
4,277
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/CreateTableOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.function.Function; import java.util.stream.Collectors; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableMetadata; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition; import software.amazon.awssdk.services.dynamodb.model.BillingMode; import software.amazon.awssdk.services.dynamodb.model.CreateTableRequest; import software.amazon.awssdk.services.dynamodb.model.CreateTableResponse; import software.amazon.awssdk.services.dynamodb.model.KeySchemaElement; import software.amazon.awssdk.services.dynamodb.model.KeyType; @SdkInternalApi public class CreateTableOperation<T> implements TableOperation<T, CreateTableRequest, CreateTableResponse, Void> { private final CreateTableEnhancedRequest request; private CreateTableOperation(CreateTableEnhancedRequest request) { this.request = request; } public static <T> CreateTableOperation<T> create(CreateTableEnhancedRequest request) { return new CreateTableOperation<>(request); } @Override public OperationName operationName() { return OperationName.CREATE_TABLE; } @Override public CreateTableRequest generateRequest(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { if (!TableMetadata.primaryIndexName().equals(operationContext.indexName())) { throw new IllegalArgumentException("PutItem cannot be executed against a secondary index."); } String primaryPartitionKey = tableSchema.tableMetadata().primaryPartitionKey(); Optional<String> primarySortKey = tableSchema.tableMetadata().primarySortKey(); Set<String> dedupedIndexKeys = new HashSet<>(); dedupedIndexKeys.add(primaryPartitionKey); primarySortKey.ifPresent(dedupedIndexKeys::add); List<software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex> sdkGlobalSecondaryIndices = null; List<software.amazon.awssdk.services.dynamodb.model.LocalSecondaryIndex> sdkLocalSecondaryIndices = null; if (this.request.globalSecondaryIndices() != null && !this.request.globalSecondaryIndices().isEmpty()) { sdkGlobalSecondaryIndices = this.request.globalSecondaryIndices().stream().map(gsi -> { String indexPartitionKey = tableSchema.tableMetadata().indexPartitionKey(gsi.indexName()); Optional<String> indexSortKey = tableSchema.tableMetadata().indexSortKey(gsi.indexName()); dedupedIndexKeys.add(indexPartitionKey); indexSortKey.ifPresent(dedupedIndexKeys::add); return software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex .builder() .indexName(gsi.indexName()) .keySchema(generateKeySchema(indexPartitionKey, indexSortKey.orElse(null))) .projection(gsi.projection()) .provisionedThroughput(gsi.provisionedThroughput()) .build(); }).collect(Collectors.toList()); } if (this.request.localSecondaryIndices() != null && !this.request.localSecondaryIndices().isEmpty()) { sdkLocalSecondaryIndices = this.request.localSecondaryIndices().stream().map(lsi -> { Optional<String> indexSortKey = tableSchema.tableMetadata().indexSortKey(lsi.indexName()); indexSortKey.ifPresent(dedupedIndexKeys::add); if (!primaryPartitionKey.equals( tableSchema.tableMetadata().indexPartitionKey(lsi.indexName()))) { throw new IllegalArgumentException("Attempt to create a local secondary index with a partition " + "key that is not the primary partition key. Index name: " + lsi.indexName()); } return software.amazon.awssdk.services.dynamodb.model.LocalSecondaryIndex .builder() .indexName(lsi.indexName()) .keySchema(generateKeySchema(primaryPartitionKey, indexSortKey.orElse(null))) .projection(lsi.projection()) .build(); }).collect(Collectors.toList()); } List<AttributeDefinition> attributeDefinitions = dedupedIndexKeys.stream() .map(attribute -> AttributeDefinition.builder() .attributeName(attribute) .attributeType(tableSchema .tableMetadata().scalarAttributeType(attribute) .orElseThrow(() -> new IllegalArgumentException( "Could not map the key attribute '" + attribute + "' to a valid scalar type."))) .build()) .collect(Collectors.toList()); BillingMode billingMode = this.request.provisionedThroughput() == null ? BillingMode.PAY_PER_REQUEST : BillingMode.PROVISIONED; return CreateTableRequest.builder() .tableName(operationContext.tableName()) .keySchema(generateKeySchema(primaryPartitionKey, primarySortKey.orElse(null))) .globalSecondaryIndexes(sdkGlobalSecondaryIndices) .localSecondaryIndexes(sdkLocalSecondaryIndices) .attributeDefinitions(attributeDefinitions) .billingMode(billingMode) .provisionedThroughput(this.request.provisionedThroughput()) .streamSpecification(this.request.streamSpecification()) .build(); } @Override public Function<CreateTableRequest, CreateTableResponse> serviceCall(DynamoDbClient dynamoDbClient) { return dynamoDbClient::createTable; } @Override public Function<CreateTableRequest, CompletableFuture<CreateTableResponse>> asyncServiceCall( DynamoDbAsyncClient dynamoDbAsyncClient) { return dynamoDbAsyncClient::createTable; } @Override public Void transformResponse(CreateTableResponse response, TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { // This operation does not return results return null; } private static Collection<KeySchemaElement> generateKeySchema(String partitionKey, String sortKey) { if (sortKey == null) { return generateKeySchema(partitionKey); } return Collections.unmodifiableList(Arrays.asList(KeySchemaElement.builder() .attributeName(partitionKey) .keyType(KeyType.HASH) .build(), KeySchemaElement.builder() .attributeName(sortKey) .keyType(KeyType.RANGE) .build())); } private static Collection<KeySchemaElement> generateKeySchema(String partitionKey) { return Collections.singletonList(KeySchemaElement.builder() .attributeName(partitionKey) .keyType(KeyType.HASH) .build()); } }
4,278
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/DeleteTableOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.concurrent.CompletableFuture; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableMetadata; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.DeleteTableRequest; import software.amazon.awssdk.services.dynamodb.model.DeleteTableResponse; @SdkInternalApi public class DeleteTableOperation<T> implements TableOperation<T, DeleteTableRequest, DeleteTableResponse, Void> { public static <T> DeleteTableOperation<T> create() { return new DeleteTableOperation<>(); } @Override public OperationName operationName() { return OperationName.DELETE_ITEM; } @Override public DeleteTableRequest generateRequest(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { if (!TableMetadata.primaryIndexName().equals(operationContext.indexName())) { throw new IllegalArgumentException("DeleteTable cannot be executed against a secondary index."); } return DeleteTableRequest.builder() .tableName(operationContext.tableName()) .build(); } @Override public Function<DeleteTableRequest, DeleteTableResponse> serviceCall(DynamoDbClient dynamoDbClient) { return dynamoDbClient::deleteTable; } @Override public Function<DeleteTableRequest, CompletableFuture<DeleteTableResponse>> asyncServiceCall( DynamoDbAsyncClient dynamoDbAsyncClient) { return dynamoDbAsyncClient::deleteTable; } @Override public Void transformResponse(DeleteTableResponse response, TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { // This operation does not return results return null; } }
4,279
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/BatchWriteItemOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.model.BatchWriteItemEnhancedRequest; import software.amazon.awssdk.enhanced.dynamodb.model.BatchWriteResult; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.BatchWriteItemRequest; import software.amazon.awssdk.services.dynamodb.model.BatchWriteItemResponse; import software.amazon.awssdk.services.dynamodb.model.WriteRequest; import software.amazon.awssdk.utils.CollectionUtils; @SdkInternalApi public class BatchWriteItemOperation implements DatabaseOperation<BatchWriteItemRequest, BatchWriteItemResponse, BatchWriteResult> { private final BatchWriteItemEnhancedRequest request; private BatchWriteItemOperation(BatchWriteItemEnhancedRequest request) { this.request = request; } public static BatchWriteItemOperation create(BatchWriteItemEnhancedRequest request) { return new BatchWriteItemOperation(request); } @Override public OperationName operationName() { return OperationName.BATCH_WRITE_ITEM; } @Override public BatchWriteItemRequest generateRequest(DynamoDbEnhancedClientExtension extension) { Map<String, List<WriteRequest>> allRequestItems = new HashMap<>(); request.writeBatches().forEach(writeBatch -> { Collection<WriteRequest> writeRequestsForTable = allRequestItems.computeIfAbsent( writeBatch.tableName(), ignored -> new ArrayList<>()); writeRequestsForTable.addAll(writeBatch.writeRequests()); }); return BatchWriteItemRequest.builder() .requestItems( Collections.unmodifiableMap(CollectionUtils.deepCopyMap(allRequestItems))) .build(); } @Override public BatchWriteResult transformResponse(BatchWriteItemResponse response, DynamoDbEnhancedClientExtension extension) { return BatchWriteResult.builder().unprocessedRequests(response.unprocessedItems()).build(); } @Override public Function<BatchWriteItemRequest, BatchWriteItemResponse> serviceCall(DynamoDbClient dynamoDbClient) { return dynamoDbClient::batchWriteItem; } @Override public Function<BatchWriteItemRequest, CompletableFuture<BatchWriteItemResponse>> asyncServiceCall( DynamoDbAsyncClient dynamoDbAsyncClient) { return dynamoDbAsyncClient::batchWriteItem; } }
4,280
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/BatchableWriteOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.services.dynamodb.model.WriteRequest; @SdkInternalApi public interface BatchableWriteOperation<T> { WriteRequest generateWriteRequest(TableSchema<T> tableSchema, OperationContext context, DynamoDbEnhancedClientExtension extension); }
4,281
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/DescribeTableOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.concurrent.CompletableFuture; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableMetadata; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.enhanced.dynamodb.model.DescribeTableEnhancedResponse; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest; import software.amazon.awssdk.services.dynamodb.model.DescribeTableResponse; @SdkInternalApi public class DescribeTableOperation<T> implements TableOperation<T, DescribeTableRequest, DescribeTableResponse, DescribeTableEnhancedResponse> { public static <T> DescribeTableOperation<T> create() { return new DescribeTableOperation<>(); } @Override public OperationName operationName() { return OperationName.DESCRIBE_TABLE; } @Override public DescribeTableRequest generateRequest(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { if (!TableMetadata.primaryIndexName().equals(operationContext.indexName())) { throw new IllegalArgumentException("DescribeTable cannot be executed against a secondary index."); } return DescribeTableRequest.builder() .tableName(operationContext.tableName()) .build(); } @Override public Function<DescribeTableRequest, DescribeTableResponse> serviceCall(DynamoDbClient dynamoDbClient) { return dynamoDbClient::describeTable; } @Override public Function<DescribeTableRequest, CompletableFuture<DescribeTableResponse>> asyncServiceCall( DynamoDbAsyncClient dynamoDbAsyncClient) { return dynamoDbAsyncClient::describeTable; } @Override public DescribeTableEnhancedResponse transformResponse(DescribeTableResponse response, TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { return DescribeTableEnhancedResponse.builder() .response(response) .build(); } }
4,282
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/TransactWriteItemsOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.concurrent.CompletableFuture; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.model.TransactWriteItemsEnhancedRequest; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.TransactWriteItemsRequest; import software.amazon.awssdk.services.dynamodb.model.TransactWriteItemsResponse; @SdkInternalApi public class TransactWriteItemsOperation implements DatabaseOperation<TransactWriteItemsRequest, TransactWriteItemsResponse, Void> { private TransactWriteItemsEnhancedRequest request; private TransactWriteItemsOperation(TransactWriteItemsEnhancedRequest request) { this.request = request; } public static TransactWriteItemsOperation create(TransactWriteItemsEnhancedRequest request) { return new TransactWriteItemsOperation(request); } @Override public OperationName operationName() { return OperationName.TRANSACT_WRITE_ITEMS; } @Override public TransactWriteItemsRequest generateRequest(DynamoDbEnhancedClientExtension extension) { return TransactWriteItemsRequest.builder() .transactItems(this.request.transactWriteItems()) .clientRequestToken(this.request.clientRequestToken()) .build(); } @Override public Void transformResponse(TransactWriteItemsResponse response, DynamoDbEnhancedClientExtension extension) { return null; // this operation does not return results } @Override public Function<TransactWriteItemsRequest, TransactWriteItemsResponse> serviceCall( DynamoDbClient dynamoDbClient) { return dynamoDbClient::transactWriteItems; } @Override public Function<TransactWriteItemsRequest, CompletableFuture<TransactWriteItemsResponse>> asyncServiceCall( DynamoDbAsyncClient dynamoDbAsyncClient) { return dynamoDbAsyncClient::transactWriteItems; } }
4,283
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/DatabaseOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.concurrent.CompletableFuture; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; /** * Interface for a single operation that can be executed against a mapped database. These operations do not operate * on a specific table or index, and may reference multiple tables and indexes (eg: batch operations). Conceptually an * operation maps 1:1 with an actual DynamoDb call. * * @param <RequestT> The type of the request object for the DynamoDb call in the low level {@link DynamoDbClient}. * @param <ResponseT> The type of the response object for the DynamoDb call in the low level {@link DynamoDbClient}. * @param <ResultT> The type of the mapped result object that will be returned by the execution of this operation. */ @SdkInternalApi public interface DatabaseOperation<RequestT, ResponseT, ResultT> { /** * This method generates the request that needs to be sent to a low level {@link DynamoDbClient}. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request of this operation. A null * value here will result in no modifications. * @return A request that can be used as an argument to a {@link DynamoDbClient} call to perform the operation. */ RequestT generateRequest(DynamoDbEnhancedClientExtension extension); /** * Provides a function for making the low level synchronous SDK call to DynamoDb. * @param dynamoDbClient A low level {@link DynamoDbClient} to make the call against. * @return A function that calls DynamoDb with a provided request object and returns the response object. */ Function<RequestT, ResponseT> serviceCall(DynamoDbClient dynamoDbClient); /** * Provides a function for making the low level non-blocking asynchronous SDK call to DynamoDb. * @param dynamoDbAsyncClient A low level {@link DynamoDbAsyncClient} to make the call against. * @return A function that calls DynamoDb with a provided request object and returns a {@link CompletableFuture} * for the response object. */ Function<RequestT, CompletableFuture<ResponseT>> asyncServiceCall(DynamoDbAsyncClient dynamoDbAsyncClient); /** * Takes the response object returned by the actual DynamoDb call and maps it into a higher level abstracted * result object. * @param response The response object returned by the DynamoDb call for this operation. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the result of this operation. A null * value here will result in no modifications. * @return A high level result object as specified by the implementation of this operation. */ ResultT transformResponse(ResponseT response, DynamoDbEnhancedClientExtension extension); /** * Default implementation of a complete synchronous execution of this operation. It performs three steps: * 1) Call generateRequest() to get the request object. * 2) Call getServiceCall() and call it using the request object generated in the previous step. * 3) Call transformResponse() to convert the response object returned in the previous step to a high level result. * * @param dynamoDbClient A {@link DynamoDbClient} to make the call against. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request or result of this * operation. A null value here will result in no modifications. * @return A high level result object as specified by the implementation of this operation. */ default ResultT execute(DynamoDbClient dynamoDbClient, DynamoDbEnhancedClientExtension extension) { RequestT request = generateRequest(extension); ResponseT response = serviceCall(dynamoDbClient).apply(request); return transformResponse(response, extension); } /** * Default implementation of a complete non-blocking asynchronous execution of this operation. It performs three * steps: * 1) Call generateRequest() to get the request object. * 2) Call getServiceCall() and call it using the request object generated in the previous step. * 3) Wraps the {@link CompletableFuture} returned by the SDK in a new one that calls transformResponse() to * convert the response object returned in the previous step to a high level result. * * @param dynamoDbAsyncClient A {@link DynamoDbAsyncClient} to make the call against. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request or result of this * operation. A null value here will result in no modifications. * @return A high level result object as specified by the implementation of this operation. */ default CompletableFuture<ResultT> executeAsync(DynamoDbAsyncClient dynamoDbAsyncClient, DynamoDbEnhancedClientExtension extension) { RequestT request = generateRequest(extension); CompletableFuture<ResponseT> response = asyncServiceCall(dynamoDbAsyncClient).apply(request); return response.thenApply(r -> transformResponse(r, extension)); } /** * The type, or name, of the operation. */ OperationName operationName(); }
4,284
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/TableOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.concurrent.CompletableFuture; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableMetadata; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; /** * Interface for a single operation that can be executed against a mapped database table. These operations will be * executed against the primary index of the table. Conceptually an operation maps 1:1 with an actual DynamoDb call. * <p> * A concrete implementation of this interface should also implement {@link IndexOperation} with the same types if * the operation supports being executed against both the primary index and secondary indices. * * @param <ItemT> The modelled object that this table maps records to. * @param <RequestT> The type of the request object for the DynamoDb call in the low level {@link DynamoDbClient}. * @param <ResponseT> The type of the response object for the DynamoDb call in the low level {@link DynamoDbClient}. * @param <ResultT> The type of the mapped result object that will be returned by the execution of this operation. */ @SdkInternalApi public interface TableOperation<ItemT, RequestT, ResponseT, ResultT> extends CommonOperation<ItemT, RequestT, ResponseT, ResultT> { /** * Default implementation of a complete synchronous execution of this operation against the primary index. It will * construct a context based on the given table name and then call execute() on the {@link CommonOperation} interface to * perform the operation. * * @param tableSchema A {@link TableSchema} that maps the table to a modelled object. * @param tableName The physical name of the table to execute the operation against. * @param dynamoDbClient A {@link DynamoDbClient} to make the call against. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request or result of this * operation. A null value here will result in no modifications. * @return A high level result object as specified by the implementation of this operation. */ default ResultT executeOnPrimaryIndex(TableSchema<ItemT> tableSchema, String tableName, DynamoDbEnhancedClientExtension extension, DynamoDbClient dynamoDbClient) { OperationContext context = DefaultOperationContext.create(tableName, TableMetadata.primaryIndexName()); return execute(tableSchema, context, extension, dynamoDbClient); } /** * Default implementation of a complete non-blocking asynchronous execution of this operation against the primary * index. It will construct a context based on the given table name and then call executeAsync() on the * {@link CommonOperation} interface to perform the operation. * * @param tableSchema A {@link TableSchema} that maps the table to a modelled object. * @param tableName The physical name of the table to execute the operation against. * @param dynamoDbAsyncClient A {@link DynamoDbAsyncClient} to make the call against. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request or result of this * operation. A null value here will result in no modifications. * @return A {@link CompletableFuture} of the high level result object as specified by the implementation of this * operation. */ default CompletableFuture<ResultT> executeOnPrimaryIndexAsync(TableSchema<ItemT> tableSchema, String tableName, DynamoDbEnhancedClientExtension extension, DynamoDbAsyncClient dynamoDbAsyncClient) { OperationContext context = DefaultOperationContext.create(tableName, TableMetadata.primaryIndexName()); return executeAsync(tableSchema, context, extension, dynamoDbAsyncClient); } }
4,285
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/TransactGetItemsOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.function.Function; import java.util.stream.Collectors; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.Document; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.internal.DefaultDocument; import software.amazon.awssdk.enhanced.dynamodb.model.TransactGetItemsEnhancedRequest; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.TransactGetItemsRequest; import software.amazon.awssdk.services.dynamodb.model.TransactGetItemsResponse; @SdkInternalApi public class TransactGetItemsOperation implements DatabaseOperation<TransactGetItemsRequest, TransactGetItemsResponse, List<Document>> { private TransactGetItemsEnhancedRequest request; private TransactGetItemsOperation(TransactGetItemsEnhancedRequest request) { this.request = request; } public static TransactGetItemsOperation create(TransactGetItemsEnhancedRequest request) { return new TransactGetItemsOperation(request); } @Override public OperationName operationName() { return OperationName.TRANSACT_GET_ITEMS; } @Override public TransactGetItemsRequest generateRequest(DynamoDbEnhancedClientExtension extension) { return TransactGetItemsRequest.builder() .transactItems(this.request.transactGetItems()) .build(); } @Override public Function<TransactGetItemsRequest, TransactGetItemsResponse> serviceCall(DynamoDbClient dynamoDbClient) { return dynamoDbClient::transactGetItems; } @Override public Function<TransactGetItemsRequest, CompletableFuture<TransactGetItemsResponse>> asyncServiceCall( DynamoDbAsyncClient dynamoDbAsyncClient) { return dynamoDbAsyncClient::transactGetItems; } @Override public List<Document> transformResponse(TransactGetItemsResponse response, DynamoDbEnhancedClientExtension extension) { return response.responses() .stream() .map(r -> r == null ? null : DefaultDocument.create(r.item())) .collect(Collectors.toList()); } }
4,286
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/QueryOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.Map; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.core.async.SdkPublisher; import software.amazon.awssdk.core.pagination.sync.SdkIterable; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.Expression; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableMetadata; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.enhanced.dynamodb.internal.EnhancedClientUtils; import software.amazon.awssdk.enhanced.dynamodb.internal.ProjectionExpression; import software.amazon.awssdk.enhanced.dynamodb.model.Page; import software.amazon.awssdk.enhanced.dynamodb.model.QueryEnhancedRequest; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import software.amazon.awssdk.services.dynamodb.model.QueryRequest; import software.amazon.awssdk.services.dynamodb.model.QueryResponse; @SdkInternalApi public class QueryOperation<T> implements PaginatedTableOperation<T, QueryRequest, QueryResponse>, PaginatedIndexOperation<T, QueryRequest, QueryResponse> { private final QueryEnhancedRequest request; private QueryOperation(QueryEnhancedRequest request) { this.request = request; } public static <T> QueryOperation<T> create(QueryEnhancedRequest request) { return new QueryOperation<>(request); } @Override public OperationName operationName() { return OperationName.QUERY; } @Override public QueryRequest generateRequest(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { Expression queryExpression = this.request.queryConditional().expression(tableSchema, operationContext.indexName()); Map<String, AttributeValue> expressionValues = queryExpression.expressionValues(); Map<String, String> expressionNames = queryExpression.expressionNames(); if (this.request.filterExpression() != null) { expressionValues = Expression.joinValues(expressionValues, this.request.filterExpression().expressionValues()); expressionNames = Expression.joinNames(expressionNames, this.request.filterExpression().expressionNames()); } String projectionExpressionAsString = null; if (this.request.attributesToProject() != null) { ProjectionExpression attributesToProject = ProjectionExpression.create(this.request.nestedAttributesToProject()); projectionExpressionAsString = attributesToProject.projectionExpressionAsString().orElse(null); expressionNames = Expression.joinNames(expressionNames, attributesToProject.expressionAttributeNames()); } QueryRequest.Builder queryRequest = QueryRequest.builder() .tableName(operationContext.tableName()) .keyConditionExpression(queryExpression.expression()) .expressionAttributeValues(expressionValues) .expressionAttributeNames(expressionNames) .scanIndexForward(this.request.scanIndexForward()) .limit(this.request.limit()) .exclusiveStartKey(this.request.exclusiveStartKey()) .consistentRead(this.request.consistentRead()) .returnConsumedCapacity(this.request.returnConsumedCapacity()) .projectionExpression(projectionExpressionAsString); if (!TableMetadata.primaryIndexName().equals(operationContext.indexName())) { queryRequest = queryRequest.indexName(operationContext.indexName()); } if (this.request.filterExpression() != null) { queryRequest = queryRequest.filterExpression(this.request.filterExpression().expression()); } return queryRequest.build(); } @Override public Function<QueryRequest, SdkIterable<QueryResponse>> serviceCall(DynamoDbClient dynamoDbClient) { return dynamoDbClient::queryPaginator; } @Override public Function<QueryRequest, SdkPublisher<QueryResponse>> asyncServiceCall(DynamoDbAsyncClient dynamoDbAsyncClient) { return dynamoDbAsyncClient::queryPaginator; } @Override public Page<T> transformResponse(QueryResponse response, TableSchema<T> tableSchema, OperationContext context, DynamoDbEnhancedClientExtension dynamoDbEnhancedClientExtension) { return EnhancedClientUtils.readAndTransformPaginatedItems(response, tableSchema, context, dynamoDbEnhancedClientExtension, QueryResponse::items, QueryResponse::lastEvaluatedKey, QueryResponse::count, QueryResponse::scannedCount, QueryResponse::consumedCapacity); } }
4,287
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/OperationName.java
/* * 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.enhanced.dynamodb.internal.operations; import software.amazon.awssdk.annotations.SdkInternalApi; @SdkInternalApi public enum OperationName { NONE(null), BATCH_GET_ITEM("BatchGetItem"), BATCH_WRITE_ITEM("BatchWriteItem"), CREATE_TABLE("CreateTable"), DELETE_ITEM("DeleteItem"), DELETE_TABLE("DeleteTable"), DESCRIBE_TABLE("DescribeTable"), GET_ITEM("GetItem"), QUERY("Query"), PUT_ITEM("PutItem"), SCAN("Scan"), TRANSACT_GET_ITEMS("TransactGetItems"), TRANSACT_WRITE_ITEMS("TransactWriteItems"), UPDATE_ITEM("UpdateItem"); private final String label; OperationName() { this.label = null; } OperationName(String label) { this.label = label; } public String label() { return label; } }
4,288
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/GetItemOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.concurrent.CompletableFuture; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.Key; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableMetadata; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.enhanced.dynamodb.internal.EnhancedClientUtils; import software.amazon.awssdk.enhanced.dynamodb.model.GetItemEnhancedRequest; import software.amazon.awssdk.enhanced.dynamodb.model.GetItemEnhancedResponse; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.Get; import software.amazon.awssdk.services.dynamodb.model.GetItemRequest; import software.amazon.awssdk.services.dynamodb.model.GetItemResponse; import software.amazon.awssdk.services.dynamodb.model.TransactGetItem; @SdkInternalApi public class GetItemOperation<T> implements TableOperation<T, GetItemRequest, GetItemResponse, GetItemEnhancedResponse<T>>, BatchableReadOperation, TransactableReadOperation<T> { private final GetItemEnhancedRequest request; private GetItemOperation(GetItemEnhancedRequest request) { this.request = request; } public static <T> GetItemOperation<T> create(GetItemEnhancedRequest request) { return new GetItemOperation<>(request); } @Override public Boolean consistentRead() { return this.request.consistentRead(); } @Override public Key key() { return this.request.key(); } @Override public OperationName operationName() { return OperationName.GET_ITEM; } @Override public GetItemRequest generateRequest(TableSchema<T> tableSchema, OperationContext context, DynamoDbEnhancedClientExtension extension) { if (!TableMetadata.primaryIndexName().equals(context.indexName())) { throw new IllegalArgumentException("GetItem cannot be executed against a secondary index."); } return GetItemRequest.builder() .tableName(context.tableName()) .key(this.request.key().keyMap(tableSchema, context.indexName())) .consistentRead(this.request.consistentRead()) .returnConsumedCapacity(this.request.returnConsumedCapacityAsString()) .build(); } @Override public GetItemEnhancedResponse<T> transformResponse(GetItemResponse response, TableSchema<T> tableSchema, OperationContext context, DynamoDbEnhancedClientExtension extension) { T attributes = EnhancedClientUtils.readAndTransformSingleItem(response.item(), tableSchema, context, extension); return GetItemEnhancedResponse.<T>builder() .attributes(attributes) .consumedCapacity(response.consumedCapacity()) .build(); } @Override public Function<GetItemRequest, GetItemResponse> serviceCall(DynamoDbClient dynamoDbClient) { return dynamoDbClient::getItem; } @Override public Function<GetItemRequest, CompletableFuture<GetItemResponse>> asyncServiceCall( DynamoDbAsyncClient dynamoDbAsyncClient) { return dynamoDbAsyncClient::getItem; } @Override public TransactGetItem generateTransactGetItem(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension dynamoDbEnhancedClientExtension) { return TransactGetItem.builder() .get(Get.builder() .tableName(operationContext.tableName()) .key(this.request.key().keyMap(tableSchema, operationContext.indexName())) .build()) .build(); } }
4,289
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/PaginatedIndexOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.core.async.SdkPublisher; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.enhanced.dynamodb.model.Page; import software.amazon.awssdk.enhanced.dynamodb.model.PageIterable; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; /** * Interface for an operation that can be executed against a secondary index of a mapped database table and is * expected to return a paginated list of results. Typically, each page of results that is served will automatically * perform an additional service call to DynamoDb to retrieve the next set of results. * <p></p> * A concrete implementation of this interface should also implement {@link PaginatedTableOperation} with the same * types if the operation supports being executed against both the primary index and secondary indices. * * @param <ItemT> The modelled object that this table maps records to. * @param <RequestT> The type of the request object for the DynamoDb call in the low level {@link DynamoDbClient}. * @param <ResponseT> The type of the response object for the DynamoDb call in the low level {@link DynamoDbClient}. */ @SdkInternalApi public interface PaginatedIndexOperation<ItemT, RequestT, ResponseT> extends PaginatedOperation<ItemT, RequestT, ResponseT> { /** * Default implementation of a complete synchronous execution of this operation against a secondary index. It will * construct a context based on the given table name and secondary index name and then call execute() on the * {@link PaginatedOperation} interface to perform the operation. * * @param tableSchema A {@link TableSchema} that maps the table to a modelled object. * @param tableName The physical name of the table that contains the secondary index to execute the operation * against. * @param indexName The physical name of the secondary index to execute the operation against. * @param dynamoDbClient A {@link DynamoDbClient} to make the call against. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request or result of this * operation. A null value here will result in no modifications. * @return A high level result object as specified by the implementation of this operation. */ default PageIterable<ItemT> executeOnSecondaryIndex(TableSchema<ItemT> tableSchema, String tableName, String indexName, DynamoDbEnhancedClientExtension extension, DynamoDbClient dynamoDbClient) { OperationContext context = DefaultOperationContext.create(tableName, indexName); return execute(tableSchema, context, extension, dynamoDbClient); } /** * Default implementation of a complete non-blocking asynchronous execution of this operation against a secondary * index. It will construct a context based on the given table name and secondary index name and then call * executeAsync() on the {@link PaginatedOperation} interface to perform the operation. * * @param tableSchema A {@link TableSchema} that maps the table to a modelled object. * @param tableName The physical name of the table that contains the secondary index to execute the operation * against. * @param indexName The physical name of the secondary index to execute the operation against. * @param dynamoDbAsyncClient A {@link DynamoDbAsyncClient} to make the call against. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request or result of this * operation. A null value here will result in no modifications. * @return A high level result object as specified by the implementation of this operation. */ default SdkPublisher<Page<ItemT>> executeOnSecondaryIndexAsync(TableSchema<ItemT> tableSchema, String tableName, String indexName, DynamoDbEnhancedClientExtension extension, DynamoDbAsyncClient dynamoDbAsyncClient) { OperationContext context = DefaultOperationContext.create(tableName, indexName); return executeAsync(tableSchema, context, extension, dynamoDbAsyncClient); } }
4,290
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/TransactableReadOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.services.dynamodb.model.TransactGetItem; @SdkInternalApi public interface TransactableReadOperation<T> { TransactGetItem generateTransactGetItem(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension dynamoDbEnhancedClientExtension); }
4,291
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/BatchableReadOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.Key; @SdkInternalApi public interface BatchableReadOperation { Boolean consistentRead(); Key key(); }
4,292
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/DeleteItemOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.Map; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.Expression; import software.amazon.awssdk.enhanced.dynamodb.Key; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableMetadata; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.enhanced.dynamodb.internal.EnhancedClientUtils; import software.amazon.awssdk.enhanced.dynamodb.model.DeleteItemEnhancedRequest; import software.amazon.awssdk.enhanced.dynamodb.model.DeleteItemEnhancedResponse; import software.amazon.awssdk.enhanced.dynamodb.model.TransactDeleteItemEnhancedRequest; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import software.amazon.awssdk.services.dynamodb.model.Delete; import software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest; import software.amazon.awssdk.services.dynamodb.model.DeleteItemResponse; import software.amazon.awssdk.services.dynamodb.model.DeleteRequest; import software.amazon.awssdk.services.dynamodb.model.ReturnValue; import software.amazon.awssdk.services.dynamodb.model.TransactWriteItem; import software.amazon.awssdk.services.dynamodb.model.WriteRequest; import software.amazon.awssdk.utils.Either; @SdkInternalApi public class DeleteItemOperation<T> implements TableOperation<T, DeleteItemRequest, DeleteItemResponse, DeleteItemEnhancedResponse<T>>, TransactableWriteOperation<T>, BatchableWriteOperation<T> { private final Either<DeleteItemEnhancedRequest, TransactDeleteItemEnhancedRequest> request; private DeleteItemOperation(DeleteItemEnhancedRequest request) { this.request = Either.left(request); } private DeleteItemOperation(TransactDeleteItemEnhancedRequest request) { this.request = Either.right(request); } public static <T> DeleteItemOperation<T> create(DeleteItemEnhancedRequest request) { return new DeleteItemOperation<>(request); } public static <T> DeleteItemOperation<T> create(TransactDeleteItemEnhancedRequest request) { return new DeleteItemOperation<>(request); } @Override public OperationName operationName() { return OperationName.DELETE_ITEM; } @Override public DeleteItemRequest generateRequest(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { if (!TableMetadata.primaryIndexName().equals(operationContext.indexName())) { throw new IllegalArgumentException("DeleteItem cannot be executed against a secondary index."); } Key key = request.map(DeleteItemEnhancedRequest::key, TransactDeleteItemEnhancedRequest::key); DeleteItemRequest.Builder requestBuilder = DeleteItemRequest.builder() .tableName(operationContext.tableName()) .key(key.keyMap(tableSchema, operationContext.indexName())) .returnValues(ReturnValue.ALL_OLD); if (request.left().isPresent()) { requestBuilder = addPlainDeleteItemParameters(requestBuilder, request.left().get()); } requestBuilder = addExpressionsIfExist(requestBuilder); return requestBuilder.build(); } @Override public DeleteItemEnhancedResponse<T> transformResponse(DeleteItemResponse response, TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { T attributes = EnhancedClientUtils.readAndTransformSingleItem(response.attributes(), tableSchema, operationContext, extension); return DeleteItemEnhancedResponse.<T>builder(null) .attributes(attributes) .consumedCapacity(response.consumedCapacity()) .itemCollectionMetrics(response.itemCollectionMetrics()) .build(); } @Override public Function<DeleteItemRequest, DeleteItemResponse> serviceCall(DynamoDbClient dynamoDbClient) { return dynamoDbClient::deleteItem; } @Override public Function<DeleteItemRequest, CompletableFuture<DeleteItemResponse>> asyncServiceCall( DynamoDbAsyncClient dynamoDbAsyncClient) { return dynamoDbAsyncClient::deleteItem; } @Override public WriteRequest generateWriteRequest(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { DeleteItemRequest deleteItemRequest = generateRequest(tableSchema, operationContext, extension); return WriteRequest.builder() .deleteRequest(DeleteRequest.builder().key(deleteItemRequest.key()).build()) .build(); } @Override public TransactWriteItem generateTransactWriteItem(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension dynamoDbEnhancedClientExtension) { DeleteItemRequest deleteItemRequest = generateRequest(tableSchema, operationContext, dynamoDbEnhancedClientExtension); Delete.Builder builder = Delete.builder() .key(deleteItemRequest.key()) .tableName(deleteItemRequest.tableName()) .conditionExpression(deleteItemRequest.conditionExpression()) .expressionAttributeValues(deleteItemRequest.expressionAttributeValues()) .expressionAttributeNames(deleteItemRequest.expressionAttributeNames()); request.right() .map(TransactDeleteItemEnhancedRequest::returnValuesOnConditionCheckFailureAsString) .ifPresent(builder::returnValuesOnConditionCheckFailure); return TransactWriteItem.builder() .delete(builder.build()) .build(); } private DeleteItemRequest.Builder addExpressionsIfExist(DeleteItemRequest.Builder requestBuilder) { Expression conditionExpression = request.map(r -> Optional.ofNullable(r.conditionExpression()), r -> Optional.ofNullable(r.conditionExpression())) .orElse(null); if (conditionExpression != null) { requestBuilder = requestBuilder.conditionExpression(conditionExpression.expression()); Map<String, String> expressionNames = conditionExpression.expressionNames(); Map<String, AttributeValue> expressionValues = conditionExpression.expressionValues(); // Avoiding adding empty collections that the low level SDK will propagate to DynamoDb where it causes error. if (expressionNames != null && !expressionNames.isEmpty()) { requestBuilder = requestBuilder.expressionAttributeNames(expressionNames); } if (expressionValues != null && !expressionValues.isEmpty()) { requestBuilder = requestBuilder.expressionAttributeValues(expressionValues); } } return requestBuilder; } private DeleteItemRequest.Builder addPlainDeleteItemParameters(DeleteItemRequest.Builder requestBuilder, DeleteItemEnhancedRequest enhancedRequest) { requestBuilder = requestBuilder.returnConsumedCapacity(enhancedRequest.returnConsumedCapacityAsString()); requestBuilder = requestBuilder.returnItemCollectionMetrics(enhancedRequest.returnItemCollectionMetricsAsString()); return requestBuilder; } }
4,293
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/PaginatedDatabaseOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.concurrent.CompletableFuture; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.core.async.SdkPublisher; import software.amazon.awssdk.core.pagination.sync.SdkIterable; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.internal.TransformIterable; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; /** * Interface for an operation that can be executed against a mapped database and is expected to return a paginated * list of results. These operations do not operate on a specific table or index, and may reference multiple tables * and indexes (eg: batch operations). Typically, each page of results that is served will automatically perform an * additional service call to DynamoDb to retrieve the next set of results. * * @param <RequestT> The type of the request object for the DynamoDb call in the low level {@link DynamoDbClient}. * @param <ResponseT> The type of the response object for the DynamoDb call in the low level {@link DynamoDbClient}. * @param <ResultT> The type of the mapped result object that will be returned by the execution of this operation. */ @SdkInternalApi public interface PaginatedDatabaseOperation<RequestT, ResponseT, ResultT> { /** * This method generates the request that needs to be sent to a low level {@link DynamoDbClient}. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request of this operation. A null value * here will result in no modifications. * @return A request that can be used as an argument to a {@link DynamoDbClient} call to perform the operation. */ RequestT generateRequest(DynamoDbEnhancedClientExtension extension); /** * Provides a function for making the low level synchronous paginated SDK call to DynamoDb. * @param dynamoDbClient A low level {@link DynamoDbClient} to make the call against. * @return A function that calls DynamoDb with a provided request object and returns the response object. */ Function<RequestT, SdkIterable<ResponseT>> serviceCall(DynamoDbClient dynamoDbClient); /** * Provides a function for making the low level non-blocking asynchronous paginated SDK call to DynamoDb. * @param dynamoDbAsyncClient A low level {@link DynamoDbAsyncClient} to make the call against. * @return A function that calls DynamoDb with a provided request object and returns the response object. */ Function<RequestT, SdkPublisher<ResponseT>> asyncServiceCall(DynamoDbAsyncClient dynamoDbAsyncClient); /** * Takes the response object returned by the actual DynamoDb call and maps it into a higher level abstracted * result object. * @param response The response object returned by the DynamoDb call for this operation. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the result of this operation. A null value * here will result in no modifications. * @return A high level result object as specified by the implementation of this operation. */ ResultT transformResponse(ResponseT response, DynamoDbEnhancedClientExtension extension); /** * Default implementation of a complete synchronous execution of this operation against a database. * It performs three steps: * 1) Call generateRequest() to get the request object. * 2) Call getServiceCall() and call it using the request object generated in the previous step. * 3) Wraps the {@link SdkIterable} that was returned by the previous step with a transformation that turns each * object returned to a high level result. * * @param dynamoDbClient A {@link DynamoDbClient} to make the call against. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request or result of this operation. A * null value here will result in no modifications. * @return An {@link SdkIterable} that will iteratively return pages of high level result objects as specified by * the implementation of this operation. */ default SdkIterable<ResultT> execute(DynamoDbClient dynamoDbClient, DynamoDbEnhancedClientExtension extension) { RequestT request = generateRequest(extension); SdkIterable<ResponseT> response = serviceCall(dynamoDbClient).apply(request); return TransformIterable.of(response, r -> transformResponse(r, extension)); } /** * Default implementation of a complete non-blocking asynchronous execution of this operation against a database. * It performs three steps: * 1) Call generateRequest() to get the request object. * 2) Call getServiceCall() and call it using the request object generated in the previous step. * 3) Wraps the {@link CompletableFuture} returned by the SDK in a new one that calls transformResponse() to * convert the response object returned in the previous step to a high level result. * * @param dynamoDbAsyncClient A {@link DynamoDbAsyncClient} to make the call against. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request or result of this operation. A * null value here will result in no modifications. * @return An {@link SdkPublisher} that will publish pages of the high level result object as specified by the * implementation of this operation. */ default SdkPublisher<ResultT> executeAsync(DynamoDbAsyncClient dynamoDbAsyncClient, DynamoDbEnhancedClientExtension extension) { RequestT request = generateRequest(extension); SdkPublisher<ResponseT> response = asyncServiceCall(dynamoDbAsyncClient).apply(request); return response.map(r -> transformResponse(r, extension)); } /** * The type, or name, of the operation. */ OperationName operationName(); }
4,294
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/BatchGetItemOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.core.async.SdkPublisher; import software.amazon.awssdk.core.pagination.sync.SdkIterable; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.model.BatchGetItemEnhancedRequest; import software.amazon.awssdk.enhanced.dynamodb.model.BatchGetResultPage; import software.amazon.awssdk.enhanced.dynamodb.model.ReadBatch; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import software.amazon.awssdk.services.dynamodb.model.BatchGetItemRequest; import software.amazon.awssdk.services.dynamodb.model.BatchGetItemResponse; import software.amazon.awssdk.services.dynamodb.model.KeysAndAttributes; @SdkInternalApi public class BatchGetItemOperation implements PaginatedDatabaseOperation<BatchGetItemRequest, BatchGetItemResponse, BatchGetResultPage> { private final BatchGetItemEnhancedRequest request; private BatchGetItemOperation(BatchGetItemEnhancedRequest request) { this.request = request; } public static BatchGetItemOperation create(BatchGetItemEnhancedRequest request) { return new BatchGetItemOperation(request); } @Override public OperationName operationName() { return OperationName.BATCH_GET_ITEM; } @Override public BatchGetItemRequest generateRequest(DynamoDbEnhancedClientExtension extension) { Map<String, KeysAndAttributes> requestItems = new HashMap<>(); request.readBatches().forEach(readBatch -> addReadRequestsToMap(readBatch, requestItems)); return BatchGetItemRequest.builder() .requestItems(Collections.unmodifiableMap(requestItems)) .returnConsumedCapacity(request.returnConsumedCapacityAsString()) .build(); } @Override public BatchGetResultPage transformResponse(BatchGetItemResponse response, DynamoDbEnhancedClientExtension extension) { return BatchGetResultPage.builder().batchGetItemResponse(response).mapperExtension(extension).build(); } @Override public Function<BatchGetItemRequest, SdkIterable<BatchGetItemResponse>> serviceCall(DynamoDbClient dynamoDbClient) { return dynamoDbClient::batchGetItemPaginator; } @Override public Function<BatchGetItemRequest, SdkPublisher<BatchGetItemResponse>> asyncServiceCall( DynamoDbAsyncClient dynamoDbAsyncClient) { return dynamoDbAsyncClient::batchGetItemPaginator; } private void addReadRequestsToMap(ReadBatch readBatch, Map<String, KeysAndAttributes> readRequestMap) { KeysAndAttributes newKeysAndAttributes = readBatch.keysAndAttributes(); KeysAndAttributes existingKeysAndAttributes = readRequestMap.get(readBatch.tableName()); if (existingKeysAndAttributes == null) { readRequestMap.put(readBatch.tableName(), newKeysAndAttributes); return; } KeysAndAttributes mergedKeysAndAttributes = mergeKeysAndAttributes(existingKeysAndAttributes, newKeysAndAttributes); readRequestMap.put(readBatch.tableName(), mergedKeysAndAttributes); } private static KeysAndAttributes mergeKeysAndAttributes(KeysAndAttributes first, KeysAndAttributes second) { if (!compareNullableBooleans(first.consistentRead(), second.consistentRead())) { throw new IllegalArgumentException("All batchable read requests for the same table must have the " + "same 'consistentRead' setting."); } Boolean consistentRead = first.consistentRead() == null ? second.consistentRead() : first.consistentRead(); List<Map<String, AttributeValue>> keys = Stream.concat(first.keys().stream(), second.keys().stream()).collect(Collectors.toList()); return KeysAndAttributes.builder() .keys(keys) .consistentRead(consistentRead) .build(); } private static boolean compareNullableBooleans(Boolean one, Boolean two) { if (one == null && two == null) { return true; } if (one != null) { return one.equals(two); } else { return false; } } }
4,295
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/CommonOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.concurrent.CompletableFuture; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncIndex; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncTable; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbIndex; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; /** * Common interface for a single operation that can be executed in a synchronous or non-blocking asynchronous fashion * against a mapped database table. These operations can be made against either the primary index of a table or a * secondary index, although some implementations of this interface do not support secondary indices and will throw * an exception when executed against one. Conceptually an operation maps 1:1 with an actual DynamoDb call. * <p> * This interface is extended by {@link TableOperation} and {@link IndexOperation} which contain implementations of * the behavior to actually execute the operation in the context of a table or secondary index and are used by * {@link DynamoDbTable} or {@link DynamoDbAsyncTable} and {@link DynamoDbIndex} or {@link DynamoDbAsyncIndex} * respectively. By sharing this common interface operations are able to re-use code regardless of whether they are * executed in the context of a primary or secondary index or whether they are being executed in a synchronous or * non-blocking asynchronous fashion. * * @param <ItemT> The modelled object that this table maps records to. * @param <RequestT> The type of the request object for the DynamoDb call in the low level {@link DynamoDbClient} or * {@link DynamoDbAsyncClient}. * @param <ResponseT> The type of the response object for the DynamoDb call in the low level {@link DynamoDbClient} * or {@link DynamoDbAsyncClient}. * @param <ResultT> The type of the mapped result object that will be returned by the execution of this operation. */ @SdkInternalApi public interface CommonOperation<ItemT, RequestT, ResponseT, ResultT> { /** * This method generates the request that needs to be sent to a low level {@link DynamoDbClient}. * @param tableSchema A {@link TableSchema} that maps the table to a modelled object. * @param context An object containing the context, or target, of the command execution. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request of this operation. A null * value here will result in no modifications. * @return A request that can be used as an argument to a {@link DynamoDbClient} call to perform the operation. */ RequestT generateRequest(TableSchema<ItemT> tableSchema, OperationContext context, DynamoDbEnhancedClientExtension extension); /** * Provides a function for making the low level synchronous SDK call to DynamoDb. * @param dynamoDbClient A low level {@link DynamoDbClient} to make the call against. * @return A function that calls DynamoDb with a provided request object and returns the response object. */ Function<RequestT, ResponseT> serviceCall(DynamoDbClient dynamoDbClient); /** * Provides a function for making the low level non-blocking asynchronous SDK call to DynamoDb. * @param dynamoDbAsyncClient A low level {@link DynamoDbAsyncClient} to make the call against. * @return A function that calls DynamoDb with a provided request object and returns the response object. */ Function<RequestT, CompletableFuture<ResponseT>> asyncServiceCall(DynamoDbAsyncClient dynamoDbAsyncClient); /** * Takes the response object returned by the actual DynamoDb call and maps it into a higher level abstracted * result object. * @param response The response object returned by the DynamoDb call for this operation. * @param tableSchema A {@link TableSchema} that maps the table to a modelled object. * @param context An object containing the context, or target, of the command execution. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the result of this operation. A null * value here will result in no modifications. * @return A high level result object as specified by the implementation of this operation. */ ResultT transformResponse(ResponseT response, TableSchema<ItemT> tableSchema, OperationContext context, DynamoDbEnhancedClientExtension extension); /** * Default implementation of a complete synchronous execution of this operation against either the primary or a * secondary index. * It performs three steps: * 1) Call generateRequest() to get the request object. * 2) Call getServiceCall() and call it using the request object generated in the previous step. * 3) Call transformResponse() to convert the response object returned in the previous step to a high level result. * * @param tableSchema A {@link TableSchema} that maps the table to a modelled object. * @param context An object containing the context, or target, of the command execution. * @param dynamoDbClient A {@link DynamoDbClient} to make the call against. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request or result of this * operation. A null value here will result in no modifications. * @return A high level result object as specified by the implementation of this operation. */ default ResultT execute(TableSchema<ItemT> tableSchema, OperationContext context, DynamoDbEnhancedClientExtension extension, DynamoDbClient dynamoDbClient) { RequestT request = generateRequest(tableSchema, context, extension); ResponseT response = serviceCall(dynamoDbClient).apply(request); return transformResponse(response, tableSchema, context, extension); } /** * Default implementation of a complete non-blocking asynchronous execution of this operation against either the * primary or a secondary index. * It performs three steps: * 1) Call generateRequest() to get the request object. * 2) Call getServiceCall() and call it using the request object generated in the previous step. * 3) Wraps the {@link CompletableFuture} returned by the SDK in a new one that calls transformResponse() to * convert the response object returned in the previous step to a high level result. * * @param tableSchema A {@link TableSchema} that maps the table to a modelled object. * @param context An object containing the context, or target, of the command execution. * @param dynamoDbAsyncClient A {@link DynamoDbAsyncClient} to make the call against. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request or result of this * operation. A null value here will result in no modifications. * @return A {@link CompletableFuture} of the high level result object as specified by the implementation of this * operation. */ default CompletableFuture<ResultT> executeAsync(TableSchema<ItemT> tableSchema, OperationContext context, DynamoDbEnhancedClientExtension extension, DynamoDbAsyncClient dynamoDbAsyncClient) { RequestT request = generateRequest(tableSchema, context, extension); CompletableFuture<ResponseT> response = asyncServiceCall(dynamoDbAsyncClient).apply(request); return response.thenApply(r -> transformResponse(r, tableSchema, context, extension)); } /** * The type, or name, of the operation. */ OperationName operationName(); }
4,296
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/IndexOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import java.util.concurrent.CompletableFuture; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; /** * Interface for a single operation that can be executed against a secondary index of a mapped database table. * Conceptually an operation maps 1:1 with an actual DynamoDb call. * <p> * A concrete implementation of this interface should also implement {@link TableOperation} with the same types if * the operation supports being executed against both the primary index and secondary indices. * * @param <ItemT> The modelled object that this table maps records to. * @param <RequestT> The type of the request object for the DynamoDb call in the low level {@link DynamoDbClient}. * @param <ResponseT> The type of the response object for the DynamoDb call in the low level {@link DynamoDbClient}. * @param <ResultT> The type of the mapped result object that will be returned by the execution of this operation. */ @SdkInternalApi public interface IndexOperation<ItemT, RequestT, ResponseT, ResultT> extends CommonOperation<ItemT, RequestT, ResponseT, ResultT> { /** * Default implementation of a complete synchronous execution of this operation against a secondary index. It will * construct a context based on the given table name and secondary index name and then call execute() on the * {@link CommonOperation} interface to perform the operation. * * @param tableSchema A {@link TableSchema} that maps the table to a modelled object. * @param tableName The physical name of the table that contains the secondary index to execute the operation * against. * @param indexName The physical name of the secondary index to execute the operation against. * @param dynamoDbClient A {@link DynamoDbClient} to make the call against. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request or result of this * operation. A null value here will result in no modifications. * @return A high level result object as specified by the implementation of this operation. */ default ResultT executeOnSecondaryIndex(TableSchema<ItemT> tableSchema, String tableName, String indexName, DynamoDbEnhancedClientExtension extension, DynamoDbClient dynamoDbClient) { OperationContext context = DefaultOperationContext.create(tableName, indexName); return execute(tableSchema, context, extension, dynamoDbClient); } /** * Default implementation of a complete non-blocking asynchronous execution of this operation against a secondary * index. It will construct a context based on the given table name and secondary index name and then call * executeAsync() on the {@link CommonOperation} interface to perform the operation. * * @param tableSchema A {@link TableSchema} that maps the table to a modelled object. * @param tableName The physical name of the table that contains the secondary index to execute the operation * against. * @param indexName The physical name of the secondary index to execute the operation against. * @param dynamoDbAsyncClient A {@link DynamoDbAsyncClient} to make the call against. * @param extension A {@link DynamoDbEnhancedClientExtension} that may modify the request or result of this * operation. A null value here will result in no modifications. * @return A high level result object as specified by the implementation of this operation. */ default CompletableFuture<ResultT> executeOnSecondaryIndexAsync(TableSchema<ItemT> tableSchema, String tableName, String indexName, DynamoDbEnhancedClientExtension extension, DynamoDbAsyncClient dynamoDbAsyncClient) { OperationContext context = DefaultOperationContext.create(tableName, indexName); return executeAsync(tableSchema, context, extension, dynamoDbAsyncClient); } }
4,297
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/UpdateItemOperation.java
/* * 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.enhanced.dynamodb.internal.operations; import static software.amazon.awssdk.enhanced.dynamodb.internal.EnhancedClientUtils.readAndTransformSingleItem; import static software.amazon.awssdk.enhanced.dynamodb.internal.update.UpdateExpressionUtils.operationExpression; import static software.amazon.awssdk.utils.CollectionUtils.filterMap; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.function.Function; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension; import software.amazon.awssdk.enhanced.dynamodb.Expression; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableMetadata; import software.amazon.awssdk.enhanced.dynamodb.TableSchema; import software.amazon.awssdk.enhanced.dynamodb.extensions.WriteModification; import software.amazon.awssdk.enhanced.dynamodb.internal.extensions.DefaultDynamoDbExtensionContext; import software.amazon.awssdk.enhanced.dynamodb.internal.update.UpdateExpressionConverter; import software.amazon.awssdk.enhanced.dynamodb.model.TransactUpdateItemEnhancedRequest; import software.amazon.awssdk.enhanced.dynamodb.model.UpdateItemEnhancedRequest; import software.amazon.awssdk.enhanced.dynamodb.model.UpdateItemEnhancedResponse; import software.amazon.awssdk.enhanced.dynamodb.update.UpdateExpression; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import software.amazon.awssdk.services.dynamodb.model.ReturnValue; import software.amazon.awssdk.services.dynamodb.model.TransactWriteItem; import software.amazon.awssdk.services.dynamodb.model.Update; import software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest; import software.amazon.awssdk.services.dynamodb.model.UpdateItemResponse; import software.amazon.awssdk.utils.CollectionUtils; import software.amazon.awssdk.utils.Either; @SdkInternalApi public class UpdateItemOperation<T> implements TableOperation<T, UpdateItemRequest, UpdateItemResponse, UpdateItemEnhancedResponse<T>>, TransactableWriteOperation<T> { private final Either<UpdateItemEnhancedRequest<T>, TransactUpdateItemEnhancedRequest<T>> request; private UpdateItemOperation(UpdateItemEnhancedRequest<T> request) { this.request = Either.left(request); } private UpdateItemOperation(TransactUpdateItemEnhancedRequest<T> request) { this.request = Either.right(request); } public static <T> UpdateItemOperation<T> create(UpdateItemEnhancedRequest<T> request) { return new UpdateItemOperation<>(request); } public static <T> UpdateItemOperation<T> create(TransactUpdateItemEnhancedRequest<T> request) { return new UpdateItemOperation<>(request); } @Override public OperationName operationName() { return OperationName.UPDATE_ITEM; } @Override public UpdateItemRequest generateRequest(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { if (!TableMetadata.primaryIndexName().equals(operationContext.indexName())) { throw new IllegalArgumentException("UpdateItem cannot be executed against a secondary index."); } T item = request.map(UpdateItemEnhancedRequest::item, TransactUpdateItemEnhancedRequest::item); Boolean ignoreNulls = request.map(r -> Optional.ofNullable(r.ignoreNulls()), r -> Optional.ofNullable(r.ignoreNulls())) .orElse(null); Map<String, AttributeValue> itemMap = tableSchema.itemToMap(item, Boolean.TRUE.equals(ignoreNulls)); TableMetadata tableMetadata = tableSchema.tableMetadata(); WriteModification transformation = extension != null ? extension.beforeWrite(DefaultDynamoDbExtensionContext.builder() .items(itemMap) .operationContext(operationContext) .tableMetadata(tableMetadata) .tableSchema(tableSchema) .operationName(operationName()) .build()) : null; if (transformation != null && transformation.transformedItem() != null) { itemMap = transformation.transformedItem(); } Collection<String> primaryKeys = tableSchema.tableMetadata().primaryKeys(); Map<String, AttributeValue> keyAttributes = filterMap(itemMap, entry -> primaryKeys.contains(entry.getKey())); Map<String, AttributeValue> nonKeyAttributes = filterMap(itemMap, entry -> !primaryKeys.contains(entry.getKey())); Expression updateExpression = generateUpdateExpressionIfExist(tableMetadata, transformation, nonKeyAttributes); Expression conditionExpression = generateConditionExpressionIfExist(transformation, request); Map<String, String> expressionNames = coalesceExpressionNames(updateExpression, conditionExpression); Map<String, AttributeValue> expressionValues = coalesceExpressionValues(updateExpression, conditionExpression); UpdateItemRequest.Builder requestBuilder = UpdateItemRequest.builder() .tableName(operationContext.tableName()) .key(keyAttributes) .returnValues(ReturnValue.ALL_NEW); if (request.left().isPresent()) { addPlainUpdateItemParameters(requestBuilder, request.left().get()); } if (updateExpression != null) { requestBuilder.updateExpression(updateExpression.expression()); } if (conditionExpression != null) { requestBuilder.conditionExpression(conditionExpression.expression()); } if (CollectionUtils.isNotEmpty(expressionNames)) { requestBuilder = requestBuilder.expressionAttributeNames(expressionNames); } if (CollectionUtils.isNotEmpty(expressionValues)) { requestBuilder = requestBuilder.expressionAttributeValues(expressionValues); } return requestBuilder.build(); } @Override public UpdateItemEnhancedResponse<T> transformResponse(UpdateItemResponse response, TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension extension) { try { T attributes = readAndTransformSingleItem(response.attributes(), tableSchema, operationContext, extension); return UpdateItemEnhancedResponse.<T>builder(null) .attributes(attributes) .consumedCapacity(response.consumedCapacity()) .itemCollectionMetrics(response.itemCollectionMetrics()) .build(); } catch (RuntimeException e) { // With a partial update it's possible to update the record into a state that the mapper can no longer // read or validate. This is more likely to happen with signed and encrypted records that undergo partial // updates (that practice is discouraged for this reason). throw new IllegalStateException("Unable to read the new item returned by UpdateItem after the update " + "occurred. Rollbacks are not supported by this operation, therefore the " + "record may no longer be readable using this model.", e); } } @Override public Function<UpdateItemRequest, UpdateItemResponse> serviceCall(DynamoDbClient dynamoDbClient) { return dynamoDbClient::updateItem; } @Override public Function<UpdateItemRequest, CompletableFuture<UpdateItemResponse>> asyncServiceCall( DynamoDbAsyncClient dynamoDbAsyncClient) { return dynamoDbAsyncClient::updateItem; } @Override public TransactWriteItem generateTransactWriteItem(TableSchema<T> tableSchema, OperationContext operationContext, DynamoDbEnhancedClientExtension dynamoDbEnhancedClientExtension) { UpdateItemRequest updateItemRequest = generateRequest(tableSchema, operationContext, dynamoDbEnhancedClientExtension); Update.Builder builder = Update.builder() .key(updateItemRequest.key()) .tableName(updateItemRequest.tableName()) .updateExpression(updateItemRequest.updateExpression()) .conditionExpression(updateItemRequest.conditionExpression()) .expressionAttributeValues(updateItemRequest.expressionAttributeValues()) .expressionAttributeNames(updateItemRequest.expressionAttributeNames()); request.right() .map(TransactUpdateItemEnhancedRequest::returnValuesOnConditionCheckFailureAsString) .ifPresent(builder::returnValuesOnConditionCheckFailure); return TransactWriteItem.builder() .update(builder.build()) .build(); } /** * Retrieves the UpdateExpression from extensions if existing, and then creates an UpdateExpression for the request POJO * if there are attributes to be updated (most likely). If both exist, they are merged and the code generates a final * Expression that represent the result. */ private Expression generateUpdateExpressionIfExist(TableMetadata tableMetadata, WriteModification transformation, Map<String, AttributeValue> attributes) { UpdateExpression updateExpression = null; if (transformation != null && transformation.updateExpression() != null) { updateExpression = transformation.updateExpression(); } if (!attributes.isEmpty()) { List<String> nonRemoveAttributes = UpdateExpressionConverter.findAttributeNames(updateExpression); UpdateExpression operationUpdateExpression = operationExpression(attributes, tableMetadata, nonRemoveAttributes); if (updateExpression == null) { updateExpression = operationUpdateExpression; } else { updateExpression = UpdateExpression.mergeExpressions(updateExpression, operationUpdateExpression); } } return UpdateExpressionConverter.toExpression(updateExpression); } /** * Retrieves the ConditionExpression from extensions if existing, and retrieves the ConditionExpression from the request * if existing. If both exist, they are merged. */ private Expression generateConditionExpressionIfExist( WriteModification transformation, Either<UpdateItemEnhancedRequest<T>, TransactUpdateItemEnhancedRequest<T>> request) { Expression conditionExpression = null; if (transformation != null && transformation.additionalConditionalExpression() != null) { conditionExpression = transformation.additionalConditionalExpression(); } Expression operationConditionExpression = request.map(r -> Optional.ofNullable(r.conditionExpression()), r -> Optional.ofNullable(r.conditionExpression())) .orElse(null); if (operationConditionExpression != null) { conditionExpression = operationConditionExpression.and(conditionExpression); } return conditionExpression; } private UpdateItemRequest.Builder addPlainUpdateItemParameters(UpdateItemRequest.Builder requestBuilder, UpdateItemEnhancedRequest<?> enhancedRequest) { requestBuilder = requestBuilder.returnConsumedCapacity(enhancedRequest.returnConsumedCapacityAsString()); requestBuilder = requestBuilder.returnItemCollectionMetrics(enhancedRequest.returnItemCollectionMetricsAsString()); return requestBuilder; } private static Map<String, String> coalesceExpressionNames(Expression firstExpression, Expression secondExpression) { Map<String, String> expressionNames = null; if (firstExpression != null && !CollectionUtils.isNullOrEmpty(firstExpression.expressionNames())) { expressionNames = firstExpression.expressionNames(); } if (secondExpression != null && !CollectionUtils.isNullOrEmpty(secondExpression.expressionNames())) { expressionNames = Expression.joinNames(expressionNames, secondExpression.expressionNames()); } return expressionNames; } private static Map<String, AttributeValue> coalesceExpressionValues(Expression firstExpression, Expression secondExpression) { Map<String, AttributeValue> expressionValues = null; if (firstExpression != null && !CollectionUtils.isNullOrEmpty(firstExpression.expressionValues())) { expressionValues = firstExpression.expressionValues(); } if (secondExpression != null && !CollectionUtils.isNullOrEmpty(secondExpression.expressionValues())) { expressionValues = Expression.joinValues(expressionValues, secondExpression.expressionValues()); } return expressionValues; } }
4,298
0
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal
Create_ds/aws-sdk-java-v2/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/operations/DefaultOperationContext.java
/* * 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.enhanced.dynamodb.internal.operations; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.enhanced.dynamodb.OperationContext; import software.amazon.awssdk.enhanced.dynamodb.TableMetadata; @SdkInternalApi public class DefaultOperationContext implements OperationContext { private final String tableName; private final String indexName; private DefaultOperationContext(String tableName, String indexName) { this.tableName = tableName; this.indexName = indexName; } public static DefaultOperationContext create(String tableName, String indexName) { return new DefaultOperationContext(tableName, indexName); } public static DefaultOperationContext create(String tableName) { return new DefaultOperationContext(tableName, TableMetadata.primaryIndexName()); } @Override public String tableName() { return tableName; } @Override public String indexName() { return indexName; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } DefaultOperationContext that = (DefaultOperationContext) o; if (tableName != null ? ! tableName.equals(that.tableName) : that.tableName != null) { return false; } return indexName != null ? indexName.equals(that.indexName) : that.indexName == null; } @Override public int hashCode() { int result = tableName != null ? tableName.hashCode() : 0; result = 31 * result + (indexName != null ? indexName.hashCode() : 0); return result; } }
4,299