Query termination for JPA 2.1 StoredProcedureQuery.execute() method

Includes backported support for JPA 2.2 getResultStream() method.

Issue: SPR-16826
This commit is contained in:
Juergen Hoeller
2018-05-16 09:46:11 +02:00
parent a54bc6650e
commit 997ca5cd3f

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -65,9 +65,9 @@ public abstract class SharedEntityManagerCreator {
private static final Class<?>[] NO_ENTITY_MANAGER_INTERFACES = new Class<?>[0]; private static final Class<?>[] NO_ENTITY_MANAGER_INTERFACES = new Class<?>[0];
private static final Set<String> transactionRequiringMethods = new HashSet<String>(6); private static final Set<String> transactionRequiringMethods = new HashSet<String>(8);
private static final Set<String> queryTerminationMethods = new HashSet<String>(3); private static final Set<String> queryTerminatingMethods = new HashSet<String>(8);
static { static {
transactionRequiringMethods.add("joinTransaction"); transactionRequiringMethods.add("joinTransaction");
@@ -77,9 +77,11 @@ public abstract class SharedEntityManagerCreator {
transactionRequiringMethods.add("remove"); transactionRequiringMethods.add("remove");
transactionRequiringMethods.add("refresh"); transactionRequiringMethods.add("refresh");
queryTerminationMethods.add("getResultList"); queryTerminatingMethods.add("execute"); // JPA 2.1 StoredProcedureQuery
queryTerminationMethods.add("getSingleResult"); queryTerminatingMethods.add("executeUpdate");
queryTerminationMethods.add("executeUpdate"); queryTerminatingMethods.add("getSingleResult");
queryTerminatingMethods.add("getResultList");
queryTerminatingMethods.add("getResultStream");
} }
@@ -376,7 +378,7 @@ public abstract class SharedEntityManagerCreator {
throw ex.getTargetException(); throw ex.getTargetException();
} }
finally { finally {
if (queryTerminationMethods.contains(method.getName())) { if (queryTerminatingMethods.contains(method.getName())) {
// Actual execution of the query: close the EntityManager right // Actual execution of the query: close the EntityManager right
// afterwards, since that was the only reason we kept it open. // afterwards, since that was the only reason we kept it open.
EntityManagerFactoryUtils.closeEntityManager(this.em); EntityManagerFactoryUtils.closeEntityManager(this.em);