annotate artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/DBConfig.java @ 8202:e4606eae8ea5

sed src/**/*.java 's/logger/log/g'
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 05 Sep 2014 12:58:17 +0200
parents af13ceeba52a
children 5e38e2924c07
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3076
diff changeset
9 package org.dive4elements.river.artifacts.datacage;
983
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3076
diff changeset
11 import org.dive4elements.artifacts.common.utils.Config;
983
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3076
diff changeset
13 import org.dive4elements.artifactdatabase.db.SQL;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3076
diff changeset
14 import org.dive4elements.artifactdatabase.db.DBConnection;
983
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import org.apache.log4j.Logger;
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 public class DBConfig
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1015
diff changeset
19 {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
20 private static Logger log = Logger.getLogger(DBConfig.class);
983
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 /**
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 * XPath to access the database driver within the global configuration.
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 */
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 public static final String DB_DRIVER =
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 "/artifact-database/datacage/driver/text()";
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 /**
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 * XPath to access the database URL within the global configuration.
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 */
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 public static final String DB_URL =
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 "/artifact-database/datacage/url/text()";
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 /**
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 * XPath to access the database use within the global configuration.
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 */
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 public static final String DB_USER =
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 "/artifact-database/datacage/user/text()";
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 /**
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 * XPath to access the database password within the global configuration.
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 */
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 public static final String DB_PASSWORD =
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 "/artifact-database/datacage/password/text()";
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 /**
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 * The default database driver: H2
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 */
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 public static final String DEFAULT_DRIVER =
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 "org.h2.Driver";
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 /**
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 * The default database user: ""
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 */
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 public static final String DEFAULT_USER = "";
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 /**
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 * The default database password: ""
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 */
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 public static final String DEFAULT_PASSWORD = "";
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 public static final String DEFAULT_URL =
994
3f9d46dd259c Fixed default connection URL to use a namend in-mermory database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 983
diff changeset
61 "jdbc:h2:mem:datacage;INIT=RUNSCRIPT FROM '${artifacts.config.dir}/datacage.sql'";
983
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 public static final String RESOURCE_PATH = "/datacage-sql";
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 private static DBConfig instance;
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 protected DBConnection dbConnection;
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 protected SQL sql;
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 public DBConfig() {
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 }
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 public DBConfig(DBConnection dbConnection, SQL sql) {
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 this.dbConnection = dbConnection;
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 this.sql = sql;
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 }
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 public static synchronized DBConfig getInstance() {
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 if (instance == null) {
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 instance = createInstance();
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 }
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 return instance;
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 }
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 protected static DBConfig createInstance() {
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 String driver = Config.getStringXPath(
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 DB_DRIVER, DEFAULT_DRIVER);
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 String url = Config.getStringXPath(
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 DB_URL, DEFAULT_URL);
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 url = Config.replaceConfigDir(url);
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 String user = Config.getStringXPath(
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 DB_USER, DEFAULT_USER);
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 String password = Config.getStringXPath(
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 DB_PASSWORD, DEFAULT_PASSWORD);
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 DBConnection dbConnection = new DBConnection(
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 driver, url, user, password);
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 SQL sql = new SQL(DBConfig.class, RESOURCE_PATH, driver);
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 return new DBConfig(dbConnection, sql);
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 }
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 public DBConnection getDBConnection() {
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 return dbConnection;
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 }
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112 public SQL getSQL() {
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 return sql;
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114 }
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115 }
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org