Skip to content

Commit 2c97493

Browse files
committed
#62 - Added a section on the Stream usage to the README.
Original pull request: #63.
1 parent f5e6b3b commit 2c97493

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

jpa/java8/README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,27 @@ interface CustomerRepository extends Repository<Customer, Long> {
1515
}
1616
```
1717

18-
* `CustomerRepository.findOne(Long)` effectively "overrides" the default `CrudRepository.findOne(…)` to return `Optional.empty()` instead of `null` in case no uniqe element satisfying the query can be found.
18+
* `CustomerRepository.findOne(Long)` effectively "overrides" the default `CrudRepository.findOne(…)` to return `Optional.empty()` instead of `null` in case no unique element satisfying the query can be found.
1919
* `CustomerRepository.findByLastname(…)` does the same for a normal query method.
2020

2121
## Support for JDK 8's date/time types in the auditing sub-system
2222

23-
* `Customer` extends `AbstractEntity` which contains fields of JDK 8's new date/time API and those can be populated the same way legacy types like `Date` and `Calendar` can.
23+
* `Customer` extends `AbstractEntity` which contains fields of JDK 8's new date/time API and those can be populated the same way legacy types like `Date` and `Calendar` can.
24+
25+
## Support for JDK 8' `Stream` in repository methods
26+
27+
JPA repositories can now use `Stream` as return type for query methods to trigger streamed execution of the query. This will cause Spring Data JPA to use persistnce provider specific API to traverse the query result one-by-one.
28+
29+
```java
30+
interface CustomerRepository extends Repository<Customer, Long> {
31+
32+
@Query("select c from Customer c")
33+
Stream<Customer> streamAllCustomers();
34+
}
35+
36+
try (Stream<Customer> customers = repository.streamAllCustomers()) {
37+
// use the stream here
38+
}
39+
```
40+
41+
Note how the returned `Stream` has to be used in a try-with-resources clause as the underlying resources have to be closed once we finished iterating over the result.

0 commit comments

Comments
 (0)