comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportElevationModel.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 145b87bcb10a
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.ElevationModel;
3 11
4 12
5 public class ImportElevationModel { 13 public class ImportElevationModel {
6 14
15 private static final Logger log =
16 Logger.getLogger(ImportElevationModel.class);
17
7 protected String name; 18 protected String name;
8 19
9 protected ImportUnit unit; 20 protected ImportUnit unit;
21
22 protected ElevationModel peer;
10 23
11 24
12 public ImportElevationModel(String name, ImportUnit unit) { 25 public ImportElevationModel(String name, ImportUnit unit) {
13 this.name = name; 26 this.name = name;
14 this.unit = unit; 27 this.unit = unit;
15 } 28 }
29
30
31 public void storeDependencies() {
32 ElevationModel model = getPeer();
33 }
34
35 public ElevationModel getPeer() {
36 if (peer == null) {
37 Session session = ImporterSession.getInstance().getDatabaseSession();
38 Query query = session.createQuery(
39 "from ElevationModel where " +
40 "name=:name and unit=:unit");
41 query.setParameter("name", name);
42 query.setParameter("unit", unit.getPeer());
43 List<ElevationModel> models = query.list();
44
45 if (models.isEmpty()) {
46 log.info("Create new ElevationModel DB instance.");
47
48 peer = new ElevationModel(name, unit.getPeer());
49 session.save(peer);
50 }
51 else {
52 peer = models.get(0);
53 }
54 }
55
56 return peer;
57 }
16 } 58 }
17 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 59 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org