Skip to content

Commit

Permalink
Update Delete operations to return object. (awspring#1185)
Browse files Browse the repository at this point in the history
Update Delete operations to return entity object
  • Loading branch information
MatejNedic authored Jul 30, 2024
1 parent 12f25ed commit 7570672
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public interface DynamoDbOperations {
* @param clazz Class of entity being deleted so {@link software.amazon.awssdk.enhanced.dynamodb.TableSchema} can be
* generated.
*/
void delete(Key key, Class<?> clazz);
<T> T delete(Key key, Class<T> clazz);

/**
* Deletes a record for a given Entity.
*
* @param entity Entity object for deletion.
*/
<T> void delete(T entity);
<T> T delete(T entity);

/**
* Loads entity for a given Key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public <T> T update(T entity) {
return prepareTable(entity).updateItem(entity);
}

public void delete(Key key, Class<?> clazz) {
public <T> T delete(Key key, Class<T> clazz) {
Assert.notNull(key, "key is required");
Assert.notNull(clazz, "clazz is required");
prepareTable(clazz).deleteItem(key);
return prepareTable(clazz).deleteItem(key);
}

public <T> void delete(T entity) {
public <T> T delete(T entity) {
Assert.notNull(entity, "entity is required");
prepareTable(entity).deleteItem(entity);
return prepareTable(entity).deleteItem(entity);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ void dynamoDbTemplate_saveAndDelete_entitySuccessful(DynamoDbTable<PersonEntity>
PersonEntity personEntity = new PersonEntity(UUID.randomUUID(), "foo", "bar");
dynamoDbTemplate.save(personEntity);

dynamoDbTemplate.delete(personEntity);
var deletedItem = dynamoDbTemplate.delete(personEntity);

PersonEntity personEntity1 = dynamoDbTemplate
.load(Key.builder().partitionValue(personEntity.getUuid().toString()).build(), PersonEntity.class);
assertThat(deletedItem.getName()).isEqualTo("foo");
assertThat(personEntity1).isEqualTo(null);
cleanUp(dynamoDbTable, personEntity.getUuid());
}
Expand Down

0 comments on commit 7570672

Please sign in to comment.