annotate flys-backend/src/main/java/de/intevation/flys/importer/ImporterSession.java @ 4198:1cdbd8a0c994

Added two new tables ClickableQDTable and ClickableWTable and made Ws and Qs clickable in historical discharge calculation. The new tables define listener interfaces (clicked lower or upper icon) to listen to user clicks. In addition to this, there is an enum ClickMode with NONE, SINGLE and RANGE options, which allows to specifiy, which icons are displayed in the tables. NONE means no icon for user clicks, SINGLE has 1 icon, RANGE 2 icons for lower and upper.
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 22 Oct 2012 13:31:25 +0200
parents cdb35d96ca09
children
rev   line source
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.importer;
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.util.Iterator;
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import java.util.Map;
503
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
5 import java.util.TreeMap;
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 import java.math.BigDecimal;
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 import org.hibernate.SessionFactory;
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 import org.hibernate.Session;
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import org.hibernate.Query;
499
cce054f27dac Importer: Only accept main value types 'Q', 'W', 'D' and 'T' by default.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
12 import org.hibernate.FlushMode;
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 import de.intevation.flys.backend.SessionFactoryProvider;
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import de.intevation.flys.model.WstColumnValue;
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 import de.intevation.flys.model.WstColumn;
498
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
18 import de.intevation.flys.model.DischargeTableValue;
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
19 import de.intevation.flys.model.DischargeTable;
500
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
20 import de.intevation.flys.model.Range;
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
21 import de.intevation.flys.model.River;
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
22
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
23 import org.apache.log4j.Logger;
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
1227
cdb35d96ca09 Importer session: Make use of the LRU cache from artifacts common.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 503
diff changeset
25 import de.intevation.artifacts.common.utils.LRUCache;
cdb35d96ca09 Importer session: Make use of the LRU cache from artifacts common.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 503
diff changeset
26
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 public class ImporterSession
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 {
500
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
29 private static Logger log = Logger.getLogger(ImporterSession.class);
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
30
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 private static final ThreadLocal<ImporterSession> SESSION =
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 new ThreadLocal<ImporterSession>() {
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 @Override
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 protected ImporterSession initialValue() {
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 return new ImporterSession();
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 }
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 };
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 protected Session databaseSession;
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
1227
cdb35d96ca09 Importer session: Make use of the LRU cache from artifacts common.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 503
diff changeset
41 protected LRUCache<Integer, Map<ValueKey, WstColumnValue>>
503
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
42 wstColumnValues;
498
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
43
1227
cdb35d96ca09 Importer session: Make use of the LRU cache from artifacts common.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 503
diff changeset
44 protected LRUCache<Integer, Map<ValueKey, DischargeTableValue>>
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
45 dischargeTableValues;
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46
1227
cdb35d96ca09 Importer session: Make use of the LRU cache from artifacts common.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 503
diff changeset
47 protected LRUCache<Integer, Map<ValueKey, Range>>
503
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
48 ranges;
500
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
49
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 public static ImporterSession getInstance() {
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 return SESSION.get();
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 }
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 public ImporterSession() {
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 SessionFactory sessionFactory =
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 SessionFactoryProvider.createSessionFactory();
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 databaseSession = sessionFactory.openSession();
502
c6889097f81f Importer: Fix silly bug and set Hibernate session flushing back to auto.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
58 //databaseSession.setFlushMode(FlushMode.MANUAL);
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
59
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
60 wstColumnValues =
1227
cdb35d96ca09 Importer session: Make use of the LRU cache from artifacts common.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 503
diff changeset
61 new LRUCache<Integer, Map<ValueKey, WstColumnValue>>();
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
62
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
63 dischargeTableValues =
1227
cdb35d96ca09 Importer session: Make use of the LRU cache from artifacts common.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 503
diff changeset
64 new LRUCache<Integer, Map<ValueKey, DischargeTableValue>>();
503
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
65
1227
cdb35d96ca09 Importer session: Make use of the LRU cache from artifacts common.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 503
diff changeset
66 ranges = new LRUCache<Integer, Map<ValueKey, Range>>();
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 }
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 public Session getDatabaseSession() {
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 return databaseSession;
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 }
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 public WstColumnValue getWstColumnValue(
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 WstColumn column,
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 BigDecimal position,
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 BigDecimal w
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 ) {
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
78 Integer c = column.getId();
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
79
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
80 Map<ValueKey, WstColumnValue> map = wstColumnValues.get(c);
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
81
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
82 if (map == null) {
503
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
83 map = new TreeMap<ValueKey, WstColumnValue>(
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
84 ValueKey.EPSILON_COMPARATOR);
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
85 wstColumnValues.put(c, map);
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
86 Query query = databaseSession.createQuery(
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
87 "from WstColumnValue where wstColumn.id=:cid");
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
88 query.setParameter("cid", c);
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
89 for (Iterator iter = query.iterate(); iter.hasNext();) {
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
90 WstColumnValue wcv = (WstColumnValue)iter.next();
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
91 map.put(new ValueKey(wcv.getPosition(), wcv.getW()), wcv);
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
92 }
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 }
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
95 ValueKey key = new ValueKey(position, w);
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
97 WstColumnValue wcv = map.get(key);
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 if (wcv != null) {
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 return wcv;
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 }
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 wcv = new WstColumnValue(column, position, w);
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 databaseSession.save(wcv);
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
107 map.put(key, wcv);
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 return wcv;
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 }
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111
498
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
112 public DischargeTableValue getDischargeTableValue(
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
113 DischargeTable table,
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
114 BigDecimal q,
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
115 BigDecimal w
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
116 ) {
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
117 Integer t = table.getId();
498
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
118
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
119 Map<ValueKey, DischargeTableValue> map =
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
120 dischargeTableValues.get(t);
498
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
121
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
122 if (map == null) {
503
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
123 map = new TreeMap<ValueKey, DischargeTableValue>(
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
124 ValueKey.EPSILON_COMPARATOR);
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
125 dischargeTableValues.put(t, map);
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
126 Query query = databaseSession.createQuery(
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
127 "from DischargeTableValue where dischargeTable.id=:tid");
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
128 query.setParameter("tid", t);
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
129 for (Iterator iter = query.iterate(); iter.hasNext();) {
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
130 DischargeTableValue dctv = (DischargeTableValue)iter.next();
503
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
131 map.put(new ValueKey(dctv.getQ(), dctv.getW()), dctv);
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
132 }
498
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
133 }
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
134
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
135 ValueKey key = new ValueKey(q, w);
498
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
136
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
137 DischargeTableValue dctv = map.get(key);
498
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
138
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
139 if (dctv != null) {
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
140 return dctv;
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
141 }
498
8ab04de0b879 Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
142
501
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
143 dctv = new DischargeTableValue(table, q, w);
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
144
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
145 databaseSession.save(dctv);
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
146
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
147 map.put(key, dctv);
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
148
04d449f7f0c9 Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 500
diff changeset
149 return dctv;
500
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
150 }
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
151
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
152 public Range getRange(River river, BigDecimal a, BigDecimal b) {
503
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
153 Integer r = river.getId();
500
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
154
503
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
155 Map<ValueKey, Range> map = ranges.get(r);
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
156
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
157 if (map == null) {
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
158 map = new TreeMap<ValueKey, Range>(
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
159 ValueKey.EPSILON_COMPARATOR);
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
160 ranges.put(r, map);
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
161 Query query = databaseSession.createQuery(
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
162 "from Range where river.id=:rid");
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
163 query.setParameter("rid", r);
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
164 for (Iterator iter = query.iterate(); iter.hasNext();) {
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
165 Range range = (Range)iter.next();
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
166 map.put(new ValueKey(range.getA(), range.getB()), range);
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
167 }
500
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
168 }
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
169
503
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
170 ValueKey key = new ValueKey(a, b);
500
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
171
503
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
172 Range range = map.get(key);
500
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
173
502
c6889097f81f Importer: Fix silly bug and set Hibernate session flushing back to auto.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
174 if (range != null) {
500
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
175 return range;
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
176 }
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
177
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
178 range = new Range(a, b, river);
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
179
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
180 databaseSession.save(range);
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
181
503
bcc18293a547 Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 502
diff changeset
182 map.put(key, range);
500
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
183
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
184 return range;
d50cd3a632e0 Importer: Use BigDecimals in hashing to prevent numerical problems. Cache ranges globally, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 499
diff changeset
185 }
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186 }
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org