forked from wix-incubator/wix-embedded-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSchemaConfig.java
77 lines (59 loc) · 1.91 KB
/
SchemaConfig.java
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
package com.wix.mysql.config;
import com.wix.mysql.Sources;
import com.wix.mysql.SqlScriptSource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SchemaConfig {
private final String name;
private final Charset charset;
private final List<SqlScriptSource> scripts;
private SchemaConfig(String name, Charset charset, List<SqlScriptSource> scripts) {
this.name = name;
this.charset = charset;
this.scripts = scripts;
}
public static Builder aSchemaConfig(final String name) {
return new Builder(name);
}
public String getName() {
return name;
}
public Charset getCharset() {
return charset;
}
public List<SqlScriptSource> getScripts() {
return scripts;
}
public static class Builder {
private final String name;
private Charset charset;
private List<SqlScriptSource> scripts = new ArrayList<>();
public Builder(final String name) {
this.name = name;
}
public Builder withCharset(final Charset charset) {
this.charset = charset;
return this;
}
public Builder withScripts(final SqlScriptSource... scripts) {
return withScripts(Arrays.asList(scripts));
}
public Builder withScripts(final List<SqlScriptSource> scripts) {
this.scripts.addAll(scripts);
return this;
}
public Builder withCommands(final String... commands) {
return withCommands(Arrays.asList(commands));
}
public Builder withCommands(final List<String> commands) {
for (String cmd: commands) {
this.scripts.add(Sources.fromString(cmd));
}
return this;
}
public SchemaConfig build() {
return new SchemaConfig(name, charset, scripts);
}
}
}