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

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
children
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2622
diff changeset
9 package org.dive4elements.river.artifacts.model;
2561
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2622
diff changeset
11 import org.dive4elements.river.artifacts.cache.CacheFactory;
2561
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2622
diff changeset
13 import org.dive4elements.river.backend.SessionHolder;
2561
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import net.sf.ehcache.Cache;
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import net.sf.ehcache.Element;
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 5994
diff changeset
18 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 5994
diff changeset
19 import org.apache.logging.log4j.LogManager;
2561
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 import org.hibernate.Session;
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 public class FixingsOverviewFactory
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 {
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 5994
diff changeset
25 private static Logger log = LogManager.getLogger(FixingsOverviewFactory.class);
2561
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 public static final String CACHE_NAME = "fixings-overviews";
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 private FixingsOverviewFactory() {
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 }
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 public static FixingsOverview getOverview(String river) {
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34
2622
8bc1e1cb7f7b Fixed the fixings columns caching problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2561
diff changeset
35 boolean debug = log.isDebugEnabled();
8bc1e1cb7f7b Fixed the fixings columns caching problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2561
diff changeset
36
8bc1e1cb7f7b Fixed the fixings columns caching problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2561
diff changeset
37 if (debug) {
8bc1e1cb7f7b Fixed the fixings columns caching problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2561
diff changeset
38 log.debug(
8bc1e1cb7f7b Fixed the fixings columns caching problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2561
diff changeset
39 "Looking for fixings overview for river '" + river + "'");
8bc1e1cb7f7b Fixed the fixings columns caching problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2561
diff changeset
40 }
2561
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 Cache cache = CacheFactory.getCache(CACHE_NAME);
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 if (cache == null) {
2622
8bc1e1cb7f7b Fixed the fixings columns caching problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2561
diff changeset
45 if (debug) {
8bc1e1cb7f7b Fixed the fixings columns caching problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2561
diff changeset
46 log.debug("Cache not configured.");
8bc1e1cb7f7b Fixed the fixings columns caching problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2561
diff changeset
47 }
2561
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 return getUncached(river);
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 }
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 String key = "fix-over-" + river;
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 Element element = cache.get(key);
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 if (element != null) {
2622
8bc1e1cb7f7b Fixed the fixings columns caching problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2561
diff changeset
56 if (debug) {
8bc1e1cb7f7b Fixed the fixings columns caching problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2561
diff changeset
57 log.debug("Overview found in cache");
8bc1e1cb7f7b Fixed the fixings columns caching problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2561
diff changeset
58 }
2561
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 return (FixingsOverview)element.getValue();
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 }
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 FixingsOverview overview = getUncached(river);
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 if (overview != null) {
2622
8bc1e1cb7f7b Fixed the fixings columns caching problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2561
diff changeset
65 if (debug) {
8bc1e1cb7f7b Fixed the fixings columns caching problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2561
diff changeset
66 log.debug("Store overview in cache.");
8bc1e1cb7f7b Fixed the fixings columns caching problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2561
diff changeset
67 }
8bc1e1cb7f7b Fixed the fixings columns caching problem.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2561
diff changeset
68 cache.put(new Element(key, overview));
2561
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 }
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 return overview;
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 }
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 public static FixingsOverview getUncached(String river) {
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 FixingsOverview overview = new FixingsOverview(river);
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 Session session = SessionHolder.HOLDER.get();
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 return overview.load(session) ? overview : null;
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 }
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 }
b3f6d49cdc80 Service to generate the data needed to build the "Fixerungen pro Fluss Uebersicht"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org