Skip to content
This repository has been archived by the owner on Apr 5, 2023. It is now read-only.

Latest commit

 

History

History
32 lines (21 loc) · 1.09 KB

File metadata and controls

32 lines (21 loc) · 1.09 KB

dyanamodb-enhanced-DynamoDbAutoGeneratedTimestamp-annotation

Annotation for dynamodb enhanced client to automatically create a timestamp on for newly created object or update existing ones.

#WARNING

  • The strategy ALWAYS does not work because DynamoDB extension WriteModification does not support update expressions, it only has updated values and a conditional expression
// When creating a client, you need to add the extension
private static final DynamoDbClient DYNAMO_CLIENT = DynamoDbClient.builder()
        .region(Region.US_WEST_2)
        .build();

private static final DynamoDbEnhancedClient CLIENT = DynamoDbEnhancedClient.builder()
        .dynamoDbClient(DYNAMO_CLIENT)
        .extensions(new AutoGeneratedTimestampExtension()) // Adding extension
        .build();



public class Customer {

    private String name;
    
    @DynamoDbAutoGeneratedTimestampAttribute(strategy = AutoGenerateStrategy.CREATE)
    private Instant joinedTimestamp;
    
    @DynamoDbAutoGeneratedTimestampAttribute(strategy = AutoGenerateStrategy.ALWAYS)
    private Instant lastUpdatedTimestamp;

}