Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportMainValueType.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-backend/src/main/java/org/dive4elements/river/importer/ImportMainValueType.java@18619c1e7c2a |
children | 4dd33b86dc61 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.importer; | |
2 | |
3 import org.dive4elements.river.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 name; | |
14 | |
15 protected MainValueType peer; | |
16 | |
17 public ImportMainValueType() { | |
18 } | |
19 | |
20 public ImportMainValueType(String name) { | |
21 this.name = name; | |
22 } | |
23 | |
24 public String getName() { | |
25 return name; | |
26 } | |
27 | |
28 public void setName(String name) { | |
29 this.name = name; | |
30 } | |
31 | |
32 public int compareTo(ImportMainValueType other) { | |
33 return name.compareTo(other.name); | |
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 name.equals(((ImportMainValueType)other).name); | |
41 } | |
42 | |
43 @Override | |
44 public int hashCode() { | |
45 return name.hashCode(); | |
46 } | |
47 | |
48 public MainValueType getPeer() { | |
49 if (peer == null) { | |
50 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
51 Query query = session.createQuery("from MainValueType where name=:name"); | |
52 query.setString("name", name); | |
53 List<MainValueType> values = query.list(); | |
54 if (values.isEmpty()) { | |
55 peer = new MainValueType(name); | |
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 : |