[PATCH 1 of 2] Fixed: finding attributes record first case sensitive, insensitive then as fallback
Wald Commits
scm-commit at wald.intevation.org
Tue Sep 18 17:28:40 CEST 2018
# HG changeset patch
# User mschaefer
# Date 1537284429 -7200
# Node ID c347512a07bd2ef9b50bfc3ed121edf4ae927432
# Parent 504f63512379359f3a76292ab64666926966c050
Fixed: finding attributes record first case sensitive, insensitive then as fallback
diff -r 504f63512379 -r c347512a07bd backend/src/main/java/org/dive4elements/river/importer/ImportAttribute.java
--- 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();
More information about the Dive4Elements-commits
mailing list