Revision c0248cde
Added by Andreas Müller over 7 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/DatabaseMapping.java | ||
---|---|---|
325 | 325 |
* @param path |
326 | 326 |
*/ |
327 | 327 |
private void makeDatasource(String path) { |
328 |
datasource = CdmDataSource.NewH2EmbeddedInstance("_tmpMapping", "a", "b", path, null);
|
|
328 |
datasource = CdmDataSource.NewH2EmbeddedInstance("_tmpMapping", "a", "b", path); |
|
329 | 329 |
} |
330 | 330 |
|
331 | 331 |
|
cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/sdd/in/SDDImportExportTest.java | ||
---|---|---|
39 | 39 |
import eu.etaxonomy.cdm.io.sdd.out.SDDCdmExporter; |
40 | 40 |
import eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator; |
41 | 41 |
import eu.etaxonomy.cdm.io.sdd.out.SDDExportState; |
42 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
43 | 42 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
44 | 43 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
45 | 44 |
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest; |
... | ... | |
139 | 138 |
//ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("192.168.2.10", "cdm_test_niels2", 3306, "edit", password, code); |
140 | 139 |
String dataSourceName = "cdm_test2"; |
141 | 140 |
String password = CdmUtils.readInputLine("Password: "); |
142 |
ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("127.0.0.1", "cdm_test2", 3306, "ljm", password, NomenclaturalCode.ICNAFP);
|
|
143 |
//ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("160.45.63.201", "cdm_test", 3306, "edit", password, NomenclaturalCode.ICBN);
|
|
141 |
ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("127.0.0.1", "cdm_test2", 3306, "ljm", password); |
|
142 |
//ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("160.45.63.201", "cdm_test", 3306, "edit", password); |
|
144 | 143 |
boolean connectionAvailable; |
145 | 144 |
try { |
146 | 145 |
connectionAvailable = dataSource.testConnection(); |
... | ... | |
148 | 147 |
Assert.assertTrue("Testdatabase is not available", connectionAvailable); |
149 | 148 |
|
150 | 149 |
} catch (ClassNotFoundException e1) { |
151 |
// TODO Auto-generated catch block |
|
152 | 150 |
e1.printStackTrace(); |
153 | 151 |
} catch (SQLException e1) { |
154 |
// TODO Auto-generated catch block |
|
155 | 152 |
e1.printStackTrace(); |
156 | 153 |
} |
157 | 154 |
|
... | ... | |
159 | 156 |
try { |
160 | 157 |
loadedDataSource = CdmPersistentDataSource.NewInstance(dataSourceName); |
161 | 158 |
// CdmApplicationController.NewInstance(loadedDataSource, DbSchemaValidation.CREATE); |
162 |
NomenclaturalCode loadedCode = loadedDataSource.getNomenclaturalCode(); |
|
163 |
|
|
164 |
Assert.assertEquals(NomenclaturalCode.ICNAFP, loadedCode); |
|
159 |
// NomenclaturalCode loadedCode = loadedDataSource.getNomenclaturalCode();
|
|
160 |
// |
|
161 |
// Assert.assertEquals(NomenclaturalCode.ICNAFP, loadedCode);
|
|
165 | 162 |
} catch (DataSourceNotFoundException e) { |
166 | 163 |
// TODO Auto-generated catch block |
167 | 164 |
e.printStackTrace(); |
... | ... | |
177 | 174 |
@Override |
178 | 175 |
public void createTestDataSet() throws FileNotFoundException { |
179 | 176 |
// TODO Auto-generated method stub |
180 |
|
|
177 |
|
|
181 | 178 |
} |
182 | 179 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/config/CdmPersistentXMLSource.java | ||
---|---|---|
22 | 22 |
|
23 | 23 |
/** |
24 | 24 |
* Cdm Source class which represents a persisted CDM source object |
25 |
* as configured in the CDM sources config file.
|
|
26 |
*
|
|
25 |
* as configured in the CDM sources config file. |
|
26 |
* |
|
27 | 27 |
* @author cmathew |
28 | 28 |
* |
29 | 29 |
*/ |
30 |
public class CdmPersistentXMLSource {
|
|
30 |
public class CdmPersistentXMLSource { |
|
31 | 31 |
private static final Logger logger = Logger.getLogger(CdmPersistentXMLSource.class); |
32 |
|
|
33 |
|
|
32 |
|
|
33 |
|
|
34 | 34 |
/** |
35 | 35 |
* CDM sources config file name |
36 | 36 |
*/ |
37 | 37 |
public final static String CDMSOURCE_FILE_NAME = "cdm.datasources.xml"; |
38 |
|
|
38 |
|
|
39 | 39 |
/** |
40 | 40 |
* Directory path of the template CDM sources config file - this file is used |
41 | 41 |
* in the case of the very first call to persist sources see {@link eu.etaxonomy.cdm.api.application.CdmApplicationUtils#getWritableResourceDir()} |
42 | 42 |
*/ |
43 | 43 |
public final static String CDMSOURCE_PATH = "/eu/etaxonomy/cdm/"; |
44 |
|
|
44 |
|
|
45 | 45 |
/** |
46 |
* jDom Element represeting the CDM source as stored in the source config file
|
|
46 |
* jDom Element represeting the CDM source as stored in the source config file |
|
47 | 47 |
*/ |
48 | 48 |
private Element bean; |
49 |
|
|
50 |
|
|
49 |
|
|
50 |
|
|
51 | 51 |
/** |
52 | 52 |
* Post fix represeting the type of source (data / remote) |
53 | 53 |
*/ |
54 | 54 |
private String postFix; |
55 |
|
|
55 |
|
|
56 | 56 |
/** |
57 | 57 |
* Enumeration containg all possible properties of all types of |
58 | 58 |
* CDM Sources |
59 |
*
|
|
59 |
* |
|
60 | 60 |
* |
61 | 61 |
*/ |
62 |
public enum CdmSourceProperties {
|
|
62 |
public enum CdmSourceProperties { |
|
63 | 63 |
URL, |
64 |
SERVER,
|
|
65 |
PORT,
|
|
64 |
SERVER, |
|
65 |
PORT, |
|
66 | 66 |
FILEPATH, |
67 | 67 |
CONTEXTPATH, |
68 | 68 |
USERNAME, |
69 |
PASSWORD, |
|
70 |
NOMENCLATURAL_CODE, |
|
69 |
PASSWORD, |
|
71 | 70 |
DRIVER_CLASS, |
72 | 71 |
DATABASE, |
73 | 72 |
MODE; |
... | ... | |
89 | 88 |
return "username"; |
90 | 89 |
case PASSWORD: |
91 | 90 |
return "password"; |
92 |
case NOMENCLATURAL_CODE: |
|
93 |
return "nomenclaturalCode"; |
|
94 | 91 |
case DRIVER_CLASS: |
95 | 92 |
return "driverClassName"; |
96 | 93 |
case DATABASE: |
97 | 94 |
return "database"; |
98 | 95 |
case MODE: |
99 | 96 |
return "mode"; |
100 |
default:
|
|
97 |
default: |
|
101 | 98 |
throw new IllegalArgumentException( "Unknown enumeration type" ); |
102 | 99 |
} |
103 | 100 |
} |
104 | 101 |
} |
105 |
|
|
102 |
|
|
106 | 103 |
private String cdmSourceName; |
107 |
|
|
104 |
|
|
108 | 105 |
/** |
109 |
* Constructor which uses the given CDM source name and post fix to initialze the
|
|
106 |
* Constructor which uses the given CDM source name and post fix to initialze the |
|
110 | 107 |
* jDom element from the source config file. |
111 |
*
|
|
108 |
* |
|
112 | 109 |
* @param cdmSourceName |
113 | 110 |
* @param postFix |
114 | 111 |
*/ |
... | ... | |
117 | 114 |
this.postFix = postFix; |
118 | 115 |
bean = CdmPersistentSourceUtils.getCdmSourceBeanXml(cdmSourceName, postFix); |
119 | 116 |
} |
120 |
|
|
117 |
|
|
121 | 118 |
/** |
122 |
* Constructor which uses the given CDM source name and post fix to initialze the
|
|
119 |
* Constructor which uses the given CDM source name and post fix to initialze the |
|
123 | 120 |
* jDom element from the source config file. |
124 |
*
|
|
121 |
* |
|
125 | 122 |
* @param strDataSourceName |
126 | 123 |
* @param postFix |
127 | 124 |
* @return new CdmPersistentXMLSource object |
128 | 125 |
*/ |
129 | 126 |
public final static CdmPersistentXMLSource NewInstance(String strDataSourceName, String postFix) { |
130 |
return new CdmPersistentXMLSource(strDataSourceName, postFix);
|
|
127 |
return new CdmPersistentXMLSource(strDataSourceName, postFix); |
|
131 | 128 |
} |
132 |
|
|
129 |
|
|
133 | 130 |
|
134 | 131 |
/** |
135 | 132 |
* Returns the loaded jDom element representing this object |
136 |
*
|
|
133 |
* |
|
137 | 134 |
* @return |
138 | 135 |
*/ |
139 | 136 |
public Element getElement() { |
140 | 137 |
return bean; |
141 | 138 |
} |
142 |
|
|
139 |
|
|
143 | 140 |
/** |
144 | 141 |
* Returns the name of the bean Element in the cdm source xml config file. |
145 | 142 |
* @return bean name |
... | ... | |
147 | 144 |
public String getBeanName(){ |
148 | 145 |
return CdmPersistentSourceUtils.getBeanName(cdmSourceName, postFix); |
149 | 146 |
} |
150 |
|
|
147 |
|
|
151 | 148 |
/** |
152 |
* Returns the list of attributes of this CDM source
|
|
153 |
* that are defined in the cdm source xml config file.
|
|
154 |
* @return
|
|
149 |
* Returns the list of attributes of this CDM source |
|
150 |
* that are defined in the cdm source xml config file. |
|
151 |
* @return |
|
155 | 152 |
*/ |
156 | 153 |
@SuppressWarnings("unchecked") |
157 | 154 |
public List<Attribute> getCdmSourceAttributes(){ |
158 |
List<Attribute> result = new ArrayList<Attribute>();
|
|
155 |
List<Attribute> result = new ArrayList<Attribute>(); |
|
159 | 156 |
if (bean == null){ |
160 | 157 |
return null; |
161 | 158 |
}else{ |
162 | 159 |
result = bean.getAttributes(); |
163 | 160 |
} |
164 | 161 |
return result; |
165 |
}
|
|
166 |
|
|
162 |
} |
|
163 |
|
|
167 | 164 |
/** |
168 |
* Returns a defined property of the cdm source xml config file.
|
|
165 |
* Returns a defined property of the cdm source xml config file. |
|
169 | 166 |
* @return the property of the cdm source or null if the datasource bean or the property does not exist. |
170 | 167 |
*/ |
171 | 168 |
public String getCdmSourceProperty(String property){ |
172 |
|
|
169 |
|
|
173 | 170 |
if (bean == null){ |
174 | 171 |
return null; |
175 | 172 |
}else{ |
... | ... | |
183 | 180 |
} |
184 | 181 |
} |
185 | 182 |
} |
186 |
|
|
183 |
|
|
187 | 184 |
/** |
188 |
* Returns the list of properties that are defined in the
|
|
185 |
* Returns the list of properties that are defined in the |
|
189 | 186 |
* cdm source xml config file. |
190 |
*
|
|
191 |
* @return
|
|
187 |
* |
|
188 |
* @return |
|
192 | 189 |
*/ |
193 | 190 |
public Properties getCdmSourceProperties(){ |
194 |
Properties result = new Properties();
|
|
191 |
Properties result = new Properties(); |
|
195 | 192 |
if (bean == null){ |
196 | 193 |
return null; |
197 | 194 |
}else{ |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/config/CdmSource.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.cdm.config; |
10 | 10 |
|
11 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
12 |
|
|
13 | 11 |
/** |
14 | 12 |
* Abstract class representing the base CDM Source object. |
15 |
* |
|
16 |
* |
|
17 | 13 |
*/ |
18 | 14 |
public abstract class CdmSource implements ICdmSource { |
19 |
|
|
15 |
|
|
20 | 16 |
private String name; |
21 | 17 |
private String server; |
22 | 18 |
private int port; |
23 |
private NomenclaturalCode nomenclaturalCode; |
|
24 |
|
|
19 |
|
|
25 | 20 |
public static final int NULL_PORT = -1; |
26 |
|
|
21 |
|
|
27 | 22 |
public static final String DEFAULT_ENTRY = "-"; |
28 |
|
|
23 |
|
|
29 | 24 |
/** |
30 | 25 |
* Sets the CDM Source name |
31 |
*
|
|
26 |
* |
|
32 | 27 |
* @param name |
33 | 28 |
*/ |
34 | 29 |
@Override |
... | ... | |
38 | 33 |
|
39 | 34 |
/** |
40 | 35 |
* Sets the CDM Source server |
41 |
*
|
|
36 |
* |
|
42 | 37 |
* @param server |
43 | 38 |
*/ |
44 | 39 |
@Override |
... | ... | |
48 | 43 |
|
49 | 44 |
/** |
50 | 45 |
* Sets the CDM Source port |
51 |
*
|
|
46 |
* |
|
52 | 47 |
* @param port |
53 | 48 |
*/ |
54 | 49 |
@Override |
... | ... | |
56 | 51 |
this.port = port; |
57 | 52 |
} |
58 | 53 |
|
59 |
/** |
|
60 |
* Sets the CDM Source {@link NomenclaturalCode} |
|
61 |
* |
|
62 |
* @param nomenclaturalCode |
|
63 |
*/ |
|
64 |
@Override |
|
65 |
public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode) { |
|
66 |
this.nomenclaturalCode = nomenclaturalCode; |
|
67 |
} |
|
68 |
|
|
69 |
|
|
70 |
/* (non-Javadoc) |
|
71 |
* @see eu.etaxonomy.cdm.config.ICdmSource#getName() |
|
72 |
*/ |
|
73 | 54 |
@Override |
74 | 55 |
public String getName() { |
75 | 56 |
return this.name; |
76 | 57 |
} |
77 | 58 |
|
78 |
/* (non-Javadoc) |
|
79 |
* @see eu.etaxonomy.cdm.config.ICdmSource#getServer() |
|
80 |
*/ |
|
81 | 59 |
@Override |
82 | 60 |
public String getServer() { |
83 | 61 |
return this.server; |
84 | 62 |
} |
85 | 63 |
|
86 |
/* (non-Javadoc) |
|
87 |
* @see eu.etaxonomy.cdm.config.ICdmSource#getPort() |
|
88 |
*/ |
|
89 | 64 |
@Override |
90 | 65 |
public int getPort() { |
91 | 66 |
return this.port; |
92 | 67 |
} |
93 | 68 |
|
94 |
/* (non-Javadoc) |
|
95 |
* @see eu.etaxonomy.cdm.config.ICdmSource#getNomenclaturalCode() |
|
96 |
*/ |
|
97 |
@Override |
|
98 |
public NomenclaturalCode getNomenclaturalCode() { |
|
99 |
return this.nomenclaturalCode; |
|
100 |
} |
|
101 |
|
|
102 |
/* (non-Javadoc) |
|
103 |
* @see eu.etaxonomy.cdm.config.ICdmSource#getDbSchemaVersion() |
|
104 |
*/ |
|
105 | 69 |
@Override |
106 | 70 |
public abstract String getDbSchemaVersion() throws CdmSourceException; |
107 |
|
|
108 |
/* (non-Javadoc) |
|
109 |
* @see eu.etaxonomy.cdm.config.ICdmSource#isDbEmpty() |
|
110 |
*/ |
|
71 |
|
|
111 | 72 |
@Override |
112 | 73 |
public abstract boolean isDbEmpty() throws CdmSourceException; |
113 |
|
|
114 |
/* (non-Javadoc) |
|
115 |
* @see eu.etaxonomy.cdm.config.ICdmSource#checkConnection() |
|
116 |
*/ |
|
74 |
|
|
117 | 75 |
@Override |
118 | 76 |
public abstract boolean checkConnection() throws CdmSourceException; |
119 |
|
|
120 |
/* (non-Javadoc) |
|
121 |
* @see eu.etaxonomy.cdm.config.ICdmSource#getConnectionMessage() |
|
122 |
*/ |
|
77 |
|
|
123 | 78 |
@Override |
124 | 79 |
public abstract String getConnectionMessage(); |
125 |
|
|
126 |
/* (non-Javadoc) |
|
127 |
* @see eu.etaxonomy.cdm.config.ICdmSource#closeOpenConnections() |
|
128 |
*/ |
|
80 |
|
|
129 | 81 |
@Override |
130 | 82 |
public void closeOpenConnections() { |
131 |
|
|
132 |
}
|
|
83 |
|
|
84 |
} |
|
133 | 85 |
|
134 | 86 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/config/ICdmSource.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2014 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
11 | 11 |
import java.util.Map; |
12 | 12 |
|
13 | 13 |
import eu.etaxonomy.cdm.model.metadata.CdmMetaData.MetaDataPropertyName; |
14 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
15 | 14 |
|
16 | 15 |
/** |
17 | 16 |
* Interface which represents any CDM Source |
18 | 17 |
* |
19 | 18 |
*/ |
20 | 19 |
public interface ICdmSource { |
21 |
|
|
20 |
|
|
22 | 21 |
/** |
23 | 22 |
* Returns the name representation of this CDM Source |
24 |
*
|
|
23 |
* |
|
25 | 24 |
* @return name representation of this CDM Source |
26 | 25 |
*/ |
27 | 26 |
public String getName(); |
28 |
|
|
27 |
|
|
29 | 28 |
/** |
30 | 29 |
* Sets the name representation of this CDM Source |
31 |
*
|
|
30 |
* |
|
32 | 31 |
* @param name |
33 | 32 |
* @return |
34 | 33 |
*/ |
35 | 34 |
public void setName(String name); |
36 |
|
|
35 |
|
|
37 | 36 |
/** |
38 | 37 |
* Returns the server (string representation) where this CDM Source resides |
39 |
*
|
|
38 |
* |
|
40 | 39 |
* @return server (string representation) where this CDM Source resides |
41 | 40 |
*/ |
42 | 41 |
public String getServer(); |
43 |
|
|
42 |
|
|
44 | 43 |
/** |
45 | 44 |
* Sets the server (string representation) where this CDM Source resides |
46 |
*
|
|
45 |
* |
|
47 | 46 |
* @param server |
48 | 47 |
* @return |
49 | 48 |
*/ |
50 | 49 |
public void setServer(String server); |
51 |
|
|
50 |
|
|
52 | 51 |
/** |
53 | 52 |
* Returns the port on which this CDM Source is listening |
54 |
*
|
|
53 |
* |
|
55 | 54 |
* @return port on which this CDM Source is listening |
56 | 55 |
*/ |
57 | 56 |
public int getPort(); |
58 |
|
|
57 |
|
|
59 | 58 |
/** |
60 | 59 |
* Sets the port on which this CDM Source is listening |
61 |
*
|
|
60 |
* |
|
62 | 61 |
* @param port |
63 | 62 |
*/ |
64 | 63 |
public void setPort(int port); |
65 |
|
|
66 |
/** |
|
67 |
* Returns the {@link NomenclaturalCode} object for this CDM Source |
|
68 |
* |
|
69 |
* @return |
|
70 |
*/ |
|
71 |
public NomenclaturalCode getNomenclaturalCode(); |
|
72 |
|
|
73 |
/** |
|
74 |
* Sets the {@link NomenclaturalCode} object for this CDM Source |
|
75 |
* |
|
76 |
* @param nomenclaturalCode |
|
77 |
*/ |
|
78 |
public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode); |
|
79 |
|
|
64 |
|
|
80 | 65 |
/** |
81 | 66 |
* Returns the CDM schema version of this CDM Source |
82 |
*
|
|
67 |
* |
|
83 | 68 |
* @return CDM schema version of this CDM Source |
84 | 69 |
* @throws CdmSourceException if any underlying error |
85 | 70 |
*/ |
86 | 71 |
public String getDbSchemaVersion() throws CdmSourceException; |
87 |
|
|
72 |
|
|
88 | 73 |
/** |
89 | 74 |
* Checks whether the underlying database is empty |
90 |
*
|
|
75 |
* |
|
91 | 76 |
* @return true if underlying database is empty, o/w false |
92 | 77 |
* @throws CdmSourceException |
93 | 78 |
*/ |
94 | 79 |
public boolean isDbEmpty() throws CdmSourceException; |
95 |
|
|
80 |
|
|
96 | 81 |
|
97 | 82 |
/** |
98 | 83 |
* Tests, if a database connection can be established. |
... | ... | |
100 | 85 |
* @throws CdmSourceException if any underlying error |
101 | 86 |
*/ |
102 | 87 |
public boolean checkConnection() throws CdmSourceException; |
103 |
|
|
88 |
|
|
104 | 89 |
/** |
105 | 90 |
* Returns the message to display when connecting to this CDM Source |
106 |
*
|
|
91 |
* |
|
107 | 92 |
* @return message to display when connecting to this CDM Source |
108 | 93 |
*/ |
109 | 94 |
public String getConnectionMessage(); |
110 | 95 |
|
111 | 96 |
/** |
112 | 97 |
* Closes any open connections to this CDM Source |
113 |
*
|
|
98 |
* |
|
114 | 99 |
*/ |
115 | 100 |
public void closeOpenConnections(); |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
public Map<MetaDataPropertyName, String> getMetaDataMap() throws CdmSourceException ; |
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 | 101 |
|
102 |
public Map<MetaDataPropertyName, String> getMetaDataMap() throws CdmSourceException ; |
|
125 | 103 |
|
126 | 104 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/CdmDataSource.java | ||
---|---|---|
24 | 24 |
import org.springframework.beans.factory.support.RootBeanDefinition; |
25 | 25 |
|
26 | 26 |
import eu.etaxonomy.cdm.common.CdmUtils; |
27 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
28 | 27 |
|
29 | 28 |
/** |
30 | 29 |
* @author a.mueller |
... | ... | |
40 | 39 |
private int port = -1; |
41 | 40 |
private String username; |
42 | 41 |
private String password; |
43 |
private NomenclaturalCode nomenclaturalCode; |
|
44 | 42 |
|
45 | 43 |
private String filePath; |
46 | 44 |
private H2Mode mode; |
... | ... | |
55 | 53 |
private Class<? extends RegionFactory> cacheProviderClass = NoCachingRegionFactory.class; |
56 | 54 |
|
57 | 55 |
public static CdmDataSource NewInstance(DatabaseTypeEnum dbType, String server, String database, String username, String password){ |
58 |
return new CdmDataSource(dbType, server, database, -1, username, password, null, null, null);
|
|
56 |
return new CdmDataSource(dbType, server, database, -1, username, password, null, null); |
|
59 | 57 |
} |
60 | 58 |
|
61 | 59 |
public static CdmDataSource NewInstance(DatabaseTypeEnum dbType, String server, String database, int port, String username, String password){ |
62 |
return new CdmDataSource(dbType, server, database, port, username, password, null, null, null); |
|
63 |
} |
|
64 |
|
|
65 |
public static CdmDataSource NewInstance(DatabaseTypeEnum dbType, String server, String database, String username, String password , NomenclaturalCode code){ |
|
66 |
return new CdmDataSource(dbType, server, database, -1, username, password, null, null, code); |
|
67 |
} |
|
68 |
|
|
69 |
public static CdmDataSource NewInstance(DatabaseTypeEnum dbType, String server, String database, int port, String username, String password , NomenclaturalCode code){ |
|
70 |
return new CdmDataSource(dbType, server, database, port, username, password, null, null, code); |
|
60 |
return new CdmDataSource(dbType, server, database, port, username, password, null, null); |
|
71 | 61 |
} |
72 | 62 |
|
73 | 63 |
|
74 | 64 |
static public CdmDataSource NewMySqlInstance(String server, String database, String username, String password ){ |
75 |
return new CdmDataSource(DatabaseTypeEnum.MySQL, server, database, -1, username, password, null, null, null); |
|
76 |
} |
|
77 |
|
|
78 |
static public CdmDataSource NewMySqlInstance(String server, String database, String username, String password , NomenclaturalCode code){ |
|
79 |
return new CdmDataSource(DatabaseTypeEnum.MySQL, server, database, -1, username, password, null, null, code); |
|
80 |
} |
|
81 |
|
|
82 |
static public CdmDataSource NewMySqlInstance(String server, String database, int port, String username, String password, NomenclaturalCode code){ |
|
83 |
return new CdmDataSource(DatabaseTypeEnum.MySQL, server, database, port, username, password, null, null, code); |
|
65 |
return new CdmDataSource(DatabaseTypeEnum.MySQL, server, database, -1, username, password, null, null); |
|
84 | 66 |
} |
85 | 67 |
|
86 |
static public CdmDataSource NewPostgreSQLInstance(String server, String database, int port, String username, String password, NomenclaturalCode code){
|
|
87 |
return new CdmDataSource(DatabaseTypeEnum.PostgreSQL, server, database, port, username, password, null, null, code);
|
|
68 |
static public CdmDataSource NewMySqlInstance(String server, String database, int port, String username, String password){
|
|
69 |
return new CdmDataSource(DatabaseTypeEnum.MySQL, server, database, port, username, password, null, null);
|
|
88 | 70 |
} |
89 | 71 |
|
90 |
static public CdmDataSource NewSqlServer2005Instance(String server, String database, int port, String username, String password, NomenclaturalCode code){
|
|
91 |
return new CdmDataSource(DatabaseTypeEnum.SqlServer2005, server, database, port, username, password, null, null, code);
|
|
72 |
static public CdmDataSource NewPostgreSQLInstance(String server, String database, int port, String username, String password){
|
|
73 |
return new CdmDataSource(DatabaseTypeEnum.PostgreSQL, server, database, port, username, password, null, null);
|
|
92 | 74 |
} |
93 | 75 |
|
94 |
static public CdmDataSource NewSqlServer2005Instance(String server, String database, int port, String username, String password /*, NomenclaturalCode code*/){
|
|
95 |
return new CdmDataSource(DatabaseTypeEnum.SqlServer2005, server, database, port, username, password, null, null, null);
|
|
76 |
static public CdmDataSource NewSqlServer2005Instance(String server, String database, int port, String username, String password){ |
|
77 |
return new CdmDataSource(DatabaseTypeEnum.SqlServer2005, server, database, port, username, password, null, null); |
|
96 | 78 |
} |
97 | 79 |
|
98 | 80 |
|
99 | 81 |
/** in work |
100 | 82 |
* @param code TODO*/ |
101 | 83 |
static public CdmDataSource NewH2EmbeddedInstance(String database, String username, String password){ |
102 |
return NewH2EmbeddedInstance(database, username, password, null, null);
|
|
84 |
return NewH2EmbeddedInstance(database, username, password, null); |
|
103 | 85 |
} |
104 | 86 |
|
105 | 87 |
/** in work |
106 | 88 |
* @param code TODO*/ |
107 |
static public CdmDataSource NewH2EmbeddedInstance(String database, String username, String password, NomenclaturalCode code){ |
|
108 |
return NewH2EmbeddedInstance(database, username, password, null, code); |
|
109 |
} |
|
110 |
|
|
111 |
/** in work |
|
112 |
* @param code TODO*/ |
|
113 |
static public CdmDataSource NewH2EmbeddedInstance(String database, String username, String password, String filePath, NomenclaturalCode code){ |
|
89 |
static public CdmDataSource NewH2EmbeddedInstance(String database, String username, String password, String filePath /*, NomenclaturalCode code*/){ |
|
114 | 90 |
//FIXME in work |
115 | 91 |
int port = -1; |
116 | 92 |
H2Mode mode = H2Mode.EMBEDDED; |
117 |
CdmDataSource dataSource = new CdmDataSource(DatabaseTypeEnum.H2, null, database, port, username, password, filePath, mode, code);
|
|
93 |
CdmDataSource dataSource = new CdmDataSource(DatabaseTypeEnum.H2, null, database, port, username, password, filePath, mode); |
|
118 | 94 |
return dataSource; |
119 | 95 |
} |
120 | 96 |
|
... | ... | |
125 | 101 |
H2Mode mode = H2Mode.IN_MEMORY; |
126 | 102 |
String username = "sa"; |
127 | 103 |
String password = ""; |
128 |
CdmDataSource dataSource = new CdmDataSource(DatabaseTypeEnum.H2, null, null, port, username, password, null, mode, null);
|
|
104 |
CdmDataSource dataSource = new CdmDataSource(DatabaseTypeEnum.H2, null, null, port, username, password, null, mode); |
|
129 | 105 |
return dataSource; |
130 | 106 |
} |
131 | 107 |
|
... | ... | |
138 | 114 |
dataSource.getUsername(), |
139 | 115 |
dataSource.getPassword(), |
140 | 116 |
dataSource.getFilePath(), |
141 |
dataSource.getMode(), |
|
142 |
dataSource.getNomenclaturalCode()); |
|
117 |
dataSource.getMode()); |
|
143 | 118 |
} |
144 | 119 |
/** |
145 | 120 |
* @param server |
146 | 121 |
* @param database |
147 | 122 |
* @param port |
148 | 123 |
*/ |
149 |
protected CdmDataSource(DatabaseTypeEnum dbType, String server, String database, int port, String username, String password, String filePath, H2Mode mode, NomenclaturalCode code) {
|
|
124 |
protected CdmDataSource(DatabaseTypeEnum dbType, String server, String database, int port, String username, String password, String filePath, H2Mode mode /*, NomenclaturalCode code*/) {
|
|
150 | 125 |
super(); |
151 | 126 |
this.dbType = dbType; |
152 | 127 |
this.server = server; |
... | ... | |
158 | 133 |
this.destroyMethodName = dbType.getDestroyMethod(); |
159 | 134 |
this.filePath = filePath; |
160 | 135 |
this.mode = mode; |
161 |
this.nomenclaturalCode = code; |
|
162 | 136 |
} |
163 | 137 |
|
164 |
|
|
165 |
/* (non-Javadoc) |
|
166 |
* @see eu.etaxonomy.cdm.database.ICdmDataSource#getName() |
|
167 |
* A CdmDataSource does not have a name representation therefore the database name is returned |
|
168 |
*/ |
|
169 | 138 |
@Override |
170 | 139 |
public String getName() { |
171 | 140 |
return database; |
... | ... | |
175 | 144 |
public String getServer() { |
176 | 145 |
return server; |
177 | 146 |
} |
178 |
|
|
147 |
|
|
179 | 148 |
@Override |
180 | 149 |
public int getPort() { |
181 | 150 |
return port; |
182 | 151 |
} |
183 | 152 |
|
184 |
@Override |
|
185 |
public NomenclaturalCode getNomenclaturalCode() { |
|
186 |
return nomenclaturalCode; |
|
187 |
} |
|
188 |
|
|
189 | 153 |
@Override |
190 | 154 |
public BeanDefinition getDatasourceBean(){ |
191 | 155 |
AbstractBeanDefinition bd = new RootBeanDefinition(dbType.getDataSourceClass()); |
... | ... | |
201 | 165 |
//properties |
202 | 166 |
MutablePropertyValues props = new MutablePropertyValues(); |
203 | 167 |
Properties persistentProperties = getDatasourceProperties(); |
204 |
Enumeration<Object> keys = (Enumeration<Object>)persistentProperties.keys();
|
|
168 |
Enumeration<Object> keys = persistentProperties.keys(); |
|
205 | 169 |
while (keys.hasMoreElements()){ |
206 | 170 |
String key = (String)keys.nextElement(); |
207 | 171 |
props.addPropertyValue(key, persistentProperties.getProperty(key)); |
... | ... | |
293 | 257 |
public String getDatabase() { |
294 | 258 |
return database; |
295 | 259 |
} |
296 |
|
|
260 |
|
|
297 | 261 |
@Override |
298 | 262 |
public void setDatabase(String database) { |
299 |
this.database = database;
|
|
263 |
this.database = database; |
|
300 | 264 |
} |
301 | 265 |
|
302 | 266 |
@Override |
... | ... | |
317 | 281 |
@Override |
318 | 282 |
public void setMode(H2Mode h2Mode) { |
319 | 283 |
this.mode = h2Mode; |
320 |
|
|
284 |
|
|
321 | 285 |
} |
322 |
|
|
286 |
|
|
323 | 287 |
@Override |
324 | 288 |
public String getPassword() { |
325 | 289 |
return password; |
... | ... | |
328 | 292 |
@Override |
329 | 293 |
public void setPassword(String password) { |
330 | 294 |
this.password = password; |
331 |
|
|
295 |
|
|
332 | 296 |
} |
333 |
|
|
297 |
|
|
334 | 298 |
@Override |
335 | 299 |
public String getUsername() { |
336 | 300 |
return username; |
... | ... | |
339 | 303 |
@Override |
340 | 304 |
public void setUsername(String username) { |
341 | 305 |
this.username = username; |
342 |
|
|
343 |
} |
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 | 306 |
|
307 |
} |
|
350 | 308 |
|
309 |
//********************* TO STRING() **********************/ |
|
351 | 310 |
|
352 | 311 |
@Override |
353 | 312 |
public String toString() { |
... | ... | |
359 | 318 |
} |
360 | 319 |
} |
361 | 320 |
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
|
366 | 321 |
} |
367 | 322 |
|
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/CdmPersistentDataSource.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
41 | 41 |
import eu.etaxonomy.cdm.config.CdmPersistentXMLSource.CdmSourceProperties; |
42 | 42 |
import eu.etaxonomy.cdm.config.ICdmPersistentSource; |
43 | 43 |
import eu.etaxonomy.cdm.database.types.IDatabaseType; |
44 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
45 | 44 |
|
46 | 45 |
|
47 | 46 |
/** |
... | ... | |
49 | 48 |
*/ |
50 | 49 |
public class CdmPersistentDataSource extends CdmDataSourceBase implements ICdmPersistentSource { |
51 | 50 |
private static final Logger logger = Logger.getLogger(CdmPersistentDataSource.class); |
52 |
|
|
51 |
|
|
53 | 52 |
public static final String DATASOURCE_BEAN_POSTFIX = "DataSource"; |
54 | 53 |
|
55 |
|
|
54 |
|
|
56 | 55 |
private String beanName; |
57 |
|
|
56 |
|
|
58 | 57 |
private String database; |
59 |
|
|
58 |
|
|
60 | 59 |
/** |
61 | 60 |
* This is strictly a <String, String> list of properties |
62 | 61 |
*/ |
... | ... | |
68 | 67 |
/** |
69 | 68 |
* The Datasource class that Spring will use to set up the connection to the database |
70 | 69 |
*/ |
71 |
private static String dataSourceClassName = ComboPooledDataSource.class.getName(); |
|
70 |
private static String dataSourceClassName = ComboPooledDataSource.class.getName(); |
|
71 |
|
|
72 | 72 |
|
73 |
|
|
74 | 73 |
/** |
75 | 74 |
* Returns the default CdmDataSource |
76 | 75 |
* @return the default CdmDataSource |
77 |
* @throws DataSourceNotFoundException
|
|
76 |
* @throws DataSourceNotFoundException |
|
78 | 77 |
*/ |
79 | 78 |
public final static CdmPersistentDataSource NewDefaultInstance() throws DataSourceNotFoundException { |
80 | 79 |
return NewInstance("default"); |
81 | 80 |
} |
82 |
|
|
83 |
|
|
81 |
|
|
82 |
|
|
84 | 83 |
/** |
85 | 84 |
* Returns the default CdmDataSource |
86 | 85 |
* @return the default CdmDataSource |
87 |
* @throws DataSourceNotFoundException
|
|
86 |
* @throws DataSourceNotFoundException |
|
88 | 87 |
*/ |
89 | 88 |
public final static CdmPersistentDataSource NewLocalHsqlInstance() throws DataSourceNotFoundException{ |
90 | 89 |
return NewInstance("localDefaultHsql"); |
91 | 90 |
} |
92 |
|
|
91 |
|
|
93 | 92 |
/** |
94 | 93 |
* Returns the CdmDataSource named by strDataSource |
95 | 94 |
* @param strDataSource |
... | ... | |
109 | 108 |
*/ |
110 | 109 |
private CdmPersistentDataSource(String strDataSource){ |
111 | 110 |
setName(strDataSource); |
112 |
loadSource(strDataSource);
|
|
111 |
loadSource(strDataSource); |
|
113 | 112 |
} |
114 |
|
|
113 |
|
|
115 | 114 |
private void loadSource(String strDataSource) { |
116 | 115 |
CdmPersistentXMLSource cdmPersistentXMLSource = CdmPersistentXMLSource.NewInstance(strDataSource, DATASOURCE_BEAN_POSTFIX); |
117 | 116 |
if(cdmPersistentXMLSource.getElement() != null) { |
118 | 117 |
beanName = cdmPersistentXMLSource.getBeanName(); |
119 |
// properties from the persistent xml file
|
|
118 |
// properties from the persistent xml file |
|
120 | 119 |
cdmSourceProperties = cdmPersistentXMLSource.getCdmSourceProperties(); |
121 | 120 |
cdmSourceAttributes = cdmPersistentXMLSource.getCdmSourceAttributes(); |
122 |
|
|
121 |
|
|
123 | 122 |
// added database specific properties if they are null |
124 | 123 |
String url = getCdmSourceProperty(CdmSourceProperties.URL); |
125 | 124 |
DatabaseTypeEnum dbTypeEnum = getDatabaseType(); |
126 | 125 |
if (dbTypeEnum != null && url != null){ |
127 |
IDatabaseType dbType = dbTypeEnum.getDatabaseType();
|
|
126 |
IDatabaseType dbType = dbTypeEnum.getDatabaseType(); |
|
128 | 127 |
if (getCdmSourceProperty(CdmSourceProperties.DATABASE) == null){ |
129 | 128 |
String database = dbType.getDatabaseNameByConnectionString(url); |
130 | 129 |
if(database != null) { |
... | ... | |
138 | 137 |
} |
139 | 138 |
} |
140 | 139 |
if(getCdmSourceProperty(CdmSourceProperties.PORT) == null){ |
141 |
int port = dbType.getPortByConnectionString(url);
|
|
140 |
int port = dbType.getPortByConnectionString(url); |
|
142 | 141 |
if(port > 0) { |
143 | 142 |
setPort(port); |
144 | 143 |
} else { |
... | ... | |
146 | 145 |
} |
147 | 146 |
} |
148 | 147 |
} |
149 |
}
|
|
148 |
} |
|
150 | 149 |
} |
151 |
|
|
152 |
public String getBeanName() { |
|
150 |
|
|
151 |
@Override |
|
152 |
public String getBeanName() { |
|
153 | 153 |
return beanName; |
154 | 154 |
} |
155 |
|
|
155 |
|
|
156 | 156 |
@Override |
157 | 157 |
public String getDatabase() { |
158 | 158 |
return database; |
... | ... | |
164 | 164 |
this.database = database; |
165 | 165 |
//update url string |
166 | 166 |
cdmSourceProperties.put(CdmSourceProperties.URL.toString(), getDatabaseType().getConnectionString(this)); |
167 |
|
|
167 |
|
|
168 | 168 |
} |
169 |
|
|
169 |
|
|
170 | 170 |
@Override |
171 | 171 |
public void setServer(String server) { |
172 | 172 |
super.setServer(server); |
173 | 173 |
//update url string |
174 | 174 |
cdmSourceProperties.put(CdmSourceProperties.URL.toString(), getDatabaseType().getConnectionString(this)); |
175 | 175 |
} |
176 |
|
|
176 |
|
|
177 | 177 |
@Override |
178 | 178 |
public void setPort(int port) { |
179 | 179 |
super.setPort(port); |
180 |
if(port != NULL_PORT) {
|
|
180 |
if(port != NULL_PORT) { |
|
181 | 181 |
//update url string |
182 | 182 |
cdmSourceProperties.put(CdmSourceProperties.URL.toString(), getDatabaseType().getConnectionString(this)); |
183 | 183 |
} |
184 | 184 |
} |
185 | 185 |
@Override |
186 |
public String getFilePath() {
|
|
186 |
public String getFilePath() { |
|
187 | 187 |
return getCdmSourceProperty(CdmSourceProperties.FILEPATH); |
188 | 188 |
} |
189 | 189 |
|
190 | 190 |
|
191 | 191 |
@Override |
192 |
public H2Mode getMode() {
|
|
192 |
public H2Mode getMode() { |
|
193 | 193 |
return H2Mode.fromString(getCdmSourceProperty(CdmSourceProperties.MODE)); |
194 | 194 |
} |
195 |
|
|
195 |
|
|
196 | 196 |
@Override |
197 | 197 |
public void setMode(H2Mode h2Mode) { |
198 | 198 |
cdmSourceProperties.put(CdmSourceProperties.MODE.toString(), h2Mode.name()); |
199 |
|
|
199 |
|
|
200 | 200 |
} |
201 |
|
|
201 |
|
|
202 | 202 |
@Override |
203 | 203 |
public String getUsername(){ |
204 | 204 |
return getCdmSourceProperty(CdmSourceProperties.USERNAME); |
205 | 205 |
} |
206 |
|
|
206 |
|
|
207 | 207 |
@Override |
208 | 208 |
public void setUsername(String username) { |
209 | 209 |
cdmSourceProperties.put(CdmSourceProperties.USERNAME.toString(), username); |
210 |
|
|
210 |
|
|
211 | 211 |
} |
212 |
|
|
212 |
|
|
213 | 213 |
@Override |
214 | 214 |
public String getPassword(){ |
215 | 215 |
return getCdmSourceProperty(CdmSourceProperties.PASSWORD); |
216 | 216 |
} |
217 |
|
|
217 |
|
|
218 | 218 |
@Override |
219 | 219 |
public void setPassword(String password) { |
220 | 220 |
cdmSourceProperties.put(CdmSourceProperties.PASSWORD.toString(), password); |
221 |
|
|
222 |
} |
|
223 | 221 |
|
224 |
@Override |
|
225 |
public NomenclaturalCode getNomenclaturalCode() { |
|
226 |
// TODO null |
|
227 |
return NomenclaturalCode.fromString(getCdmSourceProperty(CdmSourceProperties.NOMENCLATURAL_CODE)); |
|
228 |
} |
|
229 |
|
|
230 |
@Override |
|
231 |
public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode) { |
|
232 |
cdmSourceProperties.put(CdmSourceProperties.NOMENCLATURAL_CODE.toString(), nomenclaturalCode.name()); |
|
233 | 222 |
} |
234 | 223 |
|
235 |
|
|
236 |
|
|
237 | 224 |
@Override |
238 | 225 |
public DatabaseTypeEnum getDatabaseType(){ |
239 | 226 |
String strDriverClass = getCdmSourceProperty(CdmSourceProperties.DRIVER_CLASS); |
240 | 227 |
DatabaseTypeEnum dbType = DatabaseTypeEnum.byDriverClass(strDriverClass); |
241 | 228 |
return dbType; |
242 | 229 |
} |
243 |
|
|
244 |
|
|
245 |
public String getCdmSourceProperty(CdmSourceProperties property){
|
|
230 |
|
|
231 |
|
|
232 |
public String getCdmSourceProperty(CdmSourceProperties property){ |
|
246 | 233 |
return cdmSourceProperties.getProperty(property.toString(),null); |
247 | 234 |
} |
248 | 235 |
|
... | ... | |
254 | 241 |
@SuppressWarnings("unchecked") |
255 | 242 |
@Override |
256 | 243 |
public BeanDefinition getDatasourceBean(){ |
257 |
DatabaseTypeEnum dbtype =
|
|
244 |
DatabaseTypeEnum dbtype = |
|
258 | 245 |
DatabaseTypeEnum.byDriverClass(getCdmSourceProperty(CdmSourceProperties.DRIVER_CLASS)); |
259 |
|
|
246 |
|
|
260 | 247 |
AbstractBeanDefinition bd = new RootBeanDefinition(dbtype.getDataSourceClass()); |
261 | 248 |
//attributes |
262 | 249 |
Iterator<Attribute> iterator = cdmSourceAttributes.iterator(); |
... | ... | |
273 | 260 |
} |
274 | 261 |
//Attribute attribute = iterator.next(); |
275 | 262 |
//bd.setAttribute(attribute.getName(), attribute.getValue()); |
276 |
}
|
|
277 |
|
|
263 |
} |
|
264 |
|
|
278 | 265 |
//properties |
279 | 266 |
MutablePropertyValues props = new MutablePropertyValues(); |
280 |
|
|
281 |
Enumeration<String> keys = (Enumeration)cdmSourceProperties.keys();
|
|
267 |
|
|
268 |
Enumeration<String> keys = (Enumeration)cdmSourceProperties.keys(); |
|
282 | 269 |
while (keys.hasMoreElements()){ |
283 |
String key = (String)keys.nextElement(); |
|
284 |
|
|
285 |
if (key.equals("nomenclaturalCode") && cdmSourceProperties.getProperty(key).equals("ICBN")){ |
|
286 |
//bugfix for old nomenclatural codes, remove if fixed elsewhere, see https://dev.e-taxonomy.eu/trac/ticket/3658 |
|
287 |
props.addPropertyValue(key, NomenclaturalCode.ICNAFP.name()); |
|
288 |
}else{ |
|
289 |
props.addPropertyValue(key, cdmSourceProperties.getProperty(key)); |
|
290 |
} |
|
270 |
String key = keys.nextElement(); |
|
271 |
|
|
272 |
props.addPropertyValue(key, cdmSourceProperties.getProperty(key)); |
|
291 | 273 |
} |
292 | 274 |
|
293 |
|
|
294 |
|
|
295 | 275 |
bd.setPropertyValues(props); |
296 | 276 |
return bd; |
297 | 277 |
} |
298 |
|
|
278 |
|
|
299 | 279 |
/** |
300 | 280 |
* @param hbm2dll |
301 | 281 |
* @param showSql |
... | ... | |
309 | 289 |
Class<? extends RegionFactory> cacheProviderClass = NoCachingRegionFactory.class; |
310 | 290 |
return getHibernatePropertiesBean(hbm2dll, showSql, formatSql, registerSearchListener, cacheProviderClass); |
311 | 291 |
} |
312 |
|
|
313 |
|
|
292 |
|
|
293 |
|
|
314 | 294 |
/** |
315 | 295 |
* @param hbm2dll |
316 | 296 |
* @param showSql |
... | ... | |
334 | 314 |
if(registerSearchListener == null){ |
335 | 315 |
registerSearchListener = false; |
336 | 316 |
} |
337 |
|
|
317 |
|
|
338 | 318 |
DatabaseTypeEnum dbtype = getDatabaseType(); |
339 | 319 |
AbstractBeanDefinition bd = new RootBeanDefinition(PropertiesFactoryBean.class); |
340 | 320 |
MutablePropertyValues hibernateProps = new MutablePropertyValues(); |
... | ... | |
351 | 331 |
bd.setPropertyValues(hibernateProps); |
352 | 332 |
return bd; |
353 | 333 |
} |
354 |
|
|
355 |
|
|
334 |
|
|
335 |
|
|
356 | 336 |
/** |
357 | 337 |
* Tests existing of the datsource in the according config file. |
358 | 338 |
* @return true if a datasource with the given name exists in the according datasource config file. |
... | ... | |
365 | 345 |
/** |
366 | 346 |
* @param strDataSourceName |
367 | 347 |
* @param dataSource |
368 |
* @param code
|
|
348 |
* @param code |
|
369 | 349 |
* @return |
370 | 350 |
* the updated dataSource, null if not succesful |
371 | 351 |
*/ |
... | ... | |
374 | 354 |
CdmPersistentSourceUtils.delete(CdmPersistentSourceUtils.getBeanName(strDataSourceName,DATASOURCE_BEAN_POSTFIX)); |
375 | 355 |
return save(strDataSourceName, dataSource); |
376 | 356 |
} |
377 |
|
|
357 |
|
|
378 | 358 |
/** |
379 | 359 |
* Replace the persisted datasource with another one. |
380 | 360 |
* Used primarily for renaming a datasource. |
381 |
*
|
|
361 |
* |
|
382 | 362 |
* @param strDataSourceName |
383 | 363 |
* @param dataSource |
384 | 364 |
* @return |
... | ... | |
390 | 370 |
CdmPersistentSourceUtils.delete(CdmPersistentSourceUtils.getBeanName(strDataSourceName,DATASOURCE_BEAN_POSTFIX)); |
391 | 371 |
return save(dataSource); |
392 | 372 |
} |
393 |
|
|
373 |
|
|
394 | 374 |
/** |
395 | 375 |
* @param dataSource |
396 | 376 |
* @return |
... | ... | |
399 | 379 |
public static CdmPersistentDataSource save(ICdmDataSource dataSource) throws IllegalArgumentException { |
400 | 380 |
return save(dataSource.getName(),dataSource); |
401 | 381 |
} |
402 |
|
|
382 |
|
|
403 | 383 |
/** |
404 |
*
|
|
384 |
* |
|
405 | 385 |
* @param strDataSourceName |
406 | 386 |
* @param databaseTypeEnum |
407 | 387 |
* @param server |
... | ... | |
418 | 398 |
* @param mode |
419 | 399 |
* @return |
420 | 400 |
*/ |
421 |
private static CdmPersistentDataSource save(String strDataSourceName,
|
|
422 |
DatabaseTypeEnum databaseTypeEnum,
|
|
423 |
String server,
|
|
424 |
String database,
|
|
425 |
String port,
|
|
426 |
String username,
|
|
427 |
String password,
|
|
401 |
private static CdmPersistentDataSource save(String strDataSourceName, |
|
402 |
DatabaseTypeEnum databaseTypeEnum, |
|
403 |
String server, |
|
404 |
String database, |
|
405 |
String port, |
|
406 |
String username, |
|
407 |
String password, |
|
428 | 408 |
Class<? extends DataSource> dataSourceClass, |
429 | 409 |
String initMethod, |
430 | 410 |
String destroyMethod, |
431 | 411 |
Boolean startSilent, |
432 |
Boolean startServer,
|
|
412 |
Boolean startServer, |
|
433 | 413 |
String filePath, |
434 |
H2Mode mode, |
|
435 |
NomenclaturalCode code |
|
414 |
H2Mode mode |
|
436 | 415 |
){ |
437 |
|
|
416 |
|
|
438 | 417 |
int portNumber = "".equals(port) ? databaseTypeEnum.getDefaultPort() : Integer.valueOf(port); |
439 |
|
|
440 |
ICdmDataSource dataSource = new CdmDataSource(databaseTypeEnum, server, database, portNumber, username, password, filePath, mode, code);
|
|
441 |
|
|
418 |
|
|
419 |
ICdmDataSource dataSource = new CdmDataSource(databaseTypeEnum, server, database, portNumber, username, password, filePath, mode); |
|
420 |
|
|
442 | 421 |
//root |
443 | 422 |
Element root = getBeansRoot(CdmPersistentSourceUtils.getCdmSourceInputStream()); |
444 | 423 |
if (root == null){ |
... | ... | |
454 | 433 |
bean.setAttribute("lazy-init", "true"); |
455 | 434 |
if (initMethod != null) {bean.setAttribute("init-method", initMethod);} |
456 | 435 |
if (destroyMethod != null) {bean.setAttribute("destroy-method", destroyMethod);} |
457 |
|
|
436 |
|
|
458 | 437 |
//set properties |
459 | 438 |
insertXmlValueProperty(bean, "driverClassName", databaseTypeEnum.getDriverClassName()); |
460 |
|
|
439 |
|
|
461 | 440 |
insertXmlValueProperty(bean, "url", databaseTypeEnum.getConnectionString(dataSource)); |
462 | 441 |
if (username != null) {insertXmlValueProperty(bean, "username", username );} |
463 | 442 |
if (password != null) {insertXmlValueProperty(bean, "password", password );} |
... | ... | |
465 | 444 |
if (startServer != null) {insertXmlValueProperty(bean, "startServer", startServer.toString() );} |
466 | 445 |
if (filePath != null) {insertXmlValueProperty(bean, "filePath", filePath );} |
467 | 446 |
if (mode != null) {insertXmlValueProperty(bean, "mode", mode.toString() );} |
468 |
if (code != null) {insertXmlValueProperty(bean, "nomenclaturalCode", code.name());} |
|
469 |
|
|
447 |
|
|
470 | 448 |
//save |
471 |
saveToXml(root.getDocument(),
|
|
472 |
CdmPersistentSourceUtils.getResourceDirectory(),
|
|
473 |
CdmPersistentXMLSource.CDMSOURCE_FILE_NAME,
|
|
449 |
saveToXml(root.getDocument(), |
|
450 |
CdmPersistentSourceUtils.getResourceDirectory(), |
|
451 |
CdmPersistentXMLSource.CDMSOURCE_FILE_NAME, |
|
474 | 452 |
XmlHelp.prettyFormat ); |
475 | 453 |
try { |
476 | 454 |
return NewInstance(strDataSourceName) ; |
... | ... | |
479 | 457 |
return null; |
480 | 458 |
} |
481 | 459 |
} |
482 |
|
|
460 |
|
|
483 | 461 |
|
484 | 462 |
/** |
485 | 463 |
* Saves a datasource to the datasource config file. If strDataSourceName differs a new dataSource |
486 | 464 |
* will be created in config file. Use update() of real update functionality. |
487 |
*
|
|
465 |
* |
|
488 | 466 |
* @param strDataSourceName |
489 | 467 |
* @param dataSource |
490 | 468 |
* @return |
491 | 469 |
*/ |
492 | 470 |
public static CdmPersistentDataSource save(String strDataSourceName, |
493 | 471 |
ICdmDataSource dataSource) throws IllegalArgumentException{ |
494 |
|
|
472 |
|
|
495 | 473 |
if(dataSource.getDatabaseType() == null){ |
496 | 474 |
new IllegalArgumentException("Database type not specified"); |
497 | 475 |
} |
498 |
|
|
476 |
|
|
499 | 477 |
if(dataSource.getDatabaseType().equals(DatabaseTypeEnum.H2)){ |
500 | 478 |
Class<? extends DataSource> dataSourceClass = LocalH2.class; |
501 | 479 |
if(dataSource.getMode() == null) { |
502 | 480 |
new IllegalArgumentException("H2 mode not specified"); |
503 |
}
|
|
481 |
} |
|
504 | 482 |
return save( |
505 |
strDataSourceName,
|
|
506 |
dataSource.getDatabaseType(),
|
|
507 |
"localhost",
|
|
508 |
getCheckedDataSourceParameter(dataSource.getDatabase()),
|
|
509 |
dataSource.getDatabaseType().getDefaultPort() + "",
|
|
510 |
getCheckedDataSourceParameter(dataSource.getUsername()),
|
|
511 |
getCheckedDataSourceParameter(dataSource.getPassword()),
|
|
512 |
dataSourceClass,
|
|
513 |
null, null, null, null,
|
|
514 |
dataSource.getFilePath(),
|
|
515 |
dataSource.getMode(),
|
|
516 |
dataSource.getNomenclaturalCode());
|
|
483 |
strDataSourceName, |
|
484 |
dataSource.getDatabaseType(), |
|
485 |
"localhost", |
|
486 |
getCheckedDataSourceParameter(dataSource.getDatabase()), |
|
487 |
dataSource.getDatabaseType().getDefaultPort() + "", |
|
488 |
getCheckedDataSourceParameter(dataSource.getUsername()), |
|
489 |
getCheckedDataSourceParameter(dataSource.getPassword()), |
|
490 |
dataSourceClass, |
|
491 |
null, null, null, null, |
|
492 |
dataSource.getFilePath(), |
|
493 |
dataSource.getMode() |
|
494 |
); |
|
517 | 495 |
}else{ |
518 |
|
|
496 |
|
|
519 | 497 |
Class<? extends DataSource> dataSourceClass; |
520 | 498 |
try { |
521 | 499 |
dataSourceClass = (Class<? extends DataSource>) Class.forName(dataSourceClassName); |
522 | 500 |
String server = getCheckedDataSourceParameter(dataSource.getServer()); |
523 | 501 |
CdmPersistentDataSource persistendDatasource = save( |
524 |
strDataSourceName,
|
|
525 |
dataSource.getDatabaseType(),
|
|
526 |
getCheckedDataSourceParameter(dataSource.getServer()),
|
|
527 |
getCheckedDataSourceParameter(dataSource.getDatabase()),
|
|
528 |
dataSource.getPort() + "",
|
|
529 |
getCheckedDataSourceParameter(dataSource.getUsername()),
|
|
530 |
getCheckedDataSourceParameter(dataSource.getPassword()),
|
|
531 |
dataSourceClass,
|
|
532 |
null, null, null, null, null, null,
|
|
533 |
dataSource.getNomenclaturalCode());
|
|
534 |
|
|
502 |
strDataSourceName, |
|
503 |
dataSource.getDatabaseType(), |
|
504 |
getCheckedDataSourceParameter(dataSource.getServer()), |
|
505 |
getCheckedDataSourceParameter(dataSource.getDatabase()), |
|
506 |
dataSource.getPort() + "", |
|
507 |
getCheckedDataSourceParameter(dataSource.getUsername()), |
|
508 |
getCheckedDataSourceParameter(dataSource.getPassword()), |
|
509 |
dataSourceClass, |
|
510 |
null, null, null, null, null, null |
|
511 |
); |
|
512 |
|
|
535 | 513 |
return persistendDatasource; |
536 | 514 |
} catch (ClassNotFoundException e) { |
537 | 515 |
logger.error("DataSourceClass not found - stopping application", e); |
... | ... | |
542 | 520 |
} |
543 | 521 |
} |
544 | 522 |
|
545 |
private static String getCheckedDataSourceParameter(String parameter) throws IllegalArgumentException{
|
|
523 |
private static String getCheckedDataSourceParameter(String parameter) throws IllegalArgumentException{ |
|
546 | 524 |
if(parameter != null) { |
547 | 525 |
return parameter; |
548 | 526 |
} else { |
549 | 527 |
throw new IllegalArgumentException("Non obsolete paramater was assigned a null value: " + parameter); |
550 | 528 |
} |
551 | 529 |
} |
552 |
|
|
553 |
|
|
530 |
|
|
531 |
|
|
554 | 532 |
/** |
555 | 533 |
* Returns a list of all datasources stored in the datasource config file |
556 | 534 |
* @return all existing data sources |
... | ... | |
558 | 536 |
@SuppressWarnings("unchecked") |
559 | 537 |
static public List<CdmPersistentDataSource> getAllDataSources(){ |
560 | 538 |
List<CdmPersistentDataSource> dataSources = new ArrayList<CdmPersistentDataSource>(); |
561 |
|
|
539 |
|
|
562 | 540 |
Element root = getBeansRoot(CdmPersistentSourceUtils.getCdmSourceInputStream()); |
563 | 541 |
if (root == null){ |
564 | 542 |
return null; |
565 | 543 |
}else{ |
566 | 544 |
List<Element> lsChildren = root.getChildren("bean", root.getNamespace()); |
567 |
|
|
545 |
|
|
568 | 546 |
for (Element elBean : lsChildren){ |
569 | 547 |
String strId = elBean.getAttributeValue("id"); |
570 | 548 |
if (strId != null && strId.endsWith(DATASOURCE_BEAN_POSTFIX)){ |
... | ... | |
575 | 553 |
} |
576 | 554 |
return dataSources; |
577 | 555 |
} |
578 |
|
|
579 |
|
|
556 |
|
|
557 |
|
|
580 | 558 |
@Override |
581 | 559 |
public boolean equals(Object obj){ |
582 | 560 |
if (obj == null){ |
... | ... | |
589 | 567 |
} |
590 | 568 |
|
591 | 569 |
} |
592 |
|
|
570 |
|
|
593 | 571 |
@Override |
594 | 572 |
public String toString(){ |
595 | 573 |
if (getName() != null){ |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/DbcpSaveDataSource.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.cdm.database; |
|
12 |
|
|
13 |
import java.sql.SQLException; |
|
14 |
|
|
15 |
import javax.sql.DataSource; |
|
16 |
|
|
17 |
import org.apache.commons.dbcp.BasicDataSource; |
|
18 |
import org.apache.commons.pool.impl.GenericObjectPool; |
|
19 |
import org.apache.log4j.Logger; |
|
20 |
|
|
21 |
/** |
|
22 |
* @author n.hoffmann |
|
23 |
* @created Sep 22, 2009 |
|
24 |
*/ |
|
25 |
public class DbcpSaveDataSource extends BasicDataSource { |
|
26 |
@SuppressWarnings("unused") |
|
27 |
private static final Logger logger = Logger.getLogger(DbcpSaveDataSource.class); |
|
28 |
|
|
29 |
/* FIXME This is a workaround to solve a problem with dbcp connection pooling. |
|
30 |
* Remove this when dbcp connection pool gets configured correctly |
|
31 |
* |
|
32 |
* (non-Javadoc) |
|
33 |
* @see org.apache.commons.dbcp.BasicDataSource#createDataSource() |
|
34 |
*/ |
|
35 |
@Override |
|
36 |
protected synchronized DataSource createDataSource() throws SQLException { |
|
37 |
super.createDataSource(); |
|
38 |
connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW); |
|
39 |
return dataSource; |
|
40 |
} |
|
41 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/LocalH2.java | ||
---|---|---|
26 | 26 |
import org.springframework.jdbc.CannotGetJdbcConnectionException; |
27 | 27 |
|
28 | 28 |
import eu.etaxonomy.cdm.api.application.CdmApplicationUtils; |
29 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
30 | 29 |
|
31 | 30 |
|
32 | 31 |
/** |
... | ... | |
57 | 56 |
protected String DEFAULT_DRIVER_CLASS_NAME = "org.h2.Driver"; |
58 | 57 |
String mode = H2Mode.EMBEDDED.toString(); |
59 | 58 |
|
60 |
private NomenclaturalCode nomenclaturalCode; |
|
61 |
|
|
62 | 59 |
/** |
63 | 60 |
* |
64 | 61 |
*/ |
... | ... | |
231 | 228 |
return mode; |
232 | 229 |
} |
233 | 230 |
|
234 |
public void setNomenclaturalCode(NomenclaturalCode code){ |
|
235 |
this.nomenclaturalCode = code; |
|
236 |
} |
|
237 |
|
|
238 |
|
|
239 | 231 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/NomenclaturalCodeAwareDataSource.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.cdm.database; |
|
12 |
|
|
13 |
import java.sql.SQLException; |
|
14 |
|
|
15 |
import javax.sql.DataSource; |
|
16 |
|
|
17 |
import org.apache.commons.dbcp.BasicDataSource; |
|
18 |
import org.apache.commons.pool.impl.GenericObjectPool; |
|
19 |
import org.apache.log4j.Logger; |
|
20 |
|
|
21 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
22 |
|
|
23 |
/** |
|
24 |
* @author n.hoffmann |
|
25 |
* @created Sep 22, 2009 |
|
26 |
*/ |
|
27 |
public class NomenclaturalCodeAwareDataSource extends BasicDataSource { |
|
28 |
@SuppressWarnings("unused") |
|
29 |
private static final Logger logger = Logger.getLogger(NomenclaturalCodeAwareDataSource.class); |
|
30 |
|
|
31 |
private NomenclaturalCode nomenclaturalCode; |
|
32 |
|
|
33 |
public NomenclaturalCode getNomenclaturalCode() { |
|
34 |
return nomenclaturalCode; |
|
35 |
} |
Also available in: Unified diff
ref #3658 remove nomenclaturalCode from all datasource related classes