1
1
/*
2
- * Copyright 2011-2021 the original author or authors.
2
+ * Copyright 2011-2022 the original author or authors.
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.
20
20
import java .util .Set ;
21
21
import java .util .function .Consumer ;
22
22
import java .util .function .Supplier ;
23
+ import java .util .stream .Stream ;
23
24
24
25
import org .bson .Document ;
26
+
25
27
import org .springframework .data .geo .GeoResults ;
26
28
import org .springframework .data .mongodb .core .BulkOperations .BulkMode ;
27
29
import org .springframework .data .mongodb .core .aggregation .Aggregation ;
42
44
import org .springframework .data .mongodb .core .query .Query ;
43
45
import org .springframework .data .mongodb .core .query .Update ;
44
46
import org .springframework .data .mongodb .core .query .UpdateDefinition ;
45
- import org .springframework .data .util .CloseableIterator ;
46
47
import org .springframework .lang .Nullable ;
47
48
import org .springframework .util .Assert ;
48
49
import org .springframework .util .ClassUtils ;
@@ -225,34 +226,34 @@ public <T> T execute(SessionCallback<T> action, Consumer<ClientSession> onComple
225
226
* Executes the given {@link Query} on the entity collection of the specified {@code entityType} backed by a Mongo DB
226
227
* {@link com.mongodb.client.FindIterable}.
227
228
* <p>
228
- * Returns a {@link CloseableIterator} that wraps the a Mongo DB {@link com.mongodb.client.FindIterable} that needs to
229
- * be closed.
229
+ * Returns a {@link String} that wraps the Mongo DB {@link com.mongodb.client.FindIterable} that needs to be closed.
230
230
*
231
231
* @param query the query class that specifies the criteria used to find a record and also an optional fields
232
232
* specification. Must not be {@literal null}.
233
233
* @param entityType must not be {@literal null}.
234
234
* @param <T> element return type
235
- * @return will never be {@literal null}.
235
+ * @return the result {@link Stream}, containing mapped objects, needing to be closed once fully processed (e.g.
236
+ * through a try-with-resources clause).
236
237
* @since 1.7
237
238
*/
238
- <T > CloseableIterator <T > stream (Query query , Class <T > entityType );
239
+ <T > Stream <T > stream (Query query , Class <T > entityType );
239
240
240
241
/**
241
242
* Executes the given {@link Query} on the entity collection of the specified {@code entityType} and collection backed
242
243
* by a Mongo DB {@link com.mongodb.client.FindIterable}.
243
244
* <p>
244
- * Returns a {@link CloseableIterator} that wraps the a Mongo DB {@link com.mongodb.client.FindIterable} that needs to
245
- * be closed.
245
+ * Returns a {@link Stream} that wraps the Mongo DB {@link com.mongodb.client.FindIterable} that needs to be closed.
246
246
*
247
247
* @param query the query class that specifies the criteria used to find a record and also an optional fields
248
248
* specification. Must not be {@literal null}.
249
249
* @param entityType must not be {@literal null}.
250
250
* @param collectionName must not be {@literal null} or empty.
251
251
* @param <T> element return type
252
- * @return will never be {@literal null}.
252
+ * @return the result {@link Stream}, containing mapped objects, needing to be closed once fully processed (e.g.
253
+ * through a try-with-resources clause).
253
254
* @since 1.10
254
255
*/
255
- <T > CloseableIterator <T > stream (Query query , Class <T > entityType , String collectionName );
256
+ <T > Stream <T > stream (Query query , Class <T > entityType , String collectionName );
256
257
257
258
/**
258
259
* Create an uncapped collection with a name based on the provided entity class.
@@ -521,9 +522,9 @@ <T> GroupByResults<T> group(@Nullable Criteria criteria, String inputCollectionN
521
522
/**
522
523
* Execute an aggregation operation backed by a Mongo DB {@link com.mongodb.client.AggregateIterable}.
523
524
* <p>
524
- * Returns a {@link CloseableIterator } that wraps the a Mongo DB {@link com.mongodb.client.AggregateIterable} that
525
- * needs to be closed. The raw results will be mapped to the given entity class. The name of the inputCollection is
526
- * derived from the inputType of the aggregation.
525
+ * Returns a {@link Stream } that wraps the Mongo DB {@link com.mongodb.client.AggregateIterable} that needs to be
526
+ * closed. The raw results will be mapped to the given entity class. The name of the inputCollection is derived from
527
+ * the inputType of the aggregation.
527
528
* <p>
528
529
* Aggregation streaming can't be used with {@link AggregationOptions#isExplain() aggregation explain}. Enabling
529
530
* explanation mode will throw an {@link IllegalArgumentException}.
@@ -532,35 +533,37 @@ <T> GroupByResults<T> group(@Nullable Criteria criteria, String inputCollectionN
532
533
* {@literal null}.
533
534
* @param collectionName The name of the input collection to use for the aggreation.
534
535
* @param outputType The parametrized type of the returned list, must not be {@literal null}.
535
- * @return The results of the aggregation operation.
536
+ * @return the result {@link Stream}, containing mapped objects, needing to be closed once fully processed (e.g.
537
+ * through a try-with-resources clause).
536
538
* @since 2.0
537
539
*/
538
- <O > CloseableIterator <O > aggregateStream (TypedAggregation <?> aggregation , String collectionName , Class <O > outputType );
540
+ <O > Stream <O > aggregateStream (TypedAggregation <?> aggregation , String collectionName , Class <O > outputType );
539
541
540
542
/**
541
543
* Execute an aggregation operation backed by a Mongo DB {@link com.mongodb.client.AggregateIterable}.
542
- * <br / >
543
- * Returns a {@link CloseableIterator } that wraps the a Mongo DB {@link com.mongodb.client.AggregateIterable} that
544
- * needs to be closed. The raw results will be mapped to the given entity class and are returned as stream. The name
545
- * of the inputCollection is derived from the inputType of the aggregation.
546
- * <br / >
544
+ * <p >
545
+ * Returns a {@link Stream } that wraps the Mongo DB {@link com.mongodb.client.AggregateIterable} that needs to be
546
+ * closed. The raw results will be mapped to the given entity class and are returned as stream. The name of the
547
+ * inputCollection is derived from the inputType of the aggregation.
548
+ * <p >
547
549
* Aggregation streaming can't be used with {@link AggregationOptions#isExplain() aggregation explain}. Enabling
548
550
* explanation mode will throw an {@link IllegalArgumentException}.
549
551
*
550
552
* @param aggregation The {@link TypedAggregation} specification holding the aggregation operations, must not be
551
553
* {@literal null}.
552
554
* @param outputType The parametrized type of the returned list, must not be {@literal null}.
553
- * @return The results of the aggregation operation.
555
+ * @return the result {@link Stream}, containing mapped objects, needing to be closed once fully processed (e.g.
556
+ * through a try-with-resources clause).
554
557
* @since 2.0
555
558
*/
556
- <O > CloseableIterator <O > aggregateStream (TypedAggregation <?> aggregation , Class <O > outputType );
559
+ <O > Stream <O > aggregateStream (TypedAggregation <?> aggregation , Class <O > outputType );
557
560
558
561
/**
559
562
* Execute an aggregation operation backed by a Mongo DB {@link com.mongodb.client.AggregateIterable}.
560
- * <br / >
561
- * Returns a {@link CloseableIterator } that wraps the a Mongo DB {@link com.mongodb.client.AggregateIterable} that
562
- * needs to be closed. The raw results will be mapped to the given entity class.
563
- * <br / >
563
+ * <p >
564
+ * Returns a {@link Stream } that wraps the Mongo DB {@link com.mongodb.client.AggregateIterable} that needs to be
565
+ * closed. The raw results will be mapped to the given entity class.
566
+ * <p >
564
567
* Aggregation streaming can't be used with {@link AggregationOptions#isExplain() aggregation explain}. Enabling
565
568
* explanation mode will throw an {@link IllegalArgumentException}.
566
569
*
@@ -569,17 +572,18 @@ <T> GroupByResults<T> group(@Nullable Criteria criteria, String inputCollectionN
569
572
* @param inputType the inputType where the aggregation operation will read from, must not be {@literal null} or
570
573
* empty.
571
574
* @param outputType The parametrized type of the returned list, must not be {@literal null}.
572
- * @return The results of the aggregation operation.
575
+ * @return the result {@link Stream}, containing mapped objects, needing to be closed once fully processed (e.g.
576
+ * through a try-with-resources clause).
573
577
* @since 2.0
574
578
*/
575
- <O > CloseableIterator <O > aggregateStream (Aggregation aggregation , Class <?> inputType , Class <O > outputType );
579
+ <O > Stream <O > aggregateStream (Aggregation aggregation , Class <?> inputType , Class <O > outputType );
576
580
577
581
/**
578
582
* Execute an aggregation operation backed by a Mongo DB {@link com.mongodb.client.AggregateIterable}.
579
- * <br / >
580
- * Returns a {@link CloseableIterator } that wraps the a Mongo DB {@link com.mongodb.client.AggregateIterable} that
581
- * needs to be closed. The raw results will be mapped to the given entity class.
582
- * <br / >
583
+ * <p >
584
+ * Returns a {@link Stream } that wraps the Mongo DB {@link com.mongodb.client.AggregateIterable} that needs to be
585
+ * closed. The raw results will be mapped to the given entity class.
586
+ * <p >
583
587
* Aggregation streaming can't be used with {@link AggregationOptions#isExplain() aggregation explain}. Enabling
584
588
* explanation mode will throw an {@link IllegalArgumentException}.
585
589
*
@@ -588,10 +592,11 @@ <T> GroupByResults<T> group(@Nullable Criteria criteria, String inputCollectionN
588
592
* @param collectionName the collection where the aggregation operation will read from, must not be {@literal null} or
589
593
* empty.
590
594
* @param outputType The parametrized type of the returned list, must not be {@literal null}.
591
- * @return The results of the aggregation operation.
595
+ * @return the result {@link Stream}, containing mapped objects, needing to be closed once fully processed (e.g.
596
+ * through a try-with-resources clause).
592
597
* @since 2.0
593
598
*/
594
- <O > CloseableIterator <O > aggregateStream (Aggregation aggregation , String collectionName , Class <O > outputType );
599
+ <O > Stream <O > aggregateStream (Aggregation aggregation , String collectionName , Class <O > outputType );
595
600
596
601
/**
597
602
* Execute a map-reduce operation. The map-reduce operation will be formed with an output type of INLINE
0 commit comments