假设我们只需从表中获取 5 条记录,但我的 where 子句匹配数据库中的 25k 条记录。那么有没有办法ofbiz
框架只选择 5 条记录,而不是从数据库获取列表,然后从列表中只取出 5 条记录?
如果限制不可能(因为ofbiz
API 与数据库无关)我的其他选择是什么?
我建议你看看这个实体引擎食谱 http://www.opensourcestrategies.com/ofbiz/ofbiz_entity_cookbook.txt
本质上,为了从数据库获取有限的行集,您可以执行以下操作:
// 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 到您的数据库然后就这样做:
// 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)