如何从 TopLink 查询中获取前 n 行?

发布于 2024-12-07 05:41:01 字数 1163 浏览 3 评论 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。

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. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

平安喜乐 2024-12-14 05:41:01

非常简单,只需插入第二行:

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

我的错误在于我尝试了这样的操作:

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

因为我没有读postfixSQL 是做什么的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文