io.github.sinri.keel.mysql.statement.UnionStatement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Keel Show documentation
Show all versions of Keel Show documentation
A website framework with VERT.X for ex-PHP-ers, exactly Ark Framework Users.
The newest version!
package io.github.sinri.keel.mysql.statement;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import static io.github.sinri.keel.helper.KeelHelpersInterface.KeelHelpers;
public class UnionStatement extends AbstractReadStatement {
final List selections = new ArrayList<>();
public UnionStatement() {
}
public UnionStatement(@Nonnull String firstSelection) {
selections.add("(" + AbstractStatement.SQL_COMPONENT_SEPARATOR + firstSelection + AbstractStatement.SQL_COMPONENT_SEPARATOR + ")");
}
public UnionStatement union(@Nonnull String selection) {
if (this.selections.isEmpty()) {
selections.add("(" + AbstractStatement.SQL_COMPONENT_SEPARATOR + selection + AbstractStatement.SQL_COMPONENT_SEPARATOR + ")");
} else {
selections.add(" UNION (" + AbstractStatement.SQL_COMPONENT_SEPARATOR + selection + AbstractStatement.SQL_COMPONENT_SEPARATOR + ")");
}
return this;
}
public UnionStatement unionAll(@Nonnull String selection) {
if (this.selections.isEmpty()) {
selections.add("(" + AbstractStatement.SQL_COMPONENT_SEPARATOR + selection + AbstractStatement.SQL_COMPONENT_SEPARATOR + ")");
} else {
selections.add(" UNION ALL (" + AbstractStatement.SQL_COMPONENT_SEPARATOR + selection + AbstractStatement.SQL_COMPONENT_SEPARATOR + ")");
}
return this;
}
public UnionStatement union(@Nonnull List list) {
for (String selection : list) {
union(selection);
}
return this;
}
public UnionStatement unionAll(@Nonnull List list) {
for (String selection : list) {
unionAll(selection);
}
return this;
}
public String toString() {
return KeelHelpers.stringHelper().joinStringArray(selections, " ") + (
getRemarkAsComment().isEmpty() ? "" : ("\n-- " + getRemarkAsComment())
);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy