jaskell.sql.Conflict Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jaskell-java8 Show documentation
Show all versions of jaskell-java8 Show documentation
This is a utils library for java 8 project.
It include parsec combinators and sql generators library.
package jaskell.sql;
import jaskell.script.Directive;
import jaskell.script.Parameter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Conflict implements Directive {
Directive _prefix;
List _items = new ArrayList<>();
Conflict(){
}
Conflict(String names){
_items.addAll(Arrays.stream(
names.split(",")).map(String::trim).map(Name::new).collect(Collectors.toList()));
}
Conflict(String... names){
_items.addAll(Arrays.stream(names).map(Name::new).collect(Collectors.toList()));
}
@Override
public String script() {
if(_items.isEmpty()) {
return String.format("%s CONFLICT", _prefix.script());
} else {
return String.format("%s CONFLICT (%s)",
_prefix.script(),
_items.stream().map(Name::script).collect(Collectors.joining(", ")));
}
}
@Override
public List> parameters() {
return _prefix.parameters();
}
public Do do_() {
Do re = new Do();
re._prefix = this;
return re;
}
public On on(){
On re = new On();
re._prefix = this;
return re;
}
public Where where(String name){
Where re = new Where(name);
re._prefix = this;
return re;
}
public Where where(Name name){
Where re = new Where(name);
re._prefix = this;
return re;
}
public static class On implements Directive{
Directive _prefix;
@Override
public String script() {
return String.format("%s ON", _prefix.script());
}
@Override
public List> parameters() {
return _prefix.parameters();
}
public Constraint constraint(String name){
Constraint re = new Constraint(name);
re._prefix = this;
return re;
}
public Constraint constraint(Literal name){
Constraint re = new Constraint(name);
re._prefix = this;
return re;
}
}
public static class Constraint implements Directive {
Directive _prefix;
Literal _constraint;
Constraint(String name){
_constraint = new Literal(name);
}
Constraint(Literal name){
_constraint = name;
}
@Override
public String script() {
return String.format("%s CONSTRAINT %s", _prefix.script(), _constraint);
}
@Override
public List> parameters() {
return _prefix.parameters();
}
public Do do_(){
Do re = new Do();
re._prefix = this;
return re;
}
}
public static class Where extends Statement {
Directive _prefix;
Name _name;
Where(String name){
_name = new Name(name);
}
Where(Name name){
_name = name;
}
@Override
public String script() {
return String.format("%s WHERE %s", _prefix.script(), _name.script());
}
@Override
public List> parameters() {
return _prefix.parameters();
}
public Do do_() {
Do re = new Do();
re._prefix = this;
return re;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy