Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package de.unipotsdam.cs.toolup.database;
import java.io.IOException;
import java.util.Properties;
public class ToolUpProperties {
private static final String KEY_SERVERADRESS = "database server adress";
private static final String KEY_SERVERPORT = "database server port";
private static final String KEY_USERNAME = "database user name";
private static final String KEY_PASSWORD = "database password";
private static final String KEY_SCHEMA = "database schema";
private static final String DATABASE_CONNECTOR = "jdbc:mysql://";
private static String DATABASE_URL = null;
private static Properties PROPERTIES = null;
/**
* Constructs the database url out of the read properties.
*
* @return the url of the configured DB
* @throws IOException
*/
public static String getDatabaseUrl() throws IOException {
if (DATABASE_URL == null) {
DATABASE_URL = DATABASE_CONNECTOR +
getProperties().getProperty(KEY_SERVERADRESS) +
":" +
getProperties().getProperty(KEY_SERVERPORT) +
"/" +
getProperties().getProperty(KEY_SCHEMA) +
"?user=" +
getProperties().getProperty(KEY_USERNAME + "&pw=") +
getProperties().getProperty(KEY_PASSWORD);
}
return DATABASE_URL;
}
/**
* @return the ToolUp singleton Properties object
* @throws IOException
*/
public static Properties getProperties() throws IOException {
if (PROPERTIES == null) {
loadPropertiesFromFile();
}
return PROPERTIES;
}
private static synchronized void loadPropertiesFromFile() throws IOException {
if (PROPERTIES == null) {
PROPERTIES = new Properties();
PROPERTIES.loadFromXML(ToolUpProperties.class.getResourceAsStream("/Tool.UP_cfg.xml"));