Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/utils/BatchLoader.java @ 9801:1d7a72a50183 3.2.x tip
Assume Compose V2, consistently
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 23 Nov 2023 10:14:13 +0100 |
parents | 0a5239a1e46e |
children |
rev | line source |
---|---|
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 |
9726 | 17 import org.apache.logging.log4j.Logger; |
18 import org.apache.logging.log4j.LogManager; | |
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
|
19 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
|
20 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
|
21 |
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 /** 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
|
23 * (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
|
24 * 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
|
25 * 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
|
26 * 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
|
27 * 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
|
28 */ |
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 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
|
30 |
9726 | 31 private static Logger log = LogManager.getLogger(BatchLoader.class); |
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
|
32 |
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 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
|
34 |
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 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
|
36 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
|
37 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
|
38 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
|
39 |
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 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
|
41 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
|
42 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
|
43 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
|
44 ) { |
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 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
|
46 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
|
47 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
|
48 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
|
49 |
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 // 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
|
51 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
|
52 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
|
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 |
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 /** 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
|
57 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
|
58 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
|
59 |
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 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
|
61 |
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 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 } |
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 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
|
70 || (!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
|
71 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
|
72 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
|
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 |
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 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
|
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 |
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 /** 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
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 } |
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 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
|
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 |
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 /** 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
|
92 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
|
93 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
|
94 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
|
95 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
|
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 |
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 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
|
99 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
|
100 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
|
101 } |
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 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
|
103 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
|
104 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
|
105 } |
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 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
|
107 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
|
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 |
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 /** 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
|
111 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
|
112 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
|
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 |
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 /** 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
|
116 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
|
117 } |