Mercurial > dive4elements > river
view backend/src/main/java/org/dive4elements/river/importer/ImportCrossSection.java @ 9032:1f63e9d3b0ec
New columns for bed_height, tkh and depth_evolution, a few syntactic corrections for Oracle
author | mschaefer |
---|---|
date | Fri, 27 Apr 2018 17:35:12 +0200 |
parents | 392bbcd8a88b |
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.apache.log4j.Logger; import org.dive4elements.river.importer.common.StoreMode; import org.dive4elements.river.model.CrossSection; import org.dive4elements.river.model.River; import org.dive4elements.river.model.TimeInterval; import org.hibernate.Query; import org.hibernate.Session; /** CrossSection to be imported, holds list of ImportCrossSectionLines. */ public class ImportCrossSection { private static Logger log = Logger.getLogger(ImportCrossSection.class); protected ImportRiver river; protected String description; protected ImportTimeInterval timeInterval; protected List<ImportCrossSectionLine> lines; protected StoreMode storeMode; protected CrossSection peer; public ImportCrossSection() { } public ImportCrossSection( final ImportRiver river, final String description, final ImportTimeInterval timeInterval, final List<ImportCrossSectionLine> lines ) { this.river = river; this.description = description; this.timeInterval = timeInterval; this.lines = lines; this.storeMode = StoreMode.NONE; wireWithLines(); } public void wireWithLines() { for (final ImportCrossSectionLine line: this.lines) { line.setCrossSection(this); } } public ImportRiver getRiver() { return this.river; } public void setRiver(final ImportRiver river) { this.river = river; } public String getDescription() { return this.description; } public void setDescription(final String description) { this.description = description; } public ImportTimeInterval getTimeInterval() { return this.timeInterval; } public void setTimeInterval(final ImportTimeInterval timeInterval) { this.timeInterval = timeInterval; } public void storeDependencies() { log.info("store cross section '" + this.description + "'"); getPeer(); // int i = 1; // final int N = this.lines.size(); for (final ImportCrossSectionLine line: this.lines) { line.storeDependencies(); // log.info(" stored " + i + " lines. remaining: " + (N-i)); // ++i; } log.info(" lines stored: " + this.lines.size()); } public CrossSection getPeer() { if (this.peer == null) { final River r = this.river.getPeer(); final TimeInterval t = (this.timeInterval != null) ? this.timeInterval.getPeer() : null; final Session session = ImporterSession.getInstance().getDatabaseSession(); final Query query = session.createQuery( "from CrossSection where " + "river=:r and " + "timeInterval=:t and " + "description=:d"); query.setParameter("r", r); query.setParameter("t", t); query.setParameter("d", this.description); final List<CrossSection> crossSections = query.list(); if (crossSections.isEmpty()) { this.peer = new CrossSection(r, t, this.description); session.save(this.peer); this.storeMode = StoreMode.INSERT; } else { this.peer = crossSections.get(0); this.storeMode = StoreMode.UPDATE; } } return this.peer; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :