Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportLocationSystem.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-backend/src/main/java/org/dive4elements/river/importer/ImportLocationSystem.java@18619c1e7c2a |
children | 4dd33b86dc61 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.importer; | |
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 org.dive4elements.river.model.LocationSystem; | |
11 | |
12 | |
13 public class ImportLocationSystem { | |
14 | |
15 private static final Logger log = | |
16 Logger.getLogger(ImportLocationSystem.class); | |
17 | |
18 | |
19 protected String name; | |
20 protected String description; | |
21 | |
22 protected LocationSystem peer; | |
23 | |
24 | |
25 public ImportLocationSystem(String name, String description) { | |
26 this.name = name; | |
27 this.description = description; | |
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 } | |
59 } | |
60 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |