Skip to content

Conversation

@joviegas
Copy link
Contributor

@joviegas joviegas commented Mar 20, 2023

Motivation and Context

Fix for #36

Modifications

Classname Changes Type package API Access
{@link EnhancedDocument} New Interface Interface software.amazon.awssdk.enhanced.dynamodb.document Public API
{@link DocumentTableSchema} New class Implementation of {@link TableSchema} package software.amazon.awssdk.enhanced.dynamodb.document Public API
{@link TableSchema} New API added Implementation of {@link TableSchema} software.amazon.awssdk.enhanced.dynamodb Public API

Creating SCHEMA with Primary and secondary keys

DocumentTableSchema tableSchema = TableSchema.documentSchemaBuilder()
                                             .addIndexPartitionKey(TableMetadata.primaryIndexName(),"sampleHashKey", AttributeValueType.S)
                                             .addIndexSortKey(TableMetadata.primaryIndexName(),"sampleSortKey", AttributeValueType.S)
                                             .attributeConverterProviders(CustomAttributeForDocumentConverterProvider.create(),
                                                                          defaultProvider())
                                             .build();

DynamoDbTable<EnhancedDocument> documentDDBTable = enhancedClient.table("your_tableName", tableSchema);

Simple Creation of EnhancedDocument using Builder

EnhancedDocument simpleDoc = EnhancedDocument.builder()
    .attributeConverterProviders(defaultProvider())
                                             .putString("HashKey", "abcdefg123")
                                             .putNull("nullKey")
                                             .putNumber("numberKey", 2.0)
                                             .putBytes("sdkByte", SdkBytes.fromUtf8String("a"))
                                             .putBoolean("booleanKey", true)
                                             .putJson("jsonKey", "{\"1\": [\"a\", \"b\", \"c\"],\"2\": 1}")
                                             .putStringSet("stingSet",
                                                           Stream.of("a", "b", "c").collect(Collectors.toSet()))

                                             .putNumberSet("numberSet", Stream.of(1, 2, 3, 4).collect(Collectors.toSet()))
                                             .putBytesSet("sdkByteSet",
                                                          Stream.of(SdkBytes.fromUtf8String("a")).collect(Collectors.toSet()))
                                             .build();

Put Item to table with simpleDoc as created above

        table.putItem(simpleDoc);

Put Item to table with EnhancedDocument builder

        table.putItem(EnhancedDocument
                          .builder()
                          .putString(HASH_KEY, "first_hash")
                          .putString(SORT_KEY, "1_sort")
                          .putNull("null_Key")
                          .build());

Get Item from table

            table.getItem(EnhancedDocument.builder()
                             .attributeConverterProviders(defaultProvider())
                                          .putString(SORT_KEY, "1_sort")
                                          .putString(HASH_KEY, "first_hash").build()).getString(SORT_KEY));
                                          .build());
Getter Value Extracted
simpleDoc.toJson() "{"HashKey":"abcdefg123","nullKey":null,"numberKey":2.0,"sdkByte":"a","booleanKey":true,"jsonKey":{"1":["a","b","c"],"2":1},"stingSet":["a","b","c"],"numberSet":[1,2,3,4],"sdkByteSet":["a"]}")
simpleDoc.isPresent("HashKey") true
simpleDoc.isPresent("HashKey2") false
simpleDoc.getString("HashKey") "abcdefg123"
simpleDoc.isNull("nullKey") true
simpleDoc.getNumber("numberKey") SdkNumber.fromDouble(2.0)
simpleDoc.getBytes("sdkByte") SdkBytes.fromUtf8String("a"))
simpleDoc.getBoolean("booleanKey") true
simpleDoc.getJson("jsonKey") "{"1":["a","b","c"],"2":1}"
simpleDoc.getStringSet("stingSet") Stream.of("a", "b", "c").collect(Collectors.toSet()))
simpleDoc.getList("stingSet", EnhancedType.of(String.class)) Stream.of("a", "b", "c").collect(Collectors.toList()))
simpleDoc.getNumberSet("numberSet") Stream.of(1, 2, 3, 4).collect(Collectors.toSet()))
simpleDoc.getBytesSet("sdkByteSet") Stream.of(SdkBytes.fromUtf8String("a")).collect(Collectors.toSet()))

Testing

  • Junits and Functional test using Local DDB

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

License

  • I confirm that this pull request can be released under the Apache 2 license

joviegas and others added 18 commits January 20, 2023 17:26
* Adding new Interface EnhancedDocument

* Fix review comments from Anna-karin and David

* Addresed Zoe's comment
* DefaultEnhancedDocument implementation

* Updated Null check in the conveter itself while iterating Arrays of AttributeValue

* handled review comments

* Update test cases for JsonAttributeCOnverter

* Removed ctor and added a builder

* Removed ctor for toBuilder
* DocumentTableSchema Implementation

* Handle review comments -1

* Handle review comments 2
…3811)

* TableSchema API to create table and functional tests

* Surface API Review

* Surface API Review - compilation issues

* Surface API Review - Review comments

* Surface API Review comments from Matt

* Compilation issue and toStringMethod for JsonNode

* Updated after handling Matt's comments

* Functional Test added

* Update in test cases

* Removed functional tests , will create new PR for this

* Review comments handled

* Explicutly adding the dependency in th pom.xml

* Removed @code from @snippet line in javadoc
* Remove extra spaces in Json and make it same as Items as in V1

* Moved Json string helper functions to seperate class
…omments (#3843)

* Functional Test Cases for Document DDB API and Surface API Review 2 comments

* Removed extra newlines from test cases

* Handled Review comments

* Removed primitive boolean getter and replaced with Boolean getter

* Spotbug issue fixed and using StringUtils

* StringUtils corrected the right package

* Sonar quebe test bug fixed
@joviegas joviegas requested a review from a team as a code owner March 20, 2023 18:21
@joviegas joviegas changed the title Document API for DynamoDB usung EnhancedDynamoDD impementation issue #36 Document API for DynamoDB usung EnhancedDynamoDB impementation issue #36 Mar 20, 2023
@joviegas joviegas enabled auto-merge (squash) March 23, 2023 16:19
@joviegas joviegas merged commit ae4a5c0 into master Mar 23, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 9 Code Smells

81.3% 81.3% Coverage
0.3% 0.3% Duplication

@joviegas joviegas mentioned this pull request Mar 24, 2023
@joviegas joviegas deleted the feature/master/joviegas_document_db_impl branch January 15, 2025 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants