3 * Copyright (C) 2009 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.
10 package eu
.etaxonomy
.cdm
.database
.update
;
12 import java
.sql
.SQLException
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.apache
.log4j
.Logger
;
18 import eu
.etaxonomy
.cdm
.common
.monitor
.IProgressMonitor
;
19 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
20 import eu
.etaxonomy
.cdm
.model
.common
.CdmMetaData
;
27 public abstract class TermUpdaterBase
extends UpdaterBase
<ITermUpdaterStep
, ITermUpdater
> implements ITermUpdater
{
28 @SuppressWarnings("unused")
29 private static final Logger logger
= Logger
.getLogger(TermUpdaterBase
.class);
30 protected static final UUID uuidFeatureVocabulary
= UUID
.fromString("b187d555-f06f-4d65-9e53-da7c93f8eaa8");
32 protected TermUpdaterBase(String startTermVersion
, String targetTermVersion
){
33 this.startVersion
= startTermVersion
;
34 this.targetVersion
= targetTermVersion
;
35 list
= getUpdaterList();
39 protected boolean updateVersion(ICdmDataSource datasource
, IProgressMonitor monitor
) throws SQLException
{
40 int intSchemaVersion
= 1;
41 String sqlUpdateSchemaVersion
= "UPDATE CdmMetaData SET value = '" + this.targetVersion
+ "' WHERE propertyname = " + intSchemaVersion
;
43 int n
= datasource
.executeUpdate(sqlUpdateSchemaVersion
);
45 } catch (Exception e
) {
46 monitor
.warning("Error when trying to set new schemaversion: ", e
);
47 throw new SQLException(e
);
51 protected abstract List
<ITermUpdaterStep
> getUpdaterList();
55 public boolean invoke(ICdmDataSource datasource
, IProgressMonitor monitor
) throws Exception
{
56 String currentLibrarySchemaVersion
= CdmMetaData
.getTermsVersion();
57 return invoke(currentLibrarySchemaVersion
, datasource
, monitor
);
61 protected String
getCurrentVersion(ICdmDataSource datasource
, IProgressMonitor monitor
) throws SQLException
{
62 int intSchemaVersion
= 1;
64 String sqlCount
= "SELECT count(*) FROM CdmMetaData WHERE propertyname = " + intSchemaVersion
;
65 Long count
= (Long
)datasource
.getSingleValue(sqlCount
);
67 String defaultVersion
= "2.4.2.2.201006011715";
68 String sqlMaxId
= "SELECT max(id) FROM CdmMetaData";
69 Integer maxId
= (Integer
)datasource
.getSingleValue(sqlMaxId
) + 1;
70 String sqlUpdate
= "INSERT INTO CdmMetaData (id, created, uuid, propertyname, value) VALUES (" + maxId
+ ", '2010-09-21 13:52:54', '"+UUID
.randomUUID()+"', 1, '" + defaultVersion
+ "')";
71 datasource
.executeUpdate(sqlUpdate
);
72 return defaultVersion
;
74 String sqlSchemaVersion
= "SELECT value FROM CdmMetaData WHERE propertyname = " + intSchemaVersion
;
75 String value
= (String
)datasource
.getSingleValue(sqlSchemaVersion
);
78 } catch (SQLException e
) {
79 monitor
.warning("Error when trying to receive schemaversion: ", e
);