Project

General

Profile

Download (2.62 KB) Statistics
| Branch: | Tag: | Revision:
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.v47_50;
10

    
11
import java.sql.SQLException;
12
import java.util.ArrayList;
13
import java.util.List;
14

    
15
import org.apache.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 = Logger.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();
43
		stepList.add(result);
44
		return result;
45
	}
46

    
47
	private VocabularyOrderUpdater() {
48
		super(stepName);
49
	}
50

    
51
	public void add(String uuid, Integer id){
52
	    data.add(new String[]{uuid, String.valueOf(id)});
53
	}
54

    
55
    @Override
56
    public void invoke(ICdmDataSource datasource, IProgressMonitor monitor,
57
            CaseType caseType, SchemaUpdateResult result) throws SQLException {
58

    
59
        try{
60
            for (String[] dat : data){
61
                invokeSingle(datasource, monitor, caseType, result, dat);
62
            }
63

    
64
        } catch (Exception e) {
65
            String message = e.getMessage();
66
            monitor.warning(message, e);
67
            result.addException(e, message, this, "invoke");
68
        }
69

    
70
	    return;
71
	}
72

    
73
    /**
74
     * @param datasource
75
     * @param monitor
76
     * @param caseType
77
     * @param result
78
     * @param dat
79
     * @throws SQLException
80
     */
81
    private void invokeSingle(ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType,
82
            SchemaUpdateResult result, String[] dat) throws SQLException {
83
        String query = "UPDATE DefinedTermBase "
84
                + " SET orderIndex = " + dat[1] + " "
85
                + " WHERE uuid = '" + dat[0] + "'";
86
        datasource.executeUpdate(query);
87

    
88
    }
89

    
90
}
(2-2/2)