|
1 | 1 | /* |
2 | | - * Copyright 2017-2024 ObjectBox Ltd. All rights reserved. |
| 2 | + * Copyright 2017-2025 ObjectBox Ltd. All rights reserved. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
31 | 31 | import io.objectbox.BoxStore; |
32 | 32 | import io.objectbox.InternalAccess; |
33 | 33 | import io.objectbox.Property; |
| 34 | +import io.objectbox.annotation.Entity; |
34 | 35 | import io.objectbox.annotation.HnswIndex; |
35 | 36 | import io.objectbox.exception.NonUniqueResultException; |
36 | 37 | import io.objectbox.reactive.DataObserver; |
@@ -918,22 +919,26 @@ public long remove() { |
918 | 919 | } |
919 | 920 |
|
920 | 921 | /** |
921 | | - * A {@link io.objectbox.reactive.DataObserver} can be subscribed to data changes using the returned builder. |
922 | | - * The observer is supplied via {@link SubscriptionBuilder#observer(DataObserver)} and will be notified once |
923 | | - * the query results have (potentially) changed. |
| 922 | + * Returns a {@link SubscriptionBuilder} to build a subscription to observe changes to the results of this query. |
924 | 923 | * <p> |
925 | | - * With subscribing, the observer will immediately get current query results. |
926 | | - * The query is run for the subscribing observer. |
| 924 | + * Typical usage: |
| 925 | + * <pre> |
| 926 | + * DataSubscription subscription = query.subscribe() |
| 927 | + * .observer((List<T> data) -> { |
| 928 | + * // Do something with the returned results |
| 929 | + * }); |
| 930 | + * // Once the observer should no longer be notified |
| 931 | + * subscription.cancel(); |
| 932 | + * </pre> |
| 933 | + * Note that the observer will receive new results on any changes to the {@link Box} of the {@link Entity @Entity} |
| 934 | + * this queries, regardless of the conditions of this query. This is because the {@link QueryPublisher} used for the |
| 935 | + * subscription observes changes by using {@link BoxStore#subscribe(Class)} on the Box this queries. |
927 | 936 | * <p> |
928 | | - * Threading notes: |
929 | | - * Query observers are notified from a thread pooled. Observers may be notified in parallel. |
930 | | - * The notification order is the same as the subscription order, although this may not always be guaranteed in |
931 | | - * the future. |
| 937 | + * To customize this or for advanced use cases, consider using {@link BoxStore#subscribe(Class)} directly. |
932 | 938 | * <p> |
933 | | - * Stale observers: you must hold on to the Query or {@link io.objectbox.reactive.DataSubscription} objects to keep |
934 | | - * your {@link DataObserver}s active. If this Query is not referenced anymore |
935 | | - * (along with its {@link io.objectbox.reactive.DataSubscription}s, which hold a reference to the Query internally), |
936 | | - * it may be GCed and observers may become stale (won't receive anymore data). |
| 939 | + * See {@link SubscriptionBuilder#observer(DataObserver)} for additional details. |
| 940 | + * |
| 941 | + * @return A {@link SubscriptionBuilder} to build a subscription. |
937 | 942 | */ |
938 | 943 | public SubscriptionBuilder<List<T>> subscribe() { |
939 | 944 | checkOpen(); |
|
0 commit comments