https://github.com/daggerok/spring-data-java8
Java 8 CompletableFuture, Stream API return types for spring-data repositories
https://github.com/daggerok/spring-data-java8
completable-future completablefuture spring-data-java8 spring-data-jpa stream stream-api streamable
Last synced: 3 months ago
JSON representation
Java 8 CompletableFuture, Stream API return types for spring-data repositories
- Host: GitHub
- URL: https://github.com/daggerok/spring-data-java8
- Owner: daggerok
- Created: 2019-03-16T11:50:23.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-16T11:54:09.000Z (almost 7 years ago)
- Last Synced: 2025-01-10T00:41:55.240Z (about 1 year ago)
- Topics: completable-future, completablefuture, spring-data-java8, spring-data-jpa, stream, stream-api, streamable
- Language: Java
- Size: 51.8 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# spring-data-java8
Java 8 CompletableFuture, Stream API return types for spring-data (JPA) repositories
```java
@Repository
interface MessageRepository extends JpaRepository {
Streamable streamAllBy();
/*
must be executed inside transaction, otherwise you will get this error:
org.springframework.dao.InvalidDataAccessApiUsageException: You're trying to execute a streaming
query method without a surrounding transaction that keeps the connection open so that the Stream can
actually be consumed. Make sure the code consuming the stream uses @Transactional or any other way of
declaring a (read-only) transaction.
you can use TransactionTemplate for that, like so:
return transactionTemplate.execute(status -> {
try (Stream stream = messageRepository.findAnyBy()) {
return stream.collect(toList());
}
});
*/
Stream findAnyBy();
/*
you may want to configure and use custom taskExecutor:
@Bean
@Qualifier("myFutures")
public TaskExecutor taskExecutor() {
return new SimpleAsyncTaskExecutor("my-futures");
}
*/
@Async("myFutures")
CompletableFuture> findAllBy();
}
```
links:
- [read more](https://docs.spring.io/spring-data/data-jpa/docs/2.2.x/reference/html)