-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathInto.java
More file actions
93 lines (75 loc) · 2.43 KB
/
Copy pathInto.java
File metadata and controls
93 lines (75 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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<Directive> _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<Parameter<?>> parameters() {
List<Parameter<?>> 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;
}
}