|
2 | 2 |
|
3 | 3 | import com.aerospike.client.*;
|
4 | 4 | import com.aerospike.client.policy.*;
|
| 5 | +import com.aerospike.client.query.Filter; |
| 6 | +import com.aerospike.client.query.Statement; |
5 | 7 | import com.aerospike.client.reactor.IAerospikeReactorClient;
|
6 | 8 | import com.aerospike.mapper.tools.configuration.ClassConfig;
|
7 | 9 | import com.aerospike.mapper.tools.configuration.Configuration;
|
|
23 | 25 | import java.util.Arrays;
|
24 | 26 | import java.util.List;
|
25 | 27 | import java.util.Objects;
|
| 28 | +import java.util.concurrent.atomic.AtomicBoolean; |
26 | 29 | import java.util.function.Function;
|
27 | 30 |
|
28 | 31 | public class ReactiveAeroMapper implements IReactiveAeroMapper {
|
@@ -489,6 +492,106 @@ public <T> Mono<Void> find(@NotNull Class<T> clazz, Function<T, Boolean> functio
|
489 | 492 | });
|
490 | 493 | }
|
491 | 494 |
|
| 495 | + /** |
| 496 | + * Scan every record in the set associated with the passed class. Each record will be converted to the appropriate class. |
| 497 | + * |
| 498 | + * @param clazz - the class used to determine which set to scan and to convert the returned records to. |
| 499 | + */ |
| 500 | + @Override |
| 501 | + public <T> Flux<T> scan(@NotNull Class<T> clazz) { |
| 502 | + return scan(null, clazz); |
| 503 | + } |
| 504 | + |
| 505 | + /** |
| 506 | + * Scan every record in the set associated with the passed class. Each record will be converted to the appropriate class. |
| 507 | + * |
| 508 | + * @param policy - the scan policy to use. If this is null, the default scan policy of the passed class will be used. |
| 509 | + * @param clazz - the class used to determine which set to scan and to convert the returned records to. |
| 510 | + */ |
| 511 | + @Override |
| 512 | + public <T> Flux<T> scan(ScanPolicy policy, @NotNull Class<T> clazz) { |
| 513 | + return scan(policy, clazz, -1); |
| 514 | + } |
| 515 | + |
| 516 | + /** |
| 517 | + * Scan every record in the set associated with the passed class, limiting the throughput to the specified recordsPerSecond. Each record will be converted |
| 518 | + * to the appropriate class. |
| 519 | + * |
| 520 | + * @param clazz - the class used to determine which set to scan and to convert the returned records to. |
| 521 | + * @param recordsPerSecond - the maximum number of records to be processed every second. |
| 522 | + */ |
| 523 | + @Override |
| 524 | + public <T> Flux<T> scan(@NotNull Class<T> clazz, int recordsPerSecond) { |
| 525 | + return scan(null, clazz, recordsPerSecond); |
| 526 | + } |
| 527 | + |
| 528 | + /** |
| 529 | + * Scan every record in the set associated with the passed class. Each record will be converted to the appropriate class. |
| 530 | + * |
| 531 | + * @param policy - the scan policy to use. If this is null, the default scan policy of the passed class will be used. |
| 532 | + * @param clazz - the class used to determine which set to scan and to convert the returned records to. |
| 533 | + * @param recordsPerSecond - the number of records to process per second. Set to 0 for unlimited, > 0 for a finite rate, < 0 for no change |
| 534 | + * (use the value from the passed policy) |
| 535 | + */ |
| 536 | + @Override |
| 537 | + public <T> Flux<T> scan(ScanPolicy policy, @NotNull Class<T> clazz, int recordsPerSecond) { |
| 538 | + ClassCacheEntry<T> entry = MapperUtils.getEntryAndValidateNamespace(clazz, this); |
| 539 | + if (policy == null) { |
| 540 | + policy = entry.getScanPolicy(); |
| 541 | + } |
| 542 | + if (recordsPerSecond >= 0) { |
| 543 | + // Ensure the underlying rate on the policy does not change |
| 544 | + policy = new ScanPolicy(policy); |
| 545 | + policy.recordsPerSecond = recordsPerSecond; |
| 546 | + } |
| 547 | + String namespace = entry.getNamespace(); |
| 548 | + String setName = entry.getSetName(); |
| 549 | + |
| 550 | + return reactorClient.scanAll(policy, namespace, setName) |
| 551 | + .map(keyRecord -> this.getMappingConverter().convertToObject(clazz, keyRecord.record)); |
| 552 | + } |
| 553 | + |
| 554 | + /** |
| 555 | + * Perform a secondary index query with the specified query policy. Each record will be converted |
| 556 | + * to the appropriate class then passed to the processor. If the processor returns false the query is aborted |
| 557 | + * whereas if the processor returns true subsequent records (if any) are processed. |
| 558 | + * <p/> |
| 559 | + * The query policy used will be the one associated with the passed classtype. |
| 560 | + * |
| 561 | + * @param clazz - the class used to determine which set to scan and to convert the returned records to. |
| 562 | + * @param filter - the filter used to determine which secondary index to use. If this filter is null, every record in the set |
| 563 | + * associated with the passed classtype will be scanned, effectively turning the query into a scan |
| 564 | + */ |
| 565 | + @Override |
| 566 | + public <T> Flux<T> query(@NotNull Class<T> clazz, Filter filter) { |
| 567 | + return query(null, clazz, filter); |
| 568 | + } |
| 569 | + |
| 570 | + /** |
| 571 | + * Perform a secondary index query with the specified query policy. Each record will be converted |
| 572 | + * to the appropriate class then passed to the processor. If the processor returns false the query is aborted |
| 573 | + * whereas if the processor returns true subsequent records (if any) are processed. |
| 574 | + * |
| 575 | + * @param policy - The query policy to use. If this parameter is not passed, the query policy associated with the passed classtype will be used |
| 576 | + * @param clazz - the class used to determine which set to scan and to convert the returned records to. |
| 577 | + * @param filter - the filter used to determine which secondary index to use. If this filter is null, every record in the set |
| 578 | + * associated with the passed classtype will be scanned, effectively turning the query into a scan |
| 579 | + */ |
| 580 | + @Override |
| 581 | + public <T> Flux<T> query(QueryPolicy policy, @NotNull Class<T> clazz, Filter filter) { |
| 582 | + ClassCacheEntry<T> entry = MapperUtils.getEntryAndValidateNamespace(clazz, this); |
| 583 | + if (policy == null) { |
| 584 | + policy = entry.getQueryPolicy(); |
| 585 | + } |
| 586 | + Statement statement = new Statement(); |
| 587 | + statement.setFilter(filter); |
| 588 | + statement.setNamespace(entry.getNamespace()); |
| 589 | + statement.setSetName(entry.getSetName()); |
| 590 | + |
| 591 | + return reactorClient.query(policy, statement) |
| 592 | + .map(keyRecord -> this.getMappingConverter().convertToObject(clazz, keyRecord.record)); |
| 593 | + } |
| 594 | + |
492 | 595 | @Override
|
493 | 596 | public IAerospikeReactorClient getReactorClient() {
|
494 | 597 | return this.reactorClient;
|
@@ -646,7 +749,7 @@ private <T> Flux<T> readBatch(BatchPolicy batchPolicy, @NotNull Class<T> clazz,
|
646 | 749 |
|
647 | 750 | private Throwable translateError(Throwable e) {
|
648 | 751 | if (e instanceof AerospikeException) {
|
649 |
| - return translateError((AerospikeException) e); |
| 752 | + return translateError(e); |
650 | 753 | }
|
651 | 754 | return e;
|
652 | 755 | }
|
|
0 commit comments