Skip to content

Commit 6cdc65d

Browse files
authored
Merge pull request #260 from dearrudam/feat/dynamodb-document-support
Provide support to Document API for DynamoDB
2 parents 6268591 + 85704b3 commit 6cdc65d

39 files changed

+3229
-32
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version
3535
=== Added
3636

3737
- Include support to Oracle NoSQL database
38+
- Include support to Document API for DynamoDB database
3839

3940
== [1.0.4] - 2023-12-19
4041

README.adoc

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ jnosql.couchbase.user=root
390390
jnosql.couchbase.password=123456
391391
----
392392

393-
394393
The config settings are the default behavior; nevertheless, there is an option to do it programmatically. Create a class that implements the `Supplier<CouchbaseDocumentManager>` and then defines it as an `@Alternative` and the `Priority`.
395394

396395
[source,java]
@@ -519,9 +518,9 @@ jnosql.couchdb.password=password
519518

520519
image::https://user-images.githubusercontent.com/6509926/70553550-f033b980-1b40-11ea-9192-759b3b1053b3.png[Redis Project,align="center" width=50%,height=50%]
521520

522-
https://aws.amazon.com/dynamodb/[Amazon DynamoDB] is a fully managed, serverless, key-value NoSQL database designed to run high-performance applications at any scale. DynamoDB offers built-in security, continuous backups, automated multi-Region replication, in-memory caching, and data import and export tools.
521+
https://aws.amazon.com/dynamodb/[Amazon DynamoDB] is a fully managed, serverless, key-value and document NoSQL database designed to run high-performance applications at any scale. DynamoDB offers built-in security, continuous backups, automated multi-Region replication, in-memory caching, and data import and export tools.
523522

524-
This driver provides support for the *Key-Value* NoSQL API.
523+
This driver has support for two NoSQL API types: *Key-Value* and *Document*.
525524

526525
=== How To Install
527526

@@ -539,6 +538,7 @@ You can use either the Maven or Gradle dependencies:
539538
=== Configuration
540539

541540
This API provides the ```DynamoDBConfigurations``` class to programmatically establish the credentials.
541+
542542
Please note that you can establish properties using the https://microprofile.io/microprofile-config/[MicroProfile Config] specification.
543543

544544
[cols="DynamoDB"]
@@ -560,9 +560,10 @@ Please note that you can establish properties using the https://microprofile.io/
560560
|`jnosql.dynamodb.secretaccess`
561561
|The AWS secret access key, used to authenticate the user interacting with AWS.
562562

563-
564563
|===
565564

565+
=== Using the Key-value API
566+
566567
This is an example using DynamoDB's Key-Value API with MicroProfile Config.
567568

568569
[source,properties]
@@ -571,6 +572,95 @@ jnosql.keyvalue.provider=org.eclipse.jnosql.databases.dynamodb.communication.Dyn
571572
jnosql.keyvalue.database=heroes
572573
----
573574

