annotate artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/DBConfig.java @ 9801:1d7a72a50183 3.2.x tip

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
children
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
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
16 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
17 import org.apache.logging.log4j.LogManager;
983
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 public class DBConfig
3076
5642a83420f2 FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1015
diff changeset
20 {
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
21 private static Logger log = LogManager.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
22
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 /**
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 * 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
25 */
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 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
27 "/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
28 /**
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 * 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
30 */
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 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
32 "/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
33 /**
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 * 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
35 */
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 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
37 "/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
38 /**
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 * 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
40 */
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 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
42 "/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
43
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 /**
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 * 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
46 */
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 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
48 "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
49
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 /**
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 * 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
52 */
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 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
54
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 /**
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 * 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
57 */
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 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
59
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 public static final String DEFAULT_URL =
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
62 "jdbc:h2:mem:datacage;"
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
63 + "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
64
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 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
66
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 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
68
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 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
70 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
71
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 public DBConfig() {
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
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 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
76 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
77 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
78 }
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 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
81 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
82 instance = createInstance();
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 return instance;
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
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 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
88 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
89 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
90
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 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
92 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
93
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 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
95
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 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
97 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
98
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 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
100 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
101
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 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
103 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
104
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 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
106
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 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
108 }
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 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
111 return dbConnection;
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
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114 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
115 return sql;
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 }
4ea5f5a2284e Ajusted datacage to use the SQL infrastructure from the artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org