[英]How can I fetch first n rows from a TopLink query?
For optimization purpose, I want to fetch first N results in a subquery (I'm getting first N ID values) and in the main query fetch full rows for the ID values in the subquery and order them. 出于优化目的,我想在子查询中获取前N个结果(我正在获取第一个N个ID值),而在主查询中,要在子查询中获取ID值的完整行并对其进行排序。 What I have now is 我现在所拥有的是
// 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);
What I'm trying so far is using a user defined function, like this: 到目前为止,我正在尝试使用用户定义的函数,如下所示:
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);
This is literally where I stopped so this won't work but it can show you which way I'm heading. 从字面上看,这是我停下来的地方,因此无法正常工作,但可以向您显示我的前进方向。 Is something like this even possible? 这样的事情可能吗? I'm using Java 1.4 and toplink 10g. 我正在使用Java 1.4和toplink 10g。
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"); managedEmp.postfixSQL(“仅优先获取5行”);
because I didn't read what postfixSQL does. 因为我没有阅读postfixSQL的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.