Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportAttribute.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.Attribute; | |
4 | |
5 import org.hibernate.Session; | |
6 import org.hibernate.Query; | |
7 | |
8 import java.util.List; | |
2 | 9 |
3 public class ImportAttribute | 10 public class ImportAttribute |
4 implements Comparable<ImportAttribute> | 11 implements Comparable<ImportAttribute> |
5 { | 12 { |
6 protected String value; | 13 protected String value; |
14 | |
15 protected Attribute peer; | |
7 | 16 |
8 public ImportAttribute() { | 17 public ImportAttribute() { |
9 } | 18 } |
10 | 19 |
11 public ImportAttribute(String value) { | 20 public ImportAttribute(String value) { |
33 | 42 |
34 @Override | 43 @Override |
35 public int hashCode() { | 44 public int hashCode() { |
36 return value.hashCode(); | 45 return value.hashCode(); |
37 } | 46 } |
47 | |
48 public Attribute getPeer() { | |
49 if (peer != null) { | |
50 Session session = Importer.sessionHolder.get(); | |
51 Query query = session.createQuery("from Attribute where value=:value"); | |
52 query.setString("value", value); | |
53 List<Attribute> attributes = query.list(); | |
54 if (attributes.isEmpty()) { | |
55 peer = new Attribute(value); | |
56 session.save(peer); | |
57 } | |
58 else { | |
59 peer = attributes.get(0); | |
60 } | |
61 } | |
62 return peer; | |
63 } | |
38 } | 64 } |
39 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 65 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |