Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/common/AbstractKmLineImport.java @ 8971:50416a0df385
Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
author | mschaefer |
---|---|
date | Tue, 03 Apr 2018 10:18:30 +0200 |
parents | |
children | ae76f618d990 |
comparison
equal
deleted
inserted
replaced
8970:da5dc7446652 | 8971:50416a0df385 |
---|---|
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 | |
11 package org.dive4elements.river.importer.common; | |
12 | |
13 import org.dive4elements.river.importer.ImporterSession; | |
14 import org.hibernate.Session; | |
15 | |
16 /** | |
17 * Abstract base class of a river station with associated data importing from a file | |
18 * | |
19 * @author Matthias Schäfer | |
20 * | |
21 */ | |
22 public abstract class AbstractKmLineImport<SERIES, KMTUPLE> { | |
23 | |
24 /***** FIELDS *****/ | |
25 | |
26 protected double station; | |
27 | |
28 private KMTUPLE peer; | |
29 | |
30 protected StoreMode storeMode; | |
31 | |
32 /***** CONSTRUCTOR *****/ | |
33 | |
34 public AbstractKmLineImport(final double km) { | |
35 this.station = km; | |
36 } | |
37 | |
38 | |
39 /***** METHODS *****/ | |
40 | |
41 /** | |
42 * Stores the station value record in the database | |
43 */ | |
44 public StoreMode store(final SERIES parent, final StoreMode parentStoreMode) { | |
45 getPeer(parent, parentStoreMode); | |
46 return this.storeMode; | |
47 } | |
48 | |
49 | |
50 /** | |
51 * Gets the station value record from the database if existing, or creates a database record from this object and adds | |
52 * it | |
53 */ | |
54 protected KMTUPLE getPeer(final SERIES parent, final StoreMode parentStoreMode) { | |
55 if (this.peer != null) { | |
56 this.storeMode = StoreMode.NONE; | |
57 return this.peer; | |
58 } | |
59 final Session session = ImporterSession.getInstance().getDatabaseSession(); | |
60 KMTUPLE value = null; | |
61 if (parentStoreMode != StoreMode.INSERT) { | |
62 value = queryValueItem(session, parent); | |
63 } | |
64 if (value == null) { | |
65 this.peer = createValueItem(parent); | |
66 session.save(this.peer); | |
67 this.storeMode = StoreMode.INSERT; | |
68 } else { | |
69 this.peer = value; | |
70 this.storeMode = StoreMode.UPDATE; | |
71 } | |
72 return this.peer; | |
73 } | |
74 | |
75 /** | |
76 * Queries the (first matching) value item from the database | |
77 * | |
78 * @return first matching database value item, or null | |
79 */ | |
80 protected abstract KMTUPLE queryValueItem(final Session session, final SERIES parent); | |
81 | |
82 /** | |
83 * Creates a new value item | |
84 */ | |
85 protected abstract KMTUPLE createValueItem(final SERIES parent); | |
86 } |