Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportMainValueType.java @ 195:8d3533a03e10
Second part of parsing/storing main values. Should be finished now.
flys-backend/trunk@1534 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 21 Mar 2011 15:06:47 +0000 |
parents | bc3747a371cc |
children | 67fd63e4ef66 |
comparison
equal
deleted
inserted
replaced
194:0f0b98ef9b04 | 195:8d3533a03e10 |
---|---|
8 import java.util.List; | 8 import java.util.List; |
9 | 9 |
10 public class ImportMainValueType | 10 public class ImportMainValueType |
11 implements Comparable<ImportMainValueType> | 11 implements Comparable<ImportMainValueType> |
12 { | 12 { |
13 protected String value; | 13 protected String name; |
14 | 14 |
15 protected MainValueType peer; | 15 protected MainValueType peer; |
16 | 16 |
17 public ImportMainValueType() { | 17 public ImportMainValueType() { |
18 } | 18 } |
19 | 19 |
20 public ImportMainValueType(String value) { | 20 public ImportMainValueType(String name) { |
21 this.value = value; | 21 this.name = name; |
22 } | 22 } |
23 | 23 |
24 public String getValue() { | 24 public String getName() { |
25 return value; | 25 return name; |
26 } | 26 } |
27 | 27 |
28 public void setValue(String value) { | 28 public void setName(String name) { |
29 this.value = value; | 29 this.name = name; |
30 } | 30 } |
31 | 31 |
32 public int compareTo(ImportMainValueType other) { | 32 public int compareTo(ImportMainValueType other) { |
33 return value.compareTo(other.value); | 33 return name.compareTo(other.name); |
34 } | 34 } |
35 | 35 |
36 @Override | 36 @Override |
37 public boolean equals(Object other) { | 37 public boolean equals(Object other) { |
38 if (other == this) return true; | 38 if (other == this) return true; |
39 if (!(other instanceof ImportMainValueType)) return false; | 39 if (!(other instanceof ImportMainValueType)) return false; |
40 return value.equals(((ImportMainValueType)other).value); | 40 return name.equals(((ImportMainValueType)other).name); |
41 } | 41 } |
42 | 42 |
43 @Override | 43 @Override |
44 public int hashCode() { | 44 public int hashCode() { |
45 return value.hashCode(); | 45 return name.hashCode(); |
46 } | 46 } |
47 | 47 |
48 public MainValueType getPeer() { | 48 public MainValueType getPeer() { |
49 if (peer == null) { | 49 if (peer == null) { |
50 Session session = Importer.sessionHolder.get(); | 50 Session session = Importer.sessionHolder.get(); |
51 Query query = session.createQuery("from MainValueType where value=:value"); | 51 Query query = session.createQuery("from MainValueType where name=:name"); |
52 query.setString("value", value); | 52 query.setString("name", name); |
53 List<MainValueType> values = query.list(); | 53 List<MainValueType> values = query.list(); |
54 if (values.isEmpty()) { | 54 if (values.isEmpty()) { |
55 peer = new MainValueType(value); | 55 peer = new MainValueType(name); |
56 session.save(peer); | 56 session.save(peer); |
57 } | 57 } |
58 else { | 58 else { |
59 peer = values.get(0); | 59 peer = values.get(0); |
60 } | 60 } |