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

Raster elements returned from ArcSDE are put into an UncacheableSDEResultSet container that is NOT cached. geo-backend/trunk@1154 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 04 Jun 2010 08:19:38 +0000
parents 1985d5db0feb
children ebeb56428409
rev   line source
1122
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 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
2
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 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
4
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 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
6
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 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
8
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 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
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 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
12 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
13 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
14 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
15
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 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
17
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 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
19
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 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
21
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 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
23 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
24 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
25
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 /**
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 * @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
28 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 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
30
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 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
32 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
33 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
34 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
35 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
36 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
37
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 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
39
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 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
41
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 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
43 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
44 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
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 boolean cacheEnabled;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 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
48
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
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 /**
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 * 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
53 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 * @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
55 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 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
57 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
58 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
59
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 return instance;
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
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 /**
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 * 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
66 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 public Configuration() {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 cacheEnabled = false;
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 * 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
74 * 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
75 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 * @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
77 * <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
78 * 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
79 * @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
80 * @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
81 * 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
82 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 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
84 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
85 {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 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
87 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
88 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
89
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 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
91 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
92 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
93 return;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 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
97 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
98 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
99 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101
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 * 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
104 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 * @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
106 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 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
108 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
109 {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 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
111 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
112
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 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
114 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
115
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 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
117 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
118 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
119 }
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
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 /**
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123 * 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
124 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 * @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
126 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127 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
128 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
129 {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130 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
131 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
132
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133 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
134 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
135
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 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
137 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
138 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
139 }
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
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 /**
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143 * 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
144 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 * @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
146 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147 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
148 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
149 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
150
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 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
152 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
153
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154 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
155
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156 if (enabled) {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
157 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
158 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
159
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160 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
161 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
162 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
163
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
164 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
165 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
166 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167 else {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
168 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
169 "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
170 }
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 else {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173 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
174 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
175 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177
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 * 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
180 * 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
181 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182 * @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
183 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184 * @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
185 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186 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
187 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
188 }
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
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 * 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
193 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
194 * @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
195 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
196 * @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
197 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
198 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
199 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
200 {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201 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
202
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203 try {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
204 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
205 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
206 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
207
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
208 return properties;
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
209 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
210 finally {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
211 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
212 try {
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
213 inputStream.close();
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
214 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
215 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
216 }
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 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
219 }
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
220
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
221
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 * 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
224 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
225 * @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
226 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
227 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
228 return cacheEnabled;
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
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 * 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
234 *
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
235 * @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
236 */
1985d5db0feb Implemented a global configuration that should be used to initialize the geobackend.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
237 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
238 return cacheConfiguration;
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org