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
.common
;
12 import java
.lang
.reflect
.InvocationTargetException
;
13 import java
.lang
.reflect
.Method
;
15 import org
.apache
.log4j
.Logger
;
17 import eu
.etaxonomy
.cdm
.config
.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);
26 public static ICdmDataSource
cdm_test_local_mysql(){
27 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
28 String cdmServer
= "127.0.0.1";
29 String cdmDB
= "cdm_test";
30 String cdmUserName
= "root";
31 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
34 public static ICdmDataSource
cdm_test_local_faunaEu_mysql(){
35 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
36 String cdmServer
= "127.0.0.1";
37 String cdmDB
= "cdm_faunaeu_2017_03";
38 String cdmUserName
= "root";
39 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
42 public static ICdmDataSource
cdm_test_local_pesi_leer(){
43 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
44 String cdmServer
= "127.0.0.1";
45 String cdmDB
= "cdm_pesi_test_leer";
46 String cdmUserName
= "edit";
47 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
50 public static ICdmDataSource
cdm_test_local_pesi_leer2(){
51 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
52 String cdmServer
= "127.0.0.1";
53 String cdmDB
= "cdm_pesi_test_leer2";
54 String cdmUserName
= "edit";
55 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
58 public static ICdmDataSource
cdm_test_local_indexFungorum(){
59 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
60 String cdmServer
= "127.0.0.1";
61 String cdmDB
= "indexFungorum";
62 String cdmUserName
= "root";
63 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
66 public static ICdmDataSource
cdm_test_local_mysql_erms(){
67 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
68 String cdmServer
= "127.0.0.1";
69 String cdmDB
= "cdm_pesi_erms";
70 String cdmUserName
= "edit";
71 return CdmDestinations
.makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
74 public static ICdmDataSource
cdm_test_local_mysql_erms2(){
75 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
76 String cdmServer
= "127.0.0.1";
77 String cdmDB
= "cdm_pesi_erms2";
78 String cdmUserName
= "edit";
79 return CdmDestinations
.makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
82 public static ICdmDataSource
cdm_test_local_mysql_test(){
83 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
84 String cdmServer
= "127.0.0.1";
85 String cdmDB
= "test";
86 String cdmUserName
= "edit";
87 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
90 public static ICdmDataSource
NULL(){
95 public static ICdmDataSource
localH2(){
96 return CdmDataSource
.NewH2EmbeddedInstance("cdm", "sa", "");
99 public static ICdmDataSource
localH2EuroMed(){
100 return CdmDataSource
.NewH2EmbeddedInstance("euroMed", "sa", "");
103 public static ICdmDataSource
localH2Erms(){
104 return CdmDataSource
.NewH2EmbeddedInstance("erms", "sa", "");
107 public static ICdmDataSource
test_cdm_pesi_euroMed(){
108 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
109 String cdmServer
= "160.45.63.175";
110 String cdmDB
= "cdm_pesi_euromed";
111 String cdmUserName
= "edit";
112 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
115 public static ICdmDataSource
test_cdm_pesi_fauna_europaea(){
116 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
117 String cdmServer
= "160.45.63.175";
118 String cdmDB
= "cdm_pesi_fauna_europaea";
119 String cdmUserName
= "edit";
120 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
124 public static ICdmDataSource
test_cdm_pesi_erms(){
125 DatabaseTypeEnum dbType
= DatabaseTypeEnum
.MySQL
;
126 String cdmServer
= "160.45.63.175";
127 String cdmDB
= "cdm_pesi_erms";
128 String cdmUserName
= "edit";
129 return makeDestination(dbType
, cdmServer
, cdmDB
, -1, cdmUserName
, null);
135 * TODO only supports MySQL and PostgreSQL
145 public static ICdmDataSource
makeDestination(DatabaseTypeEnum dbType
, String cdmServer
, String cdmDB
, int port
, String cdmUserName
, String pwd
){
146 //establish connection
147 pwd
= AccountStore
.readOrStorePassword(cdmServer
, cdmDB
, cdmUserName
, pwd
);
148 ICdmDataSource destination
;
149 if(dbType
.equals(DatabaseTypeEnum
.MySQL
)){
150 destination
= CdmDataSource
.NewMySqlInstance(cdmServer
, cdmDB
, port
, cdmUserName
, pwd
);
151 } else if(dbType
.equals(DatabaseTypeEnum
.PostgreSQL
)){
152 destination
= CdmDataSource
.NewPostgreSQLInstance(cdmServer
, cdmDB
, port
, cdmUserName
, pwd
);
155 throw new RuntimeException("Unsupported DatabaseType");
162 * Accepts a string array and tries to find a method returning an ICdmDataSource with
163 * the name of the given first string in the array
168 public static ICdmDataSource
chooseDestination(String
[] args
) {
173 if(args
.length
!= 1) {
177 String possibleDestination
= args
[0];
179 Method
[] methods
= CdmDestinations
.class.getMethods();
181 for (Method method
: methods
){
182 if(method
.getName().equals(possibleDestination
)){
184 return (ICdmDataSource
) method
.invoke(null, null);
185 } catch (IllegalArgumentException e
) {
187 } catch (IllegalAccessException e
) {
189 } catch (InvocationTargetException e
) {