Project

General

Profile

Download (2.46 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.database.update;
10

    
11
import java.sql.SQLException;
12
import java.util.List;
13

    
14
import org.apache.log4j.Logger;
15

    
16
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
17
import eu.etaxonomy.cdm.database.ICdmDataSource;
18

    
19
/**
20
 * Base class for updating a schema.
21
 *
22
 * @author a.mueller
23
 * @date 10.09.2010
24
 *
25
 */
26
public abstract class SchemaUpdaterBase extends UpdaterBase<ISchemaUpdaterStep, ISchemaUpdater> implements ISchemaUpdater {
27
	@SuppressWarnings("unused")
28
	private static final Logger logger = Logger.getLogger(SchemaUpdaterBase.class);
29

    
30
	public static boolean INCLUDE_AUDIT = true;
31
	protected static boolean INCLUDE_CDM_BASE = true;
32
	protected static boolean NOT_NULL = 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
}
(21-21/36)