Mercurial > dive4elements > river
view backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoadLSValue.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 | 5e38e2924c07 |
children |
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.dive4elements.river.importer.common.StoreMode; import org.dive4elements.river.model.SedimentLoadLS; import org.dive4elements.river.model.SedimentLoadLSValue; import org.hibernate.Query; import org.hibernate.Session; public class ImportSedimentLoadLSValue { private final Double station; private final Double value; private SedimentLoadLSValue peer; public ImportSedimentLoadLSValue(final Double station, final Double value) { this.station = station; this.value = value; } public void storeDependencies(final SedimentLoadLS sedimentLoadLS, final StoreMode parentStoreMode) { getPeer(sedimentLoadLS, parentStoreMode); } public SedimentLoadLSValue getPeer(final SedimentLoadLS sedimentLoadLS, final StoreMode parentStoreMode) { if (this.peer == null) { List<SedimentLoadLSValue> values; final Session session = ImporterSession.getInstance().getDatabaseSession(); if (parentStoreMode == StoreMode.INSERT) values = null; else { final Query query = session.createQuery( "from SedimentLoadLSValue where " + " sedimentLoadLS=:sedimentLoadLS and " + " station=:station and " + " value=:value" ); query.setParameter("sedimentLoadLS", sedimentLoadLS); query.setParameter("station", this.station); query.setParameter("value", this.value); values = query.list(); } if ((values == null) || values.isEmpty()) { this.peer = new SedimentLoadLSValue(sedimentLoadLS, this.station, this.value); 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 :