DynamoDB Repository Layer Isolation in Java
January 19, 2021
This is based on this repo: https://github.com/helloworldless/dynamodb-java-sdk-v2.
Here are the details of how we maintain isolation:
- The
Repository
interface is public and is implemented by the package-privateDynamoDbRepository
- The
Repository
is defined in terms of public, database-agnostic value classes (in other words, nothing related to DynamoDB here) - The
DynamoDbRepository
uses MapStruct to effortlessly convert the database-agnostic value classes into DynamoDB entities (@DynamoDbBean
) - The DynamoDB entities (
@DynamoDbBean
) also live inside the repository package. They are public but should ideally be package-private. However, making them non-public would require switching to manually wiring the DynamoDB schema as opposed to using the SDK’s more convenient, annotation-driven schema capability.