Mercurial > dive4elements > river
changeset 9488:c347512a07bd
Fixed: finding attributes record first case sensitive, insensitive then as fallback
author | mschaefer |
---|---|
date | Tue, 18 Sep 2018 17:27:09 +0200 |
parents | 504f63512379 |
children | 8562c60371b8 |
files | backend/src/main/java/org/dive4elements/river/importer/ImportAttribute.java |
diffstat | 1 files changed, 20 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportAttribute.java Tue Sep 18 12:21:17 2018 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportAttribute.java Tue Sep 18 17:27:09 2018 +0200 @@ -59,6 +59,26 @@ if (this.peer != null) return this.peer; final Session session = ImporterSession.getInstance().getDatabaseSession(); + final Query query = session.createQuery("FROM Attribute WHERE value=:value"); + query.setString("value", this.value.trim()); + final List<Attribute> attributes = query.list(); + if (attributes.isEmpty()) { + this.peer = getPeerCaseInsensitive(); + if (this.peer == null) { + this.peer = new Attribute(this.value); + session.save(this.peer); + } + } + else { + this.peer = attributes.get(0); + } + return this.peer; + } + + private Attribute getPeerCaseInsensitive() { + 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();