openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r1456576 - /openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
Date Thu, 14 Mar 2013 17:59:17 GMT
Author: ppoddar
Date: Thu Mar 14 17:59:17 2013
New Revision: 1456576

URL: http://svn.apache.org/r1456576
Log:
Simple change to stringify a collection of values with proper spaces

Modified:
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java?rev=1456576&r1=1456575&r2=1456576&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
Thu Mar 14 17:59:17 2013
@@ -23,6 +23,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -669,24 +670,25 @@ class CriteriaQueryImpl<T> implements Op
         if (_where != null) {
             buffer.append(" WHERE ").append(_where.asValue(this));
         }
-        if (_orders != null) {
-            buffer.append(" ORDER BY ");
-            for (Order orderBy : getOrderList()) {
-                buffer.append(((CriteriaExpression)orderBy).asValue(this));
-            }
-        }
-        if (_groups != null) {
-            buffer.append(" GROUP BY ");
-            for (Expression<?> groupBy : getGroupList()) {
-                buffer.append(((CriteriaExpression)groupBy).asValue(this));
-            }
-        }
+        renderList(buffer, " ORDER BY ", getOrderList());
+        renderList(buffer, " GROUP BY ", getGroupList());
         if (_having != null) {
             buffer.append(" HAVING ");
             buffer.append(_having.asValue(this));
         }
     }
     
+    private void renderList(StringBuilder buffer, String clause, Collection<?> coll)
{
+    	if (coll == null || coll.isEmpty())
+    		return;
+    	
+    	buffer.append(clause);
+    	for (Iterator<?> i = coll.iterator(); i.hasNext(); ) {
+    		buffer.append(((CriteriaExpression)i.next()).asValue(this));
+    		if (i.hasNext()) buffer.append(", ");
+    	}
+    }
+    
     private void renderJoins(StringBuilder buffer, Collection<Join<?,?>> joins)
{
         if (joins == null) return;
         for (Join j : joins) {



Mime
View raw message