GutoVeronezi commented on a change in pull request #5958:
URL: https://github.com/apache/cloudstack/pull/5958#discussion_r800744583



##########
File path: framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
##########
@@ -1287,13 +1289,20 @@ protected void addJoins(StringBuilder str, 
Collection<JoinBuilder<SearchCriteria
             .append(" ");
             str.insert(fromIndex, onClause);
             String whereClause = join.getT().getWhereClause();
-            if ((whereClause != null) && !"".equals(whereClause)) {
+            if (!StringUtils.isEmpty(whereClause)) {

Review comment:
       ```suggestion
               if (StringUtils.isNotEmpty(whereClause)) {
   ```

##########
File path: framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
##########
@@ -1287,13 +1289,20 @@ protected void addJoins(StringBuilder str, 
Collection<JoinBuilder<SearchCriteria
             .append(" ");
             str.insert(fromIndex, onClause);
             String whereClause = join.getT().getWhereClause();
-            if ((whereClause != null) && !"".equals(whereClause)) {
+            if (!StringUtils.isEmpty(whereClause)) {
+                if (!hasWhereClause) {
+                    str.append(" WHERE ");
+                    hasWhereClause = true;
+                }
                 str.append(" (").append(whereClause).append(") AND");
             }
             fromIndex += onClause.length();
         }
 
-        str.delete(str.length() - 4, str.length());
+        if (hasWhereClause) {
+            // Remove ' AND' OR 'AND ' at the end of line
+            str.delete(str.length() - 4, str.length());

Review comment:
       I think it could be a method with an intuitive name instead of a comment.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to