Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentYield.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 | 71175502d868 |
children | 4ee97d914501 |
comparison
equal
deleted
inserted
replaced
3942:43aa1ac8614b | 3943:a5b003595d6c |
---|---|
31 | 31 |
32 private List<ImportSedimentYieldValue> values; | 32 private List<ImportSedimentYieldValue> values; |
33 | 33 |
34 private SedimentYield peer; | 34 private SedimentYield peer; |
35 | 35 |
36 | |
37 public ImportSedimentYield(String description) { | 36 public ImportSedimentYield(String description) { |
38 this.values = new ArrayList<ImportSedimentYieldValue>(); | 37 this.values = new ArrayList<ImportSedimentYieldValue>(); |
39 this.description = description; | 38 this.description = description; |
40 } | 39 } |
41 | |
42 | 40 |
43 public void setTimeInterval(ImportTimeInterval timeInterval) { | 41 public void setTimeInterval(ImportTimeInterval timeInterval) { |
44 this.timeInterval = timeInterval; | 42 this.timeInterval = timeInterval; |
45 } | 43 } |
46 | 44 |
47 | |
48 public void setUnit(ImportUnit unit) { | 45 public void setUnit(ImportUnit unit) { |
49 this.unit = unit; | 46 this.unit = unit; |
50 } | 47 } |
51 | |
52 | 48 |
53 public void setGrainFraction(ImportGrainFraction grainFraction) { | 49 public void setGrainFraction(ImportGrainFraction grainFraction) { |
54 this.grainFraction = grainFraction; | 50 this.grainFraction = grainFraction; |
55 } | 51 } |
56 | 52 |
57 | |
58 public void addValue(ImportSedimentYieldValue value) { | 53 public void addValue(ImportSedimentYieldValue value) { |
59 this.values.add(value); | 54 this.values.add(value); |
60 } | 55 } |
61 | 56 |
62 | 57 public void storeDependencies(River river) throws SQLException, |
63 public void storeDependencies(River river) | 58 ConstraintViolationException { |
64 throws SQLException, ConstraintViolationException | |
65 { | |
66 log.debug("store dependencies"); | 59 log.debug("store dependencies"); |
67 | 60 |
68 if (grainFraction != null) { | 61 if (grainFraction != null) { |
69 grainFraction.storeDependencies(); | 62 grainFraction.storeDependencies(); |
70 } | 63 } |
71 | 64 |
72 SedimentYield peer = getPeer(river); | 65 SedimentYield peer = getPeer(river); |
73 | 66 |
74 int i = 0; | 67 if (peer != null) { |
68 int i = 0; | |
75 | 69 |
76 for (ImportSedimentYieldValue value: values) { | 70 for (ImportSedimentYieldValue value : values) { |
77 value.storeDependencies(peer); | 71 value.storeDependencies(peer); |
78 i++; | 72 i++; |
73 } | |
74 | |
75 log.info("stored " + i + " sediment yield values."); | |
79 } | 76 } |
80 | |
81 log.info("stored " + i + " sediment yield values."); | |
82 } | 77 } |
83 | |
84 | 78 |
85 public SedimentYield getPeer(River river) { | 79 public SedimentYield getPeer(River river) { |
86 log.debug("get peer"); | 80 log.debug("get peer"); |
87 | 81 |
88 GrainFraction gf = grainFraction != null | 82 GrainFraction gf = grainFraction != null ? grainFraction.getPeer() |
89 ? grainFraction.getPeer() | |
90 : null; | 83 : null; |
91 | 84 |
92 Unit u = unit != null ? unit.getPeer() : null; | 85 Unit u = unit != null ? unit.getPeer() : null; |
93 | 86 |
94 TimeInterval ti = timeInterval != null ? timeInterval.getPeer() : null; | 87 TimeInterval ti = timeInterval != null ? timeInterval.getPeer() : null; |
97 log.warn("Skip invalid SedimentYield: time interval or unit null!"); | 90 log.warn("Skip invalid SedimentYield: time interval or unit null!"); |
98 return null; | 91 return null; |
99 } | 92 } |
100 | 93 |
101 if (peer == null) { | 94 if (peer == null) { |
102 Session session = ImporterSession.getInstance().getDatabaseSession(); | 95 Session session = ImporterSession.getInstance() |
103 Query query = session.createQuery( | 96 .getDatabaseSession(); |
104 "from SedimentYield where " + | 97 Query query = session.createQuery("from SedimentYield where " |
105 " river=:river and " + | 98 + " river=:river and " |
106 " grainFraction=:grainFraction and " + | 99 + " grainFraction=:grainFraction and " + " unit=:unit and " |
107 " unit=:unit and " + | 100 + " timeInterval=:timeInterval and " |
108 " timeInterval=:timeInterval and " + | 101 + " description=:description"); |
109 " description=:description" | |
110 ); | |
111 | 102 |
112 query.setParameter("river", river); | 103 query.setParameter("river", river); |
113 query.setParameter("grainFraction", gf); | 104 query.setParameter("grainFraction", gf); |
114 query.setParameter("unit", u); | 105 query.setParameter("unit", u); |
115 query.setParameter("timeInterval", ti); | 106 query.setParameter("timeInterval", ti); |