prefix-dynamodb-mapper

Decorator for DynamoDBMapper that will help you add prefix to your attributes

License

License

Categories

Categories

ORM Data
GroupId

GroupId

io.github.normandesjr
ArtifactId

ArtifactId

prefix-dynamodb-mapper
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

prefix-dynamodb-mapper
Decorator for DynamoDBMapper that will help you add prefix to your attributes
Project URL

Project URL

https://github.com/normandesjr/prefix-dynamodb-mapper
Source Code Management

Source Code Management

https://github.com/normandesjr/prefix-dynamodb-mapper.git

Download prefix-dynamodb-mapper

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.normandesjr/prefix-dynamodb-mapper/ -->
<dependency>
    <groupId>io.github.normandesjr</groupId>
    <artifactId>prefix-dynamodb-mapper</artifactId>
    <version>0.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.normandesjr/prefix-dynamodb-mapper/
implementation 'io.github.normandesjr:prefix-dynamodb-mapper:0.1.1'
// https://jarcasting.com/artifacts/io.github.normandesjr/prefix-dynamodb-mapper/
implementation ("io.github.normandesjr:prefix-dynamodb-mapper:0.1.1")
'io.github.normandesjr:prefix-dynamodb-mapper:jar:0.1.1'
<dependency org="io.github.normandesjr" name="prefix-dynamodb-mapper" rev="0.1.1">
  <artifact name="prefix-dynamodb-mapper" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.normandesjr', module='prefix-dynamodb-mapper', version='0.1.1')
)
libraryDependencies += "io.github.normandesjr" % "prefix-dynamodb-mapper" % "0.1.1"
[io.github.normandesjr/prefix-dynamodb-mapper "0.1.1"]

Dependencies

compile (2)

Group / Artifact Type Version
com.amazonaws : aws-java-sdk-dynamodb jar 1.11.696
com.pivovarit : throwing-function jar 1.5.0

test (3)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar 5.6.0
org.mockito : mockito-core jar 3.3.3
org.mockito : mockito-junit-jupiter jar 3.3.3

Project Modules

There are no modules declared in this project.

Prefix DynamoDB Mapper

Motivation

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.

How to use it

Configuration

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));
}

Annotation

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.

Saving

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.

Loading

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.

Developers

Check quality

There is a docker-compose.yml to start a sonarqube.

./mvnw clean install sonar:sonar

Check at localhost:9000 the report.

Release

If your version is a release version (does not end in -SNAPSHOT):

./mvnw clean deploy

Versions

Version
0.1.1
0.1.0
0.0.1-SNAPSHOTS
0.0.1