18
18
import java .util .List ;
19
19
import java .util .Map ;
20
20
import java .util .Optional ;
21
+ import java .util .stream .Stream ;
21
22
22
23
import org .springframework .dao .OptimisticLockingFailureException ;
23
24
import org .springframework .data .domain .Pageable ;
41
42
* @author Myeonghyeon Lee
42
43
* @author Chirag Tailor
43
44
* @author Diego Krupitza
45
+ * @author Sergey Korotaev
44
46
*/
45
47
public interface DataAccessStrategy extends ReadingDataAccessStrategy , RelationResolver {
46
48
@@ -252,6 +254,16 @@ public interface DataAccessStrategy extends ReadingDataAccessStrategy, RelationR
252
254
@ Override
253
255
<T > Iterable <T > findAll (Class <T > domainType );
254
256
257
+ /**
258
+ * Loads all entities of the given type to a {@link Stream}.
259
+ *
260
+ * @param domainType the type of entities to load. Must not be {@code null}.
261
+ * @param <T> the type of entities to load.
262
+ * @return Guaranteed to be not {@code null}.
263
+ */
264
+ @ Override
265
+ <T > Stream <T > streamAll (Class <T > domainType );
266
+
255
267
/**
256
268
* Loads all entities that match one of the ids passed as an argument. It is not guaranteed that the number of ids
257
269
* passed in matches the number of entities returned.
@@ -264,6 +276,18 @@ public interface DataAccessStrategy extends ReadingDataAccessStrategy, RelationR
264
276
@ Override
265
277
<T > Iterable <T > findAllById (Iterable <?> ids , Class <T > domainType );
266
278
279
+ /**
280
+ * Loads all entities that match one of the ids passed as an argument to a {@link Stream}.
281
+ * It is not guaranteed that the number of ids passed in matches the number of entities returned.
282
+ *
283
+ * @param ids the Ids of the entities to load. Must not be {@code null}.
284
+ * @param domainType the type of entities to load. Must not be {@code null}.
285
+ * @param <T> type of entities to load.
286
+ * @return the loaded entities. Guaranteed to be not {@code null}.
287
+ */
288
+ @ Override
289
+ <T > Stream <T > streamAllByIds (Iterable <?> ids , Class <T > domainType );
290
+
267
291
@ Override
268
292
Iterable <Object > findAllByPath (Identifier identifier ,
269
293
PersistentPropertyPath <? extends RelationalPersistentProperty > path );
@@ -280,6 +304,18 @@ Iterable<Object> findAllByPath(Identifier identifier,
280
304
@ Override
281
305
<T > Iterable <T > findAll (Class <T > domainType , Sort sort );
282
306
307
+ /**
308
+ * Loads all entities of the given type to a {@link Stream}, sorted.
309
+ *
310
+ * @param domainType the type of entities to load. Must not be {@code null}.
311
+ * @param <T> the type of entities to load.
312
+ * @param sort the sorting information. Must not be {@code null}.
313
+ * @return Guaranteed to be not {@code null}.
314
+ * @since 2.0
315
+ */
316
+ @ Override
317
+ <T > Stream <T > streamAll (Class <T > domainType , Sort sort );
318
+
283
319
/**
284
320
* Loads all entities of the given type, paged and sorted.
285
321
*
@@ -316,6 +352,18 @@ Iterable<Object> findAllByPath(Identifier identifier,
316
352
@ Override
317
353
<T > Iterable <T > findAll (Query query , Class <T > domainType );
318
354
355
+ /**
356
+ * Execute a {@code SELECT} query and convert the resulting items to a {@link Stream}.
357
+ *
358
+ * @param query must not be {@literal null}.
359
+ * @param domainType the type of entities. Must not be {@code null}.
360
+ * @return a non-null list with all the matching results.
361
+ * @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one match found.
362
+ * @since 3.0
363
+ */
364
+ @ Override
365
+ <T > Stream <T > streamAll (Query query , Class <T > domainType );
366
+
319
367
/**
320
368
* Execute a {@code SELECT} query and convert the resulting items to a {@link Iterable}. Applies the {@link Pageable}
321
369
* to the result.
0 commit comments