comparison backend/src/main/java/org/dive4elements/river/importer/ImportWstQRange.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 3d83a4cf33ba
children 5e38e2924c07
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 java.math.BigDecimal;
12
13 import org.dive4elements.river.model.WstQRange;
14 import org.dive4elements.river.model.River;
15 import org.dive4elements.river.model.Range;
16
17 import org.hibernate.Session;
18 import org.hibernate.Query;
19
20 import java.util.List;
21
22 public class ImportWstQRange
23 {
24 protected ImportRange range;
25 protected BigDecimal q;
26
27 protected WstQRange peer;
28
29 public ImportWstQRange() {
30 }
31
32 public ImportWstQRange(
33 ImportRange range,
34 BigDecimal q
35 ) {
36 this.range = range;
37 this.q = q;
38 }
39
40 public ImportWstQRange(
41 BigDecimal a,
42 BigDecimal b,
43 BigDecimal q
44 ) {
45 this.range = new ImportRange(a, b);
46 this.q = q;
47 }
48
49 public ImportRange getRange() {
50 return range;
51 }
52
53 public void setRange(ImportRange range) {
54 this.range = range;
55 }
56
57 public BigDecimal getQ() {
58 return q;
59 }
60
61 public void setQ(BigDecimal q) {
62 this.q = q;
63 }
64
65 public WstQRange getPeer(River river) {
66 if (peer == null) {
67 Range r = range.getPeer(river);
68 Session session = ImporterSession.getInstance().getDatabaseSession();
69 Query query = session.createQuery(
70 "from WstQRange where " +
71 "range=:range and q=:q");
72 query.setParameter("range", r);
73 query.setParameter("q", q);
74 List<WstQRange> wstQRanges = query.list();
75 if (wstQRanges.isEmpty()) {
76 peer = new WstQRange(r, q);
77 session.save(peer);
78 }
79 else {
80 peer = wstQRanges.get(0);
81 }
82 }
83 return peer;
84 }
85 }
86 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org