Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportPosition.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 | 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 org.dive4elements.river.model.Position; | |
12 | |
13 import org.hibernate.Session; | |
14 import org.hibernate.Query; | |
15 | |
16 import java.util.List; | |
17 | |
18 public class ImportPosition | |
19 implements Comparable<ImportPosition> | |
20 { | |
21 protected String value; | |
22 | |
23 protected Position peer; | |
24 | |
25 public ImportPosition() { | |
26 } | |
27 | |
28 public ImportPosition(String value) { | |
29 this.value = value; | |
30 } | |
31 | |
32 public int compareTo(ImportPosition other) { | |
33 return value.compareTo(other.value); | |
34 } | |
35 | |
36 public String getValue() { | |
37 return value; | |
38 } | |
39 | |
40 public void setValue(String value) { | |
41 this.value = value; | |
42 } | |
43 | |
44 public Position getPeer() { | |
45 if (peer == null) { | |
46 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
47 Query query = session.createQuery("from Position where value=:value"); | |
48 query.setString("value", value); | |
49 List<Position> positions = query.list(); | |
50 if (positions.isEmpty()) { | |
51 peer = new Position(value); | |
52 session.save(peer); | |
53 } | |
54 else { | |
55 peer = positions.get(0); | |
56 } | |
57 } | |
58 return peer; | |
59 } | |
60 } | |
61 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | |
62 |