Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportAttribute.java Tue Apr 03 10:29:57 2018 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportAttribute.java Tue Apr 03 10:37:30 2018 +0200 @@ -8,12 +8,11 @@ package org.dive4elements.river.importer; +import java.util.List; + import org.dive4elements.river.model.Attribute; - +import org.hibernate.Query; import org.hibernate.Session; -import org.hibernate.Query; - -import java.util.List; public class ImportAttribute implements Comparable<ImportAttribute> @@ -25,51 +24,52 @@ public ImportAttribute() { } - public ImportAttribute(String value) { + public ImportAttribute(final String value) { this.value = value; } public String getValue() { - return value; + return this.value; } - public void setValue(String value) { + public void setValue(final String value) { this.value = value; } - public int compareTo(ImportAttribute other) { - return value.compareTo(other.value); + @Override + public int compareTo(final ImportAttribute other) { + return this.value.compareTo(other.value); } @Override - public boolean equals(Object other) { - if (other == this) return true; - if (!(other instanceof ImportAttribute)) return false; - return value.equals(((ImportAttribute)other).value); + public boolean equals(final Object other) { + if (other == this) + return true; + if (!(other instanceof ImportAttribute)) + return false; + return this.value.equals(((ImportAttribute) other).value); } @Override public int hashCode() { - return value.hashCode(); + return this.value.hashCode(); } public Attribute getPeer() { - if (peer == null) { - Session session = ImporterSession.getInstance() - .getDatabaseSession(); - Query query = session.createQuery( - "from Attribute where value=:value"); - query.setString("value", value); - List<Attribute> attributes = query.list(); - if (attributes.isEmpty()) { - peer = new Attribute(value); - session.save(peer); - } - else { - peer = attributes.get(0); - } + if (this.peer != null) + return this.peer; + final Session session = ImporterSession.getInstance().getDatabaseSession(); + final Query query = session.createQuery("FROM Attribute WHERE lower(value)=:value"); + query.setString("value", this.value.trim().toLowerCase()); + final List<Attribute> attributes = query.list(); + if (attributes.isEmpty()) { + this.peer = new Attribute(this.value); + session.save(this.peer); } - return peer; + else { + this.peer = attributes.get(0); + } + return this.peer; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :