Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/DBConfig.java @ 3814:8083f6384023
merged flys-artifacts/pre2.6-2012-01-04
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:56 +0200 |
parents | 9a1a3080ad98 |
children | 5642a83420f2 |
comparison
equal
deleted
inserted
replaced
1491:2a00f4849738 | 3814:8083f6384023 |
---|---|
1 package de.intevation.flys.artifacts.datacage; | |
2 | |
3 import de.intevation.artifacts.common.utils.Config; | |
4 | |
5 import de.intevation.artifactdatabase.db.SQL; | |
6 import de.intevation.artifactdatabase.db.DBConnection; | |
7 | |
8 import org.apache.log4j.Logger; | |
9 | |
10 public class DBConfig | |
11 { | |
12 private static Logger logger = Logger.getLogger(DBConfig.class); | |
13 | |
14 /** | |
15 * XPath to access the database driver within the global configuration. | |
16 */ | |
17 public static final String DB_DRIVER = | |
18 "/artifact-database/datacage/driver/text()"; | |
19 /** | |
20 * XPath to access the database URL within the global configuration. | |
21 */ | |
22 public static final String DB_URL = | |
23 "/artifact-database/datacage/url/text()"; | |
24 /** | |
25 * XPath to access the database use within the global configuration. | |
26 */ | |
27 public static final String DB_USER = | |
28 "/artifact-database/datacage/user/text()"; | |
29 /** | |
30 * XPath to access the database password within the global configuration. | |
31 */ | |
32 public static final String DB_PASSWORD = | |
33 "/artifact-database/datacage/password/text()"; | |
34 | |
35 /** | |
36 * The default database driver: H2 | |
37 */ | |
38 public static final String DEFAULT_DRIVER = | |
39 "org.h2.Driver"; | |
40 | |
41 /** | |
42 * The default database user: "" | |
43 */ | |
44 public static final String DEFAULT_USER = ""; | |
45 | |
46 /** | |
47 * The default database password: "" | |
48 */ | |
49 public static final String DEFAULT_PASSWORD = ""; | |
50 | |
51 | |
52 public static final String DEFAULT_URL = | |
53 "jdbc:h2:mem:datacage;INIT=RUNSCRIPT FROM '${artifacts.config.dir}/datacage.sql'"; | |
54 | |
55 public static final String RESOURCE_PATH = "/datacage-sql"; | |
56 | |
57 private static DBConfig instance; | |
58 | |
59 protected DBConnection dbConnection; | |
60 protected SQL sql; | |
61 | |
62 public DBConfig() { | |
63 } | |
64 | |
65 public DBConfig(DBConnection dbConnection, SQL sql) { | |
66 this.dbConnection = dbConnection; | |
67 this.sql = sql; | |
68 } | |
69 | |
70 public static synchronized DBConfig getInstance() { | |
71 if (instance == null) { | |
72 instance = createInstance(); | |
73 } | |
74 return instance; | |
75 } | |
76 | |
77 protected static DBConfig createInstance() { | |
78 String driver = Config.getStringXPath( | |
79 DB_DRIVER, DEFAULT_DRIVER); | |
80 | |
81 String url = Config.getStringXPath( | |
82 DB_URL, DEFAULT_URL); | |
83 | |
84 url = Config.replaceConfigDir(url); | |
85 | |
86 String user = Config.getStringXPath( | |
87 DB_USER, DEFAULT_USER); | |
88 | |
89 String password = Config.getStringXPath( | |
90 DB_PASSWORD, DEFAULT_PASSWORD); | |
91 | |
92 DBConnection dbConnection = new DBConnection( | |
93 driver, url, user, password); | |
94 | |
95 SQL sql = new SQL(DBConfig.class, RESOURCE_PATH, driver); | |
96 | |
97 return new DBConfig(dbConnection, sql); | |
98 } | |
99 | |
100 public DBConnection getDBConnection() { | |
101 return dbConnection; | |
102 } | |
103 | |
104 public SQL getSQL() { | |
105 return sql; | |
106 } | |
107 } | |
108 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |