<commit_before>/*
 * 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 刘镇 (<EMAIL>) 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();
    }
}<commit_msg>优化Join构造方法支持前缀;<commit_after>/*
 * 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 刘镇 (<EMAIL>) 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 inner(null, from);
    }

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

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

    public static Join left(String from) {
        return left(null, from);
    }

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

    public static Join right(String from) {
        return right(null, from);
    }

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

    private Join(String type, String prefix, String from) {
        if (StringUtils.isNotBlank(prefix)) {
            from = prefix.concat(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 __from + __alias + " ON " + __on.toString();
    }
}
{'fraction_non_alphanumeric': 0.10244683283786873, 'fraction_numerical': 0.010061742510862108, 'mean_word_length': 2.5048076923076925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3115367', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1234, 'n_words': 430}