18
18
import java .util .concurrent .CompletableFuture ;
19
19
import java .util .function .Consumer ;
20
20
import software .amazon .awssdk .annotations .SdkPublicApi ;
21
- import software .amazon .awssdk .core .async .SdkPublisher ;
22
21
import software .amazon .awssdk .enhanced .dynamodb .model .CreateTableEnhancedRequest ;
23
22
import software .amazon .awssdk .enhanced .dynamodb .model .DeleteItemEnhancedRequest ;
24
23
import software .amazon .awssdk .enhanced .dynamodb .model .GetItemEnhancedRequest ;
25
24
import software .amazon .awssdk .enhanced .dynamodb .model .Page ;
25
+ import software .amazon .awssdk .enhanced .dynamodb .model .PagePublisher ;
26
26
import software .amazon .awssdk .enhanced .dynamodb .model .PutItemEnhancedRequest ;
27
27
import software .amazon .awssdk .enhanced .dynamodb .model .QueryConditional ;
28
28
import software .amazon .awssdk .enhanced .dynamodb .model .QueryEnhancedRequest ;
29
29
import software .amazon .awssdk .enhanced .dynamodb .model .ScanEnhancedRequest ;
30
30
import software .amazon .awssdk .enhanced .dynamodb .model .UpdateItemEnhancedRequest ;
31
+ import software .amazon .awssdk .services .dynamodb .DynamoDbAsyncClient ;
31
32
32
33
/**
33
34
* Asynchronous interface for running commands against an object that is linked to a specific DynamoDb table resource
@@ -333,68 +334,77 @@ default CompletableFuture<T> getItem(T keyItem) {
333
334
* Executes a query against the primary index of the table using a {@link QueryConditional} expression to retrieve a list of
334
335
* items matching the given conditions.
335
336
* <p>
336
- * The result is accessed through iterable pages (see {@link Page}) in an interactive way; each time a
337
- * result page is retrieved, a query call is made to DynamoDb to get those entries. If no matches are found,
338
- * the resulting iterator will contain an empty page. Results are sorted by sort key value in
337
+ * The return type is a custom publisher that can be subscribed to request a stream of {@link Page}s or
338
+ * a stream of items across all pages. Results are sorted by sort key value in
339
339
* ascending order by default; this behavior can be overridden in the {@link QueryEnhancedRequest}.
340
340
* <p>
341
341
* The additional configuration parameters that the enhanced client supports are defined
342
342
* in the {@link QueryEnhancedRequest}.
343
343
* <p>
344
- * This operation calls the low-level DynamoDB API Query operation. Consult the Query documentation for
345
- * further details and constraints.
344
+ * This operation calls the low-level DynamoDB API Query operation. Consult the Query documentation
345
+ * {@link DynamoDbAsyncClient#queryPaginator} for further details and constraints.
346
346
* <p>
347
347
* Example:
348
+ * <p>
349
+ * 1) Subscribing to {@link Page}s
350
+ * <pre>
351
+ * {@code
352
+ *
353
+ * QueryConditional queryConditional = QueryConditional.keyEqualTo(Key.builder().partitionValue("id-value").build());
354
+ * PagePublisher<MyItem> publisher = mappedTable.query(QueryEnhancedRequest.builder()
355
+ * .queryConditional(queryConditional)
356
+ * .build());
357
+ * publisher.subscribe(page -> page.items().forEach(item -> System.out.println(item)));
358
+ * }
359
+ * <p>
360
+ * 2) Subscribing to items across all pages
348
361
* <pre>
349
362
* {@code
350
363
*
351
364
* QueryConditional queryConditional = QueryConditional.keyEqualTo(Key.builder().partitionValue("id-value").build());
352
- * SdkPublisher<Page<MyItem>> publisher = mappedTable.query(QueryEnhancedRequest.builder()
353
- * .queryConditional(queryConditional)
354
- * .build());
365
+ * PagePublisher<MyItem> publisher = mappedTable.query(QueryEnhancedRequest.builder()
366
+ * .queryConditional(queryConditional)
367
+ * .build())
368
+ * .items();
369
+ * publisher.items().subscribe(item -> System.out.println(item));
355
370
* }
356
371
* </pre>
357
372
*
373
+ * @see #query(Consumer)
374
+ * @see #query(QueryConditional)
375
+ * @see DynamoDbAsyncClient#queryPaginator
358
376
* @param request A {@link QueryEnhancedRequest} defining the query conditions and how
359
377
* to handle the results.
360
- * @return a publisher {@link SdkPublisher } with paginated results (see {@link Page}).
378
+ * @return a publisher {@link PagePublisher } with paginated results (see {@link Page}).
361
379
*/
362
- default SdkPublisher < Page < T > > query (QueryEnhancedRequest request ) {
380
+ default PagePublisher < T > query (QueryEnhancedRequest request ) {
363
381
throw new UnsupportedOperationException ();
364
382
}
365
383
366
384
/**
367
385
* Executes a query against the primary index of the table using a {@link QueryConditional} expression to retrieve a list of
368
386
* items matching the given conditions.
369
387
* <p>
370
- * The result is accessed through iterable pages (see {@link Page}) in an interactive way; each time a
371
- * result page is retrieved, a query call is made to DynamoDb to get those entries. If no matches are found,
372
- * the resulting iterator will contain an empty page. Results are sorted by sort key value in
373
- * ascending order by default; this behavior can be overridden in the {@link QueryEnhancedRequest}.
374
- * <p>
375
- * The additional configuration parameters that the enhanced client supports are defined
376
- * in the {@link QueryEnhancedRequest}.
377
- * <p>
378
- * This operation calls the low-level DynamoDB API Query operation. Consult the Query documentation for
379
- * further details and constraints.
380
- * <p>
381
388
* <b>Note:</b> This is a convenience method that creates an instance of the request builder avoiding the need to create one
382
389
* manually via {@link QueryEnhancedRequest#builder()}.
383
390
* <p>
384
391
* Example:
385
392
* <pre>
386
393
* {@code
387
394
*
388
- * SdkPublisher<Page< MyItem> > publisher =
395
+ * PagePublisher< MyItem> publisher =
389
396
* mappedTable.query(r -> r.queryConditional(QueryConditional.keyEqualTo(k -> k.partitionValue("id-value"))));
390
397
* }
391
398
* </pre>
392
399
*
400
+ * @see #query(QueryEnhancedRequest)
401
+ * @see #query(QueryConditional)
402
+ * @see DynamoDbAsyncClient#queryPaginator
393
403
* @param requestConsumer A {@link Consumer} of {@link QueryEnhancedRequest} defining the query conditions and how to
394
404
* handle the results.
395
- * @return a publisher {@link SdkPublisher } with paginated results (see {@link Page}).
405
+ * @return a publisher {@link PagePublisher } with paginated results (see {@link Page}).
396
406
*/
397
- default SdkPublisher < Page < T > > query (Consumer <QueryEnhancedRequest .Builder > requestConsumer ) {
407
+ default PagePublisher < T > query (Consumer <QueryEnhancedRequest .Builder > requestConsumer ) {
398
408
throw new UnsupportedOperationException ();
399
409
}
400
410
@@ -414,15 +424,18 @@ default SdkPublisher<Page<T>> query(Consumer<QueryEnhancedRequest.Builder> reque
414
424
* <pre>
415
425
* {@code
416
426
*
417
- * SdkPublisher<Page< MyItem> > results =
427
+ * PagePublisher< MyItem> results =
418
428
* mappedTable.query(QueryConditional.keyEqualTo(Key.builder().partitionValue("id-value").build()));
419
429
* }
420
430
* </pre>
421
431
*
432
+ * @see #query(QueryEnhancedRequest)
433
+ * @see #query(Consumer)
434
+ * @see DynamoDbAsyncClient#queryPaginator
422
435
* @param queryConditional A {@link QueryConditional} defining the matching criteria for records to be queried.
423
- * @return a publisher {@link SdkPublisher } with paginated results (see {@link Page}).
436
+ * @return a publisher {@link PagePublisher } with paginated results (see {@link Page}).
424
437
*/
425
- default SdkPublisher < Page < T > > query (QueryConditional queryConditional ) {
438
+ default PagePublisher < T > query (QueryConditional queryConditional ) {
426
439
throw new UnsupportedOperationException ();
427
440
}
428
441
@@ -503,72 +516,83 @@ default CompletableFuture<Void> putItem(T item) {
503
516
/**
504
517
* Scans the table and retrieves all items.
505
518
* <p>
506
- * The result is accessed through iterable pages (see {@link Page}) in an interactive way; each time a
507
- * result page is retrieved, a scan call is made to DynamoDb to get those entries. If no matches are found,
508
- * the resulting iterator will contain an empty page.
519
+ * The return type is a custom publisher that can be subscribed to request a stream of {@link Page}s or
520
+ * a stream of flattened items across all pages. Each time a result page is retrieved, a scan call is made
521
+ * to DynamoDb to get those entries. If no matches are found, the resulting iterator will contain an empty page.
522
+ *
509
523
* <p>
510
524
* The additional configuration parameters that the enhanced client supports are defined
511
525
* in the {@link ScanEnhancedRequest}.
512
526
* <p>
513
527
* Example:
528
+ * <p>
529
+ * 1) Subscribing to {@link Page}s
530
+ * <pre>
531
+ * {@code
532
+ *
533
+ * PagePublisher<MyItem> publisher = mappedTable.scan(ScanEnhancedRequest.builder().consistentRead(true).build());
534
+ * publisher.subscribe(page -> page.items().forEach(item -> System.out.println(item)));
535
+ * }
536
+ * </pre>
537
+ *
538
+ * <p>
539
+ * 2) Subscribing to items across all pages.
514
540
* <pre>
515
541
* {@code
516
542
*
517
- * SdkPublisher<Page<MyItem>> publisher = mappedTable.scan(ScanEnhancedRequest.builder().consistentRead(true).build());
543
+ * PagePublisher<MyItem> publisher = mappedTable.scan(ScanEnhancedRequest.builder().consistentRead(true).build());
544
+ * publisher.items().subscribe(item -> System.out.println(item));
518
545
* }
519
546
* </pre>
520
547
*
548
+ * @see #scan(Consumer)
549
+ * @see #scan()
550
+ * @see DynamoDbAsyncClient#scanPaginator
521
551
* @param request A {@link ScanEnhancedRequest} defining how to handle the results.
522
- * @return a publisher {@link SdkPublisher } with paginated results (see {@link Page}).
552
+ * @return a publisher {@link PagePublisher } with paginated results (see {@link Page}).
523
553
*/
524
- default SdkPublisher < Page < T > > scan (ScanEnhancedRequest request ) {
554
+ default PagePublisher < T > scan (ScanEnhancedRequest request ) {
525
555
throw new UnsupportedOperationException ();
526
556
}
527
557
528
558
/**
529
559
* Scans the table and retrieves all items.
530
560
* <p>
531
- * The result is accessed through iterable pages (see {@link Page}) in an interactive way; each time a
532
- * result page is retrieved, a scan call is made to DynamoDb to get those entries. If no matches are found,
533
- * the resulting iterator will contain an empty page.
534
- * <p>
535
- * The additional configuration parameters that the enhanced client supports are defined
536
- * in the {@link ScanEnhancedRequest}.
537
- * <p>
538
561
* Example:
539
562
* <pre>
540
563
* {@code
541
564
*
542
- * SdkPublisher<Page< MyItem> > publisher = mappedTable.scan(r -> r.limit(5));
565
+ * PagePublisher< MyItem> publisher = mappedTable.scan(r -> r.limit(5));
543
566
* }
544
567
* </pre>
545
- *
568
+ *
569
+ * @see #scan(ScanEnhancedRequest)
570
+ * @see #scan()
571
+ * @see DynamoDbAsyncClient#scanPaginator
546
572
* @param requestConsumer A {@link Consumer} of {@link ScanEnhancedRequest} defining the query conditions and how to
547
573
* handle the results.
548
- * @return a publisher {@link SdkPublisher } with paginated results (see {@link Page}).
574
+ * @return a publisher {@link PagePublisher } with paginated results (see {@link Page}).
549
575
*/
550
- default SdkPublisher < Page < T > > scan (Consumer <ScanEnhancedRequest .Builder > requestConsumer ) {
576
+ default PagePublisher < T > scan (Consumer <ScanEnhancedRequest .Builder > requestConsumer ) {
551
577
throw new UnsupportedOperationException ();
552
578
}
553
579
554
580
/**
555
581
* Scans the table and retrieves all items using default settings.
556
- * <p>
557
- * The result is accessed through iterable pages (see {@link Page}) in an interactive way; each time a
558
- * result page is retrieved, a scan call is made to DynamoDb to get those entries. If no matches are found,
559
- * the resulting iterator will contain an empty page.
560
- * <p>
582
+ *
561
583
* Example:
562
584
* <pre>
563
585
* {@code
564
586
*
565
- * SdkPublisher<Page< MyItem> > publisher = mappedTable.scan();
587
+ * PagePublisher< MyItem> publisher = mappedTable.scan();
566
588
* }
567
589
* </pre>
568
- *
569
- * @return a publisher {@link SdkPublisher} with paginated results (see {@link Page}).
590
+ * @see #scan(ScanEnhancedRequest)
591
+ * @see #scan(Consumer)
592
+ * @see DynamoDbAsyncClient#scanPaginator
593
+ * @return a publisher {@link PagePublisher} with paginated results (see {@link Page}).
570
594
*/
571
- default SdkPublisher < Page < T > > scan () {
595
+ default PagePublisher < T > scan () {
572
596
throw new UnsupportedOperationException ();
573
597
}
574
598
0 commit comments