@@ -0,0 +1,2120 @@
+package com.angkorteam.mbaas.server.bean;%0A%0Aimport com.google.common.collect.Lists;%0Aimport org.apache.commons.lang3.StringUtils;%0A%0Aimport java.util.List;%0A%0A/**%0A * Created by socheat on 11/24/16.%0A */%0Apublic class QueryBuilder %7B%0A%0A    private List%3CString%3E select = Lists.newArrayList();%0A    private String from;%0A    private List%3CString%3E join = Lists.newArrayList();%0A    private List%3CString%3E where = Lists.newArrayList();%0A    private List%3CString%3E orderBy = Lists.newArrayList();%0A    private List%3CString%3E having = Lists.newArrayList();%0A    private List%3CString%3E groupBy = Lists.newArrayList();%0A%0A    public void addSelect(String field) %7B%0A        this.select.add(field);%0A    %7D%0A%0A    public void addJoin(String table) %7B%0A        this.join.add(table);%0A    %7D%0A%0A    public void addWhere(String field) %7B%0A        this.where.add(field);%0A    %7D%0A%0A    public void addOrderBy(String field) %7B%0A        this.orderBy.add(field);%0A    %7D%0A%0A    public void addGroupBy(String field) %7B%0A        this.groupBy.add(field);%0A    %7D%0A%0A    public void addHaving(String field) %7B%0A        this.having.add(field);%0A    %7D%0A%0A    public void setFrom(String from) %7B%0A        this.from = from;%0A    %7D%0A%0A    public String toSQL() %7B%0A        StringBuilder builder = new StringBuilder();%0A        builder.append(%22SELECT %22);%0A        if (this.select.isEmpty()) %7B%0A            this.select.add(%22*%22);%0A        %7D%0A        builder.append(StringUtils.join(this.select, %22, %22));%0A        builder.append(%22 FROM %22);%0A        builder.append(this.from).append(%22 %22);%0A        builder.append(StringUtils.join(this.join, %22 %22));%0A        if (!this.where.isEmpty()) %7B%0A            builder.append(%22 WHERE %22).append(StringUtils.join(this.where, %22 AND %22));%0A        %7D%0A        if (!this.groupBy.isEmpty()) %7B%0A            builder.append(%22 GROUP BY %22).append(StringUtils.join(this.groupBy, %22, %22));%0A        %7D%0A        if (!this.having.isEmpty()) %7B%0A            builder.append(%22 HAVING %22).append(StringUtils.join(this.having, %22 AND %22));%0A        %7D%0A        if (!this.orderBy.isEmpty()) %7B%0A            builder.append(%22 ORDER BY %22).append(StringUtils.join(this.orderBy, %22, %22));%0A        %7D%0A        return builder.toString();%0A    %7D%0A%7D

add query builder