Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
8985:27851cfda84a | 8986:392bbcd8a88b |
---|---|
9 package org.dive4elements.river.importer; | 9 package org.dive4elements.river.importer; |
10 | 10 |
11 import java.util.List; | 11 import java.util.List; |
12 | 12 |
13 import org.apache.log4j.Logger; | 13 import org.apache.log4j.Logger; |
14 import org.dive4elements.river.importer.common.StoreMode; | |
14 import org.dive4elements.river.model.BedHeight; | 15 import org.dive4elements.river.model.BedHeight; |
15 import org.dive4elements.river.model.BedHeightValue; | 16 import org.dive4elements.river.model.BedHeightValue; |
16 import org.hibernate.Query; | 17 import org.hibernate.Query; |
17 import org.hibernate.Session; | 18 import org.hibernate.Session; |
18 | 19 |
59 */ | 60 */ |
60 public BedHeightValue getPeer(final BedHeight bedHeight) { | 61 public BedHeightValue getPeer(final BedHeight bedHeight) { |
61 if (this.peer != null) | 62 if (this.peer != null) |
62 return this.peer; | 63 return this.peer; |
63 | 64 |
65 List<BedHeightValue> values; | |
64 final Session session = ImporterSession.getInstance().getDatabaseSession(); | 66 final Session session = ImporterSession.getInstance().getDatabaseSession(); |
65 final Query query = session.createQuery("FROM BedHeightValue WHERE (bedHeight=:bedHeight)" | 67 if (this.bedHeight.storeMode == StoreMode.INSERT) |
66 + " AND (station BETWEEN (:station-0.0001) AND (:station+0.0001))"); | 68 values = null; |
67 query.setParameter("bedHeight", bedHeight); | 69 else { |
68 query.setParameter("station", this.station); | 70 final Query query = session.createQuery("FROM BedHeightValue WHERE (bedHeight=:bedHeight)" |
69 final List<BedHeightValue> values = query.list(); | 71 + " AND (station BETWEEN (:station-0.0001) AND (:station+0.0001))"); |
70 if (values.isEmpty()) { | 72 query.setParameter("bedHeight", bedHeight); |
73 query.setParameter("station", this.station); | |
74 values = query.list(); | |
75 } | |
76 if ((values == null) || values.isEmpty()) { | |
71 this.peer = new BedHeightValue(bedHeight, this.station, this.height, this.uncertainty, this.dataGap, this.soundingWidth, | 77 this.peer = new BedHeightValue(bedHeight, this.station, this.height, this.uncertainty, this.dataGap, this.soundingWidth, |
72 this.minHeight, this.maxHeight); | 78 this.minHeight, this.maxHeight); |
73 session.save(this.peer); | 79 session.save(this.peer); |
74 } else { | 80 } else { |
75 this.peer = values.get(0); | 81 this.peer = values.get(0); |