2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.database
.update
.v529_532
;
11 import java
.util
.ArrayList
;
12 import java
.util
.List
;
13 import java
.util
.UUID
;
15 import org
.apache
.logging
.log4j
.LogManager
;
16 import org
.apache
.logging
.log4j
.Logger
;
18 import eu
.etaxonomy
.cdm
.database
.update
.ColumnAdder
;
19 import eu
.etaxonomy
.cdm
.database
.update
.ISchemaUpdater
;
20 import eu
.etaxonomy
.cdm
.database
.update
.ISchemaUpdaterStep
;
21 import eu
.etaxonomy
.cdm
.database
.update
.SchemaUpdaterBase
;
22 import eu
.etaxonomy
.cdm
.database
.update
.SimpleSchemaUpdaterStep
;
23 import eu
.etaxonomy
.cdm
.database
.update
.TermRepresentationUpdater
;
24 import eu
.etaxonomy
.cdm
.database
.update
.UniqueIndexDropper
;
25 import eu
.etaxonomy
.cdm
.database
.update
.v527_529
.SchemaUpdater_5271_5290
;
26 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
27 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
.CdmVersion
;
33 public class SchemaUpdater_5290_5320
extends SchemaUpdaterBase
{
35 @SuppressWarnings("unused")
36 private static final Logger logger
= LogManager
.getLogger(SchemaUpdater_5290_5320
.class);
38 private static final CdmVersion startSchemaVersion
= CdmVersion
.V_05_29_00
;
39 private static final CdmVersion endSchemaVersion
= CdmVersion
.V_05_32_00
;
41 // ********************** FACTORY METHOD *************************************
43 public static SchemaUpdater_5290_5320
NewInstance() {
44 return new SchemaUpdater_5290_5320();
47 protected SchemaUpdater_5290_5320() {
48 super(startSchemaVersion
.versionString(), endSchemaVersion
.versionString());
52 public ISchemaUpdater
getPreviousUpdater() {
53 return SchemaUpdater_5271_5290
.NewInstance();
57 protected List
<ISchemaUpdaterStep
> getUpdaterList() {
62 List
<ISchemaUpdaterStep
> stepList
= new ArrayList
<>();
64 //#10083 Update inverse representation of 'is blocking name for'
65 stepName
= "Update inverse representation of 'is blocking name for'";
66 UUID uuidTerm
= UUID
.fromString("1dab357f-2e12-4511-97a4-e5153589e6a6");
67 String description
= "has blocking name";
68 String label
= "has blocking name";
70 UUID uuidEnglish
= Language
.uuidEnglish
;
71 TermRepresentationUpdater
.NewInverseInstance(stepList
, stepName
, uuidTerm
, description
, label
, abbrev
, uuidEnglish
);
73 //#10057 add accessed columns
74 stepName
= "Add accessed_start";
75 tableName
= "OriginalSourceBase";
76 String newColumnName
= "accessed_start";
78 ColumnAdder
.NewStringInstance(stepList
, stepName
, tableName
, newColumnName
, size
, INCLUDE_AUDIT
);
80 stepName
= "Add accessed_end";
81 newColumnName
= "accessed_end";
82 ColumnAdder
.NewStringInstance(stepList
, stepName
, tableName
, newColumnName
, size
, INCLUDE_AUDIT
);
84 stepName
= "Add accessed_freetext";
85 newColumnName
= "accessed_freetext";
86 ColumnAdder
.NewStringInstance(stepList
, stepName
, tableName
, newColumnName
, INCLUDE_AUDIT
);
88 //#9901 Remove unique key Media_RightsInfo.rights_id
89 stepName
= "Remove unique key Media_RightsInfo.rights_id";
90 tableName
= "Media_RightsInfo";
91 String indexColumn
= "rights_id";
92 UniqueIndexDropper
.NewInstance(stepList
, tableName
, indexColumn
, INCLUDE_AUDIT
);
94 //#9830 Add accent to México Distrito Federal
96 uuidTerm
= UUID
.fromString("565751f1-613e-4ddc-bfbb-4b54f2267971");
97 description
= "México Distrito Federal";
98 label
= "México Distrito Federal";
99 TermRepresentationUpdater
.NewInstanceWithTitleCache(stepList
, stepName
, uuidTerm
, description
, label
, abbrev
, uuidEnglish
);
101 //#9785 Add missing unit_ids
102 stepName
= "Add missing unit_ids";
103 String query
= "UPDATE DescriptionElementBase deb LEFT OUTER JOIN DefinedTermBase fe ON fe.id = deb.feature_id"
104 + "SET deb.unit_id = ("
105 + " SELECT MN2.recommendedMeasurementUnits_id"
106 + " FROM DefinedTermBase fe2 INNER JOIN DefinedTermBase_MeasurementUnit MN2 ON MN2.Feature_id = fe2.id"
107 + " WHERE fe.id = fe2.id AND (fe2.DTYPE = 'Feature' OR fe2.DTYPE = 'Character')"
109 + " HAVING COUNT(*) = 1"
111 + "WHERE deb.DTYPE = 'QuantitativeData' AND deb.unit_id IS NULL"
114 + " FROM DefinedTermBase fe INNER JOIN DefinedTermBase_MeasurementUnit MN ON MN.Feature_id = fe.id INNER JOIN DefinedTermBase mu ON MN.recommendedMeasurementUnits_id = mu.id"
115 + " WHERE fe.DTYPE = 'Feature' OR fe.DTYPE = 'Character'"
116 + " GROUP BY fe.id, mu.id"
117 + " HAVING COUNT(*) = 1"
119 SimpleSchemaUpdaterStep
.NewNonAuditedInstance(stepList
, stepName
, query
, size
)
120 .withErrorRecovery("SQL statement for adding missing measurement unit_ids failed");