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.AccountStore;
|
16 |
|
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
|
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.model.name.NomenclaturalCode;
|
23 |
|
|
24 |
|
/**
|
25 |
|
* This class is meant for functional testing of model changes. It is not meant
|
26 |
|
* for running in maven.
|
27 |
|
* @author a.mueller
|
28 |
|
* @date 22.05.2015
|
29 |
|
*
|
30 |
|
*/
|
31 |
|
public class TestModelUpdate {
|
32 |
|
@SuppressWarnings("unused")
|
33 |
|
private static final Logger logger = Logger.getLogger(TestModelUpdate.class);
|
34 |
|
|
35 |
|
|
36 |
|
private void testSelectedDb(){
|
37 |
|
DbSchemaValidation schema = DbSchemaValidation.VALIDATE;
|
38 |
|
|
39 |
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.PostgreSQL;
|
40 |
|
|
41 |
|
|
42 |
|
String database = (schema == DbSchemaValidation.VALIDATE ? "cdm35" : "cdm36");
|
43 |
|
// database = "cdm36";
|
44 |
|
CdmDataSource dataSource = getDatasource(dbType, database);
|
45 |
|
|
46 |
|
|
47 |
|
try {
|
48 |
|
CdmUpdater updater = new CdmUpdater();
|
49 |
|
if (schema == DbSchemaValidation.VALIDATE){
|
50 |
|
updater.updateToCurrentVersion(dataSource, DefaultProgressMonitor.NewInstance());
|
51 |
|
}
|
52 |
|
} catch (Exception e) {
|
53 |
|
e.printStackTrace();
|
54 |
|
}
|
55 |
|
|
56 |
|
CdmApplicationController appCtr = CdmApplicationController.NewInstance(dataSource,schema);
|
57 |
|
|
58 |
|
// Classification classification = Classification.NewInstance("Me");
|
59 |
|
// Taxon taxon = Taxon.NewInstance(null, null);
|
60 |
|
// Person person = Person.NewInstance();
|
61 |
|
// TaxonNode node = classification.addChildTaxon(taxon, null, null);
|
62 |
|
// DefinedTerm lastScrutiny = (DefinedTerm)appCtr.getTermService().find(DefinedTerm.uuidLastScrutiny);
|
63 |
|
// TaxonNodeAgentRelation rel = node.addAgentRelation(lastScrutiny, person);
|
64 |
|
// appCtr.getClassificationService().save(classification);
|
65 |
|
|
66 |
|
// appCtr.getCommonService().createFullSampleData();
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
appCtr.close();
|
71 |
|
}
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
/**
|
76 |
|
* @param dbType
|
77 |
|
* @param database
|
78 |
|
* @return
|
79 |
|
*/
|
80 |
|
private CdmDataSource getDatasource(DatabaseTypeEnum dbType, String database) {
|
81 |
|
String server = "localhost";
|
82 |
|
String username = "edit";
|
83 |
|
String serverSql = "130.133.70.26";
|
84 |
|
|
85 |
|
if (dbType == DatabaseTypeEnum.MySQL){
|
86 |
|
return CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
|
87 |
|
}else if (dbType == DatabaseTypeEnum.H2){
|
88 |
|
//H2
|
89 |
|
String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2_" + database;
|
90 |
|
username = "sa";
|
91 |
|
CdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", username, "", path, NomenclaturalCode.ICNAFP);
|
92 |
|
return dataSource;
|
93 |
|
}else if (dbType == DatabaseTypeEnum.SqlServer2005){
|
94 |
|
server = serverSql;
|
95 |
|
username = "cdmupdater";
|
96 |
|
CdmDataSource dataSource = CdmDataSource.NewSqlServer2005Instance(server, database, 1433, username, AccountStore.readOrStorePassword(server, database, username, null));
|
97 |
|
return dataSource;
|
98 |
|
}else if (dbType == DatabaseTypeEnum.PostgreSQL){
|
99 |
|
server = serverSql;
|
100 |
|
username = "postgres";
|
101 |
|
CdmDataSource dataSource = CdmDataSource.NewPostgreSQLInstance(server, database, 5432, username, AccountStore.readOrStorePassword(server, database, username, null), null);
|
102 |
|
return dataSource;
|
103 |
|
}else{
|
104 |
|
throw new IllegalArgumentException("dbType not supported:" + dbType);
|
105 |
|
}
|
106 |
|
}
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
/**
|
111 |
|
* Updates the H2 test database in remote web-app.
|
112 |
|
* Requires that the local path to the database is adapted
|
113 |
|
*/
|
114 |
|
@SuppressWarnings("unused") //enable only if needed
|
115 |
|
private void updateRemoteWebappTestH2(){
|
116 |
|
String path = "C:\\Users\\a.mueller\\eclipse\\svn\\cdmlib-trunk\\cdmlib\\cdmlib-remote-webapp\\src\\test\\resources\\h2";
|
117 |
|
ICdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", "sa", "", path, NomenclaturalCode.ICNAFP);
|
118 |
|
|
119 |
|
|
120 |
|
try {
|
121 |
|
CdmUpdater updater = new CdmUpdater();
|
122 |
|
updater.updateToCurrentVersion(dataSource, DefaultProgressMonitor.NewInstance());
|
123 |
|
} catch (Exception e) {
|
124 |
|
e.printStackTrace();
|
125 |
|
}
|
126 |
|
|
127 |
|
//CdmPersistentDataSource.save(dataSource.getName(), dataSource);
|
128 |
|
CdmApplicationController appCtr;
|
129 |
|
appCtr = CdmApplicationController.NewInstance(dataSource,DbSchemaValidation.VALIDATE);
|
130 |
|
appCtr.close();
|
131 |
|
}
|
132 |
|
|
133 |
|
|
134 |
|
private void test(){
|
135 |
|
System.out.println("Start Datasource");
|
136 |
|
testSelectedDb();
|
137 |
|
|
138 |
|
// updateRemoteWebappTestH2();
|
139 |
|
|
140 |
|
System.out.println("\nEnd Datasource");
|
141 |
|
}
|
142 |
|
|
143 |
|
/**
|
144 |
|
* @param args
|
145 |
|
*/
|
146 |
|
public static void main(String[] args) {
|
147 |
|
TestModelUpdate cc = new TestModelUpdate();
|
148 |
|
cc.test();
|
149 |
|
}
|
150 |
|
|
151 |
|
}
|
|
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.AccountStore;
|
|
16 |
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
|
|
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.model.name.NomenclaturalCode;
|
|
23 |
|
|
24 |
/**
|
|
25 |
* This class is meant for functional testing of model changes. It is not meant
|
|
26 |
* for running in maven.
|
|
27 |
* @author a.mueller
|
|
28 |
* @date 22.05.2015
|
|
29 |
*
|
|
30 |
*/
|
|
31 |
public class TestModelUpdate {
|
|
32 |
@SuppressWarnings("unused")
|
|
33 |
private static final Logger logger = Logger.getLogger(TestModelUpdate.class);
|
|
34 |
|
|
35 |
|
|
36 |
private void testSelectedDb(){
|
|
37 |
DbSchemaValidation schema = DbSchemaValidation.VALIDATE;
|
|
38 |
|
|
39 |
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
|
40 |
|
|
41 |
|
|
42 |
String database = (schema == DbSchemaValidation.VALIDATE ? "cdm36" : "cdm40");
|
|
43 |
// database = "cdm36";
|
|
44 |
CdmDataSource dataSource = getDatasource(dbType, database);
|
|
45 |
|
|
46 |
|
|
47 |
try {
|
|
48 |
CdmUpdater updater = new CdmUpdater();
|
|
49 |
if (schema == DbSchemaValidation.VALIDATE){
|
|
50 |
updater.updateToCurrentVersion(dataSource, DefaultProgressMonitor.NewInstance());
|
|
51 |
}
|
|
52 |
} catch (Exception e) {
|
|
53 |
e.printStackTrace();
|
|
54 |
}
|
|
55 |
|
|
56 |
CdmApplicationController appCtr = CdmApplicationController.NewInstance(dataSource,schema);
|
|
57 |
|
|
58 |
// Classification classification = Classification.NewInstance("Me");
|
|
59 |
// Taxon taxon = Taxon.NewInstance(null, null);
|
|
60 |
// Person person = Person.NewInstance();
|
|
61 |
// TaxonNode node = classification.addChildTaxon(taxon, null, null);
|
|
62 |
// DefinedTerm lastScrutiny = (DefinedTerm)appCtr.getTermService().find(DefinedTerm.uuidLastScrutiny);
|
|
63 |
// TaxonNodeAgentRelation rel = node.addAgentRelation(lastScrutiny, person);
|
|
64 |
// appCtr.getClassificationService().save(classification);
|
|
65 |
|
|
66 |
// appCtr.getCommonService().createFullSampleData();
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
appCtr.close();
|
|
71 |
}
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
/**
|
|
76 |
* @param dbType
|
|
77 |
* @param database
|
|
78 |
* @return
|
|
79 |
*/
|
|
80 |
private CdmDataSource getDatasource(DatabaseTypeEnum dbType, String database) {
|
|
81 |
String server = "localhost";
|
|
82 |
String username = "edit";
|
|
83 |
String serverSql = "130.133.70.26";
|
|
84 |
|
|
85 |
if (dbType == DatabaseTypeEnum.MySQL){
|
|
86 |
return CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
|
|
87 |
}else if (dbType == DatabaseTypeEnum.H2){
|
|
88 |
//H2
|
|
89 |
String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2_" + database;
|
|
90 |
username = "sa";
|
|
91 |
CdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", username, "", path, NomenclaturalCode.ICNAFP);
|
|
92 |
return dataSource;
|
|
93 |
}else if (dbType == DatabaseTypeEnum.SqlServer2005){
|
|
94 |
server = serverSql;
|
|
95 |
username = "cdmupdater";
|
|
96 |
CdmDataSource dataSource = CdmDataSource.NewSqlServer2005Instance(server, database, 1433, username, AccountStore.readOrStorePassword(server, database, username, null));
|
|
97 |
return dataSource;
|
|
98 |
}else if (dbType == DatabaseTypeEnum.PostgreSQL){
|
|
99 |
server = serverSql;
|
|
100 |
username = "postgres";
|
|
101 |
CdmDataSource dataSource = CdmDataSource.NewPostgreSQLInstance(server, database, 5432, username, AccountStore.readOrStorePassword(server, database, username, null), null);
|
|
102 |
return dataSource;
|
|
103 |
}else{
|
|
104 |
throw new IllegalArgumentException("dbType not supported:" + dbType);
|
|
105 |
}
|
|
106 |
}
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
/**
|
|
111 |
* Updates the H2 test database in remote web-app.
|
|
112 |
* Requires that the local path to the database is adapted
|
|
113 |
*/
|
|
114 |
@SuppressWarnings("unused") //enable only if needed
|
|
115 |
private void updateRemoteWebappTestH2(){
|
|
116 |
String path = "C:\\Users\\a.mueller\\eclipse\\svn\\cdmlib-trunk\\cdmlib\\cdmlib-remote-webapp\\src\\test\\resources\\h2";
|
|
117 |
ICdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", "sa", "", path, NomenclaturalCode.ICNAFP);
|
|
118 |
|
|
119 |
|
|
120 |
try {
|
|
121 |
CdmUpdater updater = new CdmUpdater();
|
|
122 |
updater.updateToCurrentVersion(dataSource, DefaultProgressMonitor.NewInstance());
|
|
123 |
} catch (Exception e) {
|
|
124 |
e.printStackTrace();
|
|
125 |
}
|
|
126 |
|
|
127 |
//CdmPersistentDataSource.save(dataSource.getName(), dataSource);
|
|
128 |
CdmApplicationController appCtr;
|
|
129 |
appCtr = CdmApplicationController.NewInstance(dataSource,DbSchemaValidation.VALIDATE);
|
|
130 |
appCtr.close();
|
|
131 |
}
|
|
132 |
|
|
133 |
|
|
134 |
private void test(){
|
|
135 |
System.out.println("Start Datasource");
|
|
136 |
testSelectedDb();
|
|
137 |
|
|
138 |
// updateRemoteWebappTestH2();
|
|
139 |
|
|
140 |
System.out.println("\nEnd Datasource");
|
|
141 |
}
|
|
142 |
|
|
143 |
/**
|
|
144 |
* @param args
|
|
145 |
*/
|
|
146 |
public static void main(String[] args) {
|
|
147 |
TestModelUpdate cc = new TestModelUpdate();
|
|
148 |
cc.test();
|
|
149 |
}
|
|
150 |
|
|
151 |
}
|
Remove Autoincrement on AuditEvent.revisionnumber on MySQL #5718