Author: jonesde
Date: Thu Mar  4 09:24:30 2010
New Revision: 918910

URL: http://svn.apache.org/viewvc?rev=918910&view=rev
Log:
A better approach for this condition, it isn't just the COUNT function we want 
to look for, it is ANY function; a reminder for those using this: put the 
unique field first

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java

Modified: 
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java?rev=918910&r1=918909&r2=918910&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java 
(original)
+++ 
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java 
Thu Mar  4 09:24:30 2010
@@ -1012,15 +1012,15 @@
              * cause the "COUNT(DISTINCT " to appear twice, causing an attempt 
to try to count a count (function="count-distinct", distinct=true in find 
options)
              */
             if (selectFields != null && selectFields.size() > 0) {
-                String fullColName = selectFields.get(0).getColName();
-                
-                if (fullColName.indexOf("COUNT") >= 0) {
-                    // already has a COUNT in the name (generally from a 
function=count-distinct), so do it the old style
+                ModelField firstSelectField = selectFields.get(0);
+                ModelViewEntity.ModelAlias firstModelAlias = modelViewEntity 
!= null ? modelViewEntity.getAlias(firstSelectField.getName()) : null;
+                if (firstModelAlias != null && 
UtilValidate.isNotEmpty(firstModelAlias.getFunction())) {
+                    // if the field has a function already we don't want to 
count just it, would be meaningless
                     sqlBuffer.append("COUNT(DISTINCT *) ");
                 } else {
                     sqlBuffer.append("COUNT(DISTINCT ");
                     // this only seems to support a single column, which is 
not desirable but seems a lot better than no columns or in certain cases all 
columns
-                    sqlBuffer.append(selectFields.get(0).getColName());
+                    sqlBuffer.append(firstSelectField.getColName());
                     // 
sqlBuffer.append(modelEntity.colNameString(selectFields, ", ", "", 
datasourceInfo.aliasViews));
                     sqlBuffer.append(")");
                 }


Reply via email to