Author: lektran
Date: Fri Aug 28 08:40:58 2009 New Revision: 808814 URL: http://svn.apache.org/viewvc?rev=808814&view=rev Log: Changes to the performFind and performFindList services to limit the size of the resultset where possible. Changes to ModelForm to allow using form supplied pagination information as service parameters in the action tag, plus changes to how the list size is retrieved Modified: ofbiz/trunk/framework/common/servicedef/services.xml ofbiz/trunk/framework/common/src/org/ofbiz/common/FindServices.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Modified: ofbiz/trunk/framework/common/servicedef/services.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/servicedef/services.xml?rev=808814&r1=808813&r2=808814&view=diff ============================================================================== --- ofbiz/trunk/framework/common/servicedef/services.xml (original) +++ ofbiz/trunk/framework/common/servicedef/services.xml Fri Aug 28 08:40:58 2009 @@ -207,6 +207,7 @@ <attribute name="entityName" type="String" mode="IN" optional="false"/> <attribute name="fieldList" type="java.util.List" mode="IN" optional="true"/> <attribute name="orderByList" type="java.util.List" mode="IN" optional="true"/> + <attribute name="maxRows" mode="IN" type="Integer" optional="true"/> <attribute name="entityConditionList" type="org.ofbiz.entity.condition.EntityConditionList" mode="IN" optional="true"/> <attribute name="noConditionFind" type="String" mode="IN" optional="true"><!-- find with no condition (empty entityConditionList) only done when this is Y --></attribute> <attribute name="distinct" type="String" mode="IN" optional="true"><!-- distinct find only done when this is Y --></attribute> @@ -224,6 +225,8 @@ <attribute name="distinct" type="String" mode="IN" optional="true"><!-- distinct find only done when this is Y --></attribute> <attribute name="filterByDate" type="String" mode="IN" optional="true"/> <attribute name="filterByDateValue" type="Timestamp" mode="IN" optional="true"/> + <attribute name="viewIndex" type="Integer" mode="IN" optional="true"/> + <attribute name="viewSize" type="Integer" mode="IN" optional="true"/> <attribute name="listIt" type="org.ofbiz.entity.util.EntityListIterator" mode="OUT" optional="true"/> <attribute name="queryString" type="String" mode="OUT" optional="true"/> <attribute name="queryStringMap" type="java.util.Map" mode="OUT" optional="true"/> Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/FindServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/FindServices.java?rev=808814&r1=808813&r2=808814&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/FindServices.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/FindServices.java Fri Aug 28 08:40:58 2009 @@ -367,22 +367,23 @@ * @param context * @return Map */ - public static Map<String, Object> performFindList(DispatchContext dctx, Map<String, ?> context) { - Map<String, Object> result = performFind(dctx,context); - + public static Map<String, Object> performFindList(DispatchContext dctx, Map<String, Object> context) { Integer viewSize = (Integer) context.get("viewSize"); if (viewSize == null) viewSize = Integer.valueOf(20); // default + context.put("viewSize", viewSize); Integer viewIndex = (Integer) context.get("viewIndex"); if (viewIndex == null) viewIndex = Integer.valueOf(0); // default + context.put("viewIndex", viewIndex); + + Map<String, Object> result = performFind(dctx,context); int start = viewIndex.intValue() * viewSize.intValue(); List<GenericValue> list = null; Integer listSize = null; try { EntityListIterator it = (EntityListIterator) result.get("listIt"); - list = it.getPartialList(start+1, viewSize.intValue()); // list starts at '1' - it.last(); - listSize = Integer.valueOf(it.currentIndex()); + list = it.getPartialList(start+1, viewSize); // list starts at '1' + listSize = it.getResultsSizeAfterPartialList(); it.close(); } catch (Exception e) { Debug.logInfo("Problem getting partial list" + e,module); @@ -423,11 +424,21 @@ } Timestamp filterByDateValue = (Timestamp) context.get("filterByDateValue"); + Integer viewSize = (Integer) context.get("viewSize"); + Integer viewIndex = (Integer) context.get("viewIndex"); + Integer maxRows = null; + if (viewSize != null && viewIndex != null) { + maxRows = viewSize * (viewIndex + 1); + } + LocalDispatcher dispatcher = dctx.getDispatcher(); Map<String, Object> prepareResult = null; try { - prepareResult = dispatcher.runSync("prepareFind", UtilMisc.toMap("entityName", entityName, "orderBy", orderBy, "inputFields", inputFields, "filterByDate", filterByDate,"filterByDateValue", filterByDateValue, "userLogin", userLogin, "locale", context.get("locale"), "timeZone", context.get("timeZone"))); + prepareResult = dispatcher.runSync("prepareFind", UtilMisc.toMap("entityName", entityName, "orderBy", orderBy, + "inputFields", inputFields, "filterByDate", filterByDate, + "filterByDateValue", filterByDateValue, "userLogin", userLogin, + "locale", context.get("locale"), "timeZone", context.get("timeZone"))); } catch (GenericServiceException gse) { return ServiceUtil.returnError("Error preparing conditions: " + gse.getMessage()); } @@ -436,7 +447,11 @@ Map<String, Object> executeResult = null; try { - executeResult = dispatcher.runSync("executeFind", UtilMisc.toMap("entityName", entityName, "orderByList", orderByList, "fieldList", fieldList, "entityConditionList", exprList, "noConditionFind", noConditionFind, "distinct", distinct, "locale", context.get("locale"), "timeZone", context.get("timeZone"))); + executeResult = dispatcher.runSync("executeFind", UtilMisc.toMap("entityName", entityName, "orderByList", orderByList, + "fieldList", fieldList, "entityConditionList", exprList, + "noConditionFind", noConditionFind, "distinct", distinct, + "locale", context.get("locale"), "timeZone", context.get("timeZone"), + "maxRows", maxRows)); } catch (GenericServiceException gse) { return ServiceUtil.returnError("Error finding iterator: " + gse.getMessage()); } @@ -548,13 +563,15 @@ if (fieldList != null) { fieldSet = UtilMisc.makeSetWritable(fieldList); } + Integer maxRows = (Integer) context.get("maxRows"); + maxRows = maxRows != null ? maxRows : -1; GenericDelegator delegator = dctx.getDelegator(); // Retrieve entities - an iterator over all the values EntityListIterator listIt = null; try { if (noConditionFind || (entityConditionList != null && entityConditionList.getConditionListSize() > 0)) { listIt = delegator.find(entityName, entityConditionList, null, fieldSet, orderByList, - new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, distinct)); + new EntityFindOptions(true, EntityFindOptions.TYPE_FORWARD_ONLY, EntityFindOptions.CONCUR_READ_ONLY, -1, maxRows, distinct)); } } catch (GenericEntityException e) { return ServiceUtil.returnError("Error running Find on the [" + entityName + "] entity: " + e.getMessage()); @@ -655,7 +672,9 @@ * @param context * @return */ - public static Map<String, Object> performFindItem(DispatchContext dctx, Map<String, ?> context) { + public static Map<String, Object> performFindItem(DispatchContext dctx, Map<String, Object> context) { + context.put("viewSize", 1); + context.put("viewIndex", 0); Map<String, Object> result = org.ofbiz.common.FindServices.performFind(dctx,context); List<GenericValue> list = null; Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=808814&r1=808813&r2=808814&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Fri Aug 28 08:40:58 2009 @@ -780,6 +780,12 @@ * use the same form definitions for many types of form UIs */ public void renderFormString(Appendable writer, Map<String, Object> context, FormStringRenderer formStringRenderer) throws IOException { + // increment the paginator + this.incrementPaginatorNumber(context); + // Populate the viewSize and viewIndex so they are available for use during form actions + context.put("viewIndex", this.getViewIndex(context)); + context.put("viewSize", this.getViewSize(context)); + runFormActions(context); setWidgetBoundaryComments(context); @@ -1283,8 +1289,6 @@ public void preparePager(Map<String, Object> context) { - // increment the paginator - this.incrementPaginatorNumber(context); this.rowCount = 0; String lookupName = this.getListName(); if (UtilValidate.isEmpty(lookupName)) { @@ -2429,8 +2433,7 @@ } else if (entryList instanceof EntityListIterator) { EntityListIterator iter = (EntityListIterator) entryList; try { - iter.last(); - listSize = iter.currentIndex(); + listSize = iter.getResultsSizeAfterPartialList(); iter.beforeFirst(); } catch (GenericEntityException e) { Debug.logError(e, "Error getting list size", module); |
Free forum by Nabble | Edit this page |