Skip to content

Commit f61a57c

Browse files
authored
DDB Enhanced README update - add AutoGeneratedTimestampAttribute and … (#3475)
* DDB Enhanced README update - add AutoGeneratedTimestampAttribute and other examples. * Fix typo.
1 parent 0bb7d23 commit f61a57c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

services-custom/dynamodb-enhanced/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ values used are also completely arbitrary.
8787
// Maps a physical table with the name 'customers_20190205' to the schema
8888
DynamoDbTable<Customer> customerTable = enhancedClient.table("customers_20190205", CUSTOMER_TABLE_SCHEMA);
8989
```
90+
91+
The name passed to the `table()` method above must match the name of a DynamoDB table if it already exists.
92+
The DynamoDbTable object, customerTable, can now be used to perform the basic operations on the `customers_20190205` table.
93+
If the table does not already exist, the name will be used as the DynamoDB table name on a subsequent `createTable()` method.
9094

9195
### Common primitive operations
9296
These all strongly map to the primitive DynamoDB operations they are
@@ -363,6 +367,32 @@ Or using a StaticTableSchema with custom values:
363367
.tags(atomicCounter(10L, 5L))
364368
```
365369
370+
### AutoGeneratedTimestampRecordExtension
371+
372+
This extension enables selected attributes to be automatically updated with a current timestamp every time the item
373+
is successfully written to the database. One requirement is the attribute must be of `Instant` type.
374+
375+
This extension is not loaded by default, you need to specify it as custom extension while creating the enhanced
376+
client.
377+
378+
To tell the extension which attribute will be updated with the current timestamp, tag the Instant attribute in
379+
the TableSchema:
380+
```java
381+
@DynamoDbAutoGeneratedTimestampAttribute
382+
public Instant getLastUpdate() {...}
383+
public void setLastUpdate(Instant lastUpdate) {...}
384+
```
385+
386+
If using a StaticTableSchema:
387+
```java
388+
.addAttribute(Instant.class, a -> a.name("lastUpdate")
389+
.getter(Customer::getLastUpdate)
390+
.setter(Customer::setLastUpdate)
391+
// Applying the 'autoGeneratedTimestamp' tag to the attribute
392+
.tags(autoGeneratedTimestampAttribute())
393+
```
394+
395+
366396
## Advanced table schema features
367397
### Explicitly include/exclude attributes in DDB mapping
368398
#### Excluding attributes
@@ -391,6 +421,10 @@ By default, the table schema provides converters for all primitive and many comm
391421
through a default implementation of the AttributeConverterProvider interface. This behavior
392422
can be changed both at the attribute converter provider level as well as for a single attribute.
393423
424+
You can find a list of the available converters in the
425+
[AttributeConverter](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/enhanced/dynamodb/AttributeConverter.html)
426+
interface Javadoc.
427+
394428
#### Provide custom attribute converter providers
395429
You can provide a single AttributeConverterProvider or a chain of ordered AttributeConverterProviders
396430
through the @DynamoDbBean 'converterProviders' annotation. Any custom AttributeConverterProvider must extend the AttributeConverterProvider

0 commit comments

Comments
 (0)