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 still needed? Does it throw exception if table does not exist?
64 //drop TypeDesignationBase_TaxonNameBase //from schemaUpdater 301_31
65 String stepName
= "Drop duplicate TypeDesignation-TaxonName table";
66 String tableName
= "TypeDesignationBase_TaxonNameBase";
67 ISchemaUpdaterStep step
= TableDroper
.NewInstance(stepName
, tableName
, INCLUDE_AUDIT
);
70 //create original source type column
71 stepName
= "Create original source type column";
72 tableName
= "OriginalSourceBase";
73 String columnName
= "type";
74 //TODO NOT NULL unclear
75 step
= ColumnAdder
.NewIntegerInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
, true, null);
78 //TODO ?? update original source type
79 updateOriginalSourceType(stepList
);
81 //create and update elevenation max, remove error column
82 updateElevationMax(stepList
);
84 //create taxon node tree index
85 stepName
= "Create taxon node tree index";
86 tableName
= "TaxonNode";
87 columnName
= "treeIndex";
88 //TODO NOT NULL unclear
89 step
= ColumnAdder
.NewStringInstance(stepName
, tableName
, columnName
, 255, INCLUDE_AUDIT
);
92 //TODO update tree index
94 //create original source type column
95 stepName
= "Create taxon node sort index column";
96 tableName
= "TaxonNode";
97 columnName
= "sortIndex";
98 step
= ColumnAdder
.NewIntegerInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
, false, null);
101 //TODO implement sorted behaviour in model first !!
102 //TODO update sortindex (similar updater exists already for FeatureNode#sortIndex in schema update 25_30
104 //create feature node tree index
105 stepName
= "Create feature node tree index";
106 tableName
= "FeatureNode";
107 columnName
= "treeIndex";
108 //TODO NOT NULL unclear
109 step
= ColumnAdder
.NewStringInstance(stepName
, tableName
, columnName
, 255, INCLUDE_AUDIT
);
112 //TODO update tree index for feature node
114 //update introduced: adventitious (casual) label
116 stepName
= "Update introduced: adventitious (casual) label";
117 String query
= " UPDATE representation r " +
118 " SET r.abbreviatedlabel = 'ia' " +
119 " WHERE r.abbreviatedlabel = 'id' AND r.label = 'introduced: adventitious (casual)' ";
120 step
= SimpleSchemaUpdaterStep
.NewInstance(stepName
, query
);
123 //TODO update idInVocabulary for DefinedTerms
125 //TODO update termType for DefinedTerms and TermVocabulary, no type must be null
127 //TODO update DTYPE for modifiers (Stage, Scope, Sex, DeterminationModifier, Modifier -> DefinedTerm)
130 //TODO update rankClass (#3521)
132 //TODO change column type for DistanceToWaterSurface und DistanceToGround
134 //TODO add column for DistanceToWaterSurfaceMax/Text und DistanceToGroundMax/Text
136 //TODO update datatype of sequence.sequence (keeping data not necessary #3325)
138 //TODO update datatype->CLOB for URIs. (DefinedTerms, TermVocabulary, Reference
139 //Rights, MediaRepresentationPart, GenBankAccession, ) #3345
141 //TODO remove table Sequence_GenBankAccession
143 //TODO remove table GenBankAccession
145 //TODO add columns GenBankAccessionNumber(String) and GenBankUri (URI) to Sequence
147 //update Sicilia -> Sicily
149 stepName
= "Update Sicilia -> Sicily";
150 query
= " UPDATE representation r " +
151 " SET r.label = 'Sicily', r.text = 'Sicily' " +
152 " WHERE (r.abbreviatedlabel = 'SIC-SI' OR r.abbreviatedlabel = 'SIC') AND r.label = 'Sicilia' ";
153 step
= SimpleSchemaUpdaterStep
.NewInstance(stepName
, query
);
156 //remove homotypical group form type designation base
157 stepName
= "Remove column homotypical group in type designation base";
158 tableName
= "TypeDesignationBase";
159 String oldColumnName
= "homotypicalgroup_id";
160 step
= ColumnRemover
.NewInstance(stepName
, tableName
, oldColumnName
, INCLUDE_AUDIT
);
163 //add publish flag to taxon
164 stepName
= "Add publish flag column to taxon base";
165 tableName
= "TaxonBase";
166 columnName
= "publish";
167 step
= ColumnAdder
.NewBooleanInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
, true);
170 //add publish flag to specimen
171 stepName
= "Add publish flag column to SpecimenOrObservationBase";
172 tableName
= "SpecimenOrObservationBase";
173 columnName
= "publish";
174 step
= ColumnAdder
.NewBooleanInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
, true);
177 //TODO add columns abbrevTitle, abbrevTitleCache and protectedAbbrevTitleCache to Reference
180 //add start number to PolytomousKey
181 stepName
= "Add start number column to PolytomousKey";
182 tableName
= "PolytomousKey";
183 columnName
= "startNumber";
184 Integer defaultValue
= 1;
185 step
= ColumnAdder
.NewIntegerInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
, defaultValue
, true);
188 //TODO add specimenOrObservation basis of record to SpecimenOrObservationBase
190 //add kindOfUnit to SpecimenOrObservationBase
191 stepName
= "Add kindOfUnit column to SpecimenOrObservationBase";
192 tableName
= "SpecimenOrObservationBase";
193 columnName
= "kindOfUnit";
194 String relatedTable
= "DefinedTermBase";
195 step
= ColumnAdder
.NewIntegerInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
, true, relatedTable
);
202 private void updateElevationMax(List
<ISchemaUpdaterStep
> stepList
) {
204 String stepName
= "Create absoluteElevationMax column";
205 String tableName
= "GatheringEvent";
206 String columnName
= "absoluteElevationMax";
207 ISchemaUpdaterStep step
= ColumnAdder
.NewIntegerInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
, false, null);
212 stepName
= "Update gathering elevation max";
213 //all audits to unknown type
214 String query
= " UPDATE GatheringEvent ge " +
215 " SET ge.absoluteElevationMax = ge.elevation + ge.elevationErrorRadius, " +
216 " ge.absoluteElevation = ge.elevationErrorRadius - ge.elevationErrorRadius" +
217 " WHERE ge.elevationErrorRadius is not null ";
218 step
= SimpleSchemaUpdaterStep
.NewInstance(stepName
, query
);
222 //remove error column
223 stepName
= "Remove elevationErrorRadius column";
224 tableName
= "GatheringEvent";
225 columnName
= "elevationErrorRadius";
226 step
= ColumnRemover
.NewInstance(stepName
, tableName
, columnName
, INCLUDE_AUDIT
);
235 private void updateOriginalSourceType(List
<ISchemaUpdaterStep
> stepList
) {
237 ISchemaUpdaterStep step
;
238 stepName
= "Create original source type column";
239 //all audits to unknown type
240 String query
= "UPDATE OriginalSourceBase_AUD SET type = 0 ";
241 step
= SimpleSchemaUpdaterStep
.NewInstance(stepName
, query
);
244 //all data to unknown
245 query
= "UPDATE OriginalSourceBase SET type = 0 ";
246 step
= SimpleSchemaUpdaterStep
.NewInstance(stepName
, query
);
249 //all imports recognized by idInSOurce and by missing nameInSource
250 query
= "UPDATE OriginalSourceBase SET type = 3 WHERE " +
251 "((idInSource IS NOT NULL) OR (idNamespace IS NOT NULL)) AND " +
252 "( nameUsedInSource IS NULL AND originalNameString IS NULL ) ";
253 step
= SimpleSchemaUpdaterStep
.NewInstance(stepName
, query
);
255 //all imports recognized by idInSOurce and by missing nameInSource
256 query
= "UPDATE OriginalSourceBase SET type = 1 WHERE " +
257 "(idInSource IS NULL AND idNamespace IS NULL) AND " +
258 "( citation IS NOT NULL ) ";
259 step
= SimpleSchemaUpdaterStep
.NewInstance(stepName
, query
);
264 * @see eu.etaxonomy.cdm.database.update.SchemaUpdaterBase#getNextUpdater()
267 public ISchemaUpdater
getNextUpdater() {
272 * @see eu.etaxonomy.cdm.database.update.SchemaUpdaterBase#getPreviousUpdater()
275 public ISchemaUpdater
getPreviousUpdater() {
276 return SchemaUpdater_30_301
.NewInstance();