1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2009 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.database.update.v30_31;
|
11
|
|
12
|
import java.sql.SQLException;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
|
16
|
import eu.etaxonomy.cdm.common.IProgressMonitor;
|
17
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
18
|
import eu.etaxonomy.cdm.database.update.ITermUpdaterStep;
|
19
|
import eu.etaxonomy.cdm.database.update.SchemaUpdaterStepBase;
|
20
|
|
21
|
/**
|
22
|
* @author a.mueller
|
23
|
* @date 15.12.2010
|
24
|
*/
|
25
|
public class LanguageLabelUpdater extends SchemaUpdaterStepBase implements ITermUpdaterStep{
|
26
|
@SuppressWarnings("unused")
|
27
|
private static final Logger logger = Logger.getLogger(LanguageLabelUpdater.class);
|
28
|
|
29
|
private static final String stepName = "Update language labels by full language name";
|
30
|
|
31
|
// **************************** STATIC METHODS ********************************/
|
32
|
|
33
|
public static final LanguageLabelUpdater NewInstance(){
|
34
|
return new LanguageLabelUpdater(stepName);
|
35
|
}
|
36
|
|
37
|
protected LanguageLabelUpdater(String stepName) {
|
38
|
super(stepName);
|
39
|
}
|
40
|
|
41
|
@Override
|
42
|
public Integer invoke(ICdmDataSource datasource, IProgressMonitor monitor) throws SQLException {
|
43
|
|
44
|
//update representation label
|
45
|
String sql;
|
46
|
sql = " UPDATE Representation " +
|
47
|
" SET label = text " +
|
48
|
" WHERE id IN ( SELECT MN.representations_id " +
|
49
|
" FROM DefinedTermBase lang " +
|
50
|
" INNER JOIN DefinedTermBase_Representation MN ON lang.id = MN.DefinedTermBase_id " +
|
51
|
" WHERE lang.DTYPE = 'Language' " +
|
52
|
" )";
|
53
|
datasource.executeUpdate(sql);
|
54
|
|
55
|
//update term titleCache
|
56
|
sql = " UPDATE DefinedTermBase dtb " +
|
57
|
" SET titleCache = " +
|
58
|
" ( " +
|
59
|
" SELECT rep.label " +
|
60
|
" FROM DefinedTermBase_Representation MN " +
|
61
|
" INNER JOIN Representation rep ON MN.representations_id = rep.id " +
|
62
|
" WHERE dtb.id = MN.DefinedTermBase_id AND rep.language_id = @langId) " +
|
63
|
" WHERE dtb.DTYPE = 'Language'";
|
64
|
String englishId = String.valueOf(getEnglishLanguageId(datasource, monitor));
|
65
|
if (englishId == null){
|
66
|
throw new NullPointerException("English id could not be found");
|
67
|
}
|
68
|
sql = sql.replace("@langId", englishId);
|
69
|
datasource.executeUpdate(sql);
|
70
|
|
71
|
return 0;
|
72
|
}
|
73
|
|
74
|
|
75
|
}
|