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.v40_50;
|
10
|
|
11
|
import java.sql.SQLException;
|
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.common.monitor.IProgressMonitor;
|
18
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
19
|
import eu.etaxonomy.cdm.database.update.CaseType;
|
20
|
import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep;
|
21
|
import eu.etaxonomy.cdm.database.update.SchemaUpdateResult;
|
22
|
import eu.etaxonomy.cdm.database.update.SchemaUpdaterStepBase;
|
23
|
|
24
|
|
25
|
/**
|
26
|
* Updates the CdmPreference NomenclaturalCode #3658
|
27
|
*
|
28
|
* @author a.mueller
|
29
|
* @since 05.05.2018
|
30
|
*/
|
31
|
public class VocabularyOrderUpdater extends SchemaUpdaterStepBase {
|
32
|
@SuppressWarnings("unused")
|
33
|
private static final Logger logger = LogManager.getLogger(VocabularyOrderUpdater.class);
|
34
|
|
35
|
private static final String stepName = "Update vocabulary order";
|
36
|
|
37
|
private List<String[]> data = new ArrayList<>();
|
38
|
|
39
|
// **************************** STATIC METHODS ********************************/
|
40
|
|
41
|
public static final VocabularyOrderUpdater NewInstance(List<ISchemaUpdaterStep> stepList){
|
42
|
VocabularyOrderUpdater result = new VocabularyOrderUpdater(stepList);
|
43
|
return result;
|
44
|
}
|
45
|
|
46
|
private VocabularyOrderUpdater(List<ISchemaUpdaterStep> stepList) {
|
47
|
super(stepList, stepName);
|
48
|
}
|
49
|
|
50
|
public void add(String uuid, Integer id){
|
51
|
data.add(new String[]{uuid, String.valueOf(id)});
|
52
|
}
|
53
|
|
54
|
@Override
|
55
|
public void invoke(ICdmDataSource datasource, IProgressMonitor monitor,
|
56
|
CaseType caseType, SchemaUpdateResult result) throws SQLException {
|
57
|
|
58
|
try{
|
59
|
for (String[] dat : data){
|
60
|
invokeSingle(datasource, monitor, caseType, result, dat);
|
61
|
}
|
62
|
|
63
|
} catch (Exception e) {
|
64
|
String message = e.getMessage();
|
65
|
monitor.warning(message, e);
|
66
|
result.addException(e, message, this, "invoke");
|
67
|
}
|
68
|
|
69
|
return;
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* @param datasource
|
74
|
* @param monitor
|
75
|
* @param caseType
|
76
|
* @param result
|
77
|
* @param dat
|
78
|
* @throws SQLException
|
79
|
*/
|
80
|
private void invokeSingle(ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType,
|
81
|
SchemaUpdateResult result, String[] dat) throws SQLException {
|
82
|
String query = "UPDATE DefinedTermBase "
|
83
|
+ " SET orderIndex = " + dat[1] + " "
|
84
|
+ " WHERE uuid = '" + dat[0] + "'";
|
85
|
datasource.executeUpdate(query);
|
86
|
|
87
|
}
|
88
|
|
89
|
}
|