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;
|
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.ICdmDataSource;
|
19
|
|
20
|
/**
|
21
|
* Base class for updating a schema.
|
22
|
*
|
23
|
* @author a.mueller
|
24
|
* @date 10.09.2010
|
25
|
*
|
26
|
*/
|
27
|
public abstract class SchemaUpdaterBase extends UpdaterBase<ISchemaUpdaterStep, ISchemaUpdater> implements ISchemaUpdater {
|
28
|
@SuppressWarnings("unused")
|
29
|
private static final Logger logger = Logger.getLogger(SchemaUpdaterBase.class);
|
30
|
|
31
|
public static boolean INCLUDE_AUDIT = true;
|
32
|
protected static boolean INCLUDE_CDM_BASE = true;
|
33
|
|
34
|
// private List<ISchemaUpdaterStep> list;
|
35
|
|
36
|
|
37
|
protected abstract List<ISchemaUpdaterStep> getUpdaterList();
|
38
|
|
39
|
|
40
|
protected SchemaUpdaterBase(String startSchemaVersion, String endSchemaVersion){
|
41
|
this.startVersion = startSchemaVersion;
|
42
|
this.targetVersion = endSchemaVersion;
|
43
|
list = getUpdaterList();
|
44
|
}
|
45
|
|
46
|
@Override
|
47
|
protected boolean updateVersion(ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType) throws SQLException {
|
48
|
int intSchemaVersion = 0;
|
49
|
String sqlUpdateSchemaVersion = "UPDATE %s SET value = '" + this.targetVersion + "' WHERE propertyname = " + intSchemaVersion;
|
50
|
sqlUpdateSchemaVersion = String.format(sqlUpdateSchemaVersion, caseType.transformTo("CdmMetaData"), this.targetVersion);
|
51
|
try {
|
52
|
int n = datasource.executeUpdate(sqlUpdateSchemaVersion);
|
53
|
return n > 0;
|
54
|
|
55
|
} catch (Exception e) {
|
56
|
monitor.warning("Error when trying to set new schemaversion: ", e);
|
57
|
throw new SQLException(e);
|
58
|
}
|
59
|
}
|
60
|
|
61
|
@Override
|
62
|
protected String getCurrentVersion(ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType) throws SQLException {
|
63
|
int intSchemaVersion = 0;
|
64
|
String sqlSchemaVersion = caseType.replaceTableNames( "SELECT value FROM @@CdmMetaData@@ WHERE propertyname = " + intSchemaVersion);
|
65
|
|
66
|
try {
|
67
|
String value = (String)datasource.getSingleValue(sqlSchemaVersion);
|
68
|
return value;
|
69
|
} catch (SQLException e) {
|
70
|
monitor.warning("Error when trying to receive schemaversion: ", e);
|
71
|
throw e;
|
72
|
}
|
73
|
}
|
74
|
|
75
|
|
76
|
}
|