Mercurial > dive4elements > river
diff backend/src/main/java/org/dive4elements/river/importer/ImportLocationSystem.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 |
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportLocationSystem.java Tue Apr 03 10:29:57 2018 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportLocationSystem.java Tue Apr 03 10:37:30 2018 +0200 @@ -11,17 +11,15 @@ import java.util.List; import org.apache.log4j.Logger; - +import org.dive4elements.river.model.LocationSystem; +import org.hibernate.Query; import org.hibernate.Session; -import org.hibernate.Query; - -import org.dive4elements.river.model.LocationSystem; public class ImportLocationSystem { private static final Logger log = - Logger.getLogger(ImportLocationSystem.class); + Logger.getLogger(ImportLocationSystem.class); protected String name; @@ -30,40 +28,34 @@ protected LocationSystem peer; - public ImportLocationSystem(String name, String description) { + public ImportLocationSystem(final String name, final String description) { this.name = name; this.description = description; } public void storeDependencies() { - log.info("store LocationSystem '" + name + "'"); - LocationSystem ls = getPeer(); + log.info("store LocationSystem '" + this.name + "'"); + final LocationSystem ls = getPeer(); - Session session = ImporterSession.getInstance().getDatabaseSession(); + final Session session = ImporterSession.getInstance().getDatabaseSession(); session.flush(); } public LocationSystem getPeer() { - if (peer == null) { - Session session = ImporterSession.getInstance() - .getDatabaseSession(); - Query query = session.createQuery( - "from LocationSystem where " + - "name=:name and description=:description"); - query.setParameter("name", name); - query.setParameter("description", description); - - List<LocationSystem> lss = query.list(); - if (lss.isEmpty()) { - peer = new LocationSystem(name, description); - session.save(peer); - } - else { - peer = lss.get(0); - } + if (this.peer != null) + return this.peer; + final Session session = ImporterSession.getInstance().getDatabaseSession(); + final Query query = session.createQuery("FROM LocationSystem WHERE (trim(name)=:name) AND (trim(description)=:description)"); + query.setParameter("name", this.name); + query.setParameter("description", this.description); + final List<LocationSystem> lss = query.list(); + if (lss.isEmpty()) { + this.peer = new LocationSystem(this.name, this.description); + session.save(this.peer); + } else { + this.peer = lss.get(0); } - - return peer; + return this.peer; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :