2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.app
.eflora
;
12 import java
.lang
.reflect
.InvocationTargetException
;
13 import java
.lang
.reflect
.Method
;
15 import org
.apache
.log4j
.Logger
;
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
;
22 public class CdmDestinations
{
23 @SuppressWarnings("unused")
24 private static Logger logger
= Logger
.getLogger(CdmDestinations
.class);
27 * Intended to be used for imports
29 public static ICdmDataSource
import_a(){
30 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
31 String cdmServer
= "localhost";
32 String cdmDB
= "import_a";
33 String cdmUserName
= "root";
34 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
37 public static ICdmDataSource
cdm_test_local_mysql(){
38 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
39 String cdmServer
= "127.0.0.1";
40 String cdmDB
= "cdm_test";
41 String cdmUserName
= "root";
42 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
45 public static ICdmDataSource
cdm_test_local_mysql_fdac(){
46 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
47 String cdmServer
= "127.0.0.1";
48 String cdmDB
= "fdac";
49 String cdmUserName
= "edit";
50 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
53 public static ICdmDataSource
cdm_test_local_mysql_test(){
54 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
55 String cdmServer
= "127.0.0.1";
56 String cdmDB
= "test";
57 String cdmUserName
= "edit";
58 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
61 public static ICdmDataSource
cdm_test_local_fdac(){
62 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
63 String cdmServer
= "127.0.0.1";
64 String cdmDB
= "fdac";
65 String cdmUserName
= "root";
66 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
69 public static ICdmDataSource
cdm_ildis_dev(){
70 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
71 String cdmServer
= "160.45.63.201";
72 String cdmDB
= "cdm_edit_ildis";
73 String cdmUserName
= "edit";
74 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
78 public static ICdmDataSource
cdm_campanulaceae_production(){
79 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
80 String cdmServer
= "160.45.63.171";
81 String cdmDB
= "cdm_production_campanulaceae";
82 String cdmUserName
= "edit";
83 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
86 public static ICdmDataSource
cdm_flora_malesiana_preview(){
87 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
88 String cdmServer
= "160.45.63.175";
89 String cdmDB
= "cdm_edit_flora_malesiana";
90 String cdmUserName
= "edit";
91 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
94 public static ICdmDataSource
cdm_flora_malesiana_production(){
95 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
96 String cdmServer
= "160.45.63.171";
97 String cdmDB
= "cdm_production_flora_malesiana";
98 String cdmUserName
= "edit";
99 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
102 public static ICdmDataSource
cdm_flora_malesiana_prospective_production(){
103 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
104 String cdmServer
= "160.45.63.171";
105 String cdmDB
= "cdm_production_flora_malesiana_prospective";
106 String cdmUserName
= "edit";
107 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
111 public static ICdmDataSource
cdm_flora_guianas_preview(){
112 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
113 String cdmServer
= "160.45.63.175";
114 String cdmDB
= "cdm_flora_guianas";
115 String cdmUserName
= "edit";
116 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
119 public static ICdmDataSource
cdm_flora_guianas_production(){
120 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
121 String cdmServer
= "160.45.63.171";
122 String cdmDB
= "cdm_production_flora_guianas";
123 String cdmUserName
= "edit";
124 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
127 public static ICdmDataSource
cdm_flore_gabon_preview(){
128 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
129 String cdmServer
= "160.45.63.175";
130 String cdmDB
= "cdm_flore_gabon";
131 String cdmUserName
= "edit";
132 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
135 public static ICdmDataSource
cdm_flore_gabon_production(){
136 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
137 String cdmServer
= "160.45.63.171";
138 String cdmDB
= "cdm_production_flore_gabon";
139 String cdmUserName
= "edit";
140 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
144 public static ICdmDataSource
cdm_flora_central_africa_preview(){
145 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
146 String cdmServer
= "160.45.63.175";
147 String cdmDB
= "cdm_edit_flora_central_africa";
148 String cdmUserName
= "edit";
149 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
152 public static ICdmDataSource
cdm_flora_central_africa_production(){
153 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
154 String cdmServer
= "160.45.63.171";
155 String cdmDB
= "cdm_production_flora_central_africa";
156 String cdmUserName
= "edit";
157 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
160 public static ICdmDataSource
cdm_portal_test_localhost(){
161 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
162 String cdmServer
= "127.0.0.1";
163 String cdmDB
= "cdm_portal_test";
164 String cdmUserName
= "edit";
165 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
168 public static ICdmDataSource
cdm_portal_test_localhost2(){
169 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
170 String cdmServer
= "127.0.0.1";
171 String cdmDB
= "cdm_portal_test2";
172 String cdmUserName
= "edit";
173 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
176 public static ICdmDataSource
cdm_local_postgres_CdmTest(){
177 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.PostgreSQL
;
178 String cdmServer
= "127.0.0.1";
179 String cdmDB
= "CdmTest";
180 String cdmUserName
= "edit";
181 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
186 public static ICdmDataSource
NULL(){
191 public static ICdmDataSource
localH2(){
192 return CdmDataSource
.NewH2EmbeddedInstance("cdm", "sa", "");
195 public static ICdmDataSource
localH2(String database
, String username
, String filePath
){
196 return CdmDataSource
.NewH2EmbeddedInstance(database
, "sa", "", filePath
, null);
199 public static ICdmDataSource
localH2Salvador(){
200 return CdmDataSource
.NewH2EmbeddedInstance("salvador", "sa", "");
203 public static ICdmDataSource
localH2Diptera(){
204 return CdmDataSource
.NewH2EmbeddedInstance("diptera", "sa", "");
208 public static ICdmDataSource
localH2Cichorieae(){
209 return CdmDataSource
.NewH2EmbeddedInstance("cichorieae", "sa", "");
212 public static ICdmDataSource
localH2Palmae(){
213 return CdmDataSource
.NewH2EmbeddedInstance("palmae", "sa", "");
216 public static ICdmDataSource
localH2EuroMed(){
217 return CdmDataSource
.NewH2EmbeddedInstance("euroMed", "sa", "");
220 public static ICdmDataSource
localH2Erms(){
221 return CdmDataSource
.NewH2EmbeddedInstance("erms", "sa", "");
224 public static ICdmDataSource
localH2_viola(){
225 return CdmDataSource
.NewH2EmbeddedInstance("testViola", "sa", "");
228 public static ICdmDataSource
localH2_LIAS(){
229 return CdmDataSource
.NewH2EmbeddedInstance("testLIAS", "sa", "");
232 public static ICdmDataSource
localH2_Erythroneura(){
233 return CdmDataSource
.NewH2EmbeddedInstance("testErythroneura", "sa", "");
236 public static ICdmDataSource
localH2_Cicad(){
237 return CdmDataSource
.NewH2EmbeddedInstance("testCicad", "sa", "");
240 public static ICdmDataSource
localH2_ValRosandraFRIDAKey(){
241 return CdmDataSource
.NewH2EmbeddedInstance("testValRosandraFRIDAKey", "sa", "");
244 public static ICdmDataSource
localH2_FreshwaterAquaticInsects(){
245 return CdmDataSource
.NewH2EmbeddedInstance("testFreshwaterAquaticInsects", "sa", "");
248 public static ICdmDataSource
cdm_portal_test_pollux(){
249 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
250 String cdmServer
= "192.168.2.11";
251 String cdmDB
= "cdm_portal_test";
252 String cdmUserName
= "edit";
253 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
256 public static ICdmDataSource
cdm_algaterra_preview(){
257 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
258 String cdmServer
= "160.45.63.201";
259 String cdmDB
= "cdm_edit_algaterra";
260 String cdmUserName
= "edit";
261 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
264 public static ICdmDataSource
cdm_edit_cichorieae_PG(){
265 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.PostgreSQL
;
266 String cdmServer
= "127.0.0.1";
267 String cdmDB
= "cdm_edit_cichorieae_a";
268 String cdmUserName
= "edit";
270 return makeDestination(dbType
, cdmServer
, cdmDB
, port
, cdmUserName
, null);
273 public static ICdmDataSource
cdm_cichorieae_preview(){
274 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
275 String cdmServer
= "160.45.63.201";
276 String cdmDB
= "cdm_edit_cichorieae";
277 String cdmUserName
= "edit";
278 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
281 public static ICdmDataSource
cdm_production_cichorieae(){
282 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
283 String cdmServer
= "160.45.63.151";
284 // String cdmServer = "127.0.0.1";
285 String cdmDB
= "cdm_production_cichorieae";
286 String cdmUserName
= "edit";
287 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
290 public static ICdmDataSource
cdm_production_palmae(){
291 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
292 String cdmServer
= "160.45.63.151";
293 String cdmDB
= "cdm_production_palmae";
294 String cdmUserName
= "edit";
295 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
299 public static ICdmDataSource
cdm_production_diptera(){
300 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
301 String cdmServer
= "160.45.63.151";
302 String cdmDB
= "cdm_production_diptera";
303 String cdmUserName
= "edit";
304 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
307 public static ICdmDataSource
local_cdm_edit_cichorieae_a(){
308 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
309 String cdmServer
= "127.0.0.1";
310 String cdmDB
= "cdm_edit_cichorieae_a";
311 String cdmUserName
= "edit";
312 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
315 public static ICdmDataSource
local_cdm_edit_cichorieae_b(){
316 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
317 String cdmServer
= "127.0.0.1";
318 String cdmDB
= "cdm_edit_cichorieae_b";
319 String cdmUserName
= "edit";
320 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
323 public static ICdmDataSource
cdm_edit_palmae_a(){
324 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
325 String cdmServer
= "192.168.2.10";
326 String cdmDB
= "cdm_edit_palmae_a";
327 String cdmUserName
= "edit";
328 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
331 public static ICdmDataSource
cdm_edit_diptera_preview_B(){
332 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
333 String cdmServer
= "127.0.0.1";
334 String cdmDB
= "cdm_edit_diptera_b";
335 String cdmUserName
= "edit";
337 return makeDestination(dbType
, cdmServer
, cdmDB
, port
, cdmUserName
, null);
340 public static ICdmDataSource
cdm_edit_cichorieae_preview(){
341 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
342 String cdmServer
= "127.0.0.1";
343 String cdmDB
= "cdm_edit_cichorieae";
344 String cdmUserName
= "edit";
346 return makeDestination(dbType
, cdmServer
, cdmDB
, port
, cdmUserName
, null);
349 public static ICdmDataSource
cdm_edit_palmae_preview(){
350 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
351 String cdmServer
= "127.0.0.1";
352 String cdmDB
= "cdm_edit_palmae";
353 String cdmUserName
= "edit";
355 return makeDestination(dbType
, cdmServer
, cdmDB
, port
, cdmUserName
, null);
358 public static ICdmDataSource
cdm_edit_salvador(){
359 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
360 String cdmServer
= "192.168.2.10";
361 String cdmDB
= "cdm_edit_salvador";
362 String cdmUserName
= "edit";
363 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
366 public static ICdmDataSource
cdm_import_salvador() {
367 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
368 String cdmServer
= "192.168.2.10";
369 String cdmDB
= "cdm_import_salvador";
370 String cdmUserName
= "edit";
371 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
374 public static ICdmDataSource
cdm_salvador_production() {
375 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
376 String cdmServer
= "192.168.2.10";
377 String cdmDB
= "salvador_cdm";
378 String cdmUserName
= "salvador";
379 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
383 // public static ICdmDataSource LAPTOP_HP(){
384 // DatabaseTypeEnum dbType = DatabaseTypeEnum.SqlServer2005;
385 // String cdmServer = "LAPTOPHP";
386 // String cdmDB = "cdmTest";
387 // String cdmUserName = "edit";
388 // return makeDestination(cdmServer, cdmDB, -1, cdmUserName, null);
396 * TODO only supports MySQL and PostgreSQL
406 private static ICdmDataSource
makeDestination(DatabaseTypeEnum dbType
, String cdmServer
, String cdmDB
, int port
, String cdmUserName
, String pwd
){
407 //establish connection
408 pwd
= AccountStore
.readOrStorePassword(cdmServer
, cdmDB
, cdmUserName
, pwd
);
409 ICdmDataSource destination
;
410 if(dbType
.equals(DatabaseTypeEnum
.MySQL
)){
411 destination
= CdmDataSource
.NewMySqlInstance(cdmServer
, cdmDB
, port
, cdmUserName
, pwd
, null);
412 } else if(dbType
.equals(DatabaseTypeEnum
.PostgreSQL
)){
413 destination
= CdmDataSource
.NewPostgreSQLInstance(cdmServer
, cdmDB
, port
, cdmUserName
, pwd
, null);
416 throw new RuntimeException("Unsupported DatabaseType");
424 * Accepts a string array and tries to find a method returning an ICdmDataSource with
425 * the name of the given first string in the array
430 public static ICdmDataSource
chooseDestination(String
[] args
) {
437 String possibleDestination
= args
[0];
439 Method
[] methods
= CdmDestinations
.class.getMethods();
441 for (Method method
: methods
){
442 if(method
.getName().equals(possibleDestination
)){
444 return (ICdmDataSource
) method
.invoke(null, null);
445 } catch (IllegalArgumentException e
) {
446 // TODO Auto-generated catch block
448 } catch (IllegalAccessException e
) {
449 // TODO Auto-generated catch block
451 } catch (InvocationTargetException e
) {
452 // TODO Auto-generated catch block