return Collections.EMPTY_LIST;
}
else
{
List candidates = new ArrayList(candidateCollection);
JavaQueryEvaluator resultMapper = new JPQLEvaluator(this, candidates, compilation,
parameters, clr);
return resultMapper.execute(true, true, true, true, true);
}
}
else if (type == Query.SELECT)
{
// Query results are cached, so return those
List<Object> cachedResults = getQueryManager().getDatastoreQueryResult(this, parameters);
if (cachedResults != null)
{
return new CandidateIdsQueryResult(this, cachedResults);
}
}
Object results = null;
ManagedConnection mconn = ec.getStoreManager().getConnection(ec);
try
{
// Execute the query
long startTime = System.currentTimeMillis();
if (NucleusLogger.QUERY.isDebugEnabled())
{
NucleusLogger.QUERY.debug(LOCALISER.msg("021046", getLanguage(), getSingleStringQuery(),
null));
}
RDBMSStoreManager storeMgr = (RDBMSStoreManager)getStoreManager();
AbstractClassMetaData acmd = ec.getMetaDataManager().getMetaDataForClass(candidateClass, clr);
SQLController sqlControl = storeMgr.getSQLController();
PreparedStatement ps = null;
try
{
if (type == Query.SELECT)
{
// Create PreparedStatement and apply parameters, result settings etc
ps = RDBMSQueryUtils.getPreparedStatementForQuery(mconn,
datastoreCompilation.getSQL(), this);
SQLStatementHelper.applyParametersToStatement(ps, ec,
datastoreCompilation.getStatementParameters(),
null, parameters);
RDBMSQueryUtils.prepareStatementForExecution(ps, this, false);
registerTask(ps);
ResultSet rs = null;
try
{
rs = sqlControl.executeStatementQuery(mconn, toString(), ps);
}
finally
{
deregisterTask();
}
QueryResult qr = null;
try
{
if (evaluateInMemory())
{
// 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 JPQLEvaluator(this, candidates, compilation, parameters, clr);
results = resultMapper.execute(true, true, true, true, true);
}
else
{
// IN-DATASTORE EVALUATION
ResultObjectFactory rof = null;