finally
{
deregisterTask();
}
QueryResult qr = null;
try
{
if (inMemory)
{
// IN-MEMORY EVALUATION
ResultObjectFactory rof = storeMgr.newResultObjectFactory(acmd,
datastoreCompilation.getResultDefinitionForClass(),
RDBMSQueryUtils.useUpdateLockForQuery(this), getFetchPlan(),
candidateClass);
// Just instantiate the candidates for later in-memory processing
// TODO Use a queryResult rather than an ArrayList so we load when required
List candidates = new ArrayList();
while (rs.next())
{
candidates.add(rof.getObject(ec, rs));
}
// Perform in-memory filter/result/order etc
JavaQueryEvaluator resultMapper =
new JDOQLEvaluator(this, candidates, compilation, parameters, clr);
results = resultMapper.execute(true, true, true, true, true);
}
else
{
// IN-DATASTORE EVALUATION
ResultObjectFactory rof = null;
if (result != null)
{
// Each result row is of a result type
rof = new ResultClassROF(resultClass, datastoreCompilation.getResultDefinition());
}
else if (resultClass != null)
{
rof = new ResultClassROF(resultClass, datastoreCompilation.getResultDefinitionForClass());
}
else
{
// Each result row is a candidate object
rof = storeMgr.newResultObjectFactory(acmd,
datastoreCompilation.getResultDefinitionForClass(),
RDBMSQueryUtils.useUpdateLockForQuery(this), getFetchPlan(),
candidateClass);
}
// Create the required type of QueryResult
String resultSetType = RDBMSQueryUtils.getResultSetTypeForQuery(this);
if (resultSetType.equals("scroll-insensitive") ||
resultSetType.equals("scroll-sensitive"))
{
qr = new ScrollableQueryResult(this, rof, rs,
getResultDistinct() ? null : candidateCollection);
}
else
{
qr = new ForwardQueryResult(this, rof, rs,
getResultDistinct() ? null : candidateCollection);
}
final QueryResult qr1 = qr;
final ManagedConnection mconn1 = mconn;
ManagedConnectionResourceListener listener =
new ManagedConnectionResourceListener()
{
public void transactionFlushed(){}
public void transactionPreClose()
{
// Disconnect the query from this ManagedConnection (read in unread rows etc)
qr1.disconnect();
}
public void managedConnectionPreClose(){}
public void managedConnectionPostClose(){}
public void resourcePostClose()
{