0

出于优化目的,我想在子查询中获取前 N 个结果(我正在获取前 N 个 ID 值),并在主查询中获取子查询中 ID 值的完整行并对其进行排序。我现在拥有的是

// This just adds params to the subquery
Expression managedEmp = generateExpression(p_upravljackaFilter);
ReportQuery subQuery = new ReportQuery(CustomDocument.class,
    managedEmp);

subQuery.addAttribute("m_id");

Expression exp = new ExpressionBuilder().get("m_id").in(subQuery);
ReadAllQuery testQuery = new ReadAllQuery(CustomDocument.class,
    exp);
testQuery.addAscendingOrdering("m_creationDate");

List documentList = (List)getTopLinkTemplate().executeQuery(testQuery, true);

到目前为止,我正在尝试使用用户定义的函数,如下所示:

ExpressionOperator fetchFirst = new ExpressionOperator();
fetchFirst.setSelector(1);
Vector s = new Vector();
s.addElement("FETCH FIRST 5 ROWS ONLY");
fetchFirst.printsAs(s);
fetchFirst.bePostfix();
fetchFirst.setNodeClass(FunctionExpression.class);
ExpressionOperator.initializeOperators();
ExpressionOperator.addOperator(fetchFirst);
expression = expression.and(builder.get("m_datumKreiranja").getFunction(fetchFirst);

这实际上是我停下来的地方,所以这不起作用,但它可以告诉你我的前进方向。这样的事情甚至可能吗?我正在使用 Java 1.4 和 toplink 10g。

4

1 回答 1

0

Really simple, just insert into second line:

managedEmp = managedEmp.postfixSQL("FETCH FIRST 5 ROWS ONLY");

My mistake was in the fact that I tried it like this:

managedEmp.postfixSQL("FETCH FIRST 5 ROWS ONLY");

because I didn't read what postfixSQL does.

于 2011-09-28T11:52:25.077 回答