51
51
*
52
52
* @param <K> type parameter indicating the type of the data load keys
53
53
* @param <V> type parameter indicating the type of the data that is returned
54
- *
55
54
* @author <a href="https://github.com/aschrijver/">Arnold Schrijver</a>
56
55
* @author <a href="https://github.com/bbakerman/">Brad Baker</a>
57
56
*/
@@ -69,7 +68,6 @@ public class DataLoader<K, V> {
69
68
* @param batchLoadFunction the batch load function to use
70
69
* @param <K> the key type
71
70
* @param <V> the value type
72
- *
73
71
* @return a new DataLoader
74
72
*/
75
73
public static <K , V > DataLoader <K , V > newDataLoader (BatchLoader <K , V > batchLoadFunction ) {
@@ -83,7 +81,6 @@ public static <K, V> DataLoader<K, V> newDataLoader(BatchLoader<K, V> batchLoadF
83
81
* @param options the options to use
84
82
* @param <K> the key type
85
83
* @param <V> the value type
86
- *
87
84
* @return a new DataLoader
88
85
*/
89
86
public static <K , V > DataLoader <K , V > newDataLoader (BatchLoader <K , V > batchLoadFunction , DataLoaderOptions options ) {
@@ -104,7 +101,6 @@ public static <K, V> DataLoader<K, V> newDataLoader(BatchLoader<K, V> batchLoadF
104
101
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
105
102
* @param <K> the key type
106
103
* @param <V> the value type
107
- *
108
104
* @return a new DataLoader
109
105
*/
110
106
public static <K , V > DataLoader <K , V > newDataLoaderWithTry (BatchLoader <K , Try <V >> batchLoadFunction ) {
@@ -120,9 +116,7 @@ public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoader<K, Try<V>
120
116
* @param options the options to use
121
117
* @param <K> the key type
122
118
* @param <V> the value type
123
- *
124
119
* @return a new DataLoader
125
- *
126
120
* @see #newDataLoaderWithTry(BatchLoader)
127
121
*/
128
122
@ SuppressWarnings ("unchecked" )
@@ -137,7 +131,6 @@ public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoader<K, Try<V>
137
131
* @param batchLoadFunction the batch load function to use
138
132
* @param <K> the key type
139
133
* @param <V> the value type
140
- *
141
134
* @return a new DataLoader
142
135
*/
143
136
public static <K , V > DataLoader <K , V > newDataLoader (BatchLoaderWithContext <K , V > batchLoadFunction ) {
@@ -151,7 +144,6 @@ public static <K, V> DataLoader<K, V> newDataLoader(BatchLoaderWithContext<K, V>
151
144
* @param options the options to use
152
145
* @param <K> the key type
153
146
* @param <V> the value type
154
- *
155
147
* @return a new DataLoader
156
148
*/
157
149
public static <K , V > DataLoader <K , V > newDataLoader (BatchLoaderWithContext <K , V > batchLoadFunction , DataLoaderOptions options ) {
@@ -172,7 +164,6 @@ public static <K, V> DataLoader<K, V> newDataLoader(BatchLoaderWithContext<K, V>
172
164
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
173
165
* @param <K> the key type
174
166
* @param <V> the value type
175
- *
176
167
* @return a new DataLoader
177
168
*/
178
169
public static <K , V > DataLoader <K , V > newDataLoaderWithTry (BatchLoaderWithContext <K , Try <V >> batchLoadFunction ) {
@@ -188,9 +179,7 @@ public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoaderWithContex
188
179
* @param options the options to use
189
180
* @param <K> the key type
190
181
* @param <V> the value type
191
- *
192
182
* @return a new DataLoader
193
- *
194
183
* @see #newDataLoaderWithTry(BatchLoader)
195
184
*/
196
185
public static <K , V > DataLoader <K , V > newDataLoaderWithTry (BatchLoaderWithContext <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
@@ -204,7 +193,6 @@ public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoaderWithContex
204
193
* @param batchLoadFunction the batch load function to use
205
194
* @param <K> the key type
206
195
* @param <V> the value type
207
- *
208
196
* @return a new DataLoader
209
197
*/
210
198
public static <K , V > DataLoader <K , V > newMappedDataLoader (MappedBatchLoader <K , V > batchLoadFunction ) {
@@ -218,7 +206,6 @@ public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V
218
206
* @param options the options to use
219
207
* @param <K> the key type
220
208
* @param <V> the value type
221
- *
222
209
* @return a new DataLoader
223
210
*/
224
211
public static <K , V > DataLoader <K , V > newMappedDataLoader (MappedBatchLoader <K , V > batchLoadFunction , DataLoaderOptions options ) {
@@ -232,15 +219,14 @@ public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V
232
219
* <p>
233
220
* If its important you to know the exact status of each item in a batch call and whether it threw exceptions then
234
221
* you can use this form to create the data loader.
235
- *
222
+ * <p>
236
223
* Using Try objects allows you to capture a value returned or an exception that might
237
224
* have occurred trying to get a value. .
238
225
* <p>
239
226
*
240
227
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
241
228
* @param <K> the key type
242
229
* @param <V> the value type
243
- *
244
230
* @return a new DataLoader
245
231
*/
246
232
public static <K , V > DataLoader <K , V > newMappedDataLoaderWithTry (MappedBatchLoader <K , Try <V >> batchLoadFunction ) {
@@ -256,9 +242,7 @@ public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoad
256
242
* @param options the options to use
257
243
* @param <K> the key type
258
244
* @param <V> the value type
259
- *
260
245
* @return a new DataLoader
261
- *
262
246
* @see #newDataLoaderWithTry(BatchLoader)
263
247
*/
264
248
@ SuppressWarnings ("unchecked" )
@@ -273,7 +257,6 @@ public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoad
273
257
* @param batchLoadFunction the batch load function to use
274
258
* @param <K> the key type
275
259
* @param <V> the value type
276
- *
277
260
* @return a new DataLoader
278
261
*/
279
262
public static <K , V > DataLoader <K , V > newMappedDataLoader (MappedBatchLoaderWithContext <K , V > batchLoadFunction ) {
@@ -287,7 +270,6 @@ public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoaderWithC
287
270
* @param options the options to use
288
271
* @param <K> the key type
289
272
* @param <V> the value type
290
- *
291
273
* @return a new DataLoader
292
274
*/
293
275
public static <K , V > DataLoader <K , V > newMappedDataLoader (MappedBatchLoaderWithContext <K , V > batchLoadFunction , DataLoaderOptions options ) {
@@ -308,7 +290,6 @@ public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoaderWithC
308
290
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
309
291
* @param <K> the key type
310
292
* @param <V> the value type
311
- *
312
293
* @return a new DataLoader
313
294
*/
314
295
public static <K , V > DataLoader <K , V > newMappedDataLoaderWithTry (MappedBatchLoaderWithContext <K , Try <V >> batchLoadFunction ) {
@@ -324,9 +305,7 @@ public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoad
324
305
* @param options the options to use
325
306
* @param <K> the key type
326
307
* @param <V> the value type
327
- *
328
308
* @return a new DataLoader
329
- *
330
309
* @see #newDataLoaderWithTry(BatchLoader)
331
310
*/
332
311
@ SuppressWarnings ("unchecked" )
@@ -375,37 +354,57 @@ private CacheMap<Object, CompletableFuture<V>> determineCacheMap(DataLoaderOptio
375
354
* and returned from cache).
376
355
*
377
356
* @param key the key to load
378
- *
379
357
* @return the future of the value
380
358
*/
381
359
public CompletableFuture <V > load (K key ) {
382
360
return load (key , null );
383
361
}
384
362
363
+ /**
364
+ * This will return an optional promise to a value previously loaded via {@link #load(Object)} call or empty if not call has been made for that key.
365
+ * <p>
366
+ * If you do get a present CompletableFuture it does not mean it has been dispatched and completed yet. It just means
367
+ * its at least pending and in cache. Of course if caching is disabled there will never be a present Optional returned.
368
+ * <p>
369
+ * NOTE : This will NOT cause a data load to happen. You must called {@link #load(Object)} for that.
370
+ *
371
+ * @param key the key to check
372
+ * @return an Optional to the future of the value
373
+ */
385
374
public Optional <CompletableFuture <V >> getIfPresent (K key ) {
386
375
return helper .getIfPresent (key );
387
376
}
388
377
378
+ /**
379
+ * This will return an optional promise to a value previously loaded via {@link #load(Object)} call that has in fact been completed or empty
380
+ * if no call has been made for that key or the promise has not completed yet.
381
+ * <p>
382
+ * If you do get a present CompletableFuture it means it has been dispatched and completed.
383
+ * <p>
384
+ * NOTE : This will NOT cause a data load to happen. You must called {@link #load(Object)} for that.
385
+ *
386
+ * @param key the key to check
387
+ * @return an Optional to the future of the value
388
+ */
389
389
public Optional <CompletableFuture <V >> getIfCompleted (K key ) {
390
390
return helper .getIfCompleted (key );
391
391
}
392
392
393
393
394
- /**
395
- * Requests to load the data with the specified key asynchronously, and returns a future of the resulting value.
396
- * <p>
397
- * If batching is enabled (the default), you'll have to call {@link DataLoader#dispatch()} at a later stage to
398
- * start batch execution. If you forget this call the future will never be completed (unless already completed,
399
- * and returned from cache).
400
- * <p>
401
- * The key context object may be useful in the batch loader interfaces such as {@link org.dataloader.BatchLoaderWithContext} or
402
- * {@link org.dataloader.MappedBatchLoaderWithContext} to help retrieve data.
403
- *
404
- * @param key the key to load
405
- * @param keyContext a context object that is specific to this key
406
- *
407
- * @return the future of the value
408
- */
394
+ /**
395
+ * Requests to load the data with the specified key asynchronously, and returns a future of the resulting value.
396
+ * <p>
397
+ * If batching is enabled (the default), you'll have to call {@link DataLoader#dispatch()} at a later stage to
398
+ * start batch execution. If you forget this call the future will never be completed (unless already completed,
399
+ * and returned from cache).
400
+ * <p>
401
+ * The key context object may be useful in the batch loader interfaces such as {@link org.dataloader.BatchLoaderWithContext} or
402
+ * {@link org.dataloader.MappedBatchLoaderWithContext} to help retrieve data.
403
+ *
404
+ * @param key the key to load
405
+ * @param keyContext a context object that is specific to this key
406
+ * @return the future of the value
407
+ */
409
408
public CompletableFuture <V > load (K key , Object keyContext ) {
410
409
return helper .load (key , keyContext );
411
410
}
@@ -419,7 +418,6 @@ public CompletableFuture<V> load(K key, Object keyContext) {
419
418
* and returned from cache).
420
419
*
421
420
* @param keys the list of keys to load
422
- *
423
421
* @return the composite future of the list of values
424
422
*/
425
423
public CompletableFuture <List <V >> loadMany (List <K > keys ) {
@@ -439,7 +437,6 @@ public CompletableFuture<List<V>> loadMany(List<K> keys) {
439
437
*
440
438
* @param keys the list of keys to load
441
439
* @param keyContexts the list of key calling context objects
442
- *
443
440
* @return the composite future of the list of values
444
441
*/
445
442
public CompletableFuture <List <V >> loadMany (List <K > keys , List <Object > keyContexts ) {
@@ -505,7 +502,6 @@ public int dispatchDepth() {
505
502
* on the next load request.
506
503
*
507
504
* @param key the key to remove
508
- *
509
505
* @return the data loader for fluent coding
510
506
*/
511
507
public DataLoader <K , V > clear (K key ) {
@@ -533,7 +529,6 @@ public DataLoader<K, V> clearAll() {
533
529
*
534
530
* @param key the key
535
531
* @param value the value
536
- *
537
532
* @return the data loader for fluent coding
538
533
*/
539
534
public DataLoader <K , V > prime (K key , V value ) {
@@ -551,7 +546,6 @@ public DataLoader<K, V> prime(K key, V value) {
551
546
*
552
547
* @param key the key
553
548
* @param error the exception to prime instead of a value
554
- *
555
549
* @return the data loader for fluent coding
556
550
*/
557
551
public DataLoader <K , V > prime (K key , Exception error ) {
@@ -569,7 +563,6 @@ public DataLoader<K, V> prime(K key, Exception error) {
569
563
* If no cache key function is present in {@link DataLoaderOptions}, then the returned value equals the input key.
570
564
*
571
565
* @param key the input key
572
- *
573
566
* @return the cache key after the input is transformed with the cache key function
574
567
*/
575
568
public Object getCacheKey (K key ) {
0 commit comments