-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathModuleConfiguration.java
More file actions
405 lines (334 loc) · 12.8 KB
/
ModuleConfiguration.java
File metadata and controls
405 lines (334 loc) · 12.8 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE file at the root of the source
* tree and available online at
*
* https://github.com/keeps/db-preservation-toolkit
*/
package com.databasepreservation.model.modules.configuration;
import static com.databasepreservation.Constants.VIEW_NAME_PREFIX;
import static com.databasepreservation.model.modules.configuration.enums.DatabaseTechnicalFeatures.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.databasepreservation.Constants;
import com.databasepreservation.model.modules.configuration.enums.DatabaseTechnicalFeatures;
import com.fasterxml.jackson.annotation.*;
/**
* @author Miguel Guimarães <mguimaraes@keep.pt>
*/
@JsonPropertyOrder({"import", "schemas", "ignore"})
@JsonIgnoreProperties(value = {"fetchRows"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ModuleConfiguration {
private ImportModuleConfiguration importModuleConfiguration;
// Statements to run before importing database, e.g. creating temporary tables for use in custom views exported as
// tables.
private List<String> setupStatements;
private Map<String, SchemaConfiguration> schemaConfigurations;
private Map<DatabaseTechnicalFeatures, Boolean> ignore;
private boolean fetchRows;
public ModuleConfiguration() {
importModuleConfiguration = new ImportModuleConfiguration();
schemaConfigurations = new LinkedHashMap<>();
ignore = new LinkedHashMap<>();
fetchRows = true;
}
/*
* Behaviour Model
*/
@JsonIgnore
public boolean isSelectedSchema(String schemaName) {
return schemaConfigurations.get(schemaName) != null || schemaConfigurations.isEmpty();
}
@JsonIgnore
public boolean isSelectedTable(String schemaName, String tableName) {
if (schemaConfigurations.isEmpty()) {
return true;
}
return schemaConfigurations.get(schemaName) != null
&& schemaConfigurations.get(schemaName).isSelectedTable(tableName);
}
@JsonIgnore
public boolean isSelectedView(String schemaName, String viewName) {
if (schemaConfigurations.isEmpty()) {
return true;
}
return schemaConfigurations.get(schemaName) != null
&& schemaConfigurations.get(schemaName).isSelectedView(viewName);
}
@JsonIgnore
public boolean isSelectedColumnFromTable(String schemaName, String tableName, String columnName) {
if (schemaConfigurations.isEmpty()) {
return true;
}
return schemaConfigurations.get(schemaName) != null
&& schemaConfigurations.get(schemaName).isSelectedColumnFromTable(tableName, columnName);
}
@JsonIgnore
public boolean isSelectedColumnFromView(String schemaName, String viewName, String columnName) {
if (schemaConfigurations.isEmpty()) {
return true;
}
return schemaConfigurations.get(schemaName) != null
&& schemaConfigurations.get(schemaName).isSelectedColumnFromView(viewName, columnName);
}
@JsonIgnore
public boolean isMerkleColumn(String schemaName, String tableName, String columnName) {
if (schemaConfigurations.isEmpty()) {
return true;
}
return schemaConfigurations.get(schemaName) != null
&& schemaConfigurations.get(schemaName).isMerkleColumn(tableName, columnName);
}
public boolean isInventoryColumn(String schemaName, String tableName, String columnName) {
if (schemaConfigurations.isEmpty()) {
return true;
}
return schemaConfigurations.get(schemaName) != null
&& schemaConfigurations.get(schemaName).isInventoryColumn(tableName, columnName);
}
@JsonIgnore
public boolean isMaterializeView(String schemaName, String viewName) {
if (ignoreViews()) {
return false;
}
if (schemaConfigurations.isEmpty()) {
return false;
}
return schemaConfigurations.get(schemaName) != null
&& schemaConfigurations.get(schemaName).isMaterializedView(viewName);
}
@JsonIgnore
public List<CustomViewConfiguration> getCustomViews(String schemaName) {
if (schemaConfigurations.get(schemaName) == null) {
return new ArrayList<>();
}
return schemaConfigurations.get(schemaName).getCustomViewConfigurations();
}
@JsonIgnore
public TableConfiguration getTableConfiguration(String schemaName, String name) {
if (schemaConfigurations.get(schemaName) == null) {
return null;
}
return schemaConfigurations.get(schemaName).getTableConfiguration(name);
}
@JsonIgnore
public CustomViewConfiguration getCustomViewConfiguration(String schemaName, String name) {
if (schemaConfigurations.get(schemaName) == null) {
return null;
}
for (CustomViewConfiguration customViewConfiguration : schemaConfigurations.get(schemaName)
.getCustomViewConfigurations()) {
if (customViewConfiguration.getName().equals(name)) {
return customViewConfiguration;
}
}
return null;
}
@JsonIgnore
public boolean ignoreRoutines() {
return isIgnored(ROUTINES);
}
@JsonIgnore
public boolean ignoreTriggers() {
return isIgnored(TRIGGERS);
}
@JsonIgnore
public boolean ignoreUsers() {
return isIgnored(USERS);
}
@JsonIgnore
public boolean ignoreRoles() {
return isIgnored(ROLES);
}
@JsonIgnore
public boolean ignorePrivileges() {
return isIgnored(PRIVILEGES);
}
@JsonIgnore
public boolean ignorePrimaryKey() {
return isIgnored(PRIMARY_KEYS);
}
@JsonIgnore
public boolean ignoreCandidateKey() {
return isIgnored(CANDIDATE_KEYS);
}
@JsonIgnore
public boolean ignoreCheckConstraints() {
return isIgnored(CHECK_CONSTRAINTS);
}
@JsonIgnore
public boolean ignoreForeignKey() {
return isIgnored(FOREIGN_KEYS);
}
@JsonIgnore
public boolean ignoreViews() {
return isIgnored(VIEWS);
}
private boolean isIgnored(DatabaseTechnicalFeatures databaseTechnicalFeatures) {
if (ignore.get(databaseTechnicalFeatures) == null) {
return false;
}
return ignore.get(databaseTechnicalFeatures);
}
@JsonIgnore
public String getImportModuleParameterValue(String parameter) {
return importModuleConfiguration.getParameters().get(parameter);
}
@JsonIgnore
private boolean isWhereDefinedForTable(String schemaName, String tableName) {
if (schemaConfigurations.isEmpty()) {
return false;
}
return schemaConfigurations.get(schemaName) != null
&& schemaConfigurations.get(schemaName).getTableConfiguration(tableName) != null
&& !schemaConfigurations.get(schemaName).getTableConfiguration(tableName).getWhere().equals(Constants.EMPTY);
}
@JsonIgnore
private boolean isWhereDefinedForView(String schemaName, String viewName) {
if (schemaConfigurations.isEmpty()) {
return false;
}
return schemaConfigurations.get(schemaName) != null
&& schemaConfigurations.get(schemaName).getViewConfiguration(viewName) != null
&& !schemaConfigurations.get(schemaName).getViewConfiguration(viewName).getWhere().equals(Constants.EMPTY);
}
@JsonIgnore
public String getWhere(String schemaName, String tableName, boolean isTable) {
if (isTable) {
if (isWhereDefinedForTable(schemaName, tableName)) {
return schemaConfigurations.get(schemaName).getTableConfiguration(tableName).getWhere();
}
} else {
String viewNameWithoutPrefix = tableName.replace(VIEW_NAME_PREFIX, "");
if (isWhereDefinedForView(schemaName, viewNameWithoutPrefix)) {
return schemaConfigurations.get(schemaName).getViewConfiguration(viewNameWithoutPrefix).getWhere();
}
}
return null;
}
@JsonIgnore
private boolean isOrderByDefinedForTable(String schemaName, String tableName) {
if (schemaConfigurations.isEmpty()) {
return false;
}
return schemaConfigurations.get(schemaName) != null
&& schemaConfigurations.get(schemaName).getTableConfiguration(tableName) != null
&& !schemaConfigurations.get(schemaName).getTableConfiguration(tableName).getOrderBy().equals(Constants.EMPTY);
}
@JsonIgnore
private boolean isOrderByDefinedForView(String schemaName, String viewName) {
if (schemaConfigurations.isEmpty()) {
return false;
}
return schemaConfigurations.get(schemaName) != null
&& schemaConfigurations.get(schemaName).getViewConfiguration(viewName) != null
&& !schemaConfigurations.get(schemaName).getViewConfiguration(viewName).getOrderBy().equals(Constants.EMPTY);
}
public String getOrderBy(String schemaName, String tableName, boolean isTable) {
if (isTable) {
if (isOrderByDefinedForTable(schemaName, tableName)) {
return schemaConfigurations.get(schemaName).getTableConfiguration(tableName).getOrderBy();
}
} else {
String viewNameWithoutPrefix = tableName.replace(VIEW_NAME_PREFIX, "");
if (isOrderByDefinedForView(schemaName, viewNameWithoutPrefix)) {
return schemaConfigurations.get(schemaName).getViewConfiguration(viewNameWithoutPrefix).getOrderBy();
}
}
return null;
}
@JsonIgnore
public boolean hasExternalLobDefined(String schemaName, String tableName, boolean isFromView) {
if (schemaConfigurations.isEmpty()) {
return false;
}
if (!isFromView) {
if (schemaConfigurations.get(schemaName) != null
&& schemaConfigurations.get(schemaName).getTableConfiguration(tableName) != null) {
return schemaConfigurations.get(schemaName).getTableConfiguration(tableName).getColumns().stream()
.anyMatch(p -> p.getExternalLob() != null);
}
} else {
String viewNameWithoutPrefix = tableName.replace(VIEW_NAME_PREFIX, "");
if (schemaConfigurations.get(schemaName) != null
&& schemaConfigurations.get(schemaName).getViewConfiguration(viewNameWithoutPrefix) != null) {
return schemaConfigurations.get(schemaName).getViewConfiguration(viewNameWithoutPrefix).getColumns().stream()
.anyMatch(p -> p.getExternalLob() != null);
}
}
return false;
}
@JsonIgnore
public boolean isExternalLobColumn(String schema, String table, String column, boolean isFromView) {
if (schemaConfigurations.isEmpty()) {
return false;
}
if (!isFromView) {
return schemaConfigurations.get(schema) != null
&& schemaConfigurations.get(schema).getTableConfiguration(table) != null
&& schemaConfigurations.get(schema).getTableConfiguration(table).getColumnConfiguration(column) != null
&& schemaConfigurations.get(schema).getTableConfiguration(table).getColumnConfiguration(column)
.getExternalLob() != null;
} else {
String viewNameWithoutPrefix = table.replace(VIEW_NAME_PREFIX, "");
return schemaConfigurations.get(schema) != null
&& schemaConfigurations.get(schema).getViewConfiguration(viewNameWithoutPrefix) != null
&& schemaConfigurations.get(schema).getViewConfiguration(viewNameWithoutPrefix)
.getColumnConfiguration(column) != null
&& schemaConfigurations.get(schema).getViewConfiguration(viewNameWithoutPrefix).getColumnConfiguration(column)
.getExternalLob() != null;
}
}
@JsonIgnore
public ExternalLobsConfiguration getExternalLobsConfiguration(String schemaName, String tableName, String columnName,
boolean isFromView) {
if (isExternalLobColumn(schemaName, tableName, columnName, isFromView)) {
if (!isFromView) {
return schemaConfigurations.get(schemaName).getTableConfiguration(tableName).getColumnConfiguration(columnName)
.getExternalLob();
} else {
String viewNameWithoutPrefix = tableName.replace(VIEW_NAME_PREFIX, "");
return schemaConfigurations.get(schemaName).getViewConfiguration(viewNameWithoutPrefix)
.getColumnConfiguration(columnName).getExternalLob();
}
}
return null;
}
@JsonProperty("import")
public ImportModuleConfiguration getImportModuleConfiguration() {
return importModuleConfiguration;
}
@JsonProperty("setupStatements")
public List<String> getSetupStatements() {
return setupStatements;
}
public void setSetupStatements(List<String> setupStatements) {
this.setupStatements = setupStatements;
}
public void setImportModuleConfiguration(ImportModuleConfiguration importModuleConfiguration) {
this.importModuleConfiguration = importModuleConfiguration;
}
@JsonProperty("schemas")
public Map<String, SchemaConfiguration> getSchemaConfigurations() {
return schemaConfigurations;
}
public void setSchemaConfigurations(Map<String, SchemaConfiguration> schemaConfigurations) {
this.schemaConfigurations = schemaConfigurations;
}
@JsonProperty("ignore")
public Map<DatabaseTechnicalFeatures, Boolean> getIgnore() {
return ignore;
}
public void setIgnore(Map<DatabaseTechnicalFeatures, Boolean> ignore) {
this.ignore = ignore;
}
public boolean isFetchRows() {
return fetchRows;
}
public void setFetchRows(boolean fetchRows) {
this.fetchRows = fetchRows;
}
}