Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportMorphWidth.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 | 0a536eb5d668 |
children | 4ee97d914501 |
comparison
equal
deleted
inserted
replaced
3942:43aa1ac8614b | 3943:a5b003595d6c |
---|---|
1 package de.intevation.flys.importer; | 1 package de.intevation.flys.importer; |
2 | 2 |
3 import java.sql.SQLException; | 3 import java.sql.SQLException; |
4 | |
5 import java.util.ArrayList; | 4 import java.util.ArrayList; |
6 import java.util.List; | 5 import java.util.List; |
7 | 6 |
8 import org.apache.log4j.Logger; | 7 import org.apache.log4j.Logger; |
9 | 8 import org.hibernate.Query; |
10 import org.hibernate.Session; | 9 import org.hibernate.Session; |
11 import org.hibernate.Query; | |
12 import org.hibernate.exception.ConstraintViolationException; | 10 import org.hibernate.exception.ConstraintViolationException; |
13 | 11 |
14 import de.intevation.flys.model.MorphologicalWidth; | 12 import de.intevation.flys.model.MorphologicalWidth; |
15 import de.intevation.flys.model.River; | 13 import de.intevation.flys.model.River; |
16 | 14 |
17 | 15 |
18 public class ImportMorphWidth { | 16 public class ImportMorphWidth { |
19 | 17 |
20 private static Logger log = Logger.getLogger(ImportMorphWidth.class); | 18 private static Logger log = Logger.getLogger(ImportMorphWidth.class); |
21 | 19 |
22 | |
23 protected MorphologicalWidth peer; | 20 protected MorphologicalWidth peer; |
24 | 21 |
25 protected ImportUnit unit; | 22 protected ImportUnit unit; |
26 | 23 |
27 protected List<ImportMorphWidthValue> values; | 24 protected List<ImportMorphWidthValue> values; |
28 | 25 |
29 | |
30 public ImportMorphWidth() { | 26 public ImportMorphWidth() { |
31 this.values = new ArrayList<ImportMorphWidthValue>(); | 27 this.values = new ArrayList<ImportMorphWidthValue>(); |
32 } | 28 } |
33 | |
34 | 29 |
35 public void addValue(ImportMorphWidthValue value) { | 30 public void addValue(ImportMorphWidthValue value) { |
36 this.values.add(value); | 31 this.values.add(value); |
37 } | 32 } |
38 | 33 |
39 | |
40 public void setUnit(ImportUnit unit) { | 34 public void setUnit(ImportUnit unit) { |
41 this.unit = unit; | 35 this.unit = unit; |
42 } | 36 } |
43 | 37 |
44 | 38 public void storeDependencies(River river) throws SQLException, |
45 public void storeDependencies(River river) | 39 ConstraintViolationException { |
46 throws SQLException, ConstraintViolationException | |
47 { | |
48 log.info("store dependencies"); | 40 log.info("store dependencies"); |
49 | 41 |
50 MorphologicalWidth peer = getPeer(river); | 42 MorphologicalWidth peer = getPeer(river); |
51 | 43 |
52 log.info("store morphological width values"); | 44 if (peer != null) { |
45 log.info("store morphological width values"); | |
53 | 46 |
54 for (ImportMorphWidthValue value: values) { | 47 for (ImportMorphWidthValue value : values) { |
55 value.storeDependencies(peer); | 48 value.storeDependencies(peer); |
49 } | |
56 } | 50 } |
57 } | 51 } |
58 | |
59 | 52 |
60 public MorphologicalWidth getPeer(River river) { | 53 public MorphologicalWidth getPeer(River river) { |
61 log.info("get peer"); | 54 log.info("get peer"); |
62 | 55 |
63 if (peer == null) { | 56 if (peer == null) { |
64 Session session = ImporterSession.getInstance().getDatabaseSession(); | 57 Session session = ImporterSession.getInstance() |
58 .getDatabaseSession(); | |
65 | 59 |
66 Query query = session.createQuery( | 60 Query query = session.createQuery("from MorphologicalWidth where " |
67 "from MorphologicalWidth where " + | 61 + " river=:river and " + " unit=:unit"); |
68 " river=:river and " + | |
69 " unit=:unit"); | |
70 | 62 |
71 query.setParameter("river", river); | 63 query.setParameter("river", river); |
72 query.setParameter("unit", unit.getPeer()); | 64 query.setParameter("unit", unit.getPeer()); |
73 | 65 |
74 List<MorphologicalWidth> widths = query.list(); | 66 List<MorphologicalWidth> widths = query.list(); |