3 * Copyright (C) 2007 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.
11 package eu
.etaxonomy
.cdm
.database
.update
.v31_33
;
13 import java
.util
.ArrayList
;
14 import java
.util
.List
;
16 import org
.apache
.log4j
.Logger
;
18 import eu
.etaxonomy
.cdm
.database
.update
.ColumnAdder
;
19 import eu
.etaxonomy
.cdm
.database
.update
.ColumnRemover
;
20 import eu
.etaxonomy
.cdm
.database
.update
.ISchemaUpdater
;
21 import eu
.etaxonomy
.cdm
.database
.update
.ISchemaUpdaterStep
;
22 import eu
.etaxonomy
.cdm
.database
.update
.SchemaUpdaterBase
;
23 import eu
.etaxonomy
.cdm
.database
.update
.SimpleSchemaUpdaterStep
;
24 import eu
.etaxonomy
.cdm
.database
.update
.TableDroper
;
25 import eu
.etaxonomy
.cdm
.database
.update
.v30_31
.SchemaUpdater_30_301
;
31 * @created Oct 11, 2011
33 public class SchemaUpdater_31_33
extends SchemaUpdaterBase
{
36 @SuppressWarnings("unused")
37 private static final Logger logger
= Logger
.getLogger(SchemaUpdater_31_33
.class);
38 private static final String startSchemaVersion
= "3.0.1.0.201104190000";
39 private static final String endSchemaVersion
= "3.3.0.0.201306010000";
41 // ********************** FACTORY METHOD *******************************************
43 public static SchemaUpdater_31_33
NewInstance(){
44 return new SchemaUpdater_31_33();
48 * @param startSchemaVersion
49 * @param endSchemaVersion
51 protected SchemaUpdater_31_33() {
52 super(startSchemaVersion
, endSchemaVersion
);
56 * @see eu.etaxonomy.cdm.database.update.SchemaUpdaterBase#getUpdaterList()
59 protected List
<ISchemaUpdaterStep
> getUpdaterList() {
61 List
<ISchemaUpdaterStep
> stepList
= new ArrayList
<ISchemaUpdaterStep
>();
63 //TODO Does it throw exception if table does not exist?
64 //Was in Schemaupdater_301_31 which was never used and later deleted (r18331).
65 //drop TypeDesignationBase_TaxonNameBase //from schemaUpdater 301_31
66 String stepName
= "Drop duplicate TypeDesignation-TaxonName table";
67 String tableName
= "TypeDesignationBase_TaxonNameBase";
68 ISchemaUpdaterStep step
= TableDroper
.NewInstance(stepName
, tableName
, INCLUDE_AUDIT
);
71 //create original source type column
72 stepName
= "Create original source type column";
73 tableName
= "OriginalSourceBase";
74 String columnName
= "type";
75 //TODO NOT NULL unclear
76 step
= ColumnAdder
.NewIntegerInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
, true, null);
79 //TODO ?? update original source type
80 updateOriginalSourceType(stepList
);
82 //create and update elevenation max, remove error column
83 updateElevationMax(stepList
);
85 //create taxon node tree index
86 stepName
= "Create taxon node tree index";
87 tableName
= "TaxonNode";
88 columnName
= "treeIndex";
89 //TODO NOT NULL unclear
90 step
= ColumnAdder
.NewStringInstance(stepName
, tableName
, columnName
, 255, INCLUDE_AUDIT
);
93 //TODO update tree index
95 //create original source type column
96 stepName
= "Create taxon node sort index column";
97 tableName
= "TaxonNode";
98 columnName
= "sortIndex";
99 step
= ColumnAdder
.NewIntegerInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
, false, null);
102 //TODO implement sorted behaviour in model first !!
103 //TODO update sortindex (similar updater exists already for FeatureNode#sortIndex in schema update 25_30
105 //create feature node tree index
106 stepName
= "Create feature node tree index";
107 tableName
= "FeatureNode";
108 columnName
= "treeIndex";
109 //TODO NOT NULL unclear
110 step
= ColumnAdder
.NewStringInstance(stepName
, tableName
, columnName
, 255, INCLUDE_AUDIT
);
113 //TODO update tree index for feature node
115 //update introduced: adventitious (casual) label
117 stepName
= "Update introduced: adventitious (casual) label";
118 String query
= " UPDATE representation r " +
119 " SET r.abbreviatedlabel = 'ia' " +
120 " WHERE r.abbreviatedlabel = 'id' AND r.label = 'introduced: adventitious (casual)' ";
121 step
= SimpleSchemaUpdaterStep
.NewInstance(stepName
, query
);
124 //TODO update idInVocabulary for DefinedTerms
126 //TODO update termType for DefinedTerms and TermVocabulary, no type must be null
128 //TODO update DTYPE for modifiers (Stage, Scope, Sex, DeterminationModifier, Modifier -> DefinedTerm)
131 //TODO update rankClass (#3521)
133 //TODO change column type for DistanceToWaterSurface und DistanceToGround
135 //TODO add column for DistanceToWaterSurfaceMax/Text und DistanceToGroundMax/Text
137 //TODO update datatype of sequence.sequence => CLOB (keeping data not necessary #3325)
138 //NOTE: column has been changed: #3360
140 //TODO update datatype->CLOB for URIs. (DefinedTerms, TermVocabulary, Reference
141 //Rights, MediaRepresentationPart ) #3345
143 //update Sicilia -> Sicily
145 stepName
= "Update Sicilia -> Sicily";
146 query
= " UPDATE representation r " +
147 " SET r.label = 'Sicily', r.text = 'Sicily' " +
148 " WHERE (r.abbreviatedlabel = 'SIC-SI' OR r.abbreviatedlabel = 'SIC') AND r.label = 'Sicilia' ";
149 step
= SimpleSchemaUpdaterStep
.NewInstance(stepName
, query
);
152 //remove homotypical group form type designation base
153 stepName
= "Remove column homotypical group in type designation base";
154 tableName
= "TypeDesignationBase";
155 String oldColumnName
= "homotypicalgroup_id";
156 step
= ColumnRemover
.NewInstance(stepName
, tableName
, oldColumnName
, INCLUDE_AUDIT
);
159 //add publish flag to taxon
160 stepName
= "Add publish flag column to taxon base";
161 tableName
= "TaxonBase";
162 columnName
= "publish";
163 step
= ColumnAdder
.NewBooleanInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
, true);
166 //add publish flag to specimen
167 stepName
= "Add publish flag column to SpecimenOrObservationBase";
168 tableName
= "SpecimenOrObservationBase";
169 columnName
= "publish";
170 step
= ColumnAdder
.NewBooleanInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
, true);
173 //TODO add columns abbrevTitle, abbrevTitleCache and protectedAbbrevTitleCache to Reference
176 //add start number to PolytomousKey
177 stepName
= "Add start number column to PolytomousKey";
178 tableName
= "PolytomousKey";
179 columnName
= "startNumber";
180 Integer defaultValue
= 1;
181 step
= ColumnAdder
.NewIntegerInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
, defaultValue
, true);
184 //TODO add specimenOrObservation basis of record to SpecimenOrObservationBase
186 //TODO update specimenOrObservationBase DTYPE with DefinedTerm where necessary
189 //TODO update DTYPE FieldObservation -> FieldUnit #3351
190 stepName
= "Update FieldObservation -> FieldUnit";
191 query
= " UPDATE SpecimenOrObservationBase sob " +
192 " SET sob.DTYPE = 'FieldUnit' " +
193 " WHERE sob.DTYPE = 'FieldObservation' ";
194 step
= SimpleSchemaUpdaterStep
.NewInstance(stepName
, query
);
197 //add kindOfUnit to SpecimenOrObservationBase
198 stepName
= "Add kindOfUnit column to SpecimenOrObservationBase";
199 tableName
= "SpecimenOrObservationBase";
200 columnName
= "kindOfUnit";
201 String relatedTable
= "DefinedTermBase";
202 step
= ColumnAdder
.NewIntegerInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
, true, relatedTable
);
205 //TODO remove citation_id and citationmicroreference columns from Media table #2541
206 //first check if columns are always empty
208 //TODO update length of all title caches and full title cache in names
209 //https://dev.e-taxonomy.eu/trac/ticket/1592
211 //TODO rename FK column states_id -> stateData_id in DescriptionElementBase_StateData(+AUD) #2923
213 //TODO add sortIndex column to TaxonNode and fill with values (compare with FeatureNode filling, however, this
214 // had a bad performance
216 //specimen descriptions #3571
217 //TODO add column DescriptionBase.Specimen_ID #3571
218 stepName
= "Add specimen_id column to DescriptionBase";
219 tableName
= "SpecimenOrObservationBase";
220 columnName
= "specimen_id";
221 boolean notNull
= false;
222 String referencedTable
= "SpecimenOrObservationBase";
223 step
= ColumnAdder
.NewIntegerInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
, notNull
, referencedTable
);
226 //TODO update DescriptionBase.Specimen_ID data #3571
228 //TODO remove tables DescriptionBase_SpecimenOrObservationBase(_AUD) #3571
229 stepName
= "Remove table DescriptionBase_SpecimenOrObservationBase";
230 tableName
= "DescriptionBase_SpecimenOrObservationBase";
231 TableDroper
.NewInstance(stepName
, tableName
, INCLUDE_AUDIT
);
234 //TODO create table CdmPreferences #3555
236 //TODO fill CdmPreferences with default values
238 //update RightsTerm to RightsType #1306
239 stepName
= "Update RightsTerm -> RightsType";
240 String updateSql
= "UPDATE DefinedTermBase SET DTYPE = 'RightsType' WHERE DTYPE = 'RightsTerm'";
241 step
= SimpleSchemaUpdaterStep
.NewInstance(stepName
, updateSql
);
244 //remove table Sequence_GenBankAccession #3552
245 stepName
= "Remove table Sequence_GenBankAccession";
246 tableName
= "Sequence_GenBankAccession";
247 TableDroper
.NewInstance(stepName
, tableName
, INCLUDE_AUDIT
);
250 //remove table GenBankAccession #3552
251 stepName
= "Remove table GenBankAccession";
252 tableName
= "GenBankAccession";
253 TableDroper
.NewInstance(stepName
, tableName
, INCLUDE_AUDIT
);
256 //TODO (read first #3360) add columns GeneticAccessionNumber(String) to Sequence
258 //TODO update molecular data #3360
261 //add MediaSpecimen column #3614
262 stepName
= "Add mediaSpecimen column to SpecimenOrObservationBase";
263 tableName
= "SpecimenOrObservationBase";
264 columnName
= "mediaSpecimen_id";
266 referencedTable
= "Media";
267 step
= ColumnAdder
.NewIntegerInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
, notNull
, referencedTable
);
270 //remove DescriptionBase_Feature #2202
271 stepName
= "Remove table DescriptionBase_Feature";
272 tableName
= "DescriptionBase_Feature";
273 TableDroper
.NewInstance(stepName
, tableName
, INCLUDE_AUDIT
);
279 private void updateElevationMax(List
<ISchemaUpdaterStep
> stepList
) {
281 String stepName
= "Create absoluteElevationMax column";
282 String tableName
= "GatheringEvent";
283 String columnName
= "absoluteElevationMax";
284 ISchemaUpdaterStep step
= ColumnAdder
.NewIntegerInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
, false, null);
289 stepName
= "Update gathering elevation max";
290 //all audits to unknown type
291 String query
= " UPDATE GatheringEvent ge " +
292 " SET ge.absoluteElevationMax = ge.elevation + ge.elevationErrorRadius, " +
293 " ge.absoluteElevation = ge.elevationErrorRadius - ge.elevationErrorRadius" +
294 " WHERE ge.elevationErrorRadius is not null ";
295 step
= SimpleSchemaUpdaterStep
.NewInstance(stepName
, query
);
299 //remove error column
300 stepName
= "Remove elevationErrorRadius column";
301 tableName
= "GatheringEvent";
302 columnName
= "elevationErrorRadius";
303 step
= ColumnRemover
.NewInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
);
312 private void updateOriginalSourceType(List
<ISchemaUpdaterStep
> stepList
) {
314 ISchemaUpdaterStep step
;
315 stepName
= "Create original source type column";
316 //all audits to unknown type
317 String query
= "UPDATE OriginalSourceBase_AUD SET type = 0 ";
318 step
= SimpleSchemaUpdaterStep
.NewInstance(stepName
, query
);
321 //all data to unknown
322 query
= "UPDATE OriginalSourceBase SET type = 0 ";
323 step
= SimpleSchemaUpdaterStep
.NewInstance(stepName
, query
);
326 //all imports recognized by idInSOurce and by missing nameInSource
327 query
= "UPDATE OriginalSourceBase SET type = 3 WHERE " +
328 "((idInSource IS NOT NULL) OR (idNamespace IS NOT NULL)) AND " +
329 "( nameUsedInSource IS NULL AND originalNameString IS NULL ) ";
330 step
= SimpleSchemaUpdaterStep
.NewInstance(stepName
, query
);
332 //all imports recognized by idInSOurce and by missing nameInSource
333 query
= "UPDATE OriginalSourceBase SET type = 1 WHERE " +
334 "(idInSource IS NULL AND idNamespace IS NULL) AND " +
335 "( citation IS NOT NULL ) ";
336 step
= SimpleSchemaUpdaterStep
.NewInstance(stepName
, query
);
341 * @see eu.etaxonomy.cdm.database.update.SchemaUpdaterBase#getNextUpdater()
344 public ISchemaUpdater
getNextUpdater() {
349 * @see eu.etaxonomy.cdm.database.update.SchemaUpdaterBase#getPreviousUpdater()
352 public ISchemaUpdater
getPreviousUpdater() {
353 return SchemaUpdater_30_301
.NewInstance();