vorburger commented on a change in pull request #730: Added: SQL builder 
toString function
URL: https://github.com/apache/fineract/pull/730#discussion_r390261164
 
 

 ##########
 File path: 
fineract-provider/src/main/java/org/apache/fineract/infrastructure/security/utils/SQLBuilder.java
 ##########
 @@ -118,9 +121,34 @@ public String getSQLTemplate() {
     /*
      * Returns a String representation suitable for debugging and log output.
      * This is ONLY intended for debugging in logs, and NEVER for passing to a 
JDBC database.
+     */
     @Override
     public String toString() {
-        return "SQLBuilder{..."; // TODO implement this...
+        StringBuilder whereClause  = new StringBuilder();
+        ArrayList<String> modifiedArgs = new ArrayList<String>();
+        for (Object obj : args)
+        {
+            if(obj instanceof String)
+            {
+                modifiedArgs.add("['"+ obj + "']");
+            }else if(obj == null)
+            {
+                modifiedArgs.add("[null]");
+            }else{
+                modifiedArgs.add("["+ String.valueOf(obj) +"]");
+            }
+        }
+        for (int i=0;i<crts.size();i++)
+        {    if (whereClause.length() > 0)
+            {
+                whereClause.append("  AND  ");
+            }
+            if(whereClause.length()==0)
+            {
+                whereClause.append("WHERE  ");
+            }
+            whereClause.append(crts.get(i) + " " + modifiedArgs.get(i));
+        }
+        return "SQLBuilder{"+ whereClause.toString() +"}";
 
 Review comment:
   ```suggestion
           whereClause.append(" }");
           return whereClause.toString();
   ```
   
   The point of this is to avoid unnecessary String concatenation object 
creation.
   
   You should also avoid any other String `+` in this method - just `append()` 
everything.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to