Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
8973:35afa0349782 | 8974:a275ddf7a3a1 |
---|---|
9 package org.dive4elements.river.importer; | 9 package org.dive4elements.river.importer; |
10 | 10 |
11 import java.util.List; | 11 import java.util.List; |
12 | 12 |
13 import org.apache.log4j.Logger; | 13 import org.apache.log4j.Logger; |
14 | 14 import org.dive4elements.river.model.LocationSystem; |
15 import org.hibernate.Query; | |
15 import org.hibernate.Session; | 16 import org.hibernate.Session; |
16 import org.hibernate.Query; | |
17 | |
18 import org.dive4elements.river.model.LocationSystem; | |
19 | 17 |
20 | 18 |
21 public class ImportLocationSystem { | 19 public class ImportLocationSystem { |
22 | 20 |
23 private static final Logger log = | 21 private static final Logger log = |
24 Logger.getLogger(ImportLocationSystem.class); | 22 Logger.getLogger(ImportLocationSystem.class); |
25 | 23 |
26 | 24 |
27 protected String name; | 25 protected String name; |
28 protected String description; | 26 protected String description; |
29 | 27 |
30 protected LocationSystem peer; | 28 protected LocationSystem peer; |
31 | 29 |
32 | 30 |
33 public ImportLocationSystem(String name, String description) { | 31 public ImportLocationSystem(final String name, final String description) { |
34 this.name = name; | 32 this.name = name; |
35 this.description = description; | 33 this.description = description; |
36 } | 34 } |
37 | 35 |
38 public void storeDependencies() { | 36 public void storeDependencies() { |
39 log.info("store LocationSystem '" + name + "'"); | 37 log.info("store LocationSystem '" + this.name + "'"); |
40 LocationSystem ls = getPeer(); | 38 final LocationSystem ls = getPeer(); |
41 | 39 |
42 Session session = ImporterSession.getInstance().getDatabaseSession(); | 40 final Session session = ImporterSession.getInstance().getDatabaseSession(); |
43 session.flush(); | 41 session.flush(); |
44 } | 42 } |
45 | 43 |
46 public LocationSystem getPeer() { | 44 public LocationSystem getPeer() { |
47 if (peer == null) { | 45 if (this.peer != null) |
48 Session session = ImporterSession.getInstance() | 46 return this.peer; |
49 .getDatabaseSession(); | 47 final Session session = ImporterSession.getInstance().getDatabaseSession(); |
50 Query query = session.createQuery( | 48 final Query query = session.createQuery("FROM LocationSystem WHERE (trim(name)=:name) AND (trim(description)=:description)"); |
51 "from LocationSystem where " + | 49 query.setParameter("name", this.name); |
52 "name=:name and description=:description"); | 50 query.setParameter("description", this.description); |
53 query.setParameter("name", name); | 51 final List<LocationSystem> lss = query.list(); |
54 query.setParameter("description", description); | 52 if (lss.isEmpty()) { |
55 | 53 this.peer = new LocationSystem(this.name, this.description); |
56 List<LocationSystem> lss = query.list(); | 54 session.save(this.peer); |
57 if (lss.isEmpty()) { | 55 } else { |
58 peer = new LocationSystem(name, description); | 56 this.peer = lss.get(0); |
59 session.save(peer); | |
60 } | |
61 else { | |
62 peer = lss.get(0); | |
63 } | |
64 } | 57 } |
65 | 58 return this.peer; |
66 return peer; | |
67 } | 59 } |
68 } | 60 } |
69 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 61 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |