1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2009 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.database.update.v36_40;
|
11
|
|
12
|
import java.sql.SQLException;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
|
18
|
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
|
19
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
20
|
import eu.etaxonomy.cdm.database.update.CaseType;
|
21
|
import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep;
|
22
|
import eu.etaxonomy.cdm.database.update.ITermUpdaterStep;
|
23
|
import eu.etaxonomy.cdm.database.update.SchemaUpdaterStepBase;
|
24
|
|
25
|
|
26
|
/**
|
27
|
* Updates the xxxObj_type field in Annotations, Markers, Extensions, Identifiers.
|
28
|
* Not needed anymore as long as we gave up bidirectionality #5743
|
29
|
*
|
30
|
* @author a.mueller
|
31
|
* @date 25.04.2016
|
32
|
*/
|
33
|
public class RevisionNumberUpdater extends SchemaUpdaterStepBase<RevisionNumberUpdater> implements ITermUpdaterStep{
|
34
|
private static final Logger logger = Logger.getLogger(RevisionNumberUpdater.class);
|
35
|
|
36
|
private static final String stepName = "Update referenced obj_type";
|
37
|
|
38
|
// **************************** STATIC METHODS ********************************/
|
39
|
|
40
|
public static final RevisionNumberUpdater NewInstance(String stepName, List<ISchemaUpdaterStep> stepList){
|
41
|
RevisionNumberUpdater result = new RevisionNumberUpdater(stepName);
|
42
|
stepList.add(result);
|
43
|
return result;
|
44
|
}
|
45
|
|
46
|
private RevisionNumberUpdater(String stepName) {
|
47
|
super(stepName);
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
public Integer invoke(ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType) throws SQLException {
|
52
|
|
53
|
String sql;
|
54
|
String casedAuditTable = caseType.transformTo("AuditEvent");
|
55
|
|
56
|
DatabaseTypeEnum databaseType = datasource.getDatabaseType();
|
57
|
if (databaseType == DatabaseTypeEnum.MySQL){
|
58
|
sql = "ALTER TABLE "+casedAuditTable+" ALTER revisionnumber DROP DEFAULT"; //needed? There was no default before
|
59
|
datasource.executeUpdate(sql);
|
60
|
sql = "ALTER TABLE "+casedAuditTable+" CHANGE COLUMN revisionnumber revisionnumber INT(11) NOT NULL FIRST";
|
61
|
datasource.executeUpdate(sql);
|
62
|
}else if (databaseType == DatabaseTypeEnum.H2){
|
63
|
sql = "ALTER TABLE "+casedAuditTable+" ALTER COLUMN revisionnumber INT NOT NULL";
|
64
|
datasource.executeUpdate(sql);
|
65
|
}else if (databaseType == DatabaseTypeEnum.PostgreSQL){
|
66
|
//NOTHING TO DO
|
67
|
}else if (databaseType == DatabaseTypeEnum.SqlServer2005){
|
68
|
throw new RuntimeException("SQLServer not supported by RevisionNumberUpdater");
|
69
|
}else{
|
70
|
throw new RuntimeException("Database type " + databaseType.toString() + " not supported by RevisionNumberUpdater");
|
71
|
}
|
72
|
return 0;
|
73
|
}
|
74
|
|
75
|
|
76
|
|
77
|
}
|