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 org
.apache
.log4j
.Logger
;
14 import eu
.etaxonomy
.cdm
.common
.monitor
.DefaultProgressMonitor
;
15 import eu
.etaxonomy
.cdm
.common
.monitor
.IProgressMonitor
;
16 import eu
.etaxonomy
.cdm
.database
.CdmDataSource
;
17 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
18 import eu
.etaxonomy
.cdm
.database
.update
.v30_31
.TermUpdater_314_315
;
19 import eu
.etaxonomy
.cdm
.database
.update
.v31_33
.SchemaUpdater_31_33
;
26 public class CdmUpdater
{
27 private static final Logger logger
= Logger
.getLogger(CdmUpdater
.class);
29 public static CdmUpdater
NewInstance(){
30 return new CdmUpdater();
35 * @param monitor may be <code>null</code>
38 public boolean updateToCurrentVersion(ICdmDataSource datasource
, IProgressMonitor monitor
){
39 boolean result
= true;
41 monitor
= DefaultProgressMonitor
.NewInstance();
44 ISchemaUpdater currentSchemaUpdater
= getCurrentSchemaUpdater();
45 // TODO do we really always update the terms??
46 ITermUpdater currentTermUpdater
= getCurrentTermUpdater();
48 int steps
= currentSchemaUpdater
.countSteps(datasource
, monitor
);
49 steps
+= currentTermUpdater
.countSteps(datasource
, monitor
);
51 String taskName
= "Update to schema version " + currentSchemaUpdater
.getTargetVersion() + " and to term version " + currentTermUpdater
.getTargetVersion(); //+ currentSchemaUpdater.getVersion();
52 monitor
.beginTask(taskName
, steps
);
55 result
&= currentSchemaUpdater
.invoke(datasource
, monitor
);
56 // the above apparently did not work while testing. Did not want to set the version in CdmMetaData yet
57 // result &= currentSchemaUpdater.invoke(currentSchemaUpdater.getTargetVersion(), datasource, monitor);
59 result
&= currentTermUpdater
.invoke(datasource
, monitor
);
60 } catch (Exception e
) {
62 monitor
.warning("Stopped schema updater");
64 String message
= "Update finished " + (result ?
"successfully" : "with ERRORS");
65 monitor
.subTask(message
);
73 private ITermUpdater
getCurrentTermUpdater() {
74 return TermUpdater_314_315
.NewInstance();
78 * Returns the current CDM updater
81 private ISchemaUpdater
getCurrentSchemaUpdater() {
82 return SchemaUpdater_31_33
.NewInstance();
88 public static void main(String
[] args
) {
89 logger
.warn("main method not yet fully implemented (only works with mysql!!!)");
91 logger
.error("Arguments missing: server database [username [password]]");
93 //TODO better implementation
94 CdmUpdater myUpdater
= new CdmUpdater();
95 String server
= args
[0];
96 String database
= args
[1];
97 String username
= args
.length
> 2 ? args
[2] : null;
98 String password
= args
.length
> 3 ? args
[3] : null;
100 ICdmDataSource dataSource
= CdmDataSource
.NewMySqlInstance(server
, database
, username
, password
);
101 boolean success
= myUpdater
.updateToCurrentVersion(dataSource
, null);
102 System
.out
.println("DONE " + (success ?
"successfully" : "with ERRORS"));