/*
 * Copyright 2007-2107 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.ymate.platform.persistence.jdbc.query;

import org.apache.commons.lang.StringUtils;

/**
 * 连接查询语句对象
 *
 * @author 刘镇 (suninformation@163.com) on 15/5/12 下午6:04
 * @version 1.0
 */
public class Join {

    private String __from;

    private String __alias;

    private Cond __on;

    public static Join inner(String from) {
        return new Join("INNER JOIN", from);
    }

    public static Join inner(Select select) {
        return inner(select.toString());
    }

    public static Join left(String from) {
        return new Join("LEFT JOIN", from);
    }

    public static Join right(String from) {
        return new Join("RIGHT JOIN", from);
    }

    private Join(String type, String from) {
        __from = type.concat(" ").concat(from);
    }

    public Join alias(String alias) {
        __alias = alias;
        return this;
    }

    public Join on(Cond cond) {
        __on = cond;
        return this;
    }

    public Params getParams() {
        return __on.getParams();
    }

    @Override
    public String toString() {
        __alias = StringUtils.trimToNull(__alias);
        if (__alias == null) {
            __alias = "";
        } else {
            __alias = " ".concat(__alias);
        }
        return new StringBuilder(__from).append(__alias).append(" ON ").append(__on.toString()).toString();
    }
}

@@ -945,32 +945,132 @@
 (String from) %7B%0A
+        return inner(null, from);%0A    %7D%0A%0A    public static Join inner(String prefix, String from) %7B%0A
         return n
@@ -1086,24 +1086,32 @@
 INNER JOIN%22,
+ prefix,
  from);%0A    
@@ -1180,16 +1180,22 @@
 n inner(
+null, 
 select.t
@@ -1248,32 +1248,130 @@
 (String from) %7B%0A
+        return left(null, from);%0A    %7D%0A%0A    public static Join left(String prefix, String from) %7B%0A
         return n
@@ -1382,32 +1382,40 @@
 oin(%22LEFT JOIN%22,
+ prefix,
  from);%0A    %7D%0A%0A 
@@ -1449,32 +1449,132 @@
 (String from) %7B%0A
+        return right(null, from);%0A    %7D%0A%0A    public static Join right(String prefix, String from) %7B%0A
         return n
@@ -1594,16 +1594,24 @@
 T JOIN%22,
+ prefix,
  from);%0A
@@ -1646,39 +1646,150 @@
 ng type, String 
-from) %7B
+prefix, String from) %7B%0A        if (StringUtils.isNotBlank(prefix)) %7B%0A            from = prefix.concat(from);%0A        %7D
 %0A        __from 
@@ -2314,88 +2314,40 @@
 urn 
-new StringBuilder(__from).append(__alias).append(%22 ON %22).append(__on.toString())
+__from + __alias + %22 ON %22 + __on
 .toS

优化Join构造方法支持前缀;