\r
import org.apache.log4j.Logger;\r
\r
-import eu.etaxonomy.cdm.common.DefaultProgressMonitor;\r
-import eu.etaxonomy.cdm.common.IProgressMonitor;\r
+import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;\r
+import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;\r
+import eu.etaxonomy.cdm.database.CdmDataSource;\r
import eu.etaxonomy.cdm.database.ICdmDataSource;\r
+import eu.etaxonomy.cdm.database.update.v30_31.TermUpdater_314_315;\r
+import eu.etaxonomy.cdm.database.update.v31_33.SchemaUpdater_31_33;\r
\r
/**\r
* @author a.mueller\r
public class CdmUpdater {\r
private static final Logger logger = Logger.getLogger(CdmUpdater.class);\r
\r
+ public static CdmUpdater NewInstance(){\r
+ return new CdmUpdater();\r
+ }\r
+ \r
/**\r
- * \r
+ * @param datasource\r
+ * @param monitor may be <code>null</code>\r
* @return\r
*/\r
public boolean updateToCurrentVersion(ICdmDataSource datasource, IProgressMonitor monitor){\r
}\r
\r
ISchemaUpdater currentSchemaUpdater = getCurrentSchemaUpdater();\r
+ // TODO do we really always update the terms??\r
ITermUpdater currentTermUpdater = getCurrentTermUpdater();\r
\r
- int steps = currentSchemaUpdater.countSteps(datasource);\r
- steps += currentTermUpdater.countSteps(datasource);\r
+ int steps = currentSchemaUpdater.countSteps(datasource, monitor);\r
+ steps += currentTermUpdater.countSteps(datasource, monitor);\r
\r
String taskName = "Update to schema version " + currentSchemaUpdater.getTargetVersion() + " and to term version " + currentTermUpdater.getTargetVersion(); //+ currentSchemaUpdater.getVersion();\r
monitor.beginTask(taskName, steps);\r
\r
try {\r
+ datasource.startTransaction();\r
result &= currentSchemaUpdater.invoke(datasource, monitor);\r
- result &= currentTermUpdater.invoke(datasource, monitor);\r
+ if (result == true){\r
+ result &= currentTermUpdater.invoke(datasource, monitor);\r
+ }\r
+ if (result == false){\r
+ datasource.rollback();\r
+ }else{\r
+ datasource.commitTransaction();\r
+ }\r
+ \r
} catch (Exception e) {\r
- monitor.warning("Stopped schema updater");\r
+ result = false;\r
+ monitor.warning("Stopped schema updater");\r
+ } finally {\r
+ String message = "Update finished " + (result ? "successfully" : "with ERRORS");\r
+ monitor.subTask(message);\r
+ if (!result){\r
+ monitor.warning(message);\r
+ monitor.setCanceled(true);\r
+ }else{\r
+ monitor.done();\r
+ }\r
+ logger.info(message);\r
}\r
\r
return result;\r
}\r
\r
private ITermUpdater getCurrentTermUpdater() {\r
- return TermUpdater_3_0.NewInstance();\r
+ return TermUpdater_314_315.NewInstance();\r
}\r
\r
/**\r
* @return\r
*/\r
private ISchemaUpdater getCurrentSchemaUpdater() {\r
- return SchemaUpdater_3_0.NewInstance();\r
+ return SchemaUpdater_31_33.NewInstance();\r
}\r
\r
-\r
-// 5432\r
/**\r
* @param args\r
*/\r
public static void main(String[] args) {\r
- logger.warn("main method not yet implemented");\r
- //TODO\r
+ logger.warn("main method not yet fully implemented (only works with mysql!!!)");\r
+ if(args.length < 2){\r
+ logger.error("Arguments missing: server database [username [password]]");\r
+ }\r
+ //TODO better implementation\r
CdmUpdater myUpdater = new CdmUpdater();\r
-// myUpdater.updateToCurrentVersion(datasource, monitor);\r
+ String server = args[0];\r
+ String database = args[1];\r
+ String username = args.length > 2 ? args[2] : null;\r
+ String password = args.length > 3 ? args[3] : null;\r
+ \r
+ ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance(server, database, username, password);\r
+ boolean success = myUpdater.updateToCurrentVersion(dataSource, null);\r
+ System.out.println("DONE " + (success ? "successfully" : "with ERRORS"));\r
}\r
\r
}\r