Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportWst.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/ImportWst.java@18619c1e7c2a |
children | 4dd33b86dc61 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.importer; | |
2 | |
3 import org.dive4elements.river.model.Wst; | |
4 import org.dive4elements.river.model.River; | |
5 | |
6 import org.apache.log4j.Logger; | |
7 | |
8 import org.hibernate.Session; | |
9 import org.hibernate.Query; | |
10 | |
11 import java.util.ArrayList; | |
12 import java.util.List; | |
13 | |
14 public class ImportWst | |
15 { | |
16 private static Logger log = Logger.getLogger(ImportWst.class); | |
17 | |
18 protected String description; | |
19 | |
20 protected Integer kind; | |
21 | |
22 protected List<ImportWstColumn> columns; | |
23 | |
24 protected ImportUnit unit; | |
25 | |
26 /** Wst as in db. */ | |
27 protected Wst peer; | |
28 | |
29 public ImportWst() { | |
30 kind = 0; | |
31 columns = new ArrayList<ImportWstColumn>(); | |
32 } | |
33 | |
34 public ImportWst(String description) { | |
35 this(); | |
36 this.description = description; | |
37 } | |
38 | |
39 public String getDescription() { | |
40 return description; | |
41 } | |
42 | |
43 public Integer getKind() { | |
44 return kind; | |
45 } | |
46 | |
47 public void setKind(Integer kind) { | |
48 this.kind = kind; | |
49 } | |
50 | |
51 | |
52 public void setDescription(String description) { | |
53 this.description = description; | |
54 } | |
55 | |
56 /** Create columns that can be accessed with getColumn. */ | |
57 public void setNumberColumns(int numColumns) { | |
58 for (int i = 0; i < numColumns; ++i) { | |
59 columns.add(new ImportWstColumn(this, null, null, i)); | |
60 } | |
61 } | |
62 | |
63 public int getNumberColumns() { | |
64 return columns.size(); | |
65 } | |
66 | |
67 public ImportWstColumn getColumn(int index) { | |
68 return columns.get(index); | |
69 } | |
70 | |
71 public List<ImportWstColumn> getColumns() { | |
72 return columns; | |
73 } | |
74 | |
75 /** Adds a column. Assumes that columns wst is this instance. */ | |
76 public void addColumn(ImportWstColumn column) { | |
77 columns.add(column); | |
78 } | |
79 | |
80 public ImportUnit getUnit() { | |
81 return unit; | |
82 } | |
83 | |
84 public void setUnit(ImportUnit unit) { | |
85 this.unit = unit; | |
86 } | |
87 | |
88 public void storeDependencies(River river) { | |
89 | |
90 log.info("store '" + description + "'"); | |
91 Wst wst = getPeer(river); | |
92 | |
93 for (ImportWstColumn column: columns) { | |
94 column.storeDependencies(river); | |
95 } | |
96 | |
97 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
98 session.flush(); | |
99 } | |
100 | |
101 public void fixRangesOrder() { | |
102 for (ImportWstColumn column: columns) { | |
103 column.fixRangesOrder(); | |
104 } | |
105 } | |
106 | |
107 /** Get corresponding mapped wst (from database). */ | |
108 public Wst getPeer(River river) { | |
109 if (peer == null) { | |
110 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
111 Query query = session.createQuery( | |
112 "from Wst where " + | |
113 "river=:river and description=:description and kind=:kind"); | |
114 query.setParameter("river", river); | |
115 query.setParameter("description", description); | |
116 query.setParameter("kind", kind); | |
117 List<Wst> wsts = query.list(); | |
118 if (wsts.isEmpty()) { | |
119 peer = new Wst(river, description, kind); | |
120 session.save(peer); | |
121 } | |
122 else { | |
123 peer = wsts.get(0); | |
124 } | |
125 | |
126 } | |
127 return peer; | |
128 } | |
129 } | |
130 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |