Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightEpoch.java @ 3943:a5b003595d6c
Store minfo values into database only if their peer has been successfully stored.
flys-backend/trunk@5520 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 19 Sep 2012 10:05:36 +0000 |
parents | 0d27d02b1208 |
children | 145b87bcb10a |
comparison
equal
deleted
inserted
replaced
3942:43aa1ac8614b | 3943:a5b003595d6c |
---|---|
16 import de.intevation.flys.model.Range; | 16 import de.intevation.flys.model.Range; |
17 import de.intevation.flys.model.River; | 17 import de.intevation.flys.model.River; |
18 import de.intevation.flys.model.TimeInterval; | 18 import de.intevation.flys.model.TimeInterval; |
19 | 19 |
20 | 20 |
21 public class ImportBedHeightEpoch implements ImportBedHeight | 21 public class ImportBedHeightEpoch implements ImportBedHeight { |
22 { | 22 |
23 private static Logger log = Logger.getLogger(ImportBedHeightEpoch.class); | 23 private static Logger log = Logger.getLogger(ImportBedHeightEpoch.class); |
24 | 24 |
25 protected String evaluationBy; | 25 protected String evaluationBy; |
26 protected String description; | 26 protected String description; |
27 | 27 |
28 protected ImportTimeInterval timeInterval; | 28 protected ImportTimeInterval timeInterval; |
29 protected ImportRange range; | 29 protected ImportRange range; |
30 protected ImportElevationModel curElevationModel; | 30 protected ImportElevationModel curElevationModel; |
31 protected ImportElevationModel oldElevationModel; | 31 protected ImportElevationModel oldElevationModel; |
32 | 32 |
33 protected List<ImportBedHeightEpochValue> values; | 33 protected List<ImportBedHeightEpochValue> values; |
34 | 34 |
35 protected BedHeightEpoch peer; | 35 protected BedHeightEpoch peer; |
36 | 36 |
37 | |
38 public ImportBedHeightEpoch(String description) { | 37 public ImportBedHeightEpoch(String description) { |
39 this.description = description; | 38 this.description = description; |
40 this.values = new ArrayList<ImportBedHeightEpochValue>(); | 39 this.values = new ArrayList<ImportBedHeightEpochValue>(); |
41 } | 40 } |
42 | |
43 | 41 |
44 public String getDescription() { | 42 public String getDescription() { |
45 return description; | 43 return description; |
46 } | 44 } |
47 | |
48 | 45 |
49 public int getValueCount() { | 46 public int getValueCount() { |
50 return values.size(); | 47 return values.size(); |
51 } | 48 } |
52 | 49 |
53 public void setTimeInterval(ImportTimeInterval timeInterval) { | 50 public void setTimeInterval(ImportTimeInterval timeInterval) { |
54 this.timeInterval = timeInterval; | 51 this.timeInterval = timeInterval; |
55 } | 52 } |
56 | |
57 | 53 |
58 public void setEvaluationBy(String evaluationBy) { | 54 public void setEvaluationBy(String evaluationBy) { |
59 this.evaluationBy = evaluationBy; | 55 this.evaluationBy = evaluationBy; |
60 } | 56 } |
61 | 57 |
94 @Override | 90 @Override |
95 public void addValue(ImportBedHeightValue value) { | 91 public void addValue(ImportBedHeightValue value) { |
96 values.add((ImportBedHeightEpochValue) value); | 92 values.add((ImportBedHeightEpochValue) value); |
97 } | 93 } |
98 | 94 |
99 | |
100 @Override | 95 @Override |
101 public void storeDependencies(River river) | 96 public void storeDependencies(River river) throws SQLException, |
102 throws SQLException, ConstraintViolationException | 97 ConstraintViolationException { |
103 { | |
104 log.info("Store dependencies for epoch: '" + getDescription() + "'"); | 98 log.info("Store dependencies for epoch: '" + getDescription() + "'"); |
105 | 99 |
106 if (curElevationModel != null) { | 100 if (curElevationModel != null) { |
107 curElevationModel.storeDependencies(); | 101 curElevationModel.storeDependencies(); |
108 } | 102 } |
111 oldElevationModel.storeDependencies(); | 105 oldElevationModel.storeDependencies(); |
112 } | 106 } |
113 | 107 |
114 BedHeightEpoch peer = getPeer(river); | 108 BedHeightEpoch peer = getPeer(river); |
115 | 109 |
116 log.debug("store values now..."); | 110 if (peer != null) { |
111 log.debug("store values now..."); | |
117 | 112 |
118 for (ImportBedHeightEpochValue value: values) { | 113 for (ImportBedHeightEpochValue value : values) { |
119 value.storeDependencies(peer); | 114 value.storeDependencies(peer); |
115 } | |
120 } | 116 } |
121 | 117 |
122 Session session = ImporterSession.getInstance().getDatabaseSession(); | 118 Session session = ImporterSession.getInstance().getDatabaseSession(); |
123 session.flush(); | 119 session.flush(); |
124 } | 120 } |
125 | 121 |
126 | |
127 @Override | 122 @Override |
128 public BedHeightEpoch getPeer(River river) { | 123 public BedHeightEpoch getPeer(River river) { |
129 if (peer == null) { | 124 if (peer == null) { |
130 ElevationModel theCurModel = curElevationModel != null | 125 ElevationModel theCurModel = curElevationModel != null ? curElevationModel |
131 ? curElevationModel.getPeer() | 126 .getPeer() : null; |
132 : null; | |
133 | 127 |
134 if (theCurModel == null) { | 128 if (theCurModel == null) { |
135 log.warn("BHE: Skip file - invalid current elevation model."); | 129 log.warn("BHE: Skip file - invalid current elevation model."); |
136 return null; | 130 return null; |
137 } | 131 } |
138 | 132 |
139 TimeInterval theTime = timeInterval != null | 133 TimeInterval theTime = timeInterval != null ? timeInterval |
140 ? timeInterval.getPeer() | 134 .getPeer() : null; |
141 : null; | |
142 | 135 |
143 if (theTime == null) { | 136 if (theTime == null) { |
144 log.warn("BHE: Skip file - invalid time range."); | 137 log.warn("BHE: Skip file - invalid time range."); |
145 return null; | 138 return null; |
146 } | 139 } |
150 if (theRange == null) { | 143 if (theRange == null) { |
151 log.warn("BHE: Skip file - invalid km range."); | 144 log.warn("BHE: Skip file - invalid km range."); |
152 return null; | 145 return null; |
153 } | 146 } |
154 | 147 |
155 Session session = ImporterSession.getInstance().getDatabaseSession(); | 148 Session session = ImporterSession.getInstance() |
149 .getDatabaseSession(); | |
156 | 150 |
157 Query query = session.createQuery( | 151 Query query = session.createQuery("from BedHeightEpoch where " |
158 "from BedHeightEpoch where " + | 152 + " river=:river and " + " timeInterval=:timeInterval and " |
159 " river=:river and " + | 153 + " curElevationModel=:curElevationModel and " |
160 " timeInterval=:timeInterval and " + | 154 + " range=:range and " + " evaluationBy=:evaluationBy and " |
161 " curElevationModel=:curElevationModel and " + | 155 + " description=:description"); |
162 " range=:range and " + | |
163 " evaluationBy=:evaluationBy and " + | |
164 " description=:description"); | |
165 | 156 |
166 query.setParameter("river", river); | 157 query.setParameter("river", river); |
167 query.setParameter("timeInterval", theTime); | 158 query.setParameter("timeInterval", theTime); |
168 query.setParameter("curElevationModel", theCurModel); | 159 query.setParameter("curElevationModel", theCurModel); |
169 query.setParameter("range", theRange); | 160 query.setParameter("range", theRange); |
173 List<BedHeightEpoch> bedHeights = query.list(); | 164 List<BedHeightEpoch> bedHeights = query.list(); |
174 | 165 |
175 if (bedHeights.isEmpty()) { | 166 if (bedHeights.isEmpty()) { |
176 log.info("Create new BedHeightEpoch DB instance."); | 167 log.info("Create new BedHeightEpoch DB instance."); |
177 | 168 |
178 peer = new BedHeightEpoch( | 169 peer = new BedHeightEpoch(river, theTime, theRange, |
179 river, | |
180 theTime, | |
181 theRange, | |
182 theCurModel, | 170 theCurModel, |
183 oldElevationModel != null ? oldElevationModel.getPeer() : null, | 171 oldElevationModel != null ? oldElevationModel.getPeer() |
184 evaluationBy, | 172 : null, evaluationBy, description); |
185 description | |
186 ); | |
187 | 173 |
188 session.save(peer); | 174 session.save(peer); |
189 } | 175 } |
190 else { | 176 else { |
191 peer = bedHeights.get(0); | 177 peer = bedHeights.get(0); |