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 PrometheusDBConfig() {
85
86 }
87
88
89
90
91
92
93 public void setDriver(final PrometheusJDBCDriver pDriver) {
94 theDriver = pDriver;
95 }
96
97
98
99
100
101
102 public PrometheusJDBCDriver getDriver() {
103 return theDriver;
104 }
105
106
107
108
109
110
111 public void setUser(final String pUser) {
112 theUser = pUser;
113 }
114
115
116
117
118
119
120 public String getUser() {
121 return theUser;
122 }
123
124
125
126
127
128
129 public void setPassword(final char[] pPassword) {
130 thePassword = pPassword;
131 }
132
133
134
135
136
137
138 public char[] getPassword() {
139 return thePassword;
140 }
141
142
143
144
145
146
147 public void setServer(final String pServer) {
148 theServer = pServer;
149 }
150
151
152
153
154
155
156 public String getServer() {
157 return theServer;
158 }
159
160
161
162
163
164
165 public void setInstance(final String pInstance) {
166 theInstance = pInstance;
167 }
168
169
170
171
172
173
174 public String getInstance() {
175 return theInstance;
176 }
177
178
179
180
181
182
183 public void setPort(final Integer pPort) {
184 thePort = pPort;
185 }
186
187
188
189
190
191
192 public Integer getPort() {
193 return thePort;
194 }
195
196
197
198
199
200
201 public void setBatchSize(final int pSize) {
202 theBatch = pSize;
203 }
204
205
206
207
208
209
210 public int getBatchSize() {
211 return theBatch;
212 }
213
214
215
216
217
218
219
220 public static PrometheusDBConfig fromPrefs(final PrometheusDatabasePreferences pPreferences) {
221 final PrometheusDBConfig myConfig = new PrometheusDBConfig();
222 myConfig.setDriver(pPreferences.getEnumValue(PrometheusDatabasePreferenceKey.DBDRIVER, PrometheusJDBCDriver.class));
223 myConfig.setUser(pPreferences.getStringValue(PrometheusDatabasePreferenceKey.DBUSER));
224 myConfig.setPassword(pPreferences.getCharArrayValue(PrometheusDatabasePreferenceKey.DBPASS));
225 myConfig.setServer(pPreferences.getStringValue(PrometheusDatabasePreferenceKey.DBSERVER));
226 myConfig.setBatchSize(pPreferences.getIntegerValue(PrometheusDatabasePreferenceKey.DBBATCH));
227 if (myConfig.getDriver().usePort()) {
228 myConfig.setPort(pPreferences.getIntegerValue(PrometheusDatabasePreferenceKey.DBPORT));
229 }
230 if (myConfig.getDriver().useInstance()) {
231 myConfig.setInstance(pPreferences.getStringValue(PrometheusDatabasePreferenceKey.DBINSTANCE));
232 }
233 return myConfig;
234 }
235
236
237
238
239
240
241 public static PrometheusDBConfig postgres() {
242 final PrometheusDBConfig myConfig = new PrometheusDBConfig();
243 myConfig.setDriver(PrometheusJDBCDriver.POSTGRESQL);
244 myConfig.setUser(DEFAULT_USER);
245 myConfig.setPassword(DEFAULT_PASS);
246 myConfig.setServer(DEFAULT_SERVER);
247 myConfig.setPort(PrometheusJDBCDriver.PORT_POSTGRESQL);
248 myConfig.setBatchSize(DEFAULT_BATCH);
249 return myConfig;
250 }
251
252
253
254
255
256
257 public static PrometheusDBConfig mysql() {
258 final PrometheusDBConfig myConfig = new PrometheusDBConfig();
259 myConfig.setDriver(PrometheusJDBCDriver.MYSQL);
260 myConfig.setUser(DEFAULT_USER);
261 myConfig.setPassword(DEFAULT_PASS);
262 myConfig.setServer(DEFAULT_SERVER);
263 myConfig.setPort(PrometheusJDBCDriver.PORT_MARIADB);
264 myConfig.setBatchSize(DEFAULT_BATCH);
265 return myConfig;
266 }
267
268
269
270
271
272
273 public static PrometheusDBConfig mariaDB() {
274 final PrometheusDBConfig myConfig = new PrometheusDBConfig();
275 myConfig.setDriver(PrometheusJDBCDriver.MARIADB);
276 myConfig.setUser(DEFAULT_USER);
277 myConfig.setPassword(DEFAULT_PASS);
278 myConfig.setServer(DEFAULT_SERVER);
279 myConfig.setPort(PrometheusJDBCDriver.PORT_MARIADB);
280 myConfig.setBatchSize(DEFAULT_BATCH);
281 return myConfig;
282 }
283
284
285
286
287
288
289 public static PrometheusDBConfig sqlserver() {
290 final PrometheusDBConfig myConfig = new PrometheusDBConfig();
291 myConfig.setDriver(PrometheusJDBCDriver.SQLSERVER);
292 myConfig.setUser(DEFAULT_USER);
293 myConfig.setPassword(DEFAULT_PASS);
294 myConfig.setServer(DEFAULT_SERVER);
295 myConfig.setInstance(PrometheusJDBCDriver.INSTANCE_SQLEXPRESS);
296 myConfig.setBatchSize(DEFAULT_BATCH);
297 return myConfig;
298 }
299
300
301
302
303
304
305 public static PrometheusDBConfig h2() {
306 final PrometheusDBConfig myConfig = new PrometheusDBConfig();
307 myConfig.setDriver(PrometheusJDBCDriver.H2);
308 myConfig.setUser(DEFAULT_USER);
309 myConfig.setPassword(DEFAULT_PASS);
310 myConfig.setServer(DEFAULT_SERVER);
311 myConfig.setBatchSize(DEFAULT_BATCH);
312 return myConfig;
313 }
314 }