Mercurial > dive4elements > river
view backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightValue.java @ 9010:dcbdff96d1a8
Tkh import with day instead of year
author | mschaefer |
---|---|
date | Wed, 18 Apr 2018 07:42:06 +0200 |
parents | 392bbcd8a88b |
children | 8aa7d9eaaa21 |
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde * Software engineering by Intevation GmbH * * This file is Free Software under the GNU AGPL (>=v3) * and comes with ABSOLUTELY NO WARRANTY! Check out the * documentation coming with Dive4Elements River for details. */ package org.dive4elements.river.importer; import java.util.List; import org.apache.log4j.Logger; import org.dive4elements.river.importer.common.StoreMode; 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); protected ImportBedHeight bedHeight; protected Double station; protected Double height; protected Double uncertainty; protected Double dataGap; protected Double soundingWidth; protected Double minHeight; protected Double maxHeight; protected BedHeightValue peer; 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(final BedHeight bedHeight) { getPeer(bedHeight); } /** * Add this value to database or return database bound Value, assuring * that the BedHeight exists in db already. */ public BedHeightValue getPeer(final BedHeight bedHeight) { if (this.peer != null) return this.peer; List<BedHeightValue> values; final Session session = ImporterSession.getInstance().getDatabaseSession(); if (this.bedHeight.storeMode == StoreMode.INSERT) values = null; else { 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); values = query.list(); } if ((values == null) || 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 this.peer; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :