001package io.ebeaninternal.server.query; 002 003import io.ebean.Transaction; 004import io.ebeaninternal.api.SpiEbeanServer; 005import io.ebeaninternal.api.SpiQuery; 006 007import java.util.concurrent.Callable; 008 009/** 010 * Represent the findCount query as a Callable. 011 * 012 * @param <T> the entity bean type 013 */ 014public class CallableQueryCount<T> extends CallableQuery<T> implements Callable<Integer> { 015 016 /** 017 * Note that the transaction passed in is always a new transaction solely to 018 * find the row count so it must be cleaned up by this CallableQueryRowCount. 019 */ 020 public CallableQueryCount(SpiEbeanServer server, SpiQuery<T> query, Transaction t) { 021 super(server, query, t); 022 } 023 024 /** 025 * Execute the query returning the row count. 026 */ 027 @Override 028 public Integer call() { 029 try { 030 return server.findCountWithCopy(query, transaction); 031 } finally { 032 // cleanup the underlying connection 033 transaction.end(); 034 } 035 } 036 037}