Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportAttribute.java @ 7730:e1b831fe435a slt-simplify-cross-sections
Merged default into slt-simplify-cross-sections branch and updated package and class names.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 20 Jan 2014 14:04:20 +0100 |
parents | 4c3ccf2b0304 |
children | 5e38e2924c07 |
comparison
equal
deleted
inserted
replaced
5084:ca45dd039b54 | 7730:e1b831fe435a |
---|---|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.importer; | |
10 | |
11 import org.dive4elements.river.model.Attribute; | |
12 | |
13 import org.hibernate.Session; | |
14 import org.hibernate.Query; | |
15 | |
16 import java.util.List; | |
17 | |
18 public class ImportAttribute | |
19 implements Comparable<ImportAttribute> | |
20 { | |
21 protected String value; | |
22 | |
23 protected Attribute peer; | |
24 | |
25 public ImportAttribute() { | |
26 } | |
27 | |
28 public ImportAttribute(String value) { | |
29 this.value = value; | |
30 } | |
31 | |
32 public String getValue() { | |
33 return value; | |
34 } | |
35 | |
36 public void setValue(String value) { | |
37 this.value = value; | |
38 } | |
39 | |
40 public int compareTo(ImportAttribute other) { | |
41 return value.compareTo(other.value); | |
42 } | |
43 | |
44 @Override | |
45 public boolean equals(Object other) { | |
46 if (other == this) return true; | |
47 if (!(other instanceof ImportAttribute)) return false; | |
48 return value.equals(((ImportAttribute)other).value); | |
49 } | |
50 | |
51 @Override | |
52 public int hashCode() { | |
53 return value.hashCode(); | |
54 } | |
55 | |
56 public Attribute getPeer() { | |
57 if (peer == null) { | |
58 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
59 Query query = session.createQuery("from Attribute where value=:value"); | |
60 query.setString("value", value); | |
61 List<Attribute> attributes = query.list(); | |
62 if (attributes.isEmpty()) { | |
63 peer = new Attribute(value); | |
64 session.save(peer); | |
65 } | |
66 else { | |
67 peer = attributes.get(0); | |
68 } | |
69 } | |
70 return peer; | |
71 } | |
72 } | |
73 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |