package kr.pe.kwonnam.dynamicql.stringbuilderqlparams;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;

public class DynamicQlParamsQueryBuildTest extends AbstractQueryBuildTest {
    private Logger log = getLogger(DynamicQlParamsQueryBuildTest.class);

    private StringBuilder builder;
    private DynamicQlParams dqp;

    @Test
    public void build_sql() throws Exception {
        builder = new StringBuilder();
        dqp = new DynamicQlParams();

        builder
            .append("SELECT ")
            .append(StringUtils.join(User.COLUMNS, ", ")).append("\n")
            .append("FROM users as u\n")
            .append("WHERE 1 = 1\n");

        if (user.getUserId() != null) {
            builder.append("AND user_id = ").append(dqp.param(user.getUserId())).append("\n");
        }
        if (StringUtils.isNotEmpty(user.getName())) {
            builder.append("AND name = ").append(dqp.param(user.getName())).append("\n");
        }
        if (user.getBirthday() != null) {
            builder.append("AND birthday = ").append(dqp.param(user.getBirthday())).append("\n");
        }
        if (CollectionUtils.isNotEmpty(zipCodes)) {
            builder.append("AND zip_code in (").append(dqp.inParams(zipCodes)).append(")\n");
        }
        builder.append("LIMIT ").append(dqp.param(10));

        log.info("StringBuilder with DynamicQlParams : {}", builder.toString());
        log.info("Query Parameters : {}", dqp.getParameters());
    }
}

@@ -199,16 +199,55 @@
 ogger;%0A%0A
+import static java.lang.String.format;%0A
 import s
@@ -871,32 +871,613 @@
 Id() != null) %7B%0A
+            builder.append(format(%22AND user_id = %25s %25n%22, dqp.param(user.getUserId())));%0A        %7D%0A        if (StringUtils.isNotEmpty(user.getName())) %7B%0A            builder.append(format(%22AND name = %25s %25n%22, dqp.param(user.getName())));%0A        %7D%0A        if (user.getBirthday() != null) %7B%0A            builder.append(format(%22AND birthday = %25s %25n%22, dqp.param(user.getBirthday())));%0A        %7D%0A        if (CollectionUtils.isNotEmpty(zipCodes)) %7B%0A            builder.append(format(%22AND zip_code in (%25s) %25n%22,dqp.inParams(zipCodes)));%0A        %7D%0A%0A//        if (user.getUserId() != null) %7B%0A//
             buil
@@ -1547,32 +1547,34 @@
 ).append(%22%5Cn%22);%0A
+//
         %7D%0A      
@@ -1559,32 +1559,34 @@
 %22);%0A//        %7D%0A
+//
         if (Stri
@@ -1615,32 +1615,34 @@
 r.getName())) %7B%0A
+//
             buil
@@ -1707,32 +1707,34 @@
 ).append(%22%5Cn%22);%0A
+//
         %7D%0A      
@@ -1719,32 +1719,34 @@
 %22);%0A//        %7D%0A
+//
         if (user
@@ -1763,32 +1763,34 @@
 ay() != null) %7B%0A
+//
             buil
@@ -1867,24 +1867,26 @@
 pend(%22%5Cn%22);%0A
+//
         %7D%0A  
@@ -1875,32 +1875,34 @@
 %22);%0A//        %7D%0A
+//
         if (Coll
@@ -1929,32 +1929,34 @@
 ty(zipCodes)) %7B%0A
+//
             buil
@@ -2033,16 +2033,18 @@
 %22)%5Cn%22);%0A
+//
         

add String.format based example