Skip to content

Commit

Permalink
Prevent caching of projections #321
Browse files Browse the repository at this point in the history
  • Loading branch information
julgus committed May 19, 2023
1 parent fa32c08 commit b19e7f1
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ final class StandardJPAStreamer implements JPAStreamer {
@SuppressWarnings("unchecked")
public <T> Stream<T> stream(final StreamConfiguration<T> streamConfiguration) {
requireNonNull(streamConfiguration);
if (streamConfiguration.joins().isEmpty()) {
// Only cache simple configurations to limit the number of objects held
// See https://github.com/speedment/jpa-streamer/issues/56
if (cached(streamConfiguration)) {
return (Stream<T>) streamerCache
.computeIfAbsent(streamConfiguration, ec -> new StandardStreamer<>(streamConfiguration, entityManagerSupplier))
.stream();
Expand Down Expand Up @@ -85,6 +83,12 @@ public void close() {
closeHandler.run();
}

// Only cache simple configurations to limit the number of objects held
// See https://github.com/speedment/jpa-streamer/issues/56
private <T> boolean cached(final StreamConfiguration<T> streamConfiguration) {
return streamConfiguration.joins().isEmpty() && !streamConfiguration.selections().isPresent();
}

private void printGreeting(final ApplicationInformation info) {
final String greeting = String.format("%s%n" +
":: %s %s :: %s%n" +
Expand Down

0 comments on commit b19e7f1

Please sign in to comment.