Mercurial > dive4elements > river
comparison flys-backend/src/main/java/org/dive4elements/river/importer/ImportPosition.java @ 5828:dfb26b03b179
Moved directories to org.dive4elements.river
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 11:53:11 +0200 |
parents | flys-backend/src/main/java/de/intevation/flys/importer/ImportPosition.java@67fd63e4ef66 |
children | 18619c1e7c2a |
comparison
equal
deleted
inserted
replaced
5827:e308d4ecd35a | 5828:dfb26b03b179 |
---|---|
1 package de.intevation.flys.importer; | |
2 | |
3 import de.intevation.flys.model.Position; | |
4 | |
5 import org.hibernate.Session; | |
6 import org.hibernate.Query; | |
7 | |
8 import java.util.List; | |
9 | |
10 public class ImportPosition | |
11 implements Comparable<ImportPosition> | |
12 { | |
13 protected String value; | |
14 | |
15 protected Position peer; | |
16 | |
17 public ImportPosition() { | |
18 } | |
19 | |
20 public ImportPosition(String value) { | |
21 this.value = value; | |
22 } | |
23 | |
24 public int compareTo(ImportPosition other) { | |
25 return value.compareTo(other.value); | |
26 } | |
27 | |
28 public String getValue() { | |
29 return value; | |
30 } | |
31 | |
32 public void setValue(String value) { | |
33 this.value = value; | |
34 } | |
35 | |
36 public Position getPeer() { | |
37 if (peer == null) { | |
38 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
39 Query query = session.createQuery("from Position where value=:value"); | |
40 query.setString("value", value); | |
41 List<Position> positions = query.list(); | |
42 if (positions.isEmpty()) { | |
43 peer = new Position(value); | |
44 session.save(peer); | |
45 } | |
46 else { | |
47 peer = positions.get(0); | |
48 } | |
49 } | |
50 return peer; | |
51 } | |
52 } | |
53 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | |
54 |