Apache OFBiz 委托人 API 是否支持按限制或偏移量从数据库中获取记录列表 [英] Does Apache OFBiz delegator API support fetching list of records from database by limit or offset
问题描述
假设我们只需要从表中获取 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 the database. So is there a way in ofbiz
framework to just select 5 records rather than getting a list from the database and then taking just 5 from the list?
如果限制是不可能的(因为 ofbiz
API 与数据库无关)我还有哪些其他选择?
If the limit is not possible (since ofbiz
API is database agnostic) what are my other alternatives?
推荐答案
我建议你看看这个 实体引擎手册
基本上是为了从数据库中获取有限的行集,你会这样做:
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();
此外,如果您希望将直接 SQL 发送到您的数据库,那么就这样做:
Also if you prefer to send direct SQL to your database then just do like this:
// 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
这篇关于Apache OFBiz 委托人 API 是否支持按限制或偏移量从数据库中获取记录列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!