svn commit: r558245 - /ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r558245 - /ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java

jonesde
Author: jonesde
Date: Fri Jul 20 22:17:56 2007
New Revision: 558245

URL: http://svn.apache.org/viewvc?view=rev&rev=558245
Log:
Changed get states/provinces by country to get ONLY states/provinces and to be more efficient

Modified:
    ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java

Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java?view=diff&rev=558245&r1=558244&r2=558245
==============================================================================
--- ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java (original)
+++ ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java Fri Jul 20 22:17:56 2007
@@ -18,7 +18,6 @@
  *******************************************************************************/
 package org.ofbiz.common;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -68,7 +67,7 @@
     }
     
     public static List getStateList(GenericDelegator delegator) {
-        List geoList = new ArrayList();      
+        List geoList = FastList.newInstance();      
         EntityCondition condition = new EntityConditionList(UtilMisc.toList(
                 new EntityExpr("geoTypeId", EntityOperator.EQUALS, "STATE"), new EntityExpr("geoTypeId", EntityOperator.EQUALS, "PROVINCE")), EntityOperator.OR);
         List sortList = UtilMisc.toList("geoName");
@@ -76,7 +75,7 @@
             geoList = delegator.findByConditionCache("Geo", condition, null, sortList);
         } catch (GenericEntityException e) {
             Debug.logError(e, "Cannot lookup State Geos: " + e.toString(), module);
-        }                        
+        }
         return geoList;            
     }    
 
@@ -84,19 +83,27 @@
      * Returns a list of regional geo associations.
      */
     public static List getAssociatedStateList(GenericDelegator delegator, String country) {
-      if ( country == null || country.length() == 0 ) {
-        // Load the system default country
-        country = UtilProperties.getPropertyValue("general.properties", "country.geo.id.default");
-      }
-      List geoList = new ArrayList();
-      Map geoAssocFindMap = UtilMisc.toMap("geoId", country, "geoAssocTypeId", "REGIONS");
-      List sortList = UtilMisc.toList("geoIdTo");
-      try {
-          geoList = delegator.findByAndCache("GeoAssoc", geoAssocFindMap, sortList);
-      } catch (GenericEntityException e) {
-          Debug.logError(e, "Cannot lookup Geo", module);
-      }                        
-      return geoList;            
+        if (country == null || country.length() == 0) {
+            // Load the system default country
+            country = UtilProperties.getPropertyValue("general.properties", "country.geo.id.default");
+        }
+        EntityCondition stateProvinceFindCond = new EntityConditionList(UtilMisc.toList(
+                new EntityExpr("geoIdFrom", EntityOperator.EQUALS, country),
+                new EntityExpr("geoAssocTypeId", EntityOperator.EQUALS, "REGIONS"),
+                new EntityConditionList(UtilMisc.toList(
+                        new EntityExpr("geoTypeId", EntityOperator.EQUALS, "STATE"),
+                        new EntityExpr("geoTypeId", EntityOperator.EQUALS, "PROVINCE")
+                        ), EntityOperator.OR)
+                ), EntityOperator.AND);
+        List sortList = UtilMisc.toList("geoId");
 
+        List geoList = FastList.newInstance();
+        try {
+            geoList = delegator.findByConditionCache("GeoAssocAndGeoTo", stateProvinceFindCond, null, sortList);
+        } catch (GenericEntityException e) {
+            Debug.logError(e, "Cannot lookup Geo", module);
+        }                        
+        
+        return geoList;            
     }    
 }