comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportLocationSystem.java @ 2809:f283212966e8

Finished work on MINFO bed heights (single). flys-backend/trunk@4221 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 12 Apr 2012 10:42:46 +0000
parents b57c95094b68
children
comparison
equal deleted inserted replaced
2808:b57c95094b68 2809:f283212966e8
1 package de.intevation.flys.importer; 1 package de.intevation.flys.importer;
2 2
3 import java.util.List;
4
5 import org.apache.log4j.Logger;
6
7 import org.hibernate.Session;
8 import org.hibernate.Query;
9
10 import de.intevation.flys.model.LocationSystem;
3 11
4 12
5 public class ImportLocationSystem { 13 public class ImportLocationSystem {
6 14
15 private static final Logger log =
16 Logger.getLogger(ImportLocationSystem.class);
17
18
7 protected String name; 19 protected String name;
8 protected String description; 20 protected String description;
21
22 protected LocationSystem peer;
9 23
10 24
11 public ImportLocationSystem(String name, String description) { 25 public ImportLocationSystem(String name, String description) {
12 this.name = name; 26 this.name = name;
13 this.description = description; 27 this.description = description;
14 } 28 }
29
30 public void storeDependencies() {
31 log.info("store LocationSystem '" + name + "'");
32 LocationSystem ls = getPeer();
33
34 Session session = ImporterSession.getInstance().getDatabaseSession();
35 session.flush();
36 }
37
38 public LocationSystem getPeer() {
39 if (peer == null) {
40 Session session = ImporterSession.getInstance().getDatabaseSession();
41 Query query = session.createQuery(
42 "from LocationSystem where " +
43 "name=:name and description=:description");
44 query.setParameter("name", name);
45 query.setParameter("description", description);
46
47 List<LocationSystem> lss = query.list();
48 if (lss.isEmpty()) {
49 peer = new LocationSystem(name, description);
50 session.save(peer);
51 }
52 else {
53 peer = lss.get(0);
54 }
55 }
56
57 return peer;
58 }
15 } 59 }
16 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 60 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org