Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportPosition.java @ 187:ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
flys-backend/trunk@1507 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 17 Mar 2011 18:07:13 +0000 |
parents | cf8cbcb6a10d |
children | 003ac16812dd |
comparison
equal
deleted
inserted
replaced
186:cf8cbcb6a10d | 187:ecf90018563b |
---|---|
1 package de.intevation.flys.importer; | 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; | |
2 | 9 |
3 public class ImportPosition | 10 public class ImportPosition |
4 implements Comparable<ImportPosition> | 11 implements Comparable<ImportPosition> |
5 { | 12 { |
6 protected String value; | 13 protected String value; |
14 | |
15 protected Position peer; | |
7 | 16 |
8 public ImportPosition() { | 17 public ImportPosition() { |
9 } | 18 } |
10 | 19 |
11 public ImportPosition(String value) { | 20 public ImportPosition(String value) { |
21 } | 30 } |
22 | 31 |
23 public void setValue(String value) { | 32 public void setValue(String value) { |
24 this.value = value; | 33 this.value = value; |
25 } | 34 } |
35 | |
36 public Position getPeer() { | |
37 if (peer != null) { | |
38 Session session = Importer.sessionHolder.get(); | |
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 } | |
26 } | 52 } |
27 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 53 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |
28 | 54 |