Fix for Issue 35 Connection pool leak with findFutureRowCount(),

findFutureList() and findFutureIds()
This commit is contained in:
Robin Bygrave
2013-07-01 20:17:38 +12:00
parent c0b83b939d
commit 243864fef7
11 changed files with 216 additions and 65 deletions
@@ -2,29 +2,36 @@ package com.avaje.ebeaninternal.server.query;
import java.util.concurrent.Callable;
import com.avaje.ebean.Query;
import com.avaje.ebean.Transaction;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.api.SpiQuery;
/**
* Represent the findRowCount query as a Callable.
*
* @param <T> the entity bean type
*
* @param <T>
* the entity bean type
*/
public class CallableQueryRowCount<T> extends CallableQuery<T> implements Callable<Integer> {
public CallableQueryRowCount(SpiEbeanServer server, Query<T> query, Transaction t) {
super(server, query, t);
}
/**
* Execute the query returning the row count.
*/
public Integer call() throws Exception {
return server.findRowCountWithCopy(query, t);
}
/**
* Note that the transaction passed in is always a new transaction solely to
* find the row count so it must be cleaned up by this CallableQueryRowCount.
*/
public CallableQueryRowCount(SpiEbeanServer server, SpiQuery<T> query, Transaction t) {
super(server, query, t);
}
/**
* Execute the query returning the row count.
*/
public Integer call() throws Exception {
try {
return server.findRowCountWithCopy(query, transaction);
} finally {
// cleanup the underlying connection
transaction.end();
}
}
}