Class DynamoDbTemplate
java.lang.Object
io.awspring.spring.data.dynamodb.core.DynamoDbAccessor
io.awspring.spring.data.dynamodb.core.DynamoDbTemplate
- All Implemented Interfaces:
DynamoDbOperations, Aware, InitializingBean, ApplicationContextAware, ApplicationEventPublisherAware
public class DynamoDbTemplate
extends DynamoDbAccessor
implements DynamoDbOperations, ApplicationContextAware, ApplicationEventPublisherAware
Default
DynamoDbOperations implementation backed by an AWS SDK DynamoDbClient.- Since:
- 1.0.0
- Author:
- Matej Nedic
-
Constructor Summary
ConstructorsConstructorDescriptionDynamoDbTemplate(software.amazon.awssdk.services.dynamodb.DynamoDbClient dynamoDbClient, DynamoDbConverter converter) Creates a template. -
Method Summary
Modifier and TypeMethodDescription<T> longCounts every item visible through the entity mapping.<T> longcount(Class<T> entityClass, DynamoDbQueryRequest queryRequest) Counts items matching a query request.<T> longcount(Class<T> entityClass, DynamoDbScanRequest scanRequest) Counts items matching a scan request.<T> voidDeletes an item by partition and optional sort key.<T> voiddelete(Class<T> entityClass, Object primaryKey, @Nullable Object sortKey, DynamoDbConditionRequest dynamoDBConditionRequest) Deletes an item by key when the condition succeeds.voidDeletes the supplied entity.<T> EntityReadResult<List<T>> executeStatement(String statement, String nextToken, Class<T> entityClass) Executes a PartiQL statement without positional values.<T> EntityReadResult<List<T>> Executes a PartiQL statement with positional values.<T> EntityReadResult<List<T>> executeStatement(String statement, String nextToken, Class<T> entityClass, List<Object> values, Boolean consistentRead) Executes a PartiQL statement with positional values and explicit read consistency.<T> booleanexists(Class<T> entityClass, DynamoDbQueryRequest queryRequest) Checks whether a query has at least one match.<T> booleanexists(Class<T> entityClass, DynamoDbScanRequest scanRequest) Checks whether a scan has at least one match.<T> booleanexistsById(Object partitionKey, @Nullable Object sortKey, Class<T> entityClass) Checks whether an item exists without converting it.<T> List<T> Reads all items visible through the entity mapping.<T> @Nullable TFinds an item by its partition and optional sort key.<T> @Nullable TfindById(Object partitionKey, @Nullable Object sortKey, Class<T> entityClass, Boolean consistentRead) Finds an item by both keys with explicit read consistency.<T> @Nullable TFinds an item by its partition key.<T> @Nullable TFinds an item by its partition key with explicit read consistency.protected EntityOperationsgetTableName(Class<?> entityClass) <T> EntityWriteResult<T> insert(T entity) Inserts an entity and fails if its key already exists.protected <T> TmaybeCallAfterConvert(T object, String tableName) protected <T> TmaybeCallAfterSave(T object, String tableName) protected <T> TmaybeCallBeforeConvert(T object, String tableName) protected <T> TmaybeCallBeforeSave(T object, String tableName) protected <E extends DynamoDbMappingEvent<T>, T>
voidmaybeEmitEvent(E event) <T> EntityQueryResult<List<T>> query(Class<T> entityClass, DynamoDbQueryRequest qr, DynamoDbPageRequest dynamoDBPageRequest) Executes one DynamoDB query page.<T> IndexQueryBuilder<T> Starts a typed query against the named index.<A> EntityQueryResult<A> queryItemCollection(Class<A> viewClass, DynamoDbQueryRequest dynamoDbRequest, DynamoDbPageRequest dynamoDBPageRequest) Queries and folds one DynamoDB page into an item-collection view.<T> EntityWriteResult<T> save(T entity) Saves an entity withPutItem.<T> EntityWriteResult<T> save(T entity, DynamoDbConditionRequest dynamoDBConditionRequest) Saves an entity with a conditionalPutItem.<T> Iterable<T> Saves entities with chunkedBatchWriteItemrequests.<T> EntityQueryResult<List<T>> scan(Class<T> entityClass, DynamoDbScanRequest scanRequest) Executes one DynamoDB scan page.voidsetApplicationContext(@Nullable ApplicationContext applicationContext) voidsetApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) voidsetBatchWriteBackOff(BackOff batchWriteBackOff) voidsetEntityCallbacks(@Nullable EntityCallbacks entityCallbacks) <T> EntityWriteResult<T> update(Object partitionKey, @Nullable Object sortKey, DynamoDbUpdateExpressionRequestInterface builderInterface, Class<T> entityClass) Updates an item with a fluent update-expression callback.<T> EntityWriteResult<T> update(Object partitionKey, @Nullable Object sortKey, DynamoDbUpdateExpressionRequest dynamoDBUpdateExpressionRequest, Class<T> entityClass) Updates an item with an explicit update request.<T> EntityWriteResult<T> update(T entity) Updates an item from the supplied entity state.protected voidwaitBeforeRetry(long millis) Methods inherited from class DynamoDbAccessor
afterPropertiesSet, getDynamoDbClient, getExceptionTranslator, setDynamoDbClient, setExceptionTranslator, translate
-
Constructor Details
-
DynamoDbTemplate
public DynamoDbTemplate(software.amazon.awssdk.services.dynamodb.DynamoDbClient dynamoDbClient, DynamoDbConverter converter) Creates a template.- Parameters:
dynamoDbClient- AWS SDK clientconverter- entity converter
-
-
Method Details
-
setApplicationContext
public void setApplicationContext(@Nullable ApplicationContext applicationContext) throws BeansException - Specified by:
setApplicationContextin interfaceApplicationContextAware- Throws:
BeansException
-
setApplicationEventPublisher
- Specified by:
setApplicationEventPublisherin interfaceApplicationEventPublisherAware
-
setEntityCallbacks
-
maybeEmitEvent
-
setBatchWriteBackOff
-
saveAll
Description copied from interface:DynamoDbOperationsSaves entities with chunkedBatchWriteItemrequests.- Specified by:
saveAllin interfaceDynamoDbOperations
-
waitBeforeRetry
protected void waitBeforeRetry(long millis) -
findById
Description copied from interface:DynamoDbOperationsFinds an item by its partition key.- Specified by:
findByIdin interfaceDynamoDbOperations
-
findById
public <T> @Nullable T findById(Object partitionKey, @Nullable Object sortKey, Class<T> entityClass) Description copied from interface:DynamoDbOperationsFinds an item by its partition and optional sort key.- Specified by:
findByIdin interfaceDynamoDbOperations
-
findById
public <T> @Nullable T findById(Object partitionKey, @Nullable Object sortKey, Class<T> entityClass, Boolean consistentRead) Description copied from interface:DynamoDbOperationsFinds an item by both keys with explicit read consistency.- Specified by:
findByIdin interfaceDynamoDbOperations
-
findById
Description copied from interface:DynamoDbOperationsFinds an item by its partition key with explicit read consistency.- Specified by:
findByIdin interfaceDynamoDbOperations
-
existsById
Description copied from interface:DynamoDbOperationsChecks whether an item exists without converting it.- Specified by:
existsByIdin interfaceDynamoDbOperations
-
save
Description copied from interface:DynamoDbOperationsSaves an entity withPutItem.- Specified by:
savein interfaceDynamoDbOperations
-
save
Description copied from interface:DynamoDbOperationsSaves an entity with a conditionalPutItem.- Specified by:
savein interfaceDynamoDbOperations
-
insert
Description copied from interface:DynamoDbOperationsInserts an entity and fails if its key already exists.- Specified by:
insertin interfaceDynamoDbOperations
-
delete
Description copied from interface:DynamoDbOperationsDeletes the supplied entity.- Specified by:
deletein interfaceDynamoDbOperations
-
delete
Description copied from interface:DynamoDbOperationsDeletes an item by partition and optional sort key.- Specified by:
deletein interfaceDynamoDbOperations
-
delete
public <T> void delete(Class<T> entityClass, Object primaryKey, @Nullable Object sortKey, DynamoDbConditionRequest dynamoDBConditionRequest) Description copied from interface:DynamoDbOperationsDeletes an item by key when the condition succeeds.- Specified by:
deletein interfaceDynamoDbOperations
-
getConverter
- Specified by:
getConverterin interfaceDynamoDbOperations- Returns:
- the converter used by these operations
-
query
public <T> EntityQueryResult<List<T>> query(Class<T> entityClass, DynamoDbQueryRequest qr, DynamoDbPageRequest dynamoDBPageRequest) Description copied from interface:DynamoDbOperationsExecutes one DynamoDB query page.- Specified by:
queryin interfaceDynamoDbOperations
-
queryItemCollection
public <A> EntityQueryResult<A> queryItemCollection(Class<A> viewClass, DynamoDbQueryRequest dynamoDbRequest, DynamoDbPageRequest dynamoDBPageRequest) Description copied from interface:DynamoDbOperationsQueries and folds one DynamoDB page into an item-collection view.- Specified by:
queryItemCollectionin interfaceDynamoDbOperations- Returns:
- the folded page, count, and optional continuation cursor
-
scan
Description copied from interface:DynamoDbOperationsExecutes one DynamoDB scan page.- Specified by:
scanin interfaceDynamoDbOperations
-
executeStatement
public <T> EntityReadResult<List<T>> executeStatement(String statement, String nextToken, Class<T> entityClass, List<Object> values) Description copied from interface:DynamoDbOperationsExecutes a PartiQL statement with positional values.- Specified by:
executeStatementin interfaceDynamoDbOperations
-
executeStatement
public <T> EntityReadResult<List<T>> executeStatement(String statement, String nextToken, Class<T> entityClass) Description copied from interface:DynamoDbOperationsExecutes a PartiQL statement without positional values.- Specified by:
executeStatementin interfaceDynamoDbOperations
-
executeStatement
public <T> EntityReadResult<List<T>> executeStatement(String statement, String nextToken, Class<T> entityClass, List<Object> values, Boolean consistentRead) Description copied from interface:DynamoDbOperationsExecutes a PartiQL statement with positional values and explicit read consistency.- Specified by:
executeStatementin interfaceDynamoDbOperations
-
update
Description copied from interface:DynamoDbOperationsUpdates an item from the supplied entity state.- Specified by:
updatein interfaceDynamoDbOperations
-
update
public <T> EntityWriteResult<T> update(Object partitionKey, @Nullable Object sortKey, DynamoDbUpdateExpressionRequest dynamoDBUpdateExpressionRequest, Class<T> entityClass) Description copied from interface:DynamoDbOperationsUpdates an item with an explicit update request.- Specified by:
updatein interfaceDynamoDbOperations
-
update
public <T> EntityWriteResult<T> update(Object partitionKey, @Nullable Object sortKey, DynamoDbUpdateExpressionRequestInterface builderInterface, Class<T> entityClass) Description copied from interface:DynamoDbOperationsUpdates an item with a fluent update-expression callback.- Specified by:
updatein interfaceDynamoDbOperations
-
getTableName
- Specified by:
getTableNamein interfaceDynamoDbOperations- Returns:
- the resolved physical table name for the entity
-
count
Description copied from interface:DynamoDbOperationsCounts every item visible through the entity mapping.- Specified by:
countin interfaceDynamoDbOperations
-
count
Description copied from interface:DynamoDbOperationsCounts items matching a scan request.- Specified by:
countin interfaceDynamoDbOperations
-
exists
Description copied from interface:DynamoDbOperationsChecks whether a scan has at least one match.- Specified by:
existsin interfaceDynamoDbOperations
-
count
Description copied from interface:DynamoDbOperationsCounts items matching a query request.- Specified by:
countin interfaceDynamoDbOperations
-
exists
Description copied from interface:DynamoDbOperationsChecks whether a query has at least one match.- Specified by:
existsin interfaceDynamoDbOperations
-
findAll
Description copied from interface:DynamoDbOperationsReads all items visible through the entity mapping.- Specified by:
findAllin interfaceDynamoDbOperations
-
getEntityOperations
-
maybeCallBeforeConvert
-
maybeCallBeforeSave
-
maybeCallAfterSave
-
maybeCallAfterConvert
-
query
Description copied from interface:DynamoDbOperationsStarts a typed query against the named index.- Specified by:
queryin interfaceDynamoDbOperations
-