Sometimes you need to add some prefixes to attributes when using DynamoDB.
The goal of this project is to keep this task as simple as possible, using annotations.
The lib is released at Maven Central, so you can just add the dependency at your pom.xml
<dependency>
<groupId>io.github.normandesjr</groupId>
<artifactId>prefix-dynamodb-mapper</artifactId>
<version>0.1.0</version>
</dependency>
We will decorate the original DynamoDBMapper with the PrefixKeyDynamoDBMapper as follow:
@Bean
public PrefixKeyDynamoDBMapper dynamoDBMapper(AmazonDynamoDB amazonDynamoDB) {
return new PrefixKeyDynamoDBMapper(amazonDynamoDB, new DynamoDBMapper(amazonDynamoDB));
}
On a get method add the @DynamoDBPrefix with the prefix, as the following code:
@DynamoDBPrefix("PRODUCT_")
@DynamoDBHashKey(attributeName = "pk")
public String getSku() {
return sku;
}
Attention, it only works on getters methods and it's mandatory to have the setter method too.
Create the object that you would like to save and using the decorator PrefixKeyDynamoDBMapper the prefix will be added for you.
Product product = new Product("AAA111");
dynamoDBMapper.save(product)
If you check at database you'll see the value "PRODUCT_AAA111" as the value of "pk" data.
It's mandatory to use @DynamoDBHashKey and @DynamoDBRangeKey with DynamoDBMapper.load(Class clazz, Object hashKey, Object rangeKey).
Product product = dynamoDBMapper.load(Product.class, "AAA1111", "MacBook Pro");
Supposing you have hashKey with PROD_ prefix and rangeKey with "PROD_NAME_ prefix the returned product will not have these prefixes.
There is a docker-compose.yml to start a sonarqube.
./mvnw clean install sonar:sonar
Check at localhost:9000 the report.
If your version is a release version (does not end in -SNAPSHOT):
./mvnw clean deploy