1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.prometheus.database;
18
19 import io.github.tonywasher.joceanus.prometheus.database.PrometheusDatabase.PrometheusDatabasePreferenceKey;
20 import io.github.tonywasher.joceanus.prometheus.database.PrometheusDatabase.PrometheusDatabasePreferences;
21
22
23
24
25 public class PrometheusDBConfig {
26
27
28
29 private static final String DEFAULT_USER = "testUser";
30
31
32
33
34 private static final char[] DEFAULT_PASS = "testPass".toCharArray();
35
36
37
38
39 private static final String DEFAULT_SERVER = "localhost";
40
41
42
43
44 private static final int DEFAULT_BATCH = 50;
45
46
47
48
49 private PrometheusJDBCDriver theDriver;
50
51
52
53
54 private String theUser;
55
56
57
58
59 private char[] thePassword;
60
61
62
63
64 private String theServer;
65
66
67
68
69 private String theInstance;
70
71
72
73
74 private Integer thePort;
75
76
77
78
79 private int theBatch;
80
81
82
83
84 public PrometheusDBConfig() {
85 }
86
87
88
89
90
91
92 public void setDriver(final PrometheusJDBCDriver pDriver) {
93 theDriver = pDriver;
94 }
95
96
97
98
99
100
101 public PrometheusJDBCDriver getDriver() {
102 return theDriver;
103 }
104
105
106
107
108
109
110 public void setUser(final String pUser) {
111 theUser = pUser;
112 }
113
114
115
116
117
118
119 public String getUser() {
120 return theUser;
121 }
122
123
124
125
126
127
128 public void setPassword(final char[] pPassword) {
129 thePassword = pPassword;
130 }
131
132
133
134
135
136
137 public char[] getPassword() {
138 return thePassword;
139 }
140
141
142
143
144
145
146 public void setServer(final String pServer) {
147 theServer = pServer;
148 }
149
150
151
152
153
154
155 public String getServer() {
156 return theServer;
157 }
158
159
160
161
162
163
164 public void setInstance(final String pInstance) {
165 theInstance = pInstance;
166 }
167
168
169
170
171
172
173 public String getInstance() {
174 return theInstance;
175 }
176
177
178
179
180
181
182 public void setPort(final Integer pPort) {
183 thePort = pPort;
184 }
185
186
187
188
189
190
191 public Integer getPort() {
192 return thePort;
193 }
194
195
196
197
198
199
200 public void setBatchSize(final int pSize) {
201 theBatch = pSize;
202 }
203
204
205
206
207
208
209 public int getBatchSize() {
210 return theBatch;
211 }
212
213
214
215
216
217
218
219 public static PrometheusDBConfig fromPrefs(final PrometheusDatabasePreferences pPreferences) {
220 final PrometheusDBConfig myConfig = new PrometheusDBConfig();
221 myConfig.setDriver(pPreferences.getEnumValue(PrometheusDatabasePreferenceKey.DBDRIVER, PrometheusJDBCDriver.class));
222 myConfig.setUser(pPreferences.getStringValue(PrometheusDatabasePreferenceKey.DBUSER));
223 myConfig.setPassword(pPreferences.getCharArrayValue(PrometheusDatabasePreferenceKey.DBPASS));
224 myConfig.setServer(pPreferences.getStringValue(PrometheusDatabasePreferenceKey.DBSERVER));
225 myConfig.setBatchSize(pPreferences.getIntegerValue(PrometheusDatabasePreferenceKey.DBBATCH));
226 if (myConfig.getDriver().usePort()) {
227 myConfig.setPort(pPreferences.getIntegerValue(PrometheusDatabasePreferenceKey.DBPORT));
228 }
229 if (myConfig.getDriver().useInstance()) {
230 myConfig.setInstance(pPreferences.getStringValue(PrometheusDatabasePreferenceKey.DBINSTANCE));
231 }
232 return myConfig;
233 }
234
235
236
237
238
239
240 public static PrometheusDBConfig postgres() {
241 final PrometheusDBConfig myConfig = new PrometheusDBConfig();
242 myConfig.setDriver(PrometheusJDBCDriver.POSTGRESQL);
243 myConfig.setUser(DEFAULT_USER);
244 myConfig.setPassword(DEFAULT_PASS);
245 myConfig.setServer(DEFAULT_SERVER);
246 myConfig.setPort(PrometheusJDBCDriver.PORT_POSTGRESQL);
247 myConfig.setBatchSize(DEFAULT_BATCH);
248 return myConfig;
249 }
250
251
252
253
254
255
256 public static PrometheusDBConfig mysql() {
257 final PrometheusDBConfig myConfig = new PrometheusDBConfig();
258 myConfig.setDriver(PrometheusJDBCDriver.MYSQL);
259 myConfig.setUser(DEFAULT_USER);
260 myConfig.setPassword(DEFAULT_PASS);
261 myConfig.setServer(DEFAULT_SERVER);
262 myConfig.setPort(PrometheusJDBCDriver.PORT_MARIADB);
263 myConfig.setBatchSize(DEFAULT_BATCH);
264 return myConfig;
265 }
266
267
268
269
270
271
272 public static PrometheusDBConfig mariaDB() {
273 final PrometheusDBConfig myConfig = new PrometheusDBConfig();
274 myConfig.setDriver(PrometheusJDBCDriver.MARIADB);
275 myConfig.setUser(DEFAULT_USER);
276 myConfig.setPassword(DEFAULT_PASS);
277 myConfig.setServer(DEFAULT_SERVER);
278 myConfig.setPort(PrometheusJDBCDriver.PORT_MARIADB);
279 myConfig.setBatchSize(DEFAULT_BATCH);
280 return myConfig;
281 }
282
283
284
285
286
287
288 public static PrometheusDBConfig sqlserver() {
289 final PrometheusDBConfig myConfig = new PrometheusDBConfig();
290 myConfig.setDriver(PrometheusJDBCDriver.SQLSERVER);
291 myConfig.setUser(DEFAULT_USER);
292 myConfig.setPassword(DEFAULT_PASS);
293 myConfig.setServer(DEFAULT_SERVER);
294 myConfig.setInstance(PrometheusJDBCDriver.INSTANCE_SQLEXPRESS);
295 myConfig.setBatchSize(DEFAULT_BATCH);
296 return myConfig;
297 }
298
299
300
301
302
303
304 public static PrometheusDBConfig h2() {
305 final PrometheusDBConfig myConfig = new PrometheusDBConfig();
306 myConfig.setDriver(PrometheusJDBCDriver.H2);
307 myConfig.setUser(DEFAULT_USER);
308 myConfig.setPassword(DEFAULT_PASS);
309 myConfig.setServer(DEFAULT_SERVER);
310 myConfig.setBatchSize(DEFAULT_BATCH);
311 return myConfig;
312 }
313 }