Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportUnit.java @ 7730:e1b831fe435a slt-simplify-cross-sections
Merged default into slt-simplify-cross-sections branch and updated package and class names.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 20 Jan 2014 14:04:20 +0100 |
parents | 4c3ccf2b0304 |
children | 5e38e2924c07 |
comparison
equal
deleted
inserted
replaced
5084:ca45dd039b54 | 7730:e1b831fe435a |
---|---|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.importer; | |
10 | |
11 import java.util.List; | |
12 | |
13 import org.apache.log4j.Logger; | |
14 | |
15 import org.hibernate.Session; | |
16 import org.hibernate.Query; | |
17 | |
18 import org.dive4elements.river.model.Unit; | |
19 | |
20 | |
21 public class ImportUnit | |
22 { | |
23 private static final Logger log = Logger.getLogger(ImportUnit.class); | |
24 | |
25 protected String name; | |
26 | |
27 protected Unit peer; | |
28 | |
29 | |
30 public ImportUnit(String name) { | |
31 this.name = name; | |
32 } | |
33 | |
34 | |
35 public String getName() { | |
36 return name; | |
37 } | |
38 | |
39 | |
40 public Unit getPeer() { | |
41 if (peer == null) { | |
42 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
43 Query query = session.createQuery("from Unit where name=:name"); | |
44 query.setParameter("name", name); | |
45 | |
46 List<Unit> units = query.list(); | |
47 if (units.isEmpty()) { | |
48 log.info("Store new unit '" + name + "'"); | |
49 | |
50 peer = new Unit(name); | |
51 session.save(peer); | |
52 } | |
53 else { | |
54 peer = units.get(0); | |
55 } | |
56 } | |
57 return peer; | |
58 } | |
59 } | |
60 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |