comparison backend/src/main/java/org/dive4elements/river/importer/ImportHYKFlowZone.java @ 7730:e1b831fe435a slt-simplify-cross-sections

Merged default into slt-simplify-cross-sections branch and updated package and class names.
author Tom Gottfried <tom@intevation.de>
date Mon, 20 Jan 2014 14:04:20 +0100
parents 4c3ccf2b0304
children 392bbcd8a88b
comparison
equal deleted inserted replaced
5084:ca45dd039b54 7730:e1b831fe435a
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details.
7 */
8
9 package org.dive4elements.river.importer;
10
11 import org.dive4elements.river.model.HYKFormation;
12 import org.dive4elements.river.model.HYKFlowZone;
13 import org.dive4elements.river.model.HYKFlowZoneType;
14
15 import org.hibernate.Session;
16 import org.hibernate.Query;
17
18 import java.util.List;
19
20 import java.math.BigDecimal;
21
22 public class ImportHYKFlowZone
23 {
24 protected ImportHYKFormation formation;
25 protected ImportHYKFlowZoneType type;
26 protected BigDecimal a;
27 protected BigDecimal b;
28
29 protected HYKFlowZone peer;
30
31 public ImportHYKFlowZone() {
32 }
33
34 public ImportHYKFlowZone(
35 ImportHYKFormation formation,
36 ImportHYKFlowZoneType type,
37 BigDecimal a,
38 BigDecimal b
39 ) {
40 this.formation = formation;
41 this.type = type;
42 this.a = a;
43 this.b = b;
44 }
45
46 public ImportHYKFormation getFormation() {
47 return formation;
48 }
49
50 public void setFormation(ImportHYKFormation formation) {
51 this.formation = formation;
52 }
53
54 public void storeDependencies() {
55 getPeer();
56 }
57
58 public HYKFlowZone getPeer() {
59 if (peer == null) {
60 HYKFormation f = formation.getPeer();
61 HYKFlowZoneType t = type.getPeer();
62 Session session = ImporterSession.getInstance()
63 .getDatabaseSession();
64 Query query = session.createQuery(
65 "from HYKFlowZone where formation=:formation " +
66 "and type=:type and a=:a and b=:b");
67 query.setParameter("formation", f);
68 query.setParameter("type", t);
69 query.setParameter("a", a);
70 query.setParameter("b", b);
71 List<HYKFlowZone> zones = query.list();
72 if (zones.isEmpty()) {
73 peer = new HYKFlowZone(f, t, a, b);
74 session.save(peer);
75 }
76 else {
77 peer = zones.get(0);
78 }
79
80 }
81 return peer;
82 }
83 }
84 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org