Mercurial > dive4elements > river
annotate backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightValue.java @ 8986:392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
author | mschaefer |
---|---|
date | Sun, 08 Apr 2018 18:07:06 +0200 |
parents | a0a0a7f912ab |
children | 8aa7d9eaaa21 |
rev | line source |
---|---|
8559
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
3 * |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
7 */ |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
8 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
9 package org.dive4elements.river.importer; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
10 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
11 import java.util.List; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
12 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
13 import org.apache.log4j.Logger; |
8986
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
14 import org.dive4elements.river.importer.common.StoreMode; |
8559
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
15 import org.dive4elements.river.model.BedHeight; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
16 import org.dive4elements.river.model.BedHeightValue; |
8975
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
17 import org.hibernate.Query; |
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
18 import org.hibernate.Session; |
8559
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
19 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
20 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
21 public class ImportBedHeightValue { |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
22 |
8975
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
23 private static final Logger log = Logger.getLogger(ImportBedHeightValue.class); |
8559
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
24 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
25 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
26 protected ImportBedHeight bedHeight; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
27 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
28 protected Double station; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
29 protected Double height; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
30 protected Double uncertainty; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
31 protected Double dataGap; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
32 protected Double soundingWidth; |
8975
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
33 protected Double minHeight; |
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
34 protected Double maxHeight; |
8559
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
35 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
36 protected BedHeightValue peer; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
37 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
38 |
8975
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
39 public ImportBedHeightValue(final ImportBedHeight bedHeight, final Double station, final Double height, final Double uncertainty, final Double dataGap, |
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
40 final Double soundingWidth, final Double minHeight, final Double maxHeight) { |
8559
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
41 this.bedHeight = bedHeight; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
42 this.station = station; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
43 this.height = height; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
44 this.uncertainty = uncertainty; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
45 this.dataGap = dataGap; |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
46 this.soundingWidth = soundingWidth; |
8975
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
47 this.minHeight = minHeight; |
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
48 this.maxHeight = maxHeight; |
8559
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
49 } |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
50 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
51 |
8975
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
52 public void storeDependencies(final BedHeight bedHeight) { |
8559
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
53 getPeer(bedHeight); |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
54 } |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
55 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
56 |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
57 /** |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
58 * Add this value to database or return database bound Value, assuring |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
59 * that the BedHeight exists in db already. |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
60 */ |
8975
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
61 public BedHeightValue getPeer(final BedHeight bedHeight) { |
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
62 if (this.peer != null) |
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
63 return this.peer; |
8559
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
64 |
8986
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
65 List<BedHeightValue> values; |
8975
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
66 final Session session = ImporterSession.getInstance().getDatabaseSession(); |
8986
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
67 if (this.bedHeight.storeMode == StoreMode.INSERT) |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
68 values = null; |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
69 else { |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
70 final Query query = session.createQuery("FROM BedHeightValue WHERE (bedHeight=:bedHeight)" |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
71 + " AND (station BETWEEN (:station-0.0001) AND (:station+0.0001))"); |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
72 query.setParameter("bedHeight", bedHeight); |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
73 query.setParameter("station", this.station); |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
74 values = query.list(); |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
75 } |
392bbcd8a88b
Database inserts accelerated by suppressing unnecessary database queries for new data series
mschaefer
parents:
8975
diff
changeset
|
76 if ((values == null) || values.isEmpty()) { |
8975
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
77 this.peer = new BedHeightValue(bedHeight, this.station, this.height, this.uncertainty, this.dataGap, this.soundingWidth, |
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
78 this.minHeight, this.maxHeight); |
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
79 session.save(this.peer); |
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
80 } else { |
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
81 this.peer = values.get(0); |
8559
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
82 } |
8975
a0a0a7f912ab
Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents:
8856
diff
changeset
|
83 return this.peer; |
8559
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
84 } |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
85 } |
6d8d7425a6b5
Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents:
diff
changeset
|
86 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |