annotate artifacts/src/main/java/org/dive4elements/river/utils/BatchLoader.java @ 8755:30b1ddadf275

(issue1801) Unify reference gauge finding code The basic way as described in the method comment of the determineRefGauge method is now used in the WINFOArtifact, MainValuesService and RiverUtils.getGauge method. RiverUtils.getGauge previously just returned the first gauge found. While this is now a behavior change I believe that it is always more correct then the undeterministic behavior of the previous implmenentation.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 24 Jun 2015 14:07:26 +0200
parents b0c88ac9f63b
children 0a5239a1e46e
rev   line source
6847
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
3 *
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
6 * documentation coming with Dive4Elements River for details.
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
7 */
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
8
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
9 package org.dive4elements.river.utils;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
10
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
11 import java.util.ArrayList;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
12 import java.util.HashMap;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
13 import java.util.Iterator;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
14 import java.util.List;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
15 import java.util.Map;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
16
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
17 import org.apache.log4j.Logger;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
18 import org.hibernate.SQLQuery;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
19 import org.hibernate.Session;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
20
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
21 /** To reduce the number of SQL queries send to the backend
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
22 * (mainly by the fixings overviews) we execute them in batches of ids
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
23 * and store the results in a small cache.
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
24 * TODO: It currently relies on dynamic SQL.
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
25 * Is there a way to use Hibernate with java.sql.Array
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
26 * in cross database compatible manner?
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
27 */
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
28 public abstract class BatchLoader<T> {
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
29
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
30 private static Logger log = Logger.getLogger(BatchLoader.class);
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
31
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
32 public static final int BATCH_SIZE = 100;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
33
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
34 private Map<Integer, T> loaded;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
35 private List<Integer> rest;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
36 private Session session;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
37 private String sqlTemplate;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
38
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
39 public BatchLoader(
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
40 List<Integer> columns,
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
41 Session session,
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
42 String sqlTemplate
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
43 ) {
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
44 rest = new ArrayList<Integer>(columns.size());
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
45 loaded = new HashMap<Integer, T>();
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
46 this.session = session;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
47 this.sqlTemplate = sqlTemplate;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
48
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
49 // Insert in reverse order to minize searching.
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
50 for (int i = columns.size()-1; i >= 0; --i) {
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
51 rest.add(columns.get(i));
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
52 }
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
53 }
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
54
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
55 /** Searches for id and fill a batch to load containing the found id. */
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
56 private List<Integer> prepareBatch(int id) {
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
57 List<Integer> batch = new ArrayList<Integer>(BATCH_SIZE);
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
58
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
59 boolean found = false;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
60
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
61 for (int i = rest.size()-1; batch.size() < BATCH_SIZE && i >= 0; --i) {
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
62 Integer cid = rest.get(i);
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
63 if (cid == id) {
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
64 found = true;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
65 batch.add(cid);
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
66 rest.remove(i);
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
67 }
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
68 else if ((found && batch.size() < BATCH_SIZE)
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
69 || (!found && batch.size() < BATCH_SIZE-1)) {
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
70 batch.add(cid);
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
71 rest.remove(i);
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
72 }
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
73 }
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
74
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
75 return batch;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
76 }
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
77
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
78 /** Converts id to a list of comma separated ints. */
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
79 private static String idsAsString(List<Integer> ids) {
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
80 StringBuilder sb = new StringBuilder();
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
81 for (Iterator<Integer> i = ids.iterator(); i.hasNext();) {
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
82 sb.append(i.next());
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
83 if (i.hasNext()) {
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
84 sb.append(',');
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
85 }
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
86 }
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
87 return sb.toString();
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
88 }
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
89
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
90 /** Get data for id. */
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
91 public T get(int id) {
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
92 T already = loaded.get(id);
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
93 if (already != null) {
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
94 return already;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
95 }
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
96
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
97 List<Integer> batch = prepareBatch(id);
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
98 if (batch.isEmpty()) {
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
99 return null;
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
100 }
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
101 String sql = sqlTemplate.replace("$IDS", idsAsString(batch));
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
102 if (log.isDebugEnabled()) {
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
103 log.debug(sql + " " + sql.length());
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
104 }
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
105 fill(session.createSQLQuery(sql));
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
106 return get(id);
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
107 }
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
108
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
109 /** Call this from fill() to store data in the cache. */
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
110 protected void cache(int key, T data) {
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
111 loaded.put(key, data);
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
112 }
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
113
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
114 /** Override this to fill the cache */
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
115 protected abstract void fill(SQLQuery query);
b0c88ac9f63b Fixing Analysis: Significantly (8-10x) improved the performance of the generation of the overview data. The data is now prefetched in batches.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
116 }

http://dive4elements.wald.intevation.org