/[Apache-SVN]
ViewVC logotype

Revision 1867590


Jump to revision: Previous Next
Author: nmalin
Date: Thu Sep 26 16:23:50 2019 UTC (4 years, 7 months ago)
Changed paths: 1
Log Message:
Improved: OrderReadHelper.getOrderItemAttributes as non static function
(OFBIZ-11208)
Currenlty if we use the java helper class OrderReadHelper to resolve the orderItemAttributes, it didn't use the a local cache and call each time the delegator throw a static function.
I added a non static function to optimise database calling when you have multiple get to do.

	public String getOrderItemAttribute(String orderItemSeqId, String attributeName) {
	     GenericValue orderItemAttribute = null;
	     if (orderHeader != null) {
		 if (orderItemAttributes == null) {
		     try{
		           orderItemAttributes = EntityQuery.use(orderHeader.getDelegator()) .from("OrderItemAttribute") .where("orderId", getOrderId()) .queryList();
		    } catch (GenericEntityException e) { Debug.logError(e, module); }
		 }
		 orderItemAttribute = EntityUtil.getFirst(
		     EntityUtil.filterByAnd(orderItemAttributes,
		         UtilMisc.toMap("orderItemSeqId", orderItemSeqId, "attrName", attributeName)));
	     }
	     return orderItemAttribute != null ? orderItemAttribute.getString("attrValue"): null;
	 }
 

At the first call, we populate the OrderReadHelper with all orderItemAttributes liked to an order, and after just filter with the orderItemSeqId and the attribute name wanted

Example:
    OrderReadHelper orh = new OrderReadHelper(orderHeader)
    ...
    for (GenericValue orderItem : orh.getOrderItems()) {
                listAttr << 
                       [startValue   : orh.getOrderItemAttribute(orderItem.orderItemSeqId, "MyStartValue"),
                        endValue     : orh.getOrderItemAttribute(orderItem.orderItemSeqId, "MyEndValue")]
    }

We request only for the first passage, after for all other line we use the local OrderReadHelper cache.

Added also the same logical for OrderReadHelper.getOrderAttributes


Changed paths

Path Details
Directoryofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReadHelper.java modified , text changed

infrastructure at apache.org
ViewVC Help
Powered by ViewVC 1.1.26