• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 package software.amazon.awssdk.enhanced.dynamodb.mapper;
17 
18 import java.util.function.Consumer;
19 import software.amazon.awssdk.annotations.SdkPublicApi;
20 import software.amazon.awssdk.annotations.ThreadSafe;
21 import software.amazon.awssdk.enhanced.dynamodb.AttributeValueType;
22 import software.amazon.awssdk.enhanced.dynamodb.EnhancedType;
23 
24 /**
25  * Interface for a tag that can be applied to any {@link StaticAttribute}. When a tagged attribute is added to a
26  * {@link software.amazon.awssdk.enhanced.dynamodb.TableSchema}, the table metadata stored on the schema will be updated
27  * by calling the {@link #modifyMetadata(String, AttributeValueType)} method for every tag associated with the
28  * attribute.
29  * <p>
30  * Common implementations of this interface that can be used to declare indices in your schema can be found in
31  * {@link StaticAttributeTags}.
32  */
33 @SdkPublicApi
34 @ThreadSafe
35 public interface StaticAttributeTag {
36     /**
37      * A function that modifies an existing {@link StaticTableSchema.Builder} when this tag is applied to a specific
38      * attribute. This will be used by the {@link StaticTableSchema} to capture all the metadata associated with
39      * tagged attributes when constructing the table schema.
40      *
41      * @param attributeName The name of the attribute this tag has been applied to.
42      * @param attributeValueType The type of the attribute this tag has been applied to. This can be used for
43      *                           validation, for instance if you have an attribute tag that should only be associated
44      *                           with a string.
45      * @return a consumer that modifies an existing {@link StaticTableSchema.Builder}.
46      */
modifyMetadata(String attributeName, AttributeValueType attributeValueType)47     Consumer<StaticTableMetadata.Builder> modifyMetadata(String attributeName,
48                                                          AttributeValueType attributeValueType);
49 
50     /**
51      * Function that validates the Converted return type is suitable for the extension.
52      * @param <R> the class that the value of this attribute converts to.
53      * @param attributeName The name of the attribute this tag has been applied to.
54      * @param enhancedType The type of the object to be converted
55      * @param attributeValueType Attribute Value type of the attribute.
56      */
validateType(String attributeName, EnhancedType<R> enhancedType, AttributeValueType attributeValueType)57     default <R> void validateType(String attributeName, EnhancedType<R> enhancedType,
58                                   AttributeValueType attributeValueType) {
59     }
60 
61 }
62