Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportMainValueType.java @ 189:bc3747a371cc
First part of parsing main values.
flys-backend/trunk@1520 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 18 Mar 2011 16:12:24 +0000 |
parents | |
children | 8d3533a03e10 |
comparison
equal
deleted
inserted
replaced
188:003ac16812dd | 189:bc3747a371cc |
---|---|
1 package de.intevation.flys.importer; | |
2 | |
3 import de.intevation.flys.model.MainValueType; | |
4 | |
5 import org.hibernate.Session; | |
6 import org.hibernate.Query; | |
7 | |
8 import java.util.List; | |
9 | |
10 public class ImportMainValueType | |
11 implements Comparable<ImportMainValueType> | |
12 { | |
13 protected String value; | |
14 | |
15 protected MainValueType peer; | |
16 | |
17 public ImportMainValueType() { | |
18 } | |
19 | |
20 public ImportMainValueType(String value) { | |
21 this.value = value; | |
22 } | |
23 | |
24 public String getValue() { | |
25 return value; | |
26 } | |
27 | |
28 public void setValue(String value) { | |
29 this.value = value; | |
30 } | |
31 | |
32 public int compareTo(ImportMainValueType other) { | |
33 return value.compareTo(other.value); | |
34 } | |
35 | |
36 @Override | |
37 public boolean equals(Object other) { | |
38 if (other == this) return true; | |
39 if (!(other instanceof ImportMainValueType)) return false; | |
40 return value.equals(((ImportMainValueType)other).value); | |
41 } | |
42 | |
43 @Override | |
44 public int hashCode() { | |
45 return value.hashCode(); | |
46 } | |
47 | |
48 public MainValueType getPeer() { | |
49 if (peer == null) { | |
50 Session session = Importer.sessionHolder.get(); | |
51 Query query = session.createQuery("from MainValueType where value=:value"); | |
52 query.setString("value", value); | |
53 List<MainValueType> values = query.list(); | |
54 if (values.isEmpty()) { | |
55 peer = new MainValueType(value); | |
56 session.save(peer); | |
57 } | |
58 else { | |
59 peer = values.get(0); | |
60 } | |
61 } | |
62 return peer; | |
63 } | |
64 } | |
65 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |