Project

General

Profile

Download (13.6 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2007 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

    
10
package eu.etaxonomy.cdm.database.update.v512_515;
11

    
12
import java.util.ArrayList;
13
import java.util.List;
14

    
15
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
16

    
17
import eu.etaxonomy.cdm.database.update.ColumnAdder;
18
import eu.etaxonomy.cdm.database.update.ISchemaUpdater;
19
import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep;
20
import eu.etaxonomy.cdm.database.update.SchemaUpdaterBase;
21
import eu.etaxonomy.cdm.database.update.TableCreator;
22
import eu.etaxonomy.cdm.model.metadata.CdmMetaData.CdmVersion;
23

    
24
/**
25
 * @author a.mueller
26
 * @date 10.06.2020
27
 */
28
public class SchemaUpdater_5151_5152 extends SchemaUpdaterBase {
29

    
30
	@SuppressWarnings("unused")
31
	private static final Logger logger = LogManager.getLogger(SchemaUpdater_5151_5152.class);
32

    
33
	private static final CdmVersion startSchemaVersion = CdmVersion.V_05_15_01;
34
	private static final CdmVersion endSchemaVersion = CdmVersion.V_05_15_02;
35

    
36
// ********************** FACTORY METHOD *************************************
37

    
38
	public static SchemaUpdater_5151_5152 NewInstance() {
39
		return new SchemaUpdater_5151_5152();
40
	}
41

    
42
	protected SchemaUpdater_5151_5152() {
43
		super(startSchemaVersion.versionString(), endSchemaVersion.versionString());
44
	}
45

    
46
	@Override
47
	protected List<ISchemaUpdaterStep> getUpdaterList() {
48
//
49
		String stepName;
50
		String tableName;
51
		String newColumnName;
52
		String referencedTable;
53

    
54
		List<ISchemaUpdaterStep> stepList = new ArrayList<>();
55

    
56
		addExternalLinkTables(stepList);
57

    
58
		//#9067
59
		stepName = "Add link to Media";
60
		tableName = "Media";
61
		newColumnName = "link_id";
62
		referencedTable = "ExternalLink";
63
		ColumnAdder.NewIntegerInstance(stepList, stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
64

    
65
        //9004
66
        stepName = "Add source to TaxonNode";
67
        tableName = "TaxonNode";
68
        newColumnName = "source_id";
69
        referencedTable = "OriginalSourceBase";
70
        ColumnAdder.NewIntegerInstance(stepList, stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
71

    
72
        stepName = "Move taxon node citation 2 original source";
73
        Reference2SourceMover.NewInstance(stepList, stepName, tableName, "referenceForParentChildRelation_id", "microReferenceForParentChildRelation", "source_id");
74

    
75
        //6581
76
        stepName = "Add source to Classification";
77
        tableName = "Classification";
78
        newColumnName = "source_id";
79
        referencedTable = "OriginalSourceBase";
80
        ColumnAdder.NewIntegerInstance(stepList, stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
81

    
82
        //6581
83
        stepName = "Add source to NomenclaturalStatus";
84
        tableName = "NomenclaturalStatus";
85
        newColumnName = "source_id";
86
        referencedTable = "OriginalSourceBase";
87
        ColumnAdder.NewIntegerInstance(stepList, stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
88

    
89
        //6581
90
        stepName = "Add source to TypeDesignationBase";
91
        tableName = "TypeDesignationBase";
92
        newColumnName = "source_id";
93
        referencedTable = "OriginalSourceBase";
94
        ColumnAdder.NewIntegerInstance(stepList, stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
95

    
96
        //6581
97
        stepName = "Add source to TaxonRelationship";
98
        tableName = "TaxonRelationship";
99
        newColumnName = "source_id";
100
        referencedTable = "OriginalSourceBase";
101
        ColumnAdder.NewIntegerInstance(stepList, stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
102

    
103
        //6581
104
        stepName = "Add source to NameRelationship";
105
        tableName = "NameRelationship";
106
        newColumnName = "source_id";
107
        referencedTable = "OriginalSourceBase";
108
        ColumnAdder.NewIntegerInstance(stepList, stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
109

    
110
        //6581
111
        stepName = "Add source to HybridRelationship";
112
        tableName = "HybridRelationship";
113
        newColumnName = "source_id";
114
        referencedTable = "OriginalSourceBase";
115
        ColumnAdder.NewIntegerInstance(stepList, stepName, tableName, newColumnName, INCLUDE_AUDIT, !NOT_NULL, referencedTable);
116

    
117
        return stepList;
118
    }
119

    
120
    private void addExternalLinkTables(List<ISchemaUpdaterStep> stepList) {
121

    
122
        //Table itself exists already
123
//        String stepName = "Create Identifier table";
124
//        boolean includeCdmBaseAttributes = true;
125
//        String tableName = "ExternalLink";
126
//        String[] columnNames = new String[]{"identifier","identifiedObj_type", "identifiedObj_id","type_id"};
127
//        String[] columnTypes = new String[]{"string_800","string_255","int","int"};
128
//        String[] referencedTables = new String[]{null,null,null,"DefinedTermBase"};
129
//        TableCreator.NewInstance(stepList, stepName, tableName, columnNames, columnTypes, referencedTables, INCLUDE_AUDIT, includeCdmBaseAttributes);
130

    
131
        //AgentBase_ExternalLink
132
        String stepName = "Create AgentBase_ExternalLink table";
133
        boolean includeCdmBaseAttributes = false;
134
        String tableName = "AgentBase_ExternalLink";
135
        String[] columnNames = new String[]{"AgentBase_id","links_id","sortIndex"};
136
        String[] columnTypes = new String[]{"int","int","int"};
137
        String[] referencedTables = new String[]{"AgentBase","ExternalLink",null};
138
        TableCreator step = TableCreator.NewInstance(stepList, stepName, tableName, columnNames, columnTypes, referencedTables, INCLUDE_AUDIT, includeCdmBaseAttributes);
139
        step.setPrimaryKeyParams("AgentBase_id,links_id", "REV,AgentBase_id,links_id");
140

    
141
        //Classification_ExternalLink
142
        stepName = "Create Classification_ExternalLink table";
143
        includeCdmBaseAttributes = false;
144
        tableName = "Classification_ExternalLink";
145
        columnNames = new String[]{"Classification_id","links_id","sortIndex"};
146
        columnTypes = new String[]{"int","int","int"};
147
        referencedTables = new String[]{"Classification","ExternalLink",null};
148
        step = TableCreator.NewInstance(stepList, stepName, tableName, columnNames, columnTypes, referencedTables, INCLUDE_AUDIT, includeCdmBaseAttributes);
149
        step.setPrimaryKeyParams("Classification_id,links_id", "REV,Classification_id,links_id");
150

    
151
        //Collection_ExternalLink
152
        stepName = "Create Collection_ExternalLink table";
153
        includeCdmBaseAttributes = false;
154
        tableName = "Collection_ExternalLink";
155
        columnNames = new String[]{"Collection_id","links_id","sortIndex"};
156
        columnTypes = new String[]{"int","int","int"};
157
        referencedTables = new String[]{"Collection","ExternalLink",null};
158
        step = TableCreator.NewInstance(stepList, stepName, tableName, columnNames, columnTypes, referencedTables, INCLUDE_AUDIT, includeCdmBaseAttributes);
159
        step.setPrimaryKeyParams("Collection_id,links_id", "REV,Collection_id,links_id");
160

    
161
        //DefinedTermBase_ExternalLink
162
        stepName = "Create DefinedTermBase_ExternalLink table";
163
        includeCdmBaseAttributes = false;
164
        tableName = "DefinedTermBase_ExternalLink";
165
        columnNames = new String[]{"DefinedTermBase_id","links_id","sortIndex"};
166
        columnTypes = new String[]{"int","int","int"};
167
        referencedTables = new String[]{"DefinedTermBase","ExternalLink",null};
168
        step = TableCreator.NewInstance(stepList, stepName, tableName, columnNames, columnTypes, referencedTables, INCLUDE_AUDIT, includeCdmBaseAttributes);
169
        step.setPrimaryKeyParams("DefinedTermBase_id,links_id", "REV,DefinedTermBase_id,links_id");
170

    
171
        //DescriptionBase_ExternalLink
172
        stepName = "Create DescriptionBase_ExternalLink table";
173
        includeCdmBaseAttributes = false;
174
        tableName = "DescriptionBase_ExternalLink";
175
        columnNames = new String[]{"DescriptionBase_id","links_id","sortIndex"};
176
        columnTypes = new String[]{"int","int","int"};
177
        referencedTables = new String[]{"DescriptionBase","ExternalLink",null};
178
        step = TableCreator.NewInstance(stepList, stepName, tableName, columnNames, columnTypes, referencedTables, INCLUDE_AUDIT, includeCdmBaseAttributes);
179
        step.setPrimaryKeyParams("DescriptionBase_id,links_id", "REV,DescriptionBase_id,links_id");
180

    
181
        //DescriptiveDataSet_ExternalLink
182
        stepName = "Create DescriptiveDataSet_ExternalLink table";
183
        includeCdmBaseAttributes = false;
184
        tableName = "DescriptiveDataSet_ExternalLink";
185
        columnNames = new String[]{"DescriptiveDataSet_id","links_id","sortIndex"};
186
        columnTypes = new String[]{"int","int","int"};
187
        referencedTables = new String[]{"DescriptiveDataSet","ExternalLink",null};
188
        step = TableCreator.NewInstance(stepList, stepName, tableName, columnNames, columnTypes, referencedTables, INCLUDE_AUDIT, includeCdmBaseAttributes);
189
        step.setPrimaryKeyParams("DescriptiveDataSet_id,links_id", "REV,DescriptiveDataSet_id,links_id");
190

    
191
        //Media_ExternalLink
192
        stepName = "Create Media_ExternalLink table";
193
        includeCdmBaseAttributes = false;
194
        tableName = "Media_ExternalLink";
195
        columnNames = new String[]{"Media_id","links_id","sortIndex"};
196
        columnTypes = new String[]{"int","int","int"};
197
        referencedTables = new String[]{"Media","ExternalLink",null};
198
        step = TableCreator.NewInstance(stepList, stepName, tableName, columnNames, columnTypes, referencedTables, INCLUDE_AUDIT, includeCdmBaseAttributes);
199
        step.setPrimaryKeyParams("Media_id,links_id", "REV,Media_id,links_id");
200

    
201
        //PolytomousKey_ExternalLink
202
        stepName = "Create PolytomousKey_ExternalLink table";
203
        includeCdmBaseAttributes = false;
204
        tableName = "PolytomousKey_ExternalLink";
205
        columnNames = new String[]{"PolytomousKey_id","links_id","sortIndex"};
206
        columnTypes = new String[]{"int","int","int"};
207
        referencedTables = new String[]{"PolytomousKey","ExternalLink",null};
208
        step = TableCreator.NewInstance(stepList, stepName, tableName, columnNames, columnTypes, referencedTables, INCLUDE_AUDIT, includeCdmBaseAttributes);
209
        step.setPrimaryKeyParams("PolytomousKey_id,links_id", "REV,PolytomousKey_id,links_id");
210

    
211
        //Reference_ExternalLink
212
        stepName = "Create Reference_ExternalLink table";
213
        includeCdmBaseAttributes = false;
214
        tableName = "Reference_ExternalLink";
215
        columnNames = new String[]{"Reference_id","links_id","sortIndex"};
216
        columnTypes = new String[]{"int","int","int"};
217
        referencedTables = new String[]{"Reference","ExternalLink",null};
218
        step = TableCreator.NewInstance(stepList, stepName, tableName, columnNames, columnTypes, referencedTables, INCLUDE_AUDIT, includeCdmBaseAttributes);
219
        step.setPrimaryKeyParams("Reference_id,links_id", "REV,Reference_id,links_id");
220

    
221
        //SpecimenOrObservationBase_ExternalLink
222
        stepName = "Create SpecimenOrObservationBase_ExternalLink table";
223
        includeCdmBaseAttributes = false;
224
        tableName = "SpecimenOrObservationBase_ExternalLink";
225
        columnNames = new String[]{"SpecimenOrObservationBase_id","links_id","sortIndex"};
226
        columnTypes = new String[]{"int","int","int"};
227
        referencedTables = new String[]{"SpecimenOrObservationBase","ExternalLink",null};
228
        step = TableCreator.NewInstance(stepList, stepName, tableName, columnNames, columnTypes, referencedTables, INCLUDE_AUDIT, includeCdmBaseAttributes);
229
        step.setPrimaryKeyParams("SpecimenOrObservationBase_id,links_id", "REV,SpecimenOrObservationBase_id,links_id");
230

    
231
        //TaxonBase_ExternalLink
232
        stepName = "Create TaxonBase_ExternalLink table";
233
        includeCdmBaseAttributes = false;
234
        tableName = "TaxonBase_ExternalLink";
235
        columnNames = new String[]{"TaxonBase_id","links_id","sortIndex"};
236
        columnTypes = new String[]{"int","int","int"};
237
        referencedTables = new String[]{"TaxonBase","ExternalLink",null};
238
        step = TableCreator.NewInstance(stepList, stepName, tableName, columnNames, columnTypes, referencedTables, INCLUDE_AUDIT, includeCdmBaseAttributes);
239
        step.setPrimaryKeyParams("TaxonBase_id,links_id", "REV,TaxonBase_id,links_id");
240

    
241
        //TaxonName_ExternalLink
242
        stepName = "Create TaxonName_ExternalLink table";
243
        includeCdmBaseAttributes = false;
244
        tableName = "TaxonName_ExternalLink";
245
        columnNames = new String[]{"TaxonName_id","links_id","sortIndex"};
246
        columnTypes = new String[]{"int","int","int"};
247
        referencedTables = new String[]{"TaxonName","ExternalLink",null};
248
        step = TableCreator.NewInstance(stepList, stepName, tableName, columnNames, columnTypes, referencedTables, INCLUDE_AUDIT, includeCdmBaseAttributes);
249
        step.setPrimaryKeyParams("TaxonName_id,links_id", "REV,TaxonName_id,links_id");
250

    
251
        //TermCollection_ExternalLink
252
        stepName = "Create TermCollection_ExternalLink table";
253
        includeCdmBaseAttributes = false;
254
        tableName = "TermCollection_ExternalLink";
255
        columnNames = new String[]{"TermCollection_id","links_id","sortIndex"};
256
        columnTypes = new String[]{"int","int","int"};
257
        referencedTables = new String[]{"TermCollection","ExternalLink",null};
258
        step = TableCreator.NewInstance(stepList, stepName, tableName, columnNames, columnTypes, referencedTables, INCLUDE_AUDIT, includeCdmBaseAttributes);
259
        step.setPrimaryKeyParams("TermCollection_id,links_id", "REV,TermCollection_id,links_id");
260
    }
261

    
262
    @Override
263
    public ISchemaUpdater getPreviousUpdater() {
264
        return SchemaUpdater_5150_5151.NewInstance();
265
    }
266
}
(4-4/4)