575+
=== Using the Document API
576+
577+
The DynamoDB's Document API implementation follows the *SINGLE TABLE* strategy, it means, the table will store multiple entity types. To satisfy this strategy, the implementation assumes that the target table will have a composed primary key:
578+
579+
- The `entityType` field as the partitioning key;
580+
- The `id` field as the sort key;
581+
582+
To customize the partitioning key field name, you can define the following configuration
583+
584+
[source,properties]
585+
----
586+
jnosql.dynamodb.entity.pk=entityType
587+
----
588+
589+
By default, the implementation doesn't create the table on-the-fly, letting this requirement for the users. If you prefer, the implementation is able to create the table on-the-fly as well. To activate this capability you should define explicitly the following configuration:
590+
591+
[source,properties]
592+
----
593+
jnosql.dynamodb.create.tables=true
594+
----
595+
596+
The table will be created with the composed primary key mentioned previously.
597+
598+
Here's an example using DynamoDB's Document API with MicroProfile Config.
599+
600+
[source,properties]
601+
----
602+
jnosql.document.provider=org.eclipse.jnosql.databases.dynamodb.communication.DynamoDBDocumentConfiguration
603+
jnosql.document.database=heroes
604+
----
605+
606+
The config settings are the default behavior; nevertheless, there is an option to do it programmatically. Create a class that implements the `Supplier<DynamoDBDocumentManager>` and then defines it as an `@Alternative` and the `Priority`.
607+
608+
[source,java]
609+
----
610+
@ApplicationScoped
611+
@Alternative
612+
@Priority(Interceptor.Priority.APPLICATION)
613+
public class ManagerSupplier implements Supplier<DynamoDBDocumentManager> {
614+
615+
@Produces
616+
public DynamoDBDocumentManager get() {
617+
Settings settings = Settings.builder().put("credential", "value").build();
618+
DynamoDBDocumentConfiguration configuration = new DynamoDBDocumentConfiguration();
619+
DynamoDBDocumentManagerFactory factory = configuration.apply(settings);
620+
return factory.apply("database");
621+
}
622+
}
623+
----
624+
625+
626+
=== Repository
627+
628+
The ```DynamoDBRepository``` interface is an extension of the ```Repository``` interface that allows execution of PartiQL via the ```@PartiQL``` annotation.
629+
630+
WARNING: DynamoDB supports a limited subset of
631+
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ql-reference.html[PartiQL].
632+
633+
NOTE: This implementation doesn't provide pagination on the queries.
634+
635+
[source,java]
636+
----
637+
@Repository
638+
interface PersonRepository extends DynamoDBRepository<Person, String> {
639+
640+
@PartiQL("select * from Person")
641+
List<Person> findAll();
642+
643+
@PartiQL("select * from Person where name = ?")
644+
List<Person> findByName(@Param("") String name);
645+
646+
}
647+
----
648+
649+
650+
=== Template
651+
652+
The ```DynamoDBTemplate``` interface is a specialization of the ```DocumentTemplate``` interface that allows using PartiQL queries.
653+
654+
WARNING: DynamoDB supports a limited subset of
655+
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ql-reference.html[PartiQL].
656+
657+
NOTE: This implementation doesn't provide pagination on the queries.
658+
659+
[source,java]
660+
----
661+
List<Person> people = template.partiQL("select * from Person where name = ? ", params);
662+
----
663+
574664
== Elasticsearch
575665

576666
image::https://jnosql.github.io/img/logos/elastic.svg[Elasticsearch Project,align="center"width=25%,height=25%]

jnosql-dynamodb/pom.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@
2222
<description>The Eclipse JNoSQL layer implementation AWS DynamoDB</description>
2323

2424
<properties>
25-
<dynamodb.version>2.21.21</dynamodb.version>
25+
<dynamodb.version>2.23.12</dynamodb.version>
2626
</properties>
2727

2828
<dependencies>
2929
<dependency>
3030
<groupId>org.eclipse.jnosql.mapping</groupId>
3131
<artifactId>jnosql-mapping-key-value</artifactId>
3232
</dependency>
33+
<dependency>
34+
<groupId>org.eclipse.jnosql.mapping</groupId>
35+
<artifactId>jnosql-mapping-document</artifactId>
36+
</dependency>
3337
<dependency>
3438
<groupId>${project.groupId}</groupId>
3539
<artifactId>jnosql-database-commons</artifactId>
@@ -40,11 +44,5 @@
4044
<artifactId>dynamodb</artifactId>
4145
<version>${dynamodb.version}</version>
4246
</dependency>
43-
<dependency>
44-
<groupId>org.testcontainers</groupId>
45-
<artifactId>testcontainers</artifactId>
46-
<version>${testcontainers.version}</version>
47-
<scope>test</scope>
48-
</dependency>
4947
</dependencies>
5048
</project>

0 commit comments

Comments
 (0)