jaskell.sql.Into 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 Into implements Directive, ThenSelect {
Directive _prefix;
Name _name;
List _fields = new ArrayList<>();
Into(String table){
_name = new Name(table);
}
Into(String table, String fields){
_name = new Name(table);
_fields.addAll(
Arrays.stream(fields.split(",")).map(String::trim).map(Name::new).collect(Collectors.toList()));
}
Into(String table, String ... fields){
_name = new Name(table);
_fields.addAll(
Arrays.stream(fields).map(String::trim).map(Name::new).collect(Collectors.toList()));
}
Into(String table, Directive ... fields){
_name = new Name(table);
_fields.addAll(Arrays.asList(fields));
}
public Into field(String field){
_fields.add(new Name(field));
return this;
}
public Into fields(String fields){
_fields.addAll(
Arrays.stream(fields.split(",")).map(String::trim).map(Name::new).collect(Collectors.toList()));
return this;
}
public Into fields(String ... fields){
_fields.addAll(
Arrays.stream(fields).map(String::trim).map(Name::new).collect(Collectors.toList()));
return this;
}
public Into fields(String table, Directive ... fields){
_fields.addAll(Arrays.asList(fields));
return this;
}
@Override
public String script() {
return String.format("%s INTO %s(%s)",
_prefix.script(),
_name.script(),
_fields.stream().map(Directive::script).collect(Collectors.joining(", ")));
}
@Override
public List> parameters() {
List> re = new ArrayList<>(_prefix.parameters());
_fields.forEach(item->re.addAll(item.parameters()));
return re;
}
public Values values(String vs) {
Values re = new Values(vs);
re._insert = this;
return re;
}
public Values values(String ... vs) {
Values re = new Values(vs);
re._insert = this;
return re;
}
public Values values(Directive ... directives) {
Values re = new Values(directives);
re._insert = this;
return re;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy