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 software.amazon.awssdk.annotations.SdkPublicApi; 19 import software.amazon.awssdk.annotations.ThreadSafe; 20 import software.amazon.awssdk.enhanced.dynamodb.extensions.ReadModification; 21 import software.amazon.awssdk.enhanced.dynamodb.extensions.WriteModification; 22 23 /** 24 * Interface for extending the DynamoDb Enhanced client. Two hooks are provided, one that is called just before a record 25 * is written to the database, and one called just after a record is read from the database. This gives the extension the 26 * opportunity to act as an invisible layer between the application and the database and transform the data accordingly. 27 * <p> 28 * Multiple extensions can be used with the enhanced client, but the order in which they are loaded is important. For 29 * instance one extension may overwrite the value of an attribute that another extension then includes in a checksum 30 * calculation. 31 */ 32 @SdkPublicApi 33 @ThreadSafe 34 public interface DynamoDbEnhancedClientExtension { 35 /** 36 * This hook is called just before an operation is going to write data to the database. The extension that 37 * implements this method can choose to transform the item itself, or add a condition to the write operation 38 * or both. 39 * 40 * @param context The {@link DynamoDbExtensionContext.BeforeWrite} context containing the state of the execution. 41 * @return A {@link WriteModification} object that can alter the behavior of the write operation. 42 */ beforeWrite(DynamoDbExtensionContext.BeforeWrite context)43 default WriteModification beforeWrite(DynamoDbExtensionContext.BeforeWrite context) { 44 return WriteModification.builder().build(); 45 } 46 47 /** 48 * This hook is called just after an operation that has read data from the database. The extension that 49 * implements this method can choose to transform the item, and then it is the transformed item that will be 50 * mapped back to the application instead of the item that was actually read from the database. 51 * 52 * @param context The {@link DynamoDbExtensionContext.AfterRead} context containing the state of the execution. 53 * @return A {@link ReadModification} object that can alter the results of a read operation. 54 */ afterRead(DynamoDbExtensionContext.AfterRead context)55 default ReadModification afterRead(DynamoDbExtensionContext.AfterRead context) { 56 return ReadModification.builder().build(); 57 } 58 } 59