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;
17 
18 import java.util.Map;
19 import software.amazon.awssdk.annotations.SdkPublicApi;
20 import software.amazon.awssdk.annotations.ThreadSafe;
21 import software.amazon.awssdk.enhanced.dynamodb.internal.operations.OperationName;
22 import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
23 
24 /**
25  * A wrapper for the immutable context objects that are visible to the {@link DynamoDbEnhancedClientExtension}s.
26  */
27 @SdkPublicApi
28 @ThreadSafe
29 public final class DynamoDbExtensionContext {
DynamoDbExtensionContext()30     private DynamoDbExtensionContext() {
31     }
32 
33     @SdkPublicApi
34     @ThreadSafe
35     public interface Context {
36         /**
37          * @return The {@link AttributeValue} map of the items that is about to be written or has just been read.
38          */
items()39         Map<String, AttributeValue> items();
40 
41         /**
42          * @return The context under which the operation to be modified is taking place.
43          */
operationContext()44         OperationContext operationContext();
45 
46         /**
47          * @return A {@link TableMetadata} object describing the structure of the modelled table.
48          */
tableMetadata()49         TableMetadata tableMetadata();
50 
51         /**
52          * @return A {@link TableSchema} object describing the structure of the modelled table.
53          */
tableSchema()54         default TableSchema<?> tableSchema() {
55             throw new UnsupportedOperationException();
56         }
57     }
58 
59     /**
60      * The state of the execution when the {@link DynamoDbEnhancedClientExtension#beforeWrite} method is invoked.
61      */
62     @SdkPublicApi
63     @ThreadSafe
64     public interface BeforeWrite extends Context {
65 
66         /**
67          * @return The context under which the operation to be modified is taking place.
68          */
operationName()69         OperationName operationName();
70     }
71 
72     /**
73      * The state of the execution when the {@link DynamoDbEnhancedClientExtension#afterRead} method is invoked.
74      */
75     @SdkPublicApi
76     @ThreadSafe
77     public interface AfterRead extends Context {
78     }
79 }
80