annotate geo-backend/src/main/java/de/intevation/gnv/geobackend/config/Configuration.java @ 1141:f030acb8d999

dummy merge for repo head
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:15:18 +0200
parents ebeb56428409
children
rev   line source
1127
ebeb56428409 Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1122
diff changeset
1 /*
ebeb56428409 Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1122
diff changeset
2 * Copyright (c) 2010 by Intevation GmbH
ebeb56428409 Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1122
diff changeset
3 *
ebeb56428409 Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1122
diff changeset
4 * This program is free software under the LGPL (>=v2.1)
ebeb56428409 Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1122
diff changeset
5 * Read the file LGPL.txt coming with the software for details
ebeb56428409 Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1122
diff changeset
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
ebeb56428409 Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1122
diff changeset
7 */
ebeb56428409 Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1122
diff changeset
8
1122
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 package de.intevation.gnv.geobackend.config;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPoolFactory;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import de.intevation.gnv.geobackend.base.query.container.QueryContainerFactory;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import de.intevation.gnv.geobackend.base.query.container.exception.QueryContainerException;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import de.intevation.gnv.geobackend.util.XMLUtils;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 import java.io.FileInputStream;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 import java.io.FileNotFoundException;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 import java.io.IOException;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 import java.io.InputStream;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 import java.util.Properties;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 import javax.xml.xpath.XPathConstants;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 import org.apache.log4j.Logger;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 import org.w3c.dom.Document;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 import org.w3c.dom.Node;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 import org.w3c.dom.NodeList;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 /**
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 public final class Configuration {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 public static final String CONFIGURATION_ROOT = "geo-backend";
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 public static final String XPATH_QUERIES = "query-configuration";
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 public static final String XPATH_BACKEND = "backend-configuration";
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 public static final String XPATH_CACHE = "cache";
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 public static final String XPATH_CACHE_ENABLED = "@enabled";
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 public static final String XPATH_CACHE_CONFIG = "configuration";
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 private static Logger logger = Logger.getLogger(Configuration.class);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 private static Configuration instance;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 private Node config;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 private String configDir;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 private String placeholder;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 private boolean cacheEnabled;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 private String cacheConfiguration;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 /**
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 * Returns an instance of Configuration.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 * @return an instance of Configuration.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 public static Configuration getInstance() {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 if (instance == null)
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 instance = new Configuration();
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 return instance;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 /**
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 * Constructor that creates a new Configuration object with disabled cache.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 public Configuration() {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 cacheEnabled = false;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 /**
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 * Initialize the geo-backend before it is ready to be used. This method
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 * calls other <i>init*</i> methods.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 * @param conf A configuration document. This document should contain a node
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 * <i>geo-backend</i>. If there are more nodes named <i>geo-backend</i>, the
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 * first node is used.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 * @param configDir The path to the root configuration directory.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 * @param placeholder The placeholder used in the configuration document for
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 * the root configuration directory.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 public void init(Document conf, String configDir, String placeholder)
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 throws QueryContainerException, FileNotFoundException, IOException
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 this.config = conf;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 this.configDir = configDir;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 this.placeholder = placeholder;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 NodeList root = conf.getElementsByTagName(CONFIGURATION_ROOT);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 if (root == null || root.getLength() == 0) {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 logger.error("No valid configuration for this geobackend given!");
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 return;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 initQueries(root.item(0));
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 initConnection(root.item(0));
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 initCache(root.item(0));
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 /**
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 * Initialize sql statements.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 * @param conf The geo-backend configuration node.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 protected void initQueries(Node conf)
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 throws FileNotFoundException, IOException, QueryContainerException
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 String queriesFile = (String) XMLUtils.xpath(
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 conf, XPATH_QUERIES, XPathConstants.STRING, null);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 queriesFile = replaceConfigDir(queriesFile);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 logger.info("Initialize queries: " + queriesFile);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124 Properties queries = getProperties(queriesFile);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 QueryContainerFactory qcf = QueryContainerFactory.getInstance();
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126 qcf.initializeQueryContainer(queries);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130 /**
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131 * Initialize necessary objects used for the database connection.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133 * @param connection The geo-backend configuration node.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135 protected void initConnection(Node connection)
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 throws FileNotFoundException, IOException
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
137 {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 String config = (String)XMLUtils.xpath(
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139 connection, XPATH_BACKEND, XPathConstants.STRING, null);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141 config = replaceConfigDir(config);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 logger.info("Initialize database connection: " + config);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144 Properties properties = getProperties(config);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 ConnectionPoolFactory cpf = ConnectionPoolFactory.getInstance();
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146 cpf.initializeConnectionPool(properties);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150 /**
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 * Initialize necessary objects used for the sql cache.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 * @param conf The geo-backend configuration node.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 protected void initCache(Node conf) {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156 Node cache = (Node) XMLUtils.xpath(
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
157 conf, XPATH_CACHE, XPathConstants.NODE, null);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159 String on = (String) XMLUtils.xpath(
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160 cache, XPATH_CACHE_ENABLED, XPathConstants.STRING, null);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162 boolean enabled = Boolean.parseBoolean(on);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
163
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
164 if (enabled) {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165 String config = (String) XMLUtils.xpath(
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
166 cache, XPATH_CACHE_CONFIG, XPathConstants.STRING, null);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
168 if (config != null && config.length() > 0) {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
169 config = replaceConfigDir(config);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170 logger.info("Initialize sql cache with config: " + config);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
171
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
172 this.cacheConfiguration = config;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173 this.cacheEnabled = true;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
174 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
175 else {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 logger.error("SQL cache is enabled, " +
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177 "but no configuration was found.");
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
180 else {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
181 logger.info("SQL cache is disabled.");
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186 /**
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
187 * Replace placeholder in the configuration. Placeholder are used for the
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
188 * base configuration directory.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
189 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
190 * @param path A string that might contain placeholders.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
191 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
192 * @return <i>path</i> with replaced placeholder.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
193 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
194 protected String replaceConfigDir(String path) {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
195 return path.replace(placeholder, configDir);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
196 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
197
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
198
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 /**
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
200 * Read a file that contains properties and return a Java Properties object.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
202 * @param path Path to a properties file.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
204 * @return the properties contained in the file.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
205 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
206 protected Properties getProperties(String path)
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
207 throws FileNotFoundException, IOException
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
208 {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
209 InputStream inputStream = null;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
210
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
211 try {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
212 inputStream = new FileInputStream(path);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
213 Properties properties = new Properties();
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
214 properties.load(inputStream);
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
215
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
216 return properties;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
217 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
218 finally {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
219 if (inputStream != null) {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
220 try {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
221 inputStream.close();
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
222 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
223 catch (IOException ioe) {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
224 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
225 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
226 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
227 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
228
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
229
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
230 /**
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
231 * Returns the state of the cache.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
232 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
233 * @return true if sql queries are cache, otherwise false.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
234 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
235 public boolean isCacheEnabled() {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
236 return cacheEnabled;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
237 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
238
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
239
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
240 /**
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
241 * Returns the path of the cache configuration file.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
242 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
243 * @return configuration path.
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
244 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
245 public String getCacheConfiguration() {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
246 return cacheConfiguration;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
247 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
248 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
249 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org