Project

General

Profile

Revision 1e55f5c2

ID1e55f5c2544860c52cea161e4edcff5ef2e1bbfa
Parent c3c1740f
Child 84f54e17

Added by Andreas Müller over 2 years ago

fix #5634 Update excluded/unplaced for TaxonNodes with no taxon_id

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/SimpleSchemaUpdaterStep.java
26 26
 * @date 13.09.2010
27 27
 *
28 28
 */
29
public class SimpleSchemaUpdaterStep extends SchemaUpdaterStepBase<SimpleSchemaUpdaterStep> implements ISchemaUpdaterStep, ITermUpdaterStep{
29
public class SimpleSchemaUpdaterStep extends SchemaUpdaterStepBase<SimpleSchemaUpdaterStep>
30
                implements ISchemaUpdaterStep, ITermUpdaterStep{
30 31
	private static final Logger logger = Logger.getLogger(SimpleSchemaUpdaterStep.class);
31 32

  
32 33
	private final Map<DatabaseTypeEnum, String> queryMap = new HashMap<DatabaseTypeEnum, String>();
......
172 173

  
173 174
	/**
174 175
	 * For certain database types one may define special queries.<BR>
175
	 * Don't forget to put case-mask (@@) for table names
176
	 * Don't forget to put case-mask (@@) for table names and also
177
	 * add AUD query if required.
176 178
	 * @param dbType database type
177 179
	 * @param query query to use for the given database type.
178 180
	 * @return this schema updater step
181
     * @see #putAudited(DatabaseTypeEnum, String)
179 182
	 */
180 183
	public SimpleSchemaUpdaterStep put(DatabaseTypeEnum dbType, String query) {
181 184
		queryMap.put(dbType, query);
......
183 186
	}
184 187

  
185 188
	/**
189
     * For certain database types one may define special queries.
190
     * This is for the AUD query.<BR>
191
     * Don't forget to put case-mask (@@) for table names
192
     * @param dbType database type
193
     * @param query query to use for the given database type.
194
     * @return this schema updater step
195
     * @see #put(DatabaseTypeEnum, String)
196
     */
197
    public SimpleSchemaUpdaterStep putAudited(DatabaseTypeEnum dbType, String query) {
198
        auditQueryMap.put(dbType, query);
199
        return this;
200
    }
201

  
202
	/**
186 203
	 * Defines the non audited table name for computing the audited query.
187 204
	 * @param nonAuditedTableName uncased table name that is to be audited
188 205
	 * @return the step
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v40_41/SchemaUpdater_40_41.java
16 16
import org.apache.log4j.Logger;
17 17

  
18 18
import eu.etaxonomy.cdm.common.UTF8;
19
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
19 20
import eu.etaxonomy.cdm.database.update.ColumnAdder;
20 21
import eu.etaxonomy.cdm.database.update.ColumnRemover;
21 22
import eu.etaxonomy.cdm.database.update.ISchemaUpdater;
......
160 161
        //#3925
161 162
        //Move excluded from Taxon to TaxonNode
162 163
        stepName = "Move excluded from Taxon to TaxonNode";
163
        query = "UPDATE @@TaxonNode@@ " +
164
                " SET excluded = 1 " +
165
                " WHERE id IN (SELECT id FROM "
166
                +       "(SELECT tn.id FROM @@TaxonBase@@ tb  INNER JOIN @@TaxonNode@@ tn ON tn.taxon_id = tb.id  WHERE tb.excluded = 1)"
167
                + " as drvTbl)";
168 164
        query = "UPDATE @@TaxonNode@@ tn " +
169 165
                " SET excluded = (SELECT excluded FROM @@TaxonBase@@ tb WHERE tb.id = tn.taxon_id)";
170

  
171 166
        simpleStep = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, "TaxonNode", -99)
172 167
                .addDefaultAuditing("TaxonBase");
173 168
        stepList.add(simpleStep);
174 169

  
170
        stepName = "Move excluded from Taxon to TaxonNode/set null to false";
171
        query = "UPDATE @@TaxonNode@@ SET excluded = 0 WHERE excluded IS NULL";
172
        simpleStep = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, "TaxonNode", -99);
173
        simpleStep.put(DatabaseTypeEnum.PostgreSQL, query.replace("0", "false"));
174
        simpleStep.putAudited(DatabaseTypeEnum.PostgreSQL, query.replace("TaxonNode","TaxonNode_AUD").replace("0", "false"));
175
        stepList.add(simpleStep);
176

  
177

  
175 178
        //#3925
176 179
        //remove excluded from TaxonNode
177 180
        stepName = "Remove excluded from TaxonBase";
......
191 194

  
192 195
        //#3925
193 196
        //Move unplaced from Taxon to TaxonNode
197

  
194 198
        stepName = "Move unplaced from Taxon to TaxonNode";
195
        query = "UPDATE @@TaxonNode@@ " +
196
                " SET unplaced = 1 " +
197
                " WHERE id IN (SELECT id FROM "
198
                +       "(SELECT tn.id FROM @@TaxonBase@@ tb  INNER JOIN @@TaxonNode@@ tn ON tn.taxon_id = tb.id  WHERE tb.unplaced = 1)"
199
                + " as drvTbl)";
200 199
        query = "UPDATE @@TaxonNode@@ tn " +
201 200
                " SET unplaced = (SELECT unplaced FROM @@TaxonBase@@ tb WHERE tb.id = tn.taxon_id)";
202

  
203 201
        simpleStep = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, "TaxonNode", -99)
204 202
                .addDefaultAuditing("TaxonBase");
205 203
        stepList.add(simpleStep);
206 204

  
205
        stepName = "Move unplaced from Taxon to TaxonNode/set null to false";
206
        query = "UPDATE @@TaxonNode@@ SET unplaced = 0 WHERE unplaced IS NULL";
207
        simpleStep = SimpleSchemaUpdaterStep.NewAuditedInstance(stepName, query, "TaxonNode", -99);
208
        simpleStep.put(DatabaseTypeEnum.PostgreSQL, query.replace("0", "false"));
209
        simpleStep.putAudited(DatabaseTypeEnum.PostgreSQL, query.replace("TaxonNode","TaxonNode_AUD").replace("0", "false"));
210
        stepList.add(simpleStep);
211

  
212

  
207 213
        //#3925
208 214
        //remove unplaced from TaxonNode
209 215
        stepName = "Remove unplaced from TaxonBase";

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)