1 |
335dbebe
|
Andreas Müller
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
c483dd7e
|
Katja Luther
|
* European Distributed Institute of Taxonomy
|
4 |
335dbebe
|
Andreas Müller
|
* http://www.e-taxonomy.eu
|
5 |
c483dd7e
|
Katja Luther
|
*
|
6 |
335dbebe
|
Andreas Müller
|
* 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.app.common;
|
11 |
|
|
|
12 |
|
|
import java.lang.reflect.InvocationTargetException;
|
13 |
|
|
import java.lang.reflect.Method;
|
14 |
|
|
|
15 |
|
|
import org.apache.log4j.Logger;
|
16 |
|
|
|
17 |
|
|
import eu.etaxonomy.cdm.common.AccountStore;
|
18 |
|
|
import eu.etaxonomy.cdm.database.CdmDataSource;
|
19 |
|
|
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
|
20 |
|
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
21 |
|
|
|
22 |
|
|
public class CdmDestinations {
|
23 |
|
|
@SuppressWarnings("unused")
|
24 |
|
|
private static Logger logger = Logger.getLogger(CdmDestinations.class);
|
25 |
|
|
|
26 |
|
|
public static ICdmDataSource cdm_test_local_mysql(){
|
27 |
|
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
28 |
|
|
String cdmServer = "127.0.0.1";
|
29 |
c483dd7e
|
Katja Luther
|
String cdmDB = "cdm_test";
|
30 |
ecee792d
|
Andreas Müller
|
String cdmUserName = "root";
|
31 |
335dbebe
|
Andreas Müller
|
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
|
32 |
|
|
}
|
33 |
c483dd7e
|
Katja Luther
|
|
34 |
d9894eaf
|
Katja Luther
|
public static ICdmDataSource cdm_test_local_faunaEu_mysql(){
|
35 |
|
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
36 |
|
|
String cdmServer = "127.0.0.1";
|
37 |
f9288024
|
Katja Luther
|
String cdmDB = "cdm_faunaeu_2017_03";
|
38 |
d9894eaf
|
Katja Luther
|
String cdmUserName = "root";
|
39 |
|
|
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
|
40 |
|
|
}
|
41 |
335dbebe
|
Andreas Müller
|
|
42 |
c483dd7e
|
Katja Luther
|
|
43 |
cf13b0cd
|
Andreas Müller
|
public static ICdmDataSource cdm_test_local_indexFungorum(){
|
44 |
335dbebe
|
Andreas Müller
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
45 |
|
|
String cdmServer = "127.0.0.1";
|
46 |
c483dd7e
|
Katja Luther
|
String cdmDB = "indexFungorum";
|
47 |
cf13b0cd
|
Andreas Müller
|
String cdmUserName = "root";
|
48 |
335dbebe
|
Andreas Müller
|
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
|
49 |
|
|
}
|
50 |
c483dd7e
|
Katja Luther
|
|
51 |
|
|
|
52 |
05907bae
|
Andreas Müller
|
public static ICdmDataSource cdm_test_local_mysql_erms(){
|
53 |
|
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
54 |
|
|
String cdmServer = "127.0.0.1";
|
55 |
43142f39
|
Andreas Müller
|
String cdmDB = "pesi_erms";
|
56 |
|
|
String cdmUserName = "edit";
|
57 |
8ebb95fc
|
Andreas Müller
|
return CdmDestinations.makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
|
58 |
|
|
}
|
59 |
c483dd7e
|
Katja Luther
|
|
60 |
|
|
|
61 |
335dbebe
|
Andreas Müller
|
public static ICdmDataSource cdm_test_local_mysql_test(){
|
62 |
|
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
63 |
|
|
String cdmServer = "127.0.0.1";
|
64 |
c483dd7e
|
Katja Luther
|
String cdmDB = "test";
|
65 |
335dbebe
|
Andreas Müller
|
String cdmUserName = "edit";
|
66 |
|
|
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
|
67 |
|
|
}
|
68 |
|
|
public static ICdmDataSource cdm_portal_test_localhost(){
|
69 |
|
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
70 |
|
|
String cdmServer = "127.0.0.1";
|
71 |
|
|
String cdmDB = "cdm_portal_test";
|
72 |
|
|
String cdmUserName = "edit";
|
73 |
|
|
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
|
74 |
|
|
}
|
75 |
c483dd7e
|
Katja Luther
|
|
76 |
335dbebe
|
Andreas Müller
|
public static ICdmDataSource cdm_portal_test_localhost2(){
|
77 |
|
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
78 |
|
|
String cdmServer = "127.0.0.1";
|
79 |
|
|
String cdmDB = "cdm_portal_test2";
|
80 |
|
|
String cdmUserName = "edit";
|
81 |
|
|
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
|
82 |
|
|
}
|
83 |
ecee792d
|
Andreas Müller
|
|
84 |
335dbebe
|
Andreas Müller
|
public static ICdmDataSource cdm_local_postgres_CdmTest(){
|
85 |
|
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.PostgreSQL;
|
86 |
|
|
String cdmServer = "127.0.0.1";
|
87 |
|
|
String cdmDB = "CdmTest";
|
88 |
|
|
String cdmUserName = "edit";
|
89 |
|
|
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
|
90 |
|
|
}
|
91 |
c483dd7e
|
Katja Luther
|
|
92 |
|
|
|
93 |
335dbebe
|
Andreas Müller
|
public static ICdmDataSource NULL(){
|
94 |
|
|
return null;
|
95 |
|
|
}
|
96 |
c483dd7e
|
Katja Luther
|
|
97 |
|
|
|
98 |
335dbebe
|
Andreas Müller
|
public static ICdmDataSource localH2(){
|
99 |
|
|
return CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", "");
|
100 |
|
|
}
|
101 |
c483dd7e
|
Katja Luther
|
|
102 |
335dbebe
|
Andreas Müller
|
public static ICdmDataSource localH2EuroMed(){
|
103 |
|
|
return CdmDataSource.NewH2EmbeddedInstance("euroMed", "sa", "");
|
104 |
|
|
}
|
105 |
c483dd7e
|
Katja Luther
|
|
106 |
335dbebe
|
Andreas Müller
|
public static ICdmDataSource localH2Erms(){
|
107 |
|
|
return CdmDataSource.NewH2EmbeddedInstance("erms", "sa", "");
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
public static ICdmDataSource cdm_algaterra_preview(){
|
111 |
|
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
112 |
|
|
String cdmServer = "160.45.63.201";
|
113 |
c483dd7e
|
Katja Luther
|
String cdmDB = "cdm_edit_algaterra";
|
114 |
335dbebe
|
Andreas Müller
|
String cdmUserName = "edit";
|
115 |
|
|
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
|
116 |
|
|
}
|
117 |
ecee792d
|
Andreas Müller
|
|
118 |
13ed367b
|
Andreas Müller
|
|
119 |
b54f16a7
|
Andreas Müller
|
public static ICdmDataSource cdm_pesi_euroMed(){
|
120 |
13ed367b
|
Andreas Müller
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
121 |
152d9fee
|
Andreas Müller
|
String cdmServer = "160.45.63.175";
|
122 |
c483dd7e
|
Katja Luther
|
String cdmDB = "cdm_pesi_euromed";
|
123 |
13ed367b
|
Andreas Müller
|
String cdmUserName = "edit";
|
124 |
|
|
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
|
125 |
|
|
}
|
126 |
335dbebe
|
Andreas Müller
|
|
127 |
b54f16a7
|
Andreas Müller
|
public static ICdmDataSource cdm_pesi_fauna_europaea(){
|
128 |
|
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
129 |
152d9fee
|
Andreas Müller
|
String cdmServer = "160.45.63.175";
|
130 |
c483dd7e
|
Katja Luther
|
String cdmDB = "cdm_pesi_fauna_europaea";
|
131 |
b54f16a7
|
Andreas Müller
|
String cdmUserName = "edit";
|
132 |
|
|
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
|
133 |
|
|
}
|
134 |
c483dd7e
|
Katja Luther
|
|
135 |
b54f16a7
|
Andreas Müller
|
|
136 |
|
|
public static ICdmDataSource cdm_pesi_erms(){
|
137 |
|
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
138 |
152d9fee
|
Andreas Müller
|
String cdmServer = "160.45.63.175";
|
139 |
c483dd7e
|
Katja Luther
|
String cdmDB = "cdm_pesi_erms";
|
140 |
b54f16a7
|
Andreas Müller
|
String cdmUserName = "edit";
|
141 |
|
|
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
|
142 |
|
|
}
|
143 |
|
|
|
144 |
c483dd7e
|
Katja Luther
|
|
145 |
335dbebe
|
Andreas Müller
|
/**
|
146 |
|
|
* initializes source
|
147 |
|
|
* TODO only supports MySQL and PostgreSQL
|
148 |
c483dd7e
|
Katja Luther
|
*
|
149 |
335dbebe
|
Andreas Müller
|
* @param dbType
|
150 |
|
|
* @param cdmServer
|
151 |
|
|
* @param cdmDB
|
152 |
|
|
* @param port
|
153 |
|
|
* @param cdmUserName
|
154 |
|
|
* @param pwd
|
155 |
|
|
* @return
|
156 |
|
|
*/
|
157 |
818b8a04
|
Andreas Müller
|
public static ICdmDataSource makeDestination(DatabaseTypeEnum dbType, String cdmServer, String cdmDB, int port, String cdmUserName, String pwd ){
|
158 |
335dbebe
|
Andreas Müller
|
//establish connection
|
159 |
|
|
pwd = AccountStore.readOrStorePassword(cdmServer, cdmDB, cdmUserName, pwd);
|
160 |
|
|
ICdmDataSource destination;
|
161 |
|
|
if(dbType.equals(DatabaseTypeEnum.MySQL)){
|
162 |
a4947270
|
Andreas Müller
|
destination = CdmDataSource.NewMySqlInstance(cdmServer, cdmDB, port, cdmUserName, pwd);
|
163 |
335dbebe
|
Andreas Müller
|
} else if(dbType.equals(DatabaseTypeEnum.PostgreSQL)){
|
164 |
a4947270
|
Andreas Müller
|
destination = CdmDataSource.NewPostgreSQLInstance(cdmServer, cdmDB, port, cdmUserName, pwd);
|
165 |
335dbebe
|
Andreas Müller
|
} else {
|
166 |
|
|
//TODO others
|
167 |
|
|
throw new RuntimeException("Unsupported DatabaseType");
|
168 |
|
|
}
|
169 |
|
|
return destination;
|
170 |
|
|
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
/**
|
175 |
c483dd7e
|
Katja Luther
|
* Accepts a string array and tries to find a method returning an ICdmDataSource with
|
176 |
335dbebe
|
Andreas Müller
|
* the name of the given first string in the array
|
177 |
c483dd7e
|
Katja Luther
|
*
|
178 |
335dbebe
|
Andreas Müller
|
* @param args
|
179 |
|
|
* @return
|
180 |
|
|
*/
|
181 |
|
|
public static ICdmDataSource chooseDestination(String[] args) {
|
182 |
c483dd7e
|
Katja Luther
|
if(args == null) {
|
183 |
|
|
return null;
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
if(args.length != 1) {
|
187 |
|
|
return null;
|
188 |
|
|
}
|
189 |
|
|
|
190 |
335dbebe
|
Andreas Müller
|
String possibleDestination = args[0];
|
191 |
c483dd7e
|
Katja Luther
|
|
192 |
335dbebe
|
Andreas Müller
|
Method[] methods = CdmDestinations.class.getMethods();
|
193 |
c483dd7e
|
Katja Luther
|
|
194 |
335dbebe
|
Andreas Müller
|
for (Method method : methods){
|
195 |
|
|
if(method.getName().equals(possibleDestination)){
|
196 |
|
|
try {
|
197 |
|
|
return (ICdmDataSource) method.invoke(null, null);
|
198 |
|
|
} catch (IllegalArgumentException e) {
|
199 |
|
|
// TODO Auto-generated catch block
|
200 |
|
|
e.printStackTrace();
|
201 |
|
|
} catch (IllegalAccessException e) {
|
202 |
|
|
// TODO Auto-generated catch block
|
203 |
|
|
e.printStackTrace();
|
204 |
|
|
} catch (InvocationTargetException e) {
|
205 |
|
|
// TODO Auto-generated catch block
|
206 |
|
|
e.printStackTrace();
|
207 |
|
|
}
|
208 |
|
|
}
|
209 |
|
|
}
|
210 |
|
|
return null;
|
211 |
|
|
}
|
212 |
c483dd7e
|
Katja Luther
|
|
213 |
335dbebe
|
Andreas Müller
|
}
|