All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.jinghui70.rainbow.dbaccess.cnd.CndPlus Maven / Gradle / Ivy

There is a newer version: 5.2.11
Show newest version
package io.github.jinghui70.rainbow.dbaccess.cnd;

import cn.hutool.core.lang.Assert;
import io.github.jinghui70.rainbow.dbaccess.NamedSql;
import io.github.jinghui70.rainbow.dbaccess.Sql;
import io.github.jinghui70.rainbow.utils.StringBuilderX;

import java.util.List;

public class CndPlus extends Cnd {

    private List children;

    public List getChildren() {
        return children;
    }

    public void setChildren(List children) {
        this.children = children;
    }

    private String tag() {
        switch (field) {
            case AND:
            case OR:
                Assert.notEmpty(children, "{} CndPlus must have children", field);
                return field;
            default:
                return null;
        }
    }
    
    public void toSql(Sql sql) {
        String tag = tag();
        if (tag == null) super.toSql(sql);
        sql.append("(");
        for (CndPlus child : children) {
            child.toSql(sql);
            sql.appendTemp(tag);
        }
        sql.clearTemp().append(")");
    }

    @Override
    public void toNamedSql(NamedSql sql) {
        String tag = tag();
        if (tag == null) super.toNamedSql(sql);
        sql.append("(");
        for (CndPlus child : children) {
            child.toNamedSql(sql);
            sql.appendTemp(tag);
        }
        sql.clearTemp().append(")");
    }

    @Override
    public String toString() {
        String tag = tag();
        if (tag == null) super.toString();
        return new StringBuilderX("(").join(children, tag).append(")").toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy