removing @Override for compatibility with java 1.6
[cdmlib.git] / cdmlib-persistence / src / main / java / eu / etaxonomy / cdm / database / update / SchemaUpdaterStepBase.java
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.ResultSet;
13 import java.sql.SQLException;
14 import java.util.ArrayList;
15 import java.util.List;
16 import java.util.UUID;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.log4j.Logger;
20 import org.joda.time.DateTime;
21
22 import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
23 import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
24 import eu.etaxonomy.cdm.database.ICdmDataSource;
25 import eu.etaxonomy.cdm.model.common.Language;
26
27 /**
28 * @author a.mueller
29 * @date 13.09.2010
30 *
31 */
32 public abstract class SchemaUpdaterStepBase<T extends SchemaUpdaterStepBase<T>> implements ISchemaUpdaterStep {
33 private static final Logger logger = Logger.getLogger(SchemaUpdaterStepBase.class);
34
35 protected String stepName;
36
37 private boolean ignoreErrors;
38
39
40 //************************ CONSTRUCTOR ***********************************/
41
42 protected SchemaUpdaterStepBase(String stepName){
43 this.setStepName(stepName);
44 }
45
46 /* (non-Javadoc)
47 * @see eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep#invoke(eu.etaxonomy.cdm.database.ICdmDataSource, eu.etaxonomy.cdm.common.IProgressMonitor)
48 */
49 public abstract Integer invoke (ICdmDataSource datasource, IProgressMonitor monitor) throws SQLException;
50
51 /* (non-Javadoc)
52 * @see eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep#setStepName(java.lang.String)
53 */
54 public void setStepName(String stepName) {
55 this.stepName = stepName;
56 }
57
58 /* (non-Javadoc)
59 * @see eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep#getStepName()
60 */
61 public String getStepName() {
62 return stepName;
63 }
64
65
66
67 protected String getBoolean(boolean value, ICdmDataSource datasource) {
68 String result;
69 DatabaseTypeEnum type = datasource.getDatabaseType();
70 int intValue = value == true? 1 : 0;
71 if (type.equals(DatabaseTypeEnum.MySQL)){
72 result = "b'"+intValue+"'";
73 }else if (type.equals(DatabaseTypeEnum.PostgreSQL)){
74 result = "'"+intValue+"'";
75 }else if (type.equals(DatabaseTypeEnum.H2)){
76 result = value == true ? "TRUE" : "FALSE";
77 }else if (type.equals(DatabaseTypeEnum.SqlServer2005)){
78 logger.warn("SQLServer boolean not tested yet");
79 result = "b'"+intValue+"'";
80 }else{
81 throw new RuntimeException("Database type not supported for boolean" + type.getName());
82 }
83 return result;
84 }
85
86 protected Integer getEnglishLanguageId(ICdmDataSource datasource, IProgressMonitor monitor) throws SQLException {
87 return getLanguageId(Language.uuidEnglish, datasource, monitor);
88 }
89
90 /**
91 * @param uuidLanguage
92 * @param datasource
93 * @param monitor
94 * @return
95 * @throws SQLException
96 */
97 protected Integer getLanguageId(UUID uuidLanguage, ICdmDataSource datasource, IProgressMonitor monitor) throws SQLException {
98 ResultSet rs;
99 Integer langId = null;
100 String sqlLangId = " SELECT id FROM DefinedTermBase WHERE uuid = '" + uuidLanguage + "'";
101 rs = datasource.executeQuery(sqlLangId);
102 if (rs.next()){
103 langId = rs.getInt("id");
104 }else{
105 String warning = "Term for language (" + uuidLanguage + ") does not exist!";
106 monitor.warning(warning);
107 }
108 return langId;
109 }
110
111
112 public List<ISchemaUpdaterStep> getInnerSteps(){
113 return new ArrayList<ISchemaUpdaterStep>();
114 }
115
116 @Override
117 public boolean isIgnoreErrors() {
118 return ignoreErrors;
119 }
120
121
122 @Override
123 public void setIgnoreErrors(boolean ignoreErrors) {
124 this.ignoreErrors = ignoreErrors;
125 }
126
127
128 /**
129 * Returns a time string with date and time (without millis) that
130 * can be used as a time string for database insert and update
131 * @return
132 */
133 protected String getNowString() {
134 return DateTime.now().toString("YYYY-MM-dd HH:mm:ss");
135 }
136
137 @Override
138 public String toString(){
139 if (StringUtils.isNotBlank(stepName)){
140 return stepName;
141 }else{
142 return super.toString();
143 }
144 }
145
146 }