Close StoredProcedureQuery if it implements AutoCloseable.
If the JPA provider's implementation of StoredProcedureQuery implements AutoCloseable, invoke the close method when completed. Resolves #2915. Original pull request: #2938
This commit is contained in:
committed by
Mark Paluch
parent
0f8279bbfa
commit
32c8951a93
@@ -332,24 +332,36 @@ public abstract class JpaQueryExecution {
|
||||
Assert.isInstanceOf(StoredProcedureJpaQuery.class, jpaQuery);
|
||||
|
||||
StoredProcedureJpaQuery storedProcedureJpaQuery = (StoredProcedureJpaQuery) jpaQuery;
|
||||
|
||||
StoredProcedureQuery storedProcedure = storedProcedureJpaQuery.createQuery(accessor);
|
||||
|
||||
boolean returnsResultSet = storedProcedure.execute();
|
||||
try {
|
||||
|
||||
if (returnsResultSet) {
|
||||
boolean returnsResultSet = storedProcedure.execute();
|
||||
|
||||
if (!SurroundingTransactionDetectorMethodInterceptor.INSTANCE.isSurroundingTransactionActive()) {
|
||||
throw new InvalidDataAccessApiUsageException(NO_SURROUNDING_TRANSACTION);
|
||||
if (returnsResultSet) {
|
||||
|
||||
if (!SurroundingTransactionDetectorMethodInterceptor.INSTANCE.isSurroundingTransactionActive()) {
|
||||
throw new InvalidDataAccessApiUsageException(NO_SURROUNDING_TRANSACTION);
|
||||
}
|
||||
|
||||
if (storedProcedureJpaQuery.getQueryMethod().isCollectionQuery()) {
|
||||
return storedProcedure.getResultList();
|
||||
} else {
|
||||
return storedProcedure.getSingleResult();
|
||||
}
|
||||
}
|
||||
|
||||
if (storedProcedureJpaQuery.getQueryMethod().isCollectionQuery()) {
|
||||
return storedProcedure.getResultList();
|
||||
} else {
|
||||
return storedProcedure.getSingleResult();
|
||||
return storedProcedureJpaQuery.extractOutputValue(storedProcedure);
|
||||
|
||||
} finally {
|
||||
|
||||
if (storedProcedure instanceof AutoCloseable autoCloseable) {
|
||||
try {
|
||||
autoCloseable.close();
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
return storedProcedureJpaQuery.extractOutputValue(storedProcedure);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user