Mercurial > dive4elements > gnv-client
comparison geo-backend/src/main/java/de/intevation/gnv/geobackend/base/query/CachingQueryExecutorFactory.java @ 1122:1985d5db0feb
Implemented a global configuration that should be used to initialize the geobackend.
geo-backend/trunk@1149 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 03 Jun 2010 13:31:07 +0000 |
parents | 02cd2935b5fa |
children | f3fdbeef1c68 |
comparison
equal
deleted
inserted
replaced
1121:9d530f913729 | 1122:1985d5db0feb |
---|---|
9 | 9 |
10 import org.apache.log4j.Logger; | 10 import org.apache.log4j.Logger; |
11 | 11 |
12 import de.intevation.gnv.geobackend.base.Result; | 12 import de.intevation.gnv.geobackend.base.Result; |
13 import de.intevation.gnv.geobackend.base.query.cache.CacheCleaner; | 13 import de.intevation.gnv.geobackend.base.query.cache.CacheCleaner; |
14 import de.intevation.gnv.geobackend.config.Configuration; | |
14 | 15 |
15 /** | 16 /** |
16 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> | 17 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
17 */ | 18 */ |
18 public class CachingQueryExecutorFactory | 19 public class CachingQueryExecutorFactory |
19 extends QueryExecutorFactory | 20 extends QueryExecutorFactory |
20 { | 21 { |
21 public static final String QUERY_EXECUTOR_FACTORY = "caching.query.executor.config"; | |
22 public static final String CACHE_NAME = "sql.cache"; | 22 public static final String CACHE_NAME = "sql.cache"; |
23 | 23 |
24 private static Logger log = Logger.getLogger(CachingQueryExecutorFactory.class); | 24 private static Logger log = Logger.getLogger(CachingQueryExecutorFactory.class); |
25 | 25 |
26 protected CacheManager manager; | 26 protected CacheManager manager; |
27 | 27 |
28 public CachingQueryExecutorFactory() { | 28 public CachingQueryExecutorFactory() { |
29 log.info("using SQL cache"); | 29 log.info("using SQL cache"); |
30 String configFile = System.getProperty(QUERY_EXECUTOR_FACTORY); | 30 |
31 manager = configFile != null | 31 init(); |
32 ? new CacheManager(configFile) | 32 } |
33 : new CacheManager(); | 33 |
34 manager.addCache(CACHE_NAME); | 34 private void init() { |
35 CacheCleaner cc = new CacheCleaner(); | 35 Configuration config = Configuration.getInstance(); |
36 cc.start(); | 36 |
37 if (config == null) { | |
38 log.error("No geobackend configuration found. " + | |
39 "Wasn't able to initialize cache."); | |
40 return; | |
41 } | |
42 else { | |
43 String configFile = config.getCacheConfiguration(); | |
44 manager = configFile != null | |
45 ? new CacheManager(configFile) | |
46 : new CacheManager(); | |
47 manager.addCache(CACHE_NAME); | |
48 CacheCleaner cc = new CacheCleaner(); | |
49 cc.start(); | |
50 } | |
37 } | 51 } |
38 | 52 |
39 public QueryExecutor getQueryExecutor() { | 53 public QueryExecutor getQueryExecutor() { |
40 return new DefaultQueryExceutor() { | 54 return new DefaultQueryExceutor() { |
41 | 55 |