comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportWstColumn.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 29a408f80a89
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.WstColumn; 4 import de.intevation.flys.model.WstColumn;
5 import de.intevation.flys.model.River;
6
7 import org.hibernate.Session;
8 import org.hibernate.Query;
9
10 import java.util.List;
11 import java.util.ArrayList;
4 12
5 public class ImportWstColumn 13 public class ImportWstColumn
6 { 14 {
15 protected ImportWst wst;
16 protected String name;
17 protected String description;
18
19 protected List<ImportWstColumnQRange> columnQRanges;
20
7 protected WstColumn peer; 21 protected WstColumn peer;
8 22
9 public ImportWstColumn() { 23 public ImportWstColumn() {
24 columnQRanges = new ArrayList<ImportWstColumnQRange>();
10 } 25 }
11 26
12 public WstColumn getPeer() { 27 public ImportWstColumn(
28 ImportWst wst,
29 String name,
30 String description
31 ) {
32 this();
33 this.wst = wst;
34 this.name = name;
35 this.description = description;
36 }
37
38 public ImportWst getWst() {
39 return wst;
40 }
41
42 public void setWst(ImportWst wst) {
43 this.wst = wst;
44 }
45
46 public String getName() {
47 return name;
48 }
49
50 public void setName(String name) {
51 this.name = name;
52 }
53
54 public String getDescription() {
55 return description;
56 }
57
58 public void setDescription(String description) {
59 this.description = description;
60 }
61
62 public void addColumnQRange(ImportWstQRange columnQRange) {
63 columnQRanges.add(
64 new ImportWstColumnQRange(this, columnQRange));
65 }
66
67 public void storeDependencies(River river) {
68 WstColumn column = getPeer(river);
69 for (ImportWstColumnQRange columnQRange: columnQRanges) {
70 columnQRange.getPeer(river);
71 }
72 // TODO: Implement me!
73 }
74
75 public WstColumn getPeer(River river) {
13 if (peer == null) { 76 if (peer == null) {
14 // TODO: Implement me! 77 Wst w = wst.getPeer(river);
78 Session session = Importer.sessionHolder.get();
79 Query query = session.createQuery(
80 "from WstColumn where " +
81 "wst=:wst and name=:name and description=:description");
82 query.setParameter("wst", w);
83 query.setParameter("name", name);
84 query.setParameter("description", description);
85 List<WstColumn> columns = query.list();
86 if (columns.isEmpty()) {
87 peer = new WstColumn(w, name, description, null);
88 session.save(peer);
89 }
90 else {
91 peer = columns.get(0);
92 }
15 } 93 }
16 return peer; 94 return peer;
17 } 95 }
18 } 96 }
19 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 97 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org