Skip to content

Commit fafa5df

Browse files
committed
DDB Enhanced: Add support for a 'key item' in operations that take a key
1 parent cdc37ba commit fafa5df

20 files changed

+385
-178
lines changed

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/DynamoDbAsyncTable.java

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ default CompletableFuture<Void> createTable() {
152152
* <pre>
153153
* {@code
154154
*
155-
* mappedTable.delete(DeleteItemEnhancedRequest.builder().key(key).build()).join();
155+
* MyItem previouslyPersistedItem = mappedTable.delete(DeleteItemEnhancedRequest.builder().key(key).build()).join();
156156
* }
157157
* </pre>
158158
*
159159
* @param request A {@link DeleteItemEnhancedRequest} with key and optional directives for deleting an item from the table.
160-
* @return a {@link CompletableFuture} of the deleted item
160+
* @return a {@link CompletableFuture} of the item that was persisted in the database before it was deleted.
161161
*/
162162
default CompletableFuture<T> deleteItem(DeleteItemEnhancedRequest request) {
163163
throw new UnsupportedOperationException();
@@ -179,13 +179,13 @@ default CompletableFuture<T> deleteItem(DeleteItemEnhancedRequest request) {
179179
* <pre>
180180
* {@code
181181
*
182-
* mappedTable.delete(r -> r.key(key)).join();
182+
* MyItem previouslyPersistedItem = mappedTable.delete(r -> r.key(key)).join();
183183
* }
184184
* </pre>
185185
*
186186
* @param requestConsumer A {@link Consumer} of {@link DeleteItemEnhancedRequest} with key and
187187
* optional directives for deleting an item from the table.
188-
* @return a {@link CompletableFuture} of the deleted item
188+
* @return a {@link CompletableFuture} of the item that was persisted in the database before it was deleted.
189189
*/
190190
default CompletableFuture<T> deleteItem(Consumer<DeleteItemEnhancedRequest.Builder> requestConsumer) {
191191
throw new UnsupportedOperationException();
@@ -201,17 +201,39 @@ default CompletableFuture<T> deleteItem(Consumer<DeleteItemEnhancedRequest.Build
201201
* <pre>
202202
* {@code
203203
*
204-
* mappedTable.delete(key);
204+
* MyItem previouslyPersistedItem = mappedTable.delete(key).join;
205205
* }
206206
* </pre>
207207
*
208208
* @param key A {@link Key} that will be used to match a specific record to delete from the database table.
209-
* @return a {@link CompletableFuture} of the deleted item
209+
* @return a {@link CompletableFuture} of the item that was persisted in the database before it was deleted.
210210
*/
211211
default CompletableFuture<T> deleteItem(Key key) {
212212
throw new UnsupportedOperationException();
213213
}
214214

215+
/**
216+
* Deletes a single item from the mapped table using just the key of a supplied modelled 'key item' object.
217+
* <p>
218+
* This operation calls the low-level DynamoDB API DeleteItem operation. Consult the DeleteItem documentation for
219+
* further details and constraints.
220+
* <p>
221+
* Example:
222+
* <pre>
223+
* {@code
224+
*
225+
* MyItem previouslyPersistedItem = mappedTable.deleteItem(keyItem).join();
226+
* }
227+
* </pre>
228+
*
229+
* @param keyItem A modelled item with the primary key fields set that will be used to match a specific record to
230+
* delete from the database table.
231+
* @return a {@link CompletableFuture} of the item that was persisted in the database before it was deleted.
232+
*/
233+
default CompletableFuture<T> deleteItem(T keyItem) {
234+
throw new UnsupportedOperationException();
235+
}
236+
215237
/**
216238
* Retrieves a single item from the mapped table using a supplied primary {@link Key}.
217239
* <p>
@@ -230,7 +252,7 @@ default CompletableFuture<T> deleteItem(Key key) {
230252
* </pre>
231253
*
232254
* @param request A {@link GetItemEnhancedRequest} with key and optional directives for retrieving an item from the table.
233-
* @return a {@link CompletableFuture} of the retrieved item
255+
* @return a {@link CompletableFuture} of the item that was persisted in the database before it was deleted.
234256
*/
235257
default CompletableFuture<T> getItem(GetItemEnhancedRequest request) {
236258
throw new UnsupportedOperationException();
@@ -274,7 +296,7 @@ default CompletableFuture<T> getItem(Consumer<GetItemEnhancedRequest.Builder> re
274296
* <pre>
275297
* {@code
276298
*
277-
* MyItem item = mappedTable.getItem(key);
299+
* MyItem item = mappedTable.getItem(key).join();
278300
* }
279301
* </pre>
280302
*
@@ -285,6 +307,28 @@ default CompletableFuture<T> getItem(Key key) {
285307
throw new UnsupportedOperationException();
286308
}
287309

310+
/**
311+
* Retrieves a single item from the mapped table using just the key of a supplied modelled 'key item'.
312+
* <p>
313+
* This operation calls the low-level DynamoDB API GetItem operation. Consult the GetItem documentation for
314+
* further details and constraints.
315+
* <p>
316+
* Example:
317+
* <pre>
318+
* {@code
319+
*
320+
* MyItem item = mappedTable.getItem(keyItem).join();
321+
* }
322+
* </pre>
323+
*
324+
* @param keyItem A modelled item with the primary key fields set that will be used to match a specific record to
325+
* retrieve from the database table.
326+
* @return a {@link CompletableFuture} of the retrieved item
327+
*/
328+
default CompletableFuture<T> getItem(T keyItem) {
329+
throw new UnsupportedOperationException();
330+
}
331+
288332
/**
289333
* Executes a query against the primary index of the table using a {@link QueryConditional} expression to retrieve a list of
290334
* items matching the given conditions.
@@ -588,7 +632,7 @@ default CompletableFuture<T> updateItem(Consumer<UpdateItemEnhancedRequest.Build
588632
* <pre>
589633
* {@code
590634
*
591-
* MyItem item = mappedTable.updateItem(item);
635+
* MyItem item = mappedTable.updateItem(item).join();
592636
* }
593637
* </pre>
594638
*

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/DynamoDbTable.java

Lines changed: 88 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
* Synchronous interface for running commands against an object that is linked to a specific DynamoDb table resource
3333
* and therefore knows how to map records from that table into a modelled object.
3434
* <p>
35-
* By default, all command methods throw an {@link UnsupportedOperationException} to prevent interface extensions from breaking
36-
* implementing classes.
35+
* By default, all command methods throw an {@link UnsupportedOperationException} to prevent interface extensions from
36+
* breaking implementing classes.
3737
* <p>
3838
* @param <T> The type of the modelled object.
3939
*/
@@ -55,10 +55,10 @@ public interface DynamoDbTable<T> extends MappedTableResource<T> {
5555
* <p>
5656
* Use {@link DynamoDbEnhancedClient#table(String, TableSchema)} to define the mapped table resource.
5757
* <p>
58-
* This operation calls the low-level DynamoDB API CreateTable operation. Note that this is an asynchronous operation and that
59-
* the table may not immediately be available for writes and reads. Currently, there is no mechanism supported within this
60-
* library to wait for/check the status of a created table. You must provide this functionality yourself.
61-
* Consult the CreateTable documentation for further details and constraints.
58+
* This operation calls the low-level DynamoDB API CreateTable operation. Note that this is an asynchronous
59+
* operation and that the table may not immediately be available for writes and reads. Currently, there is no
60+
* mechanism supported within this library to wait for/check the status of a created table. You must provide this
61+
* functionality yourself. Consult the CreateTable documentation for further details and constraints.
6262
* <p>
6363
* Example:
6464
* <pre>
@@ -86,13 +86,13 @@ default void createTable(CreateTableEnhancedRequest request) {
8686
* <p>
8787
* Use {@link DynamoDbEnhancedClient#table(String, TableSchema)} to define the mapped table resource.
8888
* <p>
89-
* This operation calls the low-level DynamoDB API CreateTable operation. Note that this is an asynchronous operation and that
90-
* the table may not immediately be available for writes and reads. Currently, there is no mechanism supported within this
91-
* library to wait for/check the status of a created table. You must provide this functionality yourself.
92-
* Consult the CreateTable documentation for further details and constraints.
89+
* This operation calls the low-level DynamoDB API CreateTable operation. Note that this is an asynchronous
90+
* operation and that the table may not immediately be available for writes and reads. Currently, there is no
91+
* mechanism supported within this library to wait for/check the status of a created table. You must provide this
92+
* functionality yourself. Consult the CreateTable documentation for further details and constraints.
9393
* <p>
94-
* <b>Note:</b> This is a convenience method that creates an instance of the request builder avoiding the need to create one
95-
* manually via {@link CreateTableEnhancedRequest#builder()}.
94+
* <b>Note:</b> This is a convenience method that creates an instance of the request builder avoiding the need to
95+
* create one manually via {@link CreateTableEnhancedRequest#builder()}.
9696
* <p>
9797
* Example:
9898
* <pre>
@@ -106,8 +106,8 @@ default void createTable(CreateTableEnhancedRequest request) {
106106
* }
107107
* </pre>
108108
*
109-
* @param requestConsumer A {@link Consumer} of {@link CreateTableEnhancedRequest.Builder} containing optional parameters
110-
* for table creation.
109+
* @param requestConsumer A {@link Consumer} of {@link CreateTableEnhancedRequest.Builder} containing optional
110+
* parameters for table creation.
111111
*/
112112
default void createTable(Consumer<CreateTableEnhancedRequest.Builder> requestConsumer) {
113113
throw new UnsupportedOperationException();
@@ -118,10 +118,10 @@ default void createTable(Consumer<CreateTableEnhancedRequest.Builder> requestCon
118118
* <p>
119119
* Use {@link DynamoDbEnhancedClient#table(String, TableSchema)} to define the mapped table resource.
120120
* <p>
121-
* This operation calls the low-level DynamoDB API CreateTable operation. Note that this is an asynchronous operation and that
122-
* the table may not immediately be available for writes and reads. Currently, there is no mechanism supported within this
123-
* library to wait for/check the status of a created table. You must provide this functionality yourself.
124-
* Consult the CreateTable documentation for further details and constraints.
121+
* This operation calls the low-level DynamoDB API CreateTable operation. Note that this is an asynchronous
122+
* operation and that the table may not immediately be available for writes and reads. Currently, there is no
123+
* mechanism supported within this library to wait for/check the status of a created table. You must provide this
124+
* functionality yourself. Consult the CreateTable documentation for further details and constraints.
125125
* <p>
126126
* Example:
127127
* <pre>
@@ -149,12 +149,13 @@ default void createTable() {
149149
* <pre>
150150
* {@code
151151
*
152-
* mappedTable.delete(DeleteItemEnhancedRequest.builder().key(key).build());
152+
* MyItem previouslyPersistedItem = mappedTable.delete(DeleteItemEnhancedRequest.builder().key(key).build());
153153
* }
154154
* </pre>
155155
*
156-
* @param request A {@link DeleteItemEnhancedRequest} with key and optional directives for deleting an item from the table.
157-
* @return The deleted item
156+
* @param request A {@link DeleteItemEnhancedRequest} with key and optional directives for deleting an item from the
157+
* table.
158+
* @return The item that was persisted in the database before it was deleted.
158159
*/
159160
default T deleteItem(DeleteItemEnhancedRequest request) {
160161
throw new UnsupportedOperationException();
@@ -169,20 +170,20 @@ default T deleteItem(DeleteItemEnhancedRequest request) {
169170
* This operation calls the low-level DynamoDB API DeleteItem operation. Consult the DeleteItem documentation for
170171
* further details and constraints.
171172
* <p>
172-
* <b>Note:</b> This is a convenience method that creates an instance of the request builder avoiding the need to create one
173-
* manually via {@link DeleteItemEnhancedRequest#builder()}.
173+
* <b>Note:</b> This is a convenience method that creates an instance of the request builder avoiding the need to
174+
* create one manually via {@link DeleteItemEnhancedRequest#builder()}.
174175
* <p>
175176
* Example:
176177
* <pre>
177178
* {@code
178179
*
179-
* mappedTable.delete(r -> r.key(key));
180+
* MyItem previouslyPersistedItem = mappedTable.delete(r -> r.key(key));
180181
* }
181182
* </pre>
182183
*
183184
* @param requestConsumer A {@link Consumer} of {@link DeleteItemEnhancedRequest} with key and
184185
* optional directives for deleting an item from the table.
185-
* @return The deleted item
186+
* @return The item that was persisted in the database before it was deleted.
186187
*/
187188
default T deleteItem(Consumer<DeleteItemEnhancedRequest.Builder> requestConsumer) {
188189
throw new UnsupportedOperationException();
@@ -198,17 +199,39 @@ default T deleteItem(Consumer<DeleteItemEnhancedRequest.Builder> requestConsumer
198199
* <pre>
199200
* {@code
200201
*
201-
* mappedTable.delete(key);
202+
* MyItem previouslyPersistedItem = mappedTable.delete(key);
202203
* }
203204
* </pre>
204205
*
205206
* @param key A {@link Key} that will be used to match a specific record to delete from the database table.
206-
* @return The deleted item
207+
* @return The item that was persisted in the database before it was deleted.
207208
*/
208209
default T deleteItem(Key key) {
209210
throw new UnsupportedOperationException();
210211
}
211212

213+
/**
214+
* Deletes a single item from the mapped table using just the key of a supplied modelled 'key item' object.
215+
* <p>
216+
* This operation calls the low-level DynamoDB API DeleteItem operation. Consult the DeleteItem documentation for
217+
* further details and constraints.
218+
* <p>
219+
* Example:
220+
* <pre>
221+
* {@code
222+
*
223+
* MyItem previouslyPersistedItem = mappedTable.deleteItem(keyItem);
224+
* }
225+
* </pre>
226+
*
227+
* @param keyItem A modelled item with the primary key fields set that will be used to match a specific record to
228+
* delete from the database table.
229+
* @return The item that was persisted in the database before it was deleted.
230+
*/
231+
default T deleteItem(T keyItem) {
232+
throw new UnsupportedOperationException();
233+
}
234+
212235
/**
213236
* Retrieves a single item from the mapped table using a supplied primary {@link Key}.
214237
* <p>
@@ -243,8 +266,8 @@ default T getItem(GetItemEnhancedRequest request) {
243266
* This operation calls the low-level DynamoDB API GetItem operation. Consult the GetItem documentation for
244267
* further details and constraints.
245268
* <p>
246-
* <b>Note:</b> This is a convenience method that creates an instance of the request builder avoiding the need to create one
247-
* manually via {@link GetItemEnhancedRequest#builder()}.
269+
* <b>Note:</b> This is a convenience method that creates an instance of the request builder avoiding the need to
270+
* create one manually via {@link GetItemEnhancedRequest#builder()}.
248271
* <p>
249272
* Example:
250273
* <pre>
@@ -254,8 +277,8 @@ default T getItem(GetItemEnhancedRequest request) {
254277
* }
255278
* </pre>
256279
*
257-
* @param requestConsumer A {@link Consumer} of {@link GetItemEnhancedRequest.Builder} with key and optional directives
258-
* for retrieving an item from the table.
280+
* @param requestConsumer A {@link Consumer} of {@link GetItemEnhancedRequest.Builder} with key and optional
281+
* directives for retrieving an item from the table.
259282
* @return The retrieved item
260283
*/
261284
default T getItem(Consumer<GetItemEnhancedRequest.Builder> requestConsumer) {
@@ -284,8 +307,30 @@ default T getItem(Key key) {
284307
}
285308

286309
/**
287-
* Executes a query against the primary index of the table using a {@link QueryConditional} expression to retrieve a list of
288-
* items matching the given conditions.
310+
* Retrieves a single item from the mapped table using just the key of a supplied modelled 'key item'.
311+
* <p>
312+
* This operation calls the low-level DynamoDB API GetItem operation. Consult the GetItem documentation for
313+
* further details and constraints.
314+
* <p>
315+
* Example:
316+
* <pre>
317+
* {@code
318+
*
319+
* MyItem item = mappedTable.getItem(keyItem);
320+
* }
321+
* </pre>
322+
*
323+
* @param keyItem A modelled item with the primary key fields set that will be used to match a specific record to
324+
* retrieve from the database table.
325+
* @return The retrieved item
326+
*/
327+
default T getItem(T keyItem) {
328+
throw new UnsupportedOperationException();
329+
}
330+
331+
/**
332+
* Executes a query against the primary index of the table using a {@link QueryConditional} expression to retrieve a
333+
* list of items matching the given conditions.
289334
* <p>
290335
* The result is accessed through iterable pages (see {@link Page}) in an interactive way; each time a
291336
* result page is retrieved, a query call is made to DynamoDb to get those entries. If no matches are found,
@@ -318,8 +363,8 @@ default SdkIterable<Page<T>> query(QueryEnhancedRequest request) {
318363
}
319364

320365
/**
321-
* Executes a query against the primary index of the table using a {@link QueryConditional} expression to retrieve a list of
322-
* items matching the given conditions.
366+
* Executes a query against the primary index of the table using a {@link QueryConditional} expression to retrieve a
367+
* list of items matching the given conditions.
323368
* <p>
324369
* The result is accessed through iterable pages (see {@link Page}) in an interactive way; each time a
325370
* result page is retrieved, a query call is made to DynamoDb to get those entries. If no matches are found,
@@ -332,8 +377,8 @@ default SdkIterable<Page<T>> query(QueryEnhancedRequest request) {
332377
* This operation calls the low-level DynamoDB API Query operation. Consult the Query documentation for
333378
* further details and constraints.
334379
* <p>
335-
* <b>Note:</b> This is a convenience method that creates an instance of the request builder avoiding the need to create one
336-
* manually via {@link DeleteItemEnhancedRequest#builder()}.
380+
* <b>Note:</b> This is a convenience method that creates an instance of the request builder avoiding the need to
381+
* create one manually via {@link DeleteItemEnhancedRequest#builder()}.
337382
* <p>
338383
* Example:
339384
* <pre>
@@ -344,8 +389,8 @@ default SdkIterable<Page<T>> query(QueryEnhancedRequest request) {
344389
* }
345390
* </pre>
346391
*
347-
* @param requestConsumer A {@link Consumer} of {@link QueryEnhancedRequest} defining the query conditions and how to
348-
* handle the results.
392+
* @param requestConsumer A {@link Consumer} of {@link QueryEnhancedRequest} defining the query conditions and how
393+
* to handle the results.
349394
* @return an iterator of type {@link SdkIterable} with paginated results (see {@link Page}).
350395
*/
351396
default SdkIterable<Page<T>> query(Consumer<QueryEnhancedRequest.Builder> requestConsumer) {
@@ -381,8 +426,8 @@ default SdkIterable<Page<T>> query(QueryConditional queryConditional) {
381426
}
382427

383428
/**
384-
* Puts a single item in the mapped table. If the table contains an item with the same primary key, it will be replaced with
385-
* this item.
429+
* Puts a single item in the mapped table. If the table contains an item with the same primary key, it will be
430+
* replaced with this item.
386431
* <p>
387432
* The additional configuration parameters that the enhanced client supports are defined
388433
* in the {@link PutItemEnhancedRequest}.
@@ -406,8 +451,8 @@ default void putItem(PutItemEnhancedRequest<T> request) {
406451
}
407452

408453
/**
409-
* Puts a single item in the mapped table. If the table contains an item with the same primary key, it will be replaced with
410-
* this item.
454+
* Puts a single item in the mapped table. If the table contains an item with the same primary key, it will be
455+
* replaced with this item.
411456
* <p>
412457
* The additional configuration parameters that the enhanced client supports are defined
413458
* in the {@link PutItemEnhancedRequest}.

0 commit comments

Comments
 (0)