db.sql.api.cmd.struct.query.Withs Maven / Gradle / Ivy
package db.sql.api.cmd.struct.query;
import db.sql.api.Cmd;
import db.sql.api.SqlBuilderContext;
import db.sql.api.tookit.CmdUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Withs implements Cmd {
private List withs;
public void add(IWith with) {
if (withs == null) {
withs = new ArrayList<>();
}
withs.add(with);
}
@Override
public StringBuilder sql(Cmd module, Cmd parent, SqlBuilderContext context, StringBuilder sqlBuilder) {
if (withs == null || withs.isEmpty()) {
return sqlBuilder;
}
sqlBuilder.append(" WITH ");
CmdUtils.join(module, this, context, sqlBuilder, this.withs, ",".toCharArray());
return sqlBuilder;
}
@Override
public boolean contain(Cmd cmd) {
return CmdUtils.contain(cmd, this.withs);
}
public List getUnions() {
return Collections.unmodifiableList(this.withs);
}
}