Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportAttribute.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/ImportAttribute.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.Attribute; | |
4 | |
5 import org.hibernate.Session; | |
6 import org.hibernate.Query; | |
7 | |
8 import java.util.List; | |
9 | |
10 public class ImportAttribute | |
11 implements Comparable<ImportAttribute> | |
12 { | |
13 protected String value; | |
14 | |
15 protected Attribute peer; | |
16 | |
17 public ImportAttribute() { | |
18 } | |
19 | |
20 public ImportAttribute(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(ImportAttribute 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 ImportAttribute)) return false; | |
40 return value.equals(((ImportAttribute)other).value); | |
41 } | |
42 | |
43 @Override | |
44 public int hashCode() { | |
45 return value.hashCode(); | |
46 } | |
47 | |
48 public Attribute getPeer() { | |
49 if (peer == null) { | |
50 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
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 } | |
64 } | |
65 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |