#1187 - Fix connection leak regression introduced in 11.2.3 for findEach() with invalid SQL

This commit is contained in:
Rob Bygrave
2017-10-31 10:49:35 +13:00
parent 89dac3820b
commit f5cfcbd56e
@@ -29,6 +29,8 @@ import io.ebeaninternal.server.loadcontext.DLoadContext;
import io.ebeaninternal.server.query.CQueryPlan;
import io.ebeaninternal.server.query.CancelableQuery;
import io.ebeaninternal.server.transaction.DefaultPersistenceContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.persistence.PersistenceException;
import java.sql.SQLException;
@@ -47,6 +49,8 @@ import java.util.function.Predicate;
*/
public final class OrmQueryRequest<T> extends BeanRequest implements BeanQueryRequest<T>, SpiOrmQueryRequest<T> {
private static final Logger log = LoggerFactory.getLogger(OrmQueryRequest.class);
private final BeanDescriptor<T> beanDescriptor;
private final OrmQueryEngine queryEngine;
@@ -232,6 +236,22 @@ public final class OrmQueryRequest<T> extends BeanRequest implements BeanQueryRe
loadContext = new DLoadContext(this, secondaryQueries);
}
/**
* Rollback the transaction if it was created for this request.
*/
public void rollbackTransIfRequired() {
if (createdTransaction) {
try {
transaction.end();
} catch (Exception e) {
// Just log this and carry on. A previous exception has been
// thrown and if this rollback throws exception it likely means
// that the connection is broken (and the dataSource and db will cleanup)
log.error("Error trying to rollback a transaction (after a prior exception thrown)", e);
}
}
}
/**
* Return the JsonReadOptions taking into account lazy loading and persistence context.
*/