Mercurial > dive4elements > river
view backend/src/main/java/org/dive4elements/river/importer/common/AbstractKmLineImport.java @ 8988:ae76f618d990
Checks added for missing import directory
author | mschaefer |
---|---|
date | Sun, 08 Apr 2018 18:09:32 +0200 |
parents | 50416a0df385 |
children | ddebd4c2fe93 |
line wrap: on
line source
/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde * Software engineering by * Björnsen Beratende Ingenieure GmbH * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt * * 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.common; import org.dive4elements.river.importer.ImporterSession; import org.hibernate.Session; /** * Abstract base class of a river station with associated data importing from a file * * @author Matthias Schäfer * */ public abstract class AbstractKmLineImport<SERIES, KMTUPLE> { /***** FIELDS *****/ protected double station; private KMTUPLE peer; protected StoreMode storeMode; /***** CONSTRUCTOR *****/ public AbstractKmLineImport(final double km) { this.station = km; this.storeMode = StoreMode.NONE; } /***** METHODS *****/ /** * Stores the station value record in the database */ public StoreMode store(final SERIES parent, final StoreMode parentStoreMode) { getPeer(parent, parentStoreMode); return this.storeMode; } /** * Gets the station value record from the database if existing, or creates a database record from this object and adds * it */ protected KMTUPLE getPeer(final SERIES parent, final StoreMode parentStoreMode) { if (this.peer != null) return this.peer; final Session session = ImporterSession.getInstance().getDatabaseSession(); KMTUPLE value = null; if (parentStoreMode != StoreMode.INSERT) { value = queryValueItem(session, parent); } if (value == null) { this.peer = createValueItem(parent); session.save(this.peer); this.storeMode = StoreMode.INSERT; } else { this.peer = value; this.storeMode = StoreMode.UPDATE; } return this.peer; } /** * Queries the (first matching) value item from the database * * @return first matching database value item, or null */ protected abstract KMTUPLE queryValueItem(final Session session, final SERIES parent); /** * Creates a new value item */ protected abstract KMTUPLE createValueItem(final SERIES parent); }