if (log.isTraceEnabled()) {
log.trace("executing dynamic-ql: " + args[0]);
}
JDBCStoreManager2 manager = (JDBCStoreManager2) entity.getManager();
QLCompiler compiler = new EJBQLToSQL92Compiler(manager.getCatalog());
try {
compiler.compileJBossQL((String) args[0],
metadata.getMethod().getReturnType(),
getParamTypes(args),
metadata
);
} catch (Throwable t) {
log.error("Error compiling JBossQL statement '" + args[0] + "'", t);
throw new FinderException("Error compiling JBossQL statement '" + args[0] + "'");
}
String sql = compiler.getSQL();
int offsetParam = compiler.getOffsetParam();
int offsetValue = compiler.getOffsetValue();
int limitParam = compiler.getLimitParam();
int limitValue = compiler.getLimitValue();
AbstractQueryCommand.ResultReader resultReader;
if (!compiler.isSelectEntity()) {
if (compiler.isSelectField()) {
resultReader = new AbstractQueryCommand.FieldReader((JDBCCMPFieldBridge2) compiler.getSelectField());
} else {
resultReader = new AbstractQueryCommand.FunctionReader(compiler.getSelectFunction());
}
} else {
resultReader = new AbstractQueryCommand.EntityReader((JDBCEntityBridge2) compiler.getSelectEntity(), compiler.isSelectDistinct());
}
return AbstractQueryCommand.fetchCollection(
entity, sql, toArray(compiler.getInputParameters()),
AbstractQueryCommand.toInt(args, offsetParam, offsetValue), AbstractQueryCommand.toInt(args, limitParam, limitValue),
new AbstractQueryCommand.EagerCollectionStrategy(collectionFactory, resultReader, log),
schema, (Object[]) args[1], factory, log);
}