Project

General

Profile

« Previous | Next » 

Revision 6d832edc

Added by Andreas Müller almost 6 years ago

ref #7384 Order SpecimenTypeDesignationStatus according to new order in vocabulary

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v47_49/SchemaUpdater_47_49.java
211 211
        step = ColumnTypeChanger.NewInt2StringInstance(stepName, tableName, columnName, size, INCLUDE_AUDIT, null, !NOT_NULL);
212 212
        stepList.add(step);
213 213

  
214
        updateSpecimenTypeDesignationStatusOrder(stepList);
214 215

  
215 216
        //7276  Make User.emailAddress a unique field
216 217
        //TODO H2 / PostGreSQL / SQL Server
......
224 225
        return stepList;
225 226
    }
226 227

  
228
    /**
229
     * @param stepList
230
     */
231
    private void updateSpecimenTypeDesignationStatusOrder(List<ISchemaUpdaterStep> stepList) {
232
        VocabularyOrderUpdater updater = VocabularyOrderUpdater.NewInstance(stepList);
233
        updater.add("a407dbc7-e60c-46ff-be11-eddf4c5a970d", 1);
234
        updater.add("05002d46-083e-4b27-8731-2e7c28a8825c", 2);
235
        updater.add("93ef8257-0a08-47bb-9b36-542417ae7560", 3);
236
        updater.add("7a1a8a53-78f4-4fc0-89f7-782e94992d08", 4);
237
        updater.add("f3b60bdb-4638-4ca9-a0c7-36e77d8459bb", 5);
238
        updater.add("052a5ff0-8e9a-4355-b24f-5e4bb6071f44", 6);
239
        updater.add("26e13359-8f77-4e40-a85a-56c01782fce0", 7);
240
        updater.add("7afc2f4f-f70a-4aa5-80a5-87764f746bde", 8);
241
        updater.add("989a2715-71d5-4fbe-aa9a-db9168353744", 9);
242
        updater.add("95b90696-e103-4bc0-b60b-c594983fb566", 10);
243
        updater.add("eb7df2e5-d9a7-479d-970c-c6f2b0a761d7", 11);
244
        updater.add("497137f3-b614-4183-8a22-97fcd6e2bdd8", 12);
245
        updater.add("7244bc51-14d8-41a6-9524-7dc5303bba29", 13);
246
        updater.add("0c39e2a5-2fe0-4d4f-819a-f609b5340339", 14);
247
        updater.add("01d91053-7004-4984-aa0d-9f4de59d6205", 15);
248
        updater.add("8d2fed1f-242e-4bcf-bbd7-e85133e479dc", 16);
249
        updater.add("49c96cae-6be6-401e-9b36-1bc12d9dc8f9", 17);
250
        updater.add("643513d0-32f5-46ba-840b-d9b9caf8160f", 18);
251
        updater.add("b7807acc-f559-474e-ad4a-e7a41e085e34", 19);
252
        updater.add("230fd762-b143-49de-ac2e-744bcc48a63b", 20);
253
        updater.add("7194020b-a326-4b47-9bfe-9f31a30aba7f", 21);
254
    }
255

  
227 256
    /**
228 257
     * @param #6368
229 258
     */
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v47_49/VocabularyOrderUpdater.java
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_49;
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 13.10.2016
30
 */
31
public class VocabularyOrderUpdater extends SchemaUpdaterStepBase {
32
    private static final Logger logger = Logger.getLogger(VocabularyOrderUpdater.class);
33

  
34
	private static final String stepName = "Update vocabulary order";
35

  
36
	private List<String[]> data = new ArrayList<>();
37

  
38
// **************************** STATIC METHODS ********************************/
39

  
40
	public static final VocabularyOrderUpdater NewInstance(List<ISchemaUpdaterStep> stepList){
41
		VocabularyOrderUpdater result = new VocabularyOrderUpdater();
42
		stepList.add(result);
43
		return result;
44
	}
45

  
46
	private VocabularyOrderUpdater() {
47
		super(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
}

Also available in: Unified diff