通过限制或偏移是否从数据库记录的ofbiz委托API支持获取列表 [英] Does ofbiz delegator API support fetching list of records from database by limit or offset

查看:179
本文介绍了通过限制或偏移是否从数据库记录的ofbiz委托API支持获取列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我们有来从表中只有5条记录,但我的where子句匹配25K记录数据库。那么,有没有在ofbiz框架的方式来只选择5条记录,而不是正从数据库列表,然后从列表中服用仅有5?

Let's say we have to fetch only 5 records from a table but my where clause is matching 25k records in database. So is there a way in ofbiz framework to just select 5 records rather than getting a list from database and then taking just 5 from the list?

如果限制是不可能的(因为他的ofbiz API是数据库无关),我有哪些其他的替代品?

If limit is not possible (since ofbiz API is database agnostic) what are my other alternatives?

推荐答案

我会建议你去看看这个的实体引擎食谱

I would you suggest you to take a look into this entity engine cookbook

实际上从数据库中你会做让有限的行:

Essentially for getting limited set of rows from database you would do:

// first get a list iterator
productsELI = delegator.findListIteratorByCondition("Product", 
  new EntityExpr("productId", EntityOperator.NOT_EQUAL, null), 
                  UtilMisc.toList("productId"), null);

// then get a partial list by count TO RETURN first 5 records
productsELI.getPartialList(0, 5);

// and finally just close the iterator
productsELI.close();

此外,如果你preFER发送 SQL直接到数据库,然后就去做这样的:

// gets the helper (localmysql, localpostgres, etc.) for your entity group org.ofbiz
String helperName = delegator.getGroupHelperName("org.ofbiz");
SQLProcessor sqlproc = new SQLProcessor(helperName);
sqlproc.prepareStatement("SELECT * FROM PARTY LMIT 0, 5");
ResultSet rs1 = sqlproc.executeQuery();

// and then get your data from ResultSet like regular JDBC

这篇关于通过限制或偏移是否从数据库记录的ofbiz委托API支持获取列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