*/\r
package eu.etaxonomy.cdm.database.update;\r
\r
+import java.sql.ResultSet;\r
import java.sql.SQLException;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.UUID;\r
\r
+import org.apache.commons.lang.StringUtils;\r
import org.apache.log4j.Logger;\r
+import org.joda.time.DateTime;\r
\r
-import eu.etaxonomy.cdm.common.IProgressMonitor;\r
+import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;\r
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;\r
import eu.etaxonomy.cdm.database.ICdmDataSource;\r
+import eu.etaxonomy.cdm.model.common.Language;\r
\r
/**\r
* @author a.mueller\r
* @date 13.09.2010\r
*\r
*/\r
-public abstract class SchemaUpdaterStepBase implements ISchemaUpdaterStep {\r
- @SuppressWarnings("unused")\r
+public abstract class SchemaUpdaterStepBase<T extends SchemaUpdaterStepBase<T>> implements ISchemaUpdaterStep {\r
private static final Logger logger = Logger.getLogger(SchemaUpdaterStepBase.class);\r
\r
- private String stepName;\r
+ protected String stepName;\r
+\r
+ private boolean ignoreErrors;\r
\r
\r
//************************ CONSTRUCTOR ***********************************/\r
- \r
+\r
protected SchemaUpdaterStepBase(String stepName){\r
this.setStepName(stepName);\r
}\r
\r
- /* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep#invoke(eu.etaxonomy.cdm.database.ICdmDataSource, eu.etaxonomy.cdm.common.IProgressMonitor)\r
- */\r
- public abstract Integer invoke (ICdmDataSource datasource, IProgressMonitor monitor) throws SQLException;\r
\r
- /* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep#setStepName(java.lang.String)\r
- */\r
+ @Override\r
+ public abstract Integer invoke (ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType) throws SQLException;\r
+\r
+\r
+ @Override\r
public void setStepName(String stepName) {\r
this.stepName = stepName;\r
}\r
\r
- /* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep#getStepName()\r
- */\r
+ @Override\r
public String getStepName() {\r
return stepName;\r
}\r
\r
-\r
-\r
protected String getBoolean(boolean value, ICdmDataSource datasource) {\r
+ \r
String result;\r
DatabaseTypeEnum type = datasource.getDatabaseType();\r
+ //TODO use\r
+// type.getHibernateDialect().toBooleanValueString(bool);\r
int intValue = value == true? 1 : 0;\r
if (type.equals(DatabaseTypeEnum.MySQL)){\r
result = "b'"+intValue+"'";\r
}else if (type.equals(DatabaseTypeEnum.PostgreSQL)){\r
result = "'"+intValue+"'";\r
}else if (type.equals(DatabaseTypeEnum.H2)){\r
- logger.warn("H2 boolean not tested yet");\r
- result = "b'"+intValue+"'";\r
+ result = value == true ? "TRUE" : "FALSE";\r
}else if (type.equals(DatabaseTypeEnum.SqlServer2005)){\r
logger.warn("SQLServer boolean not tested yet");\r
result = "b'"+intValue+"'";\r
}\r
return result;\r
}\r
+ \r
+ protected Integer getEnglishLanguageId(ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType) throws SQLException {\r
+ return getLanguageId(Language.uuidEnglish, datasource, monitor, caseType);\r
+ }\r
+\r
+ /**\r
+ * @param uuidLanguage\r
+ * @param datasource\r
+ * @param monitor\r
+ * @return\r
+ * @throws SQLException\r
+ */\r
+ protected Integer getLanguageId(UUID uuidLanguage, ICdmDataSource datasource, IProgressMonitor monitor, CaseType caseType) throws SQLException {\r
+ \r
+ ResultSet rs;\r
+ Integer langId = null;\r
+ String sqlLangId = " SELECT id FROM %s WHERE uuid = '%s'";\r
+ sqlLangId = String.format(sqlLangId, caseType.transformTo("DefinedTermBase"), uuidLanguage.toString() );\r
+ rs = datasource.executeQuery(sqlLangId);\r
+ if (rs.next()){\r
+ langId = rs.getInt("id");\r
+ }else{\r
+ String warning = "Term for language (" + uuidLanguage + ") does not exist!";\r
+ monitor.warning(warning);\r
+ }\r
+ return langId;\r
+ }\r
\r
\r
+ public List<ISchemaUpdaterStep> getInnerSteps(){\r
+ return new ArrayList<ISchemaUpdaterStep>();\r
+ }\r
+ \r
+ @Override\r
+ public boolean isIgnoreErrors() {\r
+ return ignoreErrors;\r
+ }\r
+ \r
+ \r
+ @Override\r
+ public void setIgnoreErrors(boolean ignoreErrors) {\r
+ this.ignoreErrors = ignoreErrors;\r
+ }\r
+ \r
+\r
+ /**\r
+ * Returns a time string with date and time (without millis) that \r
+ * can be used as a time string for database insert and update\r
+ * @return\r
+ */\r
+ protected String getNowString() {\r
+ return DateTime.now().toString("YYYY-MM-dd HH:mm:ss");\r
+ }\r
+\r
+ @Override\r
+ public String toString(){\r
+ if (StringUtils.isNotBlank(stepName)){\r
+ return stepName;\r
+ }else{\r
+ return super.toString();\r
+ }\r
+ }\r
\r
}\r