1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.database.update;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.List;
|
13
|
|
14
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
15
|
|
16
|
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
|
17
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
18
|
|
19
|
/**
|
20
|
* Updates the base type of a class.
|
21
|
* E.g. if a class is VersionableEntity it may be upgraded to AnnotatableEntity
|
22
|
* @since 2015-03-20
|
23
|
* @author a.mueller
|
24
|
*/
|
25
|
public class ClassBaseTypeUpdater extends AuditedSchemaUpdaterStepBase {
|
26
|
|
27
|
@SuppressWarnings("unused")
|
28
|
private static final Logger logger = LogManager.getLogger(TableCreator.class);
|
29
|
|
30
|
private final boolean includeIdentifiableEntity;
|
31
|
private final boolean includeAnnotatableEntity;
|
32
|
protected List<ISchemaUpdaterStep> mnTablesStepList = new ArrayList<>();
|
33
|
protected List<ISchemaUpdaterStep> columnAdderStepList = new ArrayList<>();
|
34
|
|
35
|
|
36
|
public static final ClassBaseTypeUpdater NewVersionableToAnnotatableInstance(List<ISchemaUpdaterStep> stepList, String stepName, String tableName, boolean includeAudTable){
|
37
|
return new ClassBaseTypeUpdater(stepList, stepName, tableName, includeAudTable, true, false);
|
38
|
}
|
39
|
public static final ClassBaseTypeUpdater NewAnnotatableToIdentifiableInstance(List<ISchemaUpdaterStep> stepList, String stepName, String tableName, boolean includeAudTable){
|
40
|
return new ClassBaseTypeUpdater(stepList, stepName, tableName, includeAudTable, false, true);
|
41
|
}
|
42
|
public static final ClassBaseTypeUpdater NewVersionableToIdentifiableInstance(List<ISchemaUpdaterStep> stepList, String stepName, String tableName, boolean includeAudTable){
|
43
|
return new ClassBaseTypeUpdater(stepList, stepName, tableName, includeAudTable, true, true);
|
44
|
}
|
45
|
|
46
|
protected ClassBaseTypeUpdater(List<ISchemaUpdaterStep> stepList, String stepName, String tableName, boolean includeAudit, boolean includeAnnotatable, boolean includeIdentifiable) {
|
47
|
super(stepList, stepName, tableName, includeAudit);
|
48
|
this.includeAnnotatableEntity = includeAnnotatable;
|
49
|
this.includeIdentifiableEntity = includeIdentifiable;
|
50
|
TableCreator.makeMnTables(mnTablesStepList, tableName, includeAnnotatable, includeIdentifiable);
|
51
|
makeColumns();
|
52
|
}
|
53
|
|
54
|
|
55
|
private void makeColumns() {
|
56
|
String innerStepName;
|
57
|
String newColumnName;
|
58
|
if (this.includeIdentifiableEntity){
|
59
|
|
60
|
//lsid authority
|
61
|
innerStepName = "-add lsid_authority";
|
62
|
newColumnName = "lsid_authority";
|
63
|
ColumnAdder.NewStringInstance(columnAdderStepList, stepName + innerStepName, tableName,
|
64
|
newColumnName, SchemaUpdaterBase.INCLUDE_AUDIT);
|
65
|
|
66
|
//lsid lsid
|
67
|
innerStepName = "-add lsid_lsid";
|
68
|
newColumnName = "lsid_lsid";
|
69
|
ColumnAdder.NewStringInstance(columnAdderStepList, stepName + innerStepName, tableName,
|
70
|
newColumnName, SchemaUpdaterBase.INCLUDE_AUDIT);
|
71
|
|
72
|
//lsid namespace
|
73
|
innerStepName = "-add lsid_namespace";
|
74
|
newColumnName = "lsid_namespace";
|
75
|
ColumnAdder.NewStringInstance(columnAdderStepList, stepName + innerStepName, tableName,
|
76
|
newColumnName, SchemaUpdaterBase.INCLUDE_AUDIT);
|
77
|
|
78
|
//lsid object
|
79
|
innerStepName = "-add lsid_object";
|
80
|
newColumnName = "lsid_object";
|
81
|
ColumnAdder.NewStringInstance(columnAdderStepList, stepName + innerStepName, tableName,
|
82
|
newColumnName, SchemaUpdaterBase.INCLUDE_AUDIT);
|
83
|
|
84
|
//lsid revision
|
85
|
innerStepName = "-add lsid_revision";
|
86
|
newColumnName = "lsid_revision";
|
87
|
ColumnAdder.NewStringInstance(columnAdderStepList, stepName + innerStepName, tableName,
|
88
|
newColumnName, SchemaUpdaterBase.INCLUDE_AUDIT);
|
89
|
|
90
|
//protected title cache
|
91
|
innerStepName = "-add protected title cache";
|
92
|
newColumnName = "protectedTitleCache";
|
93
|
ColumnAdder.NewBooleanInstance(columnAdderStepList, innerStepName, tableName, newColumnName,
|
94
|
SchemaUpdaterBase.INCLUDE_AUDIT, false);
|
95
|
|
96
|
//title cache
|
97
|
innerStepName = "-add titleCache";
|
98
|
newColumnName = "titleCache";
|
99
|
ColumnAdder.NewStringInstance(columnAdderStepList, stepName + innerStepName, tableName,
|
100
|
newColumnName, SchemaUpdaterBase.INCLUDE_AUDIT);
|
101
|
}
|
102
|
}
|
103
|
|
104
|
@Override
|
105
|
protected void invokeOnTable(String tableName, ICdmDataSource datasource,
|
106
|
IProgressMonitor monitor, CaseType caseType, SchemaUpdateResult result) {
|
107
|
//we only do have inner steps here
|
108
|
return;
|
109
|
}
|
110
|
|
111
|
|
112
|
@Override
|
113
|
public List<ISchemaUpdaterStep> getInnerSteps() {
|
114
|
List<ISchemaUpdaterStep> result = new ArrayList<>( mnTablesStepList);
|
115
|
result.addAll(columnAdderStepList);
|
116
|
return result;
|
117
|
}
|
118
|
|
119
|
}
|