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
.ResultSet
;
13 import java
.sql
.SQLException
;
14 import java
.util
.UUID
;
16 import org
.apache
.log4j
.Logger
;
18 import eu
.etaxonomy
.cdm
.common
.IProgressMonitor
;
19 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
26 public class SingleTermUpdater
extends SchemaUpdaterStepBase
{
27 @SuppressWarnings("unused")
28 private static final Logger logger
= Logger
.getLogger(SingleTermUpdater
.class);
30 public static final SingleTermUpdater
NewInstance(String stepName
, UUID uuidTerm
, String description
, String label
, String abbrev
, String dtype
, Integer orderIndex
, UUID uuidVocabulary
){
31 return new SingleTermUpdater(stepName
, uuidTerm
, description
, label
, abbrev
, dtype
, orderIndex
, uuidVocabulary
);
35 // private ICdmDataSource datasource;
36 // private IProgressMonitor monitor;
37 private UUID uuidTerm
;
38 private String description
;
40 private String abbrev
;
42 private UUID uuidVocabulary
;
43 private Integer orderIndex
;
47 private SingleTermUpdater(String stepName
, UUID uuidTerm
, String description
, String label
, String abbrev
, String dtype
, Integer orderIndex
, UUID uuidVocabulary
) {
50 // this.datasource = datasource;
51 // this.monitor = monitor;
52 this.description
= description
;
55 this.orderIndex
= orderIndex
;
56 this.uuidTerm
= uuidTerm
;
57 this.uuidVocabulary
= uuidVocabulary
;
62 public boolean invoke(ICdmDataSource datasource
, IProgressMonitor monitor
) throws SQLException
{
66 String sqlVocId
= " SELECT id FROM TermVocabulary WHERE uuid = " + uuidVocabulary
;
67 ResultSet rs
= datasource
.executeQuery(sqlVocId
);
69 vocId
= rs
.getInt("id");
71 String warning
= "Vocabulary ( "+ uuidVocabulary
+" ) for term does not exist!";
72 monitor
.warning(warning
);
77 String sqlMaxId
= " SELECT max(id)+1 as maxId FROM DefinedTermBase";
78 rs
= datasource
.executeQuery(sqlMaxId
);
80 termId
= rs
.getInt("maxId");
82 String warning
= "No defined terms do exist yet. Can't update terms!";
83 monitor
.warning(warning
);
87 String id
= Integer
.toString(termId
);
88 String created
= "'2010-09-01 10:15:00'";
89 String defaultColor
= "null";
90 String protectedTitleCache
= "b'0'";
91 String titleCache
= label
!= null ? label
: (abbrev
!= null ? abbrev
: description
);
92 String sqlInsertTerm
= " INSERT INTO DefinedTermBase (DTYPE, id, uuid, created, protectedtitlecache, titleCache, orderindex, defaultcolor, vocabulary_id)" +
93 "VALUES ('" + dtype
+ "', " + id
+ ", '" + uuidTerm
+ "', '" + created
+ "', " + protectedTitleCache
+ ", '" + titleCache
+ "', " + orderIndex
+ ", " + defaultColor
+ ", " + vocId
+ ")";
94 datasource
.executeQuery(sqlInsertTerm
);
97 // INSERT INTO DefinedTermBase (DTYPE, id, uuid, created, protectedtitlecache, titleCache, orderindex, defaultcolor, vocabulary_id)
98 // SELECT 'ReferenceSystem' , (@defTermId := max(id)+1) as maxId , '1bb67042-2814-4b09-9e76-c8c1e68aa281', '2010-06-01 10:15:00', b'0', 'Google Earth', null, null, @refSysVocId
99 // FROM DefinedTermBase ;
104 String sqlLangId
= " SELECT id FROM DefinedTermBase WHERE uuid = 'e9f8cdb7-6819-44e8-95d3-e2d0690c3523'";
105 rs
= datasource
.executeQuery(sqlLangId
);
107 langId
= rs
.getInt("id");
109 String warning
= "Term for default language (English) not does not exist!";
110 monitor
.warning(warning
);
116 sqlMaxId
= " SELECT max(id)+1 as maxId FROM Representation";
117 rs
= datasource
.executeQuery(sqlMaxId
);
119 repId
= rs
.getInt("maxId");
121 String warning
= "No representations do exist yet. Can't update terms!";
122 monitor
.warning(warning
);
126 UUID uuidRepresentation
= UUID
.randomUUID();
127 String sqlInsertRepresentation
= " INSERT INTO Representation (id, created, uuid, text, abbreviatedlabel, label, language_id) " +
128 "VALUES (" + repId
+ ", '" + created
+ "', '" + uuidRepresentation
+ "', '" + description
+ "', '" + label
+ "', '" + abbrev
+ "', " + langId
+ ")";
130 datasource
.executeQuery(sqlInsertRepresentation
);
134 // INSERT INTO Representation (id, created, uuid, text, abbreviatedlabel, label, language_id)
135 // SELECT ( @repId := max(id)+1 ) AS maxId ,'2010-06-01 18:49:07','fadb1730-9936-44e7-8911-884a84662b08', 'Google Earth','Google','Google Earth', @langId
136 // FROM Representation;
141 // INSERT INTO Representation (id, created, uuid, text, abbreviatedlabel, label, language_id)
142 // SELECT ( @repId := max(id)+1 ) AS maxId ,'2010-06-01 18:49:07','fadb1730-9936-44e7-8911-884a84662b08', 'Google Earth','Google','Google Earth', @langId
143 // FROM Representation;
146 String sqlInsertMN
= "INSERT INTO DefinedTermBase_Representation (DefinedTermBase_id, representations_id) " +
147 " VALUES ("+ termId
+"," +repId
+ " )";
149 datasource
.executeUpdate(sqlInsertMN
);
151 // -- defTerm <-> representation
152 // INSERT INTO DefinedTermBase_Representation (DefinedTermBase_id, representations_id)
153 // VALUES (@defTermId,@repId);