Mercurial > dive4elements > river
diff backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightValue.java @ 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
author | mschaefer |
---|---|
date | Tue, 03 Apr 2018 10:40:57 +0200 |
parents | 5e38e2924c07 |
children | 392bbcd8a88b |
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightValue.java Tue Apr 03 10:37:30 2018 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightValue.java Tue Apr 03 10:40:57 2018 +0200 @@ -11,18 +11,15 @@ import java.util.List; import org.apache.log4j.Logger; - -import org.hibernate.Session; -import org.hibernate.Query; - import org.dive4elements.river.model.BedHeight; import org.dive4elements.river.model.BedHeightValue; +import org.hibernate.Query; +import org.hibernate.Session; public class ImportBedHeightValue { - private static final Logger log = - Logger.getLogger(ImportBedHeightValue.class); + private static final Logger log = Logger.getLogger(ImportBedHeightValue.class); protected ImportBedHeight bedHeight; @@ -32,28 +29,26 @@ protected Double uncertainty; protected Double dataGap; protected Double soundingWidth; + protected Double minHeight; + protected Double maxHeight; protected BedHeightValue peer; - public ImportBedHeightValue( - ImportBedHeight bedHeight, - Double station, - Double height, - Double uncertainty, - Double dataGap, - Double soundingWidth - ) { + public ImportBedHeightValue(final ImportBedHeight bedHeight, final Double station, final Double height, final Double uncertainty, final Double dataGap, + final Double soundingWidth, final Double minHeight, final Double maxHeight) { this.bedHeight = bedHeight; this.station = station; this.height = height; this.uncertainty = uncertainty; this.dataGap = dataGap; this.soundingWidth = soundingWidth; + this.minHeight = minHeight; + this.maxHeight = maxHeight; } - public void storeDependencies(BedHeight bedHeight) { + public void storeDependencies(final BedHeight bedHeight) { getPeer(bedHeight); } @@ -62,37 +57,24 @@ * Add this value to database or return database bound Value, assuring * that the BedHeight exists in db already. */ - public BedHeightValue getPeer(BedHeight bedHeight) { - if (peer == null) { - Session session = ImporterSession.getInstance() - .getDatabaseSession(); - - Query query = session.createQuery( - "from BedHeightValue where " + - " bedHeight=:bedHeight and " + - " station=:station"); - - query.setParameter("bedHeight", bedHeight); - query.setParameter("station", station); + public BedHeightValue getPeer(final BedHeight bedHeight) { + if (this.peer != null) + return this.peer; - List<BedHeightValue> values = query.list(); - if (values.isEmpty()) { - peer = new BedHeightValue( - bedHeight, - station, - height, - uncertainty, - dataGap, - soundingWidth - ); - session.save(peer); - } - else { - peer = values.get(0); - } + final Session session = ImporterSession.getInstance().getDatabaseSession(); + final Query query = session.createQuery("FROM BedHeightValue WHERE (bedHeight=:bedHeight)" + + " AND (station BETWEEN (:station-0.0001) AND (:station+0.0001))"); + query.setParameter("bedHeight", bedHeight); + query.setParameter("station", this.station); + final List<BedHeightValue> values = query.list(); + if (values.isEmpty()) { + this.peer = new BedHeightValue(bedHeight, this.station, this.height, this.uncertainty, this.dataGap, this.soundingWidth, + this.minHeight, this.maxHeight); + session.save(this.peer); + } else { + this.peer = values.get(0); } - - return peer; + return this.peer; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :