Apache OFBiz Delegator API是否支持按限制或偏移量从数据库中获取记录列表 [英] Does Apache OFBiz delegator API support fetching list of records from database by limit or offset

查看:174
本文介绍了Apache OFBiz Delegator 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?

如果没有限制(因为biz API是数据库不可知的),我还有其他选择吗?

If 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 Delegator API是否支持按限制或偏移量从数据库中获取记录列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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