Skip to content

DATAJPA-1241 - Removed dynamic check for getResultStream. #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.1.0.DATAJPA-1241-SNAPSHOT</version>

<name>Spring Data JPA</name>
<description>Spring Data module for JPA repositories.</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2017 the original author or authors.
* Copyright 2008-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,6 +54,7 @@
* @author Thomas Darimont
* @author Mark Paluch
* @author Christoph Strobl
* @author Jens Schauder
*/
public abstract class JpaQueryExecution {

Expand Down Expand Up @@ -334,7 +335,6 @@ static class StreamExecution extends JpaQueryExecution {
private static final String NO_SURROUNDING_TRANSACTION = "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.";

private static Method streamMethod = ReflectionUtils.findMethod(Query.class, "getResultStream");
private static boolean dynamicCheck = streamMethod == null;

/*
* (non-Javadoc)
Expand All @@ -354,27 +354,7 @@ protected Object doExecute(final AbstractJpaQuery query, Object[] values) {
return ReflectionUtils.invokeMethod(streamMethod, jpaQuery);
}

if (dynamicCheck) {

Method method = ReflectionUtils.findMethod(jpaQuery.getClass(), "getResultStream");

// Implementation available but on JPA 2.1
if (method != null) {

// Cache for subsequent reuse to prevent repeated reflection lookups
streamMethod = method;

return ReflectionUtils.invokeMethod(method, jpaQuery);

} else {

// Not available on implementation, skip further lookups
dynamicCheck = false;
}
}

// Fall back to legacy stream execution

PersistenceProvider persistenceProvider = PersistenceProvider.fromEntityManager(query.getEntityManager());
CloseableIterator<Object> iter = persistenceProvider.executeQueryWithResultStream(jpaQuery);

Expand Down