3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.database
.update
.v30_31
;
12 import java
.sql
.SQLException
;
14 import org
.apache
.log4j
.Logger
;
16 import eu
.etaxonomy
.cdm
.common
.monitor
.IProgressMonitor
;
17 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
18 import eu
.etaxonomy
.cdm
.database
.update
.ITermUpdaterStep
;
19 import eu
.etaxonomy
.cdm
.database
.update
.SchemaUpdaterStepBase
;
25 public class LanguageLabelUpdater
extends SchemaUpdaterStepBase
<LanguageLabelUpdater
> implements ITermUpdaterStep
{
26 @SuppressWarnings("unused")
27 private static final Logger logger
= Logger
.getLogger(LanguageLabelUpdater
.class);
29 private static final String stepName
= "Update language labels by full language name";
31 // **************************** STATIC METHODS ********************************/
33 public static final LanguageLabelUpdater
NewInstance(){
34 return new LanguageLabelUpdater(stepName
);
37 protected LanguageLabelUpdater(String stepName
) {
42 public Integer
invoke(ICdmDataSource datasource
, IProgressMonitor monitor
) {
45 //update representation label
47 sql
= " UPDATE Representation " +
48 " SET label = text " +
49 " WHERE id IN ( SELECT MN.representations_id " +
50 " FROM DefinedTermBase lang " +
51 " INNER JOIN DefinedTermBase_Representation MN ON lang.id = MN.DefinedTermBase_id " +
52 " WHERE lang.DTYPE = 'Language' " +
54 datasource
.executeUpdate(sql
);
56 //update term titleCache
57 sql
= " UPDATE DefinedTermBase dtb " +
58 " SET titleCache = " +
60 " SELECT rep.label " +
61 " FROM DefinedTermBase_Representation MN " +
62 " INNER JOIN Representation rep ON MN.representations_id = rep.id " +
63 " WHERE dtb.id = MN.DefinedTermBase_id AND rep.language_id = @langId) " +
64 " WHERE dtb.DTYPE = 'Language'";
65 String englishId
= String
.valueOf(getEnglishLanguageId(datasource
, monitor
));
66 if (englishId
== null){
67 throw new NullPointerException("English id could not be found");
69 sql
= sql
.replace("@langId", englishId
);
70 datasource
.executeUpdate(sql
);
73 } catch (Exception e
) {
74 monitor
.warning(e
.getMessage(), e
);
75 logger
.warn(e
.getMessage());