annotate artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/DBConfig.java @ 8856:5e38e2924c07 3.2.x

Fix code style.
author Tom Gottfried <tom@intevation.de>
date Thu, 18 Jan 2018 20:12:01 +0100
parents e4606eae8ea5
children 0a5239a1e46e
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 =
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
61 "jdbc:h2:mem:datacage;"
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
62 + "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
63
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 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
65
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 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
67
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 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
69 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
70
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 public DBConfig() {
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
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 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
75 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
76 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
77 }
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 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
80 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
81 instance = createInstance();
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 }
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 return instance;
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
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 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
87 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
88 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
89
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 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
91 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
92
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 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
94
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 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
96 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
97
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 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
99 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
100
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 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
102 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
103
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 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
105
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 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
107 }
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 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
110 return dbConnection;
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
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 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
114 return sql;
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 }
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org