Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportAttribute.java @ 8974:a275ddf7a3a1
Added some trim and lowercase in the where clauses of the selects of existing recordsets; added AnnotationType select
author | mschaefer |
---|---|
date | Tue, 03 Apr 2018 10:37:30 +0200 |
parents | 5e38e2924c07 |
children | c347512a07bd |
comparison
equal
deleted
inserted
replaced
8973:35afa0349782 | 8974:a275ddf7a3a1 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.importer; | 9 package org.dive4elements.river.importer; |
10 | 10 |
11 import java.util.List; | |
12 | |
11 import org.dive4elements.river.model.Attribute; | 13 import org.dive4elements.river.model.Attribute; |
12 | 14 import org.hibernate.Query; |
13 import org.hibernate.Session; | 15 import org.hibernate.Session; |
14 import org.hibernate.Query; | |
15 | |
16 import java.util.List; | |
17 | 16 |
18 public class ImportAttribute | 17 public class ImportAttribute |
19 implements Comparable<ImportAttribute> | 18 implements Comparable<ImportAttribute> |
20 { | 19 { |
21 protected String value; | 20 protected String value; |
23 protected Attribute peer; | 22 protected Attribute peer; |
24 | 23 |
25 public ImportAttribute() { | 24 public ImportAttribute() { |
26 } | 25 } |
27 | 26 |
28 public ImportAttribute(String value) { | 27 public ImportAttribute(final String value) { |
29 this.value = value; | 28 this.value = value; |
30 } | 29 } |
31 | 30 |
32 public String getValue() { | 31 public String getValue() { |
33 return value; | 32 return this.value; |
34 } | 33 } |
35 | 34 |
36 public void setValue(String value) { | 35 public void setValue(final String value) { |
37 this.value = value; | 36 this.value = value; |
38 } | 37 } |
39 | 38 |
40 public int compareTo(ImportAttribute other) { | 39 @Override |
41 return value.compareTo(other.value); | 40 public int compareTo(final ImportAttribute other) { |
41 return this.value.compareTo(other.value); | |
42 } | 42 } |
43 | 43 |
44 @Override | 44 @Override |
45 public boolean equals(Object other) { | 45 public boolean equals(final Object other) { |
46 if (other == this) return true; | 46 if (other == this) |
47 if (!(other instanceof ImportAttribute)) return false; | 47 return true; |
48 return value.equals(((ImportAttribute)other).value); | 48 if (!(other instanceof ImportAttribute)) |
49 return false; | |
50 return this.value.equals(((ImportAttribute) other).value); | |
49 } | 51 } |
50 | 52 |
51 @Override | 53 @Override |
52 public int hashCode() { | 54 public int hashCode() { |
53 return value.hashCode(); | 55 return this.value.hashCode(); |
54 } | 56 } |
55 | 57 |
56 public Attribute getPeer() { | 58 public Attribute getPeer() { |
57 if (peer == null) { | 59 if (this.peer != null) |
58 Session session = ImporterSession.getInstance() | 60 return this.peer; |
59 .getDatabaseSession(); | 61 final Session session = ImporterSession.getInstance().getDatabaseSession(); |
60 Query query = session.createQuery( | 62 final Query query = session.createQuery("FROM Attribute WHERE lower(value)=:value"); |
61 "from Attribute where value=:value"); | 63 query.setString("value", this.value.trim().toLowerCase()); |
62 query.setString("value", value); | 64 final List<Attribute> attributes = query.list(); |
63 List<Attribute> attributes = query.list(); | 65 if (attributes.isEmpty()) { |
64 if (attributes.isEmpty()) { | 66 this.peer = new Attribute(this.value); |
65 peer = new Attribute(value); | 67 session.save(this.peer); |
66 session.save(peer); | |
67 } | |
68 else { | |
69 peer = attributes.get(0); | |
70 } | |
71 } | 68 } |
72 return peer; | 69 else { |
70 this.peer = attributes.get(0); | |
71 } | |
72 return this.peer; | |
73 } | 73 } |
74 } | 74 } |
75 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 75 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |