Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportOfficialLine.java @ 6344:bc28de00e423
Backend: Added importer model for official lines.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 14 Jun 2013 17:56:52 +0200 |
parents | |
children | 75c483450c96 |
comparison
equal
deleted
inserted
replaced
6343:588e99129883 | 6344:bc28de00e423 |
---|---|
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.dive4elements.river.model.NamedMainValue; | |
14 import org.dive4elements.river.model.OfficialLine; | |
15 import org.dive4elements.river.model.River; | |
16 import org.dive4elements.river.model.WstColumn; | |
17 import org.hibernate.Query; | |
18 import org.hibernate.Session; | |
19 | |
20 public class ImportOfficialLine | |
21 { | |
22 protected String name; | |
23 protected ImportWstColumn wstColumn; | |
24 | |
25 protected OfficialLine peer; | |
26 | |
27 public ImportOfficialLine() { | |
28 } | |
29 | |
30 public ImportOfficialLine(String name, ImportWstColumn wstColumn) { | |
31 this.name = name; | |
32 this.wstColumn = wstColumn; | |
33 } | |
34 | |
35 public OfficialLine getPeer(River river) { | |
36 if (peer == null) { | |
37 // XXX: This is a bit odd. We do not have not enough infos here | |
38 // to create a new NamedMainValue. So we just look for existing ones. | |
39 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
40 NamedMainValue nmv = NamedMainValue.fetchByName(name, session); | |
41 if (nmv == null) { | |
42 // failed -> failed to create OfficialLine | |
43 return null; | |
44 } | |
45 WstColumn wc = wstColumn.getPeer(river); | |
46 Query query = session.createQuery( | |
47 "from OfficialLine " + | |
48 "where namedMainValue = :nmv and wstColumn = :wc"); | |
49 query.setParameter("nmv", nmv); | |
50 query.setParameter("wc", wc); | |
51 List<OfficialLine> lines = query.list(); | |
52 if (lines.isEmpty()) { | |
53 peer = new OfficialLine(wc, nmv); | |
54 session.save(peer); | |
55 } | |
56 else { | |
57 peer = lines.get(0); | |
58 } | |
59 | |
60 } | |
61 return peer; | |
62 } | |
63 } | |
64 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | |
65 |