Mercurial > dive4elements > river
annotate backend/src/main/java/org/dive4elements/river/importer/ImporterSession.java @ 8856:5e38e2924c07 3.2.x
Fix code style.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 18 Jan 2018 20:12:01 +0100 |
parents | 32a91eac0bc2 |
children |
rev | line source |
---|---|
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5992
4c3ccf2b0304
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5992
4c3ccf2b0304
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5829
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
9 package org.dive4elements.river.importer; |
497
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
8029
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
11 import java.util.ArrayList; |
8027
1e327d86c898
Load grain fractions from database only. Do not store new ones.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
12 import java.util.HashMap; |
497
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 import java.util.Iterator; |
8029
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
14 import java.util.List; |
497
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 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
|
16 import java.util.TreeMap; |
497
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import java.math.BigDecimal; |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 import org.hibernate.SessionFactory; |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 import org.hibernate.Session; |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 import org.hibernate.Query; |
5829
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
22 import org.dive4elements.river.backend.SessionFactoryProvider; |
8027
1e327d86c898
Load grain fractions from database only. Do not store new ones.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
23 import org.dive4elements.river.model.GrainFraction; |
8029
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
24 import org.dive4elements.river.model.MeasurementStation; |
5829
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
25 import org.dive4elements.river.model.WstColumnValue; |
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
26 import org.dive4elements.river.model.WstColumn; |
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
27 import org.dive4elements.river.model.DischargeTableValue; |
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
28 import org.dive4elements.river.model.DischargeTable; |
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
29 import org.dive4elements.river.model.Range; |
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
30 import org.dive4elements.river.model.River; |
8187
3bb1c62ad732
Moved package org.dive4elements.river.utils to org.dive4elements.river.backend.utils.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8054
diff
changeset
|
31 import org.dive4elements.river.backend.utils.EpsilonComparator; |
5829
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
32 import org.dive4elements.artifacts.common.utils.LRUCache; |
1227
cdb35d96ca09
Importer session: Make use of the LRU cache from artifacts common.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
503
diff
changeset
|
33 |
497
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 public class ImporterSession |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 { |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 private static final ThreadLocal<ImporterSession> SESSION = |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 new ThreadLocal<ImporterSession>() { |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 @Override |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 protected ImporterSession initialValue() { |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 return new ImporterSession(); |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 } |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 }; |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 protected Session databaseSession; |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
8029
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
46 private 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
|
47 wstColumnValues; |
498
8ab04de0b879
Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
48 |
8029
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
49 private 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
|
50 dischargeTableValues; |
497
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
8029
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
52 private 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
|
53 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
|
54 |
8027
1e327d86c898
Load grain fractions from database only. Do not store new ones.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
55 private Map<String, GrainFraction> grainFractions; |
1e327d86c898
Load grain fractions from database only. Do not store new ones.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
56 |
8029
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
57 private Map<String, Map<Double, List<MeasurementStation>>> |
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
58 riversToMeasurementStations; |
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
59 |
497
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 public static ImporterSession getInstance() { |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 return SESSION.get(); |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 } |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 public ImporterSession() { |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 SessionFactory sessionFactory = |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 SessionFactoryProvider.createSessionFactory(); |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 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
|
68 //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
|
69 |
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
70 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
|
71 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
|
72 |
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
73 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
|
74 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
|
75 |
1227
cdb35d96ca09
Importer session: Make use of the LRU cache from artifacts common.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
503
diff
changeset
|
76 ranges = new LRUCache<Integer, Map<ValueKey, Range>>(); |
497
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 } |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 public Session getDatabaseSession() { |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 return databaseSession; |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 } |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 public WstColumnValue getWstColumnValue( |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 WstColumn column, |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 BigDecimal position, |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 BigDecimal w |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 ) { |
501
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
88 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
|
89 |
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
90 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
|
91 |
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
92 if (map == null) { |
503
bcc18293a547
Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
502
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 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
|
97 "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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 } |
497
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 } |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 |
501
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
105 ValueKey key = new ValueKey(position, w); |
497
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 WstColumnValue wcv = map.get(key); |
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 if (wcv != null) { |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 return wcv; |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 } |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 wcv = new WstColumnValue(column, position, w); |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 databaseSession.save(wcv); |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
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 map.put(key, wcv); |
497
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 return wcv; |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 } |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 |
498
8ab04de0b879
Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
122 public DischargeTableValue getDischargeTableValue( |
8ab04de0b879
Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
123 DischargeTable table, |
8ab04de0b879
Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
124 BigDecimal q, |
8ab04de0b879
Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
125 BigDecimal w |
8ab04de0b879
Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
126 ) { |
501
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
127 Integer t = table.getId(); |
498
8ab04de0b879
Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
128 |
501
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
129 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
|
130 dischargeTableValues.get(t); |
498
8ab04de0b879
Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
131 |
501
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
132 if (map == null) { |
503
bcc18293a547
Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
502
diff
changeset
|
133 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
|
134 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
|
135 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
|
136 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
|
137 "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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 } |
498
8ab04de0b879
Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
143 } |
8ab04de0b879
Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
144 |
501
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
145 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
|
146 |
501
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
147 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
|
148 |
501
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
149 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
|
150 return dctv; |
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
151 } |
498
8ab04de0b879
Importer: Cache the discharge table values, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
152 |
501
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
153 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
|
154 |
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
155 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
|
156 |
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
157 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
|
158 |
04d449f7f0c9
Importer: Change caching strategy not to cause OOM any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
500
diff
changeset
|
159 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
|
160 } |
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
|
161 |
8027
1e327d86c898
Load grain fractions from database only. Do not store new ones.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
162 public GrainFraction getGrainFraction(String name) { |
1e327d86c898
Load grain fractions from database only. Do not store new ones.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
163 if (grainFractions == null) { |
1e327d86c898
Load grain fractions from database only. Do not store new ones.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
164 grainFractions = new HashMap<String, GrainFraction>(); |
1e327d86c898
Load grain fractions from database only. Do not store new ones.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
165 Query query = databaseSession.createQuery("from GrainFraction"); |
1e327d86c898
Load grain fractions from database only. Do not store new ones.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
166 for (Iterator iter = query.iterate(); iter.hasNext();) { |
1e327d86c898
Load grain fractions from database only. Do not store new ones.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
167 GrainFraction gf = (GrainFraction)iter.next(); |
1e327d86c898
Load grain fractions from database only. Do not store new ones.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
168 grainFractions.put(gf.getName(), gf); |
1e327d86c898
Load grain fractions from database only. Do not store new ones.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
169 } |
1e327d86c898
Load grain fractions from database only. Do not store new ones.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
170 } |
1e327d86c898
Load grain fractions from database only. Do not store new ones.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
171 return grainFractions.get(name); |
1e327d86c898
Load grain fractions from database only. Do not store new ones.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
172 } |
1e327d86c898
Load grain fractions from database only. Do not store new ones.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5992
diff
changeset
|
173 |
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
|
174 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
|
175 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
|
176 |
503
bcc18293a547
Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
502
diff
changeset
|
177 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
|
178 |
bcc18293a547
Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
502
diff
changeset
|
179 if (map == null) { |
bcc18293a547
Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
502
diff
changeset
|
180 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
|
181 ValueKey.EPSILON_COMPARATOR); |
bcc18293a547
Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
502
diff
changeset
|
182 ranges.put(r, map); |
bcc18293a547
Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
502
diff
changeset
|
183 Query query = databaseSession.createQuery( |
bcc18293a547
Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
502
diff
changeset
|
184 "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
|
185 query.setParameter("rid", r); |
bcc18293a547
Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
502
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 } |
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
|
190 } |
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
|
191 |
503
bcc18293a547
Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
502
diff
changeset
|
192 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
|
193 |
503
bcc18293a547
Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
502
diff
changeset
|
194 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
|
195 |
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
|
196 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
|
197 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
|
198 } |
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
|
199 |
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
|
200 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
|
201 |
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
|
202 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
|
203 |
503
bcc18293a547
Importer: Added unsharp lookup to avoid numerical problems.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
502
diff
changeset
|
204 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
|
205 |
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
|
206 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
|
207 } |
8029
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
208 |
8692
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
209 public MeasurementStation getMeasurementStation( |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
210 River river, |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
211 double station, |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
212 String measurementType |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
213 ) { |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
214 List<MeasurementStation> stations = getMeasurementStations( |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
215 river, station); |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
216 |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
217 if (stations != null) { |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
218 /* Assume there is only one MeasurementStation per type at |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
219 any station. Should be enforced in database schema. */ |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
220 for (MeasurementStation m: stations) { |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
221 if (m.getMeasurementType().equals(measurementType)) { |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
222 return m; |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
223 } |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
224 } |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
225 } |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
226 |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
227 return null; |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
228 } |
67e53dbe05d2
(issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents:
8412
diff
changeset
|
229 |
8412
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
230 public List<MeasurementStation> getMeasurementStations( |
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
231 River river, |
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
232 double station |
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
233 ) { |
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
234 String rivername = river.getName(); |
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
235 |
8029
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
236 if (riversToMeasurementStations == null) { |
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
237 riversToMeasurementStations = |
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
238 new HashMap<String, Map<Double, List<MeasurementStation>>>(); |
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
239 } |
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
240 |
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
241 Map<Double, List<MeasurementStation>> km2Stations = |
8412
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
242 riversToMeasurementStations.get(rivername); |
8029
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
243 if (km2Stations == null) { |
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
244 km2Stations = |
8856 | 245 new TreeMap<Double, List<MeasurementStation>>( |
246 EpsilonComparator.CMP); | |
8412
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
247 riversToMeasurementStations.put(rivername, km2Stations); |
8029
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
248 Query query = databaseSession.createQuery( |
8412
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
249 "from MeasurementStation where range.river = :river"); |
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
250 query.setParameter("river", river); |
8029
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
251 for (Iterator iter = query.iterate(); iter.hasNext();) { |
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
252 MeasurementStation st = (MeasurementStation)iter.next(); |
8412
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
253 |
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
254 // In case river is km_up, station is at larger value of range |
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
255 double stKm = river.getKmUp() && st.getRange().getB() != null |
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
256 ? st.getRange().getB().doubleValue() |
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
257 : st.getRange().getA().doubleValue(); |
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
258 |
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
259 List<MeasurementStation> ms = km2Stations.get(stKm); |
8029
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
260 if (ms == null) { |
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
261 ms = new ArrayList<MeasurementStation>(2); |
8412
17db08570637
SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents:
8187
diff
changeset
|
262 km2Stations.put(stKm, ms); |
8029
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
263 } |
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
264 ms.add(st); |
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
265 } |
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
266 |
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
267 } |
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
268 return km2Stations.get(station); |
cdb9f6d97f6a
Added method to importer session to fetch the measurement station for given (river, km).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
8027
diff
changeset
|
269 } |
497
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
270 } |
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
271 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |