comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportWst.java @ 201:3169b559ca3c

Build models for wsts, wst columns and q ranges and store them in the backend. flys-backend/trunk@1549 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 23 Mar 2011 15:22:32 +0000
parents a33c065b95eb
children c8c09e31cdb8
comparison
equal deleted inserted replaced
200:88048d4f6e4d 201:3169b559ca3c
1 package de.intevation.flys.importer; 1 package de.intevation.flys.importer;
2 2
3 import de.intevation.flys.model.Wst; 3 import de.intevation.flys.model.Wst;
4 import de.intevation.flys.model.River;
5
6 import org.hibernate.Session;
7 import org.hibernate.Query;
8
9 import java.util.List;
10 import java.util.Map;
11 import java.util.HashMap;
4 12
5 public class ImportWst 13 public class ImportWst
6 { 14 {
15 protected String description;
16
17 protected Map<String, ImportWstColumn> columns;
18
7 protected Wst peer; 19 protected Wst peer;
8 20
9 public ImportWst() { 21 public ImportWst() {
22 columns = new HashMap<String, ImportWstColumn>();
10 } 23 }
11 24
12 public Wst getPeer() { 25 public ImportWst(String description) {
26 this();
27 this.description = description;
28 }
29
30 public String getDescription() {
31 return description;
32 }
33
34 public void setDescription(String description) {
35 this.description = description;
36 }
37
38 public ImportWstColumn getColumn(String name) {
39 ImportWstColumn column = columns.get(name);
40 if (column == null) {
41 column = new ImportWstColumn(this, name, null);
42 columns.put(name, column);
43 }
44 return column;
45 }
46
47 public void storeDependencies(River river) {
48 Wst wst = getPeer(river);
49
50 for (ImportWstColumn column: columns.values()) {
51 column.storeDependencies(river);
52 }
53 }
54
55 public Wst getPeer(River river) {
13 if (peer == null) { 56 if (peer == null) {
14 // TODO: Implement me! 57 Session session = Importer.sessionHolder.get();
58 Query query = session.createQuery(
59 "from Wst where " +
60 "river=:river and description=:description");
61 query.setParameter("river", river);
62 query.setParameter("description", description);
63 List<Wst> wsts = query.list();
64 if (wsts.isEmpty()) {
65 peer = new Wst(river, description);
66 session.save(peer);
67 }
68 else {
69 peer = wsts.get(0);
70 }
71
15 } 72 }
16 return peer; 73 return peer;
17 } 74 }
18 } 75 }
19 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 76 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org