public final class AtomicCounterExtension extends Object implements DynamoDbEnhancedClientExtension
DynamoDbEnhancedClient
and only needs to be added to the client if you are adding custom extensions to the client.
To utilize atomic counters, first create a field in your model that will be used to store the counter.
This class field should of type Long
and you need to tag it as an atomic counter:
BeanTableSchema
, you should annotate with
DynamoDbAtomicCounter
StaticTableSchema
,
use the StaticAttributeTags.atomicCounter()
static attribute tag.
Every time a new update of the record is successfully written to the database, the counter will be updated automatically.
By default, the counter starts at 0 and increments by 1 for each update. The tags provide the capability of adjusting
the counter start and increment/decrement values such as described in DynamoDbAtomicCounter
.
Example 1: Using a bean based table schema
{@code
Modifier and Type | Class and Description |
---|---|
static class |
AtomicCounterExtension.Builder |
Modifier and Type | Method and Description |
---|---|
WriteModification |
beforeWrite(DynamoDbExtensionContext.BeforeWrite context)
This hook is called just before an operation is going to write data to the database.
|
static AtomicCounterExtension.Builder |
builder() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
afterRead
public static AtomicCounterExtension.Builder builder()
public WriteModification beforeWrite(DynamoDbExtensionContext.BeforeWrite context)
DynamoDbEnhancedClientExtension
beforeWrite
in interface DynamoDbEnhancedClientExtension
context
- The DynamoDbExtensionContext.BeforeWrite
context containing the state of the execution.Copyright © 2023. All rights reserved.