1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.test.function;
|
11
|
|
12
|
import org.apache.log4j.Logger;
|
13
|
|
14
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
15
|
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
|
16
|
import eu.etaxonomy.cdm.config.AccountStore;
|
17
|
import eu.etaxonomy.cdm.database.CdmDataSource;
|
18
|
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
|
19
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
20
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
21
|
import eu.etaxonomy.cdm.database.update.CdmUpdater;
|
22
|
import eu.etaxonomy.cdm.database.update.SchemaUpdateResult;
|
23
|
|
24
|
/**
|
25
|
* This class is meant for functional testing of model changes. It is not meant
|
26
|
* for running in maven.
|
27
|
*
|
28
|
* For testing
|
29
|
*
|
30
|
* 1. First run with CREATE first against H2, than MySQL, PostGreSQL, (SQLServer)
|
31
|
* 2. Save old schema databases
|
32
|
* 3. Run with VALIDATE
|
33
|
*
|
34
|
*
|
35
|
* @author a.mueller
|
36
|
* @since 22.05.2015
|
37
|
* @see CdmUpdater
|
38
|
*/
|
39
|
public class TestModelUpdate {
|
40
|
@SuppressWarnings("unused")
|
41
|
private static final Logger logger = Logger.getLogger(TestModelUpdate.class);
|
42
|
|
43
|
|
44
|
private void testSelectedDb(){
|
45
|
DbSchemaValidation schema = DbSchemaValidation.VALIDATE;
|
46
|
|
47
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
48
|
|
49
|
|
50
|
String database = (schema == DbSchemaValidation.VALIDATE ? "cdm50" : "cdm55");
|
51
|
CdmDataSource dataSource = getDatasource(dbType, database);
|
52
|
|
53
|
|
54
|
try {
|
55
|
// int n = dataSource.executeUpdate("UPDATE CdmMetaData SET value = '3.1.0.0.201607300000' WHERE propertyname = 0 ");
|
56
|
CdmUpdater updater = new CdmUpdater();
|
57
|
if (schema == DbSchemaValidation.VALIDATE){
|
58
|
SchemaUpdateResult result = updater.updateToCurrentVersion(dataSource,
|
59
|
DefaultProgressMonitor.NewInstance());
|
60
|
String report = result.createReport().toString();
|
61
|
System.out.println(report);
|
62
|
}
|
63
|
} catch (Exception e) {
|
64
|
e.printStackTrace();
|
65
|
}
|
66
|
try{
|
67
|
CdmApplicationController appCtr = CdmApplicationController.NewInstance(dataSource, schema);
|
68
|
|
69
|
// Classification classification = Classification.NewInstance("Me");
|
70
|
// Taxon taxon = Taxon.NewInstance(null, null);
|
71
|
// Person person = Person.NewInstance();
|
72
|
// TaxonNode node = classification.addChildTaxon(taxon, null, null);
|
73
|
// DefinedTerm lastScrutiny = (DefinedTerm)appCtr.getTermService().find(DefinedTerm.uuidLastScrutiny);
|
74
|
// TaxonNodeAgentRelation rel = node.addAgentRelation(lastScrutiny, person);
|
75
|
// appCtr.getClassificationService().save(classification);
|
76
|
|
77
|
if (schema == DbSchemaValidation.CREATE){
|
78
|
System.out.println("fillData");
|
79
|
appCtr.getCommonService().createFullSampleData();
|
80
|
appCtr.getNameService().list(null, null, null, null, null);
|
81
|
}
|
82
|
|
83
|
|
84
|
appCtr.close();
|
85
|
}catch (Exception e) {
|
86
|
e.printStackTrace();
|
87
|
}
|
88
|
System.out.println("Ready");
|
89
|
System.exit(0);
|
90
|
}
|
91
|
|
92
|
|
93
|
|
94
|
/**
|
95
|
* @param dbType
|
96
|
* @param database
|
97
|
* @return
|
98
|
*/
|
99
|
private CdmDataSource getDatasource(DatabaseTypeEnum dbType, String database) {
|
100
|
String server = "localhost";
|
101
|
String username = "edit";
|
102
|
String serverSql = "130.133.70.26";
|
103
|
|
104
|
if (dbType == DatabaseTypeEnum.MySQL){
|
105
|
return CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
|
106
|
}else if (dbType == DatabaseTypeEnum.H2){
|
107
|
//H2
|
108
|
String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2_" + database;
|
109
|
// String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2_xyz";
|
110
|
username = "sa";
|
111
|
CdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", username, "", path);
|
112
|
return dataSource;
|
113
|
}else if (dbType == DatabaseTypeEnum.SqlServer2005){
|
114
|
server = serverSql;
|
115
|
username = "cdmupdater";
|
116
|
CdmDataSource dataSource = CdmDataSource.NewSqlServer2005Instance(server, database, 1433, username, AccountStore.readOrStorePassword(server, database, username, null));
|
117
|
return dataSource;
|
118
|
}else if (dbType == DatabaseTypeEnum.PostgreSQL){
|
119
|
server = serverSql;
|
120
|
username = "postgres";
|
121
|
CdmDataSource dataSource = CdmDataSource.NewPostgreSQLInstance(server, database, 5432, username, AccountStore.readOrStorePassword(server, database, username, null));
|
122
|
return dataSource;
|
123
|
}else{
|
124
|
throw new IllegalArgumentException("dbType not supported:" + dbType);
|
125
|
}
|
126
|
}
|
127
|
|
128
|
|
129
|
|
130
|
/**
|
131
|
* Updates the H2 test database in remote web-app.
|
132
|
* Requires that the local path to the database is adapted
|
133
|
*/
|
134
|
@SuppressWarnings("unused") //enable only if needed
|
135
|
private void updateRemoteWebappTestH2(){
|
136
|
String pathToProject = "C:\\Users\\a.mueller\\eclipse\\git\\cdmlib\\cdmlib-remote-webapp\\";
|
137
|
// String pathToProject = "C:\\Users\\a.mueller\\eclipse\\git\\cdm-vaadin\\";
|
138
|
// String pathToProject = "C:\\Users\\a.mueller\\eclipse\\git\\taxeditor2\\eu.etaxonomy.taxeditor.test\\";
|
139
|
|
140
|
String pathInProject = "src\\test\\resources\\h2";
|
141
|
|
142
|
String path = pathToProject + pathInProject;
|
143
|
ICdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", "sa", "", path);
|
144
|
|
145
|
|
146
|
try {
|
147
|
CdmUpdater updater = new CdmUpdater();
|
148
|
SchemaUpdateResult result = updater.updateToCurrentVersion(dataSource, DefaultProgressMonitor.NewInstance());
|
149
|
System.out.println(result.createReport());
|
150
|
} catch (Exception e) {
|
151
|
e.printStackTrace();
|
152
|
}
|
153
|
|
154
|
//CdmPersistentDataSource.save(dataSource.getName(), dataSource);
|
155
|
CdmApplicationController appCtr;
|
156
|
appCtr = CdmApplicationController.NewInstance(dataSource,DbSchemaValidation.VALIDATE);
|
157
|
appCtr.close();
|
158
|
System.out.println("\nEnd Datasource");
|
159
|
System.exit(0);
|
160
|
}
|
161
|
|
162
|
@SuppressWarnings("unused") //enable only if needed
|
163
|
private void updateEdaphobasePostgres(){
|
164
|
String serverSql = "130.133.70.26";
|
165
|
String database = "cdm_edaphobase";
|
166
|
int port = 5433;
|
167
|
String username = "edaphobase";
|
168
|
String password = AccountStore.readOrStorePassword(database, serverSql, username, null);
|
169
|
|
170
|
ICdmDataSource dataSource = CdmDataSource.NewPostgreSQLInstance(serverSql,
|
171
|
database, port, username, password);
|
172
|
|
173
|
try {
|
174
|
CdmUpdater updater = new CdmUpdater();
|
175
|
SchemaUpdateResult result = updater.updateToCurrentVersion(dataSource, DefaultProgressMonitor.NewInstance());
|
176
|
System.out.println(result.createReport());
|
177
|
} catch (Exception e) {
|
178
|
e.printStackTrace();
|
179
|
}
|
180
|
|
181
|
//CdmPersistentDataSource.save(dataSource.getName(), dataSource);
|
182
|
CdmApplicationController appCtr;
|
183
|
appCtr = CdmApplicationController.NewInstance(dataSource,DbSchemaValidation.VALIDATE);
|
184
|
appCtr.close();
|
185
|
System.out.println("\nEnd Datasource");
|
186
|
System.exit(0);
|
187
|
}
|
188
|
|
189
|
|
190
|
private void test(){
|
191
|
System.out.println("Start TestModelUpdate");
|
192
|
testSelectedDb();
|
193
|
|
194
|
// updateRemoteWebappTestH2(); //also updates vaadin and taxeditor model
|
195
|
// updateEdaphobasePostgres();
|
196
|
|
197
|
System.out.println("\nEnd Datasource");
|
198
|
}
|
199
|
|
200
|
/**
|
201
|
* @param args
|
202
|
*/
|
203
|
public static void main(String[] args) {
|
204
|
TestModelUpdate cc = new TestModelUpdate();
|
205
|
cc.test();
|
206
|
}
|
207
|
|
208
|
}
|