Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportSQRelation.java @ 3329:cc8fc6b29649
Store sq relations into database after parsing.
flys-backend/trunk@4647 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 13 Jun 2012 08:12:00 +0000 |
parents | a41f279a66e2 |
children | 0d27d02b1208 |
comparison
equal
deleted
inserted
replaced
3328:a41f279a66e2 | 3329:cc8fc6b29649 |
---|---|
4 import java.util.ArrayList; | 4 import java.util.ArrayList; |
5 import java.util.List; | 5 import java.util.List; |
6 | 6 |
7 import org.apache.log4j.Logger; | 7 import org.apache.log4j.Logger; |
8 | 8 |
9 import org.hibernate.Query; | |
10 import org.hibernate.Session; | |
9 import org.hibernate.exception.ConstraintViolationException; | 11 import org.hibernate.exception.ConstraintViolationException; |
10 | 12 |
11 import de.intevation.flys.model.River; | 13 import de.intevation.flys.model.River; |
12 import de.intevation.flys.model.SQRelation; | 14 import de.intevation.flys.model.SQRelation; |
15 import de.intevation.flys.model.TimeInterval; | |
13 | 16 |
14 | 17 |
15 public class ImportSQRelation { | 18 public class ImportSQRelation { |
16 | 19 |
17 private static Logger log = Logger.getLogger(ImportSQRelation.class); | 20 private static Logger log = Logger.getLogger(ImportSQRelation.class); |
18 | 21 |
19 | 22 |
20 private ImportTimeInterval timeInterval; | 23 private ImportTimeInterval timeInterval; |
24 | |
25 private String description; | |
21 | 26 |
22 private List<ImportSQRelationValue> values; | 27 private List<ImportSQRelationValue> values; |
23 | 28 |
24 private SQRelation peer; | 29 private SQRelation peer; |
25 | 30 |
31 | 36 |
32 public void storeDependencies(River river) | 37 public void storeDependencies(River river) |
33 throws SQLException, ConstraintViolationException | 38 throws SQLException, ConstraintViolationException |
34 { | 39 { |
35 log.info("store dependencies"); | 40 log.info("store dependencies"); |
36 log.warn("TODO: IMPLEMENT 'storeDependencies()'"); | 41 |
42 SQRelation peer = getPeer(river); | |
43 | |
44 timeInterval.getPeer(); | |
45 | |
46 int count = 0; | |
47 | |
48 for (ImportSQRelationValue value: values) { | |
49 try { | |
50 value.storeDependencies(peer); | |
51 count++; | |
52 } | |
53 catch (SQLException sqle) { | |
54 log.warn("Unable to store sq relation value.", sqle); | |
55 } | |
56 catch (ConstraintViolationException cve) { | |
57 log.warn("Unable to store sq relation value.", cve); | |
58 } | |
59 } | |
60 | |
61 log.info("stored " + count + " sq relation values."); | |
37 } | 62 } |
38 | 63 |
39 | 64 |
40 public SQRelation getPeer() { | 65 public SQRelation getPeer(River river) { |
41 log.debug("getPeer()"); | 66 log.debug("getPeer()"); |
42 | 67 |
43 if (peer == null) { | 68 if (peer == null) { |
44 // TODO | 69 TimeInterval timeInter = timeInterval.getPeer(); |
70 | |
71 if (timeInter == null) { | |
72 log.warn("Cannot determine sq relation without time interval"); | |
73 return null; | |
74 } | |
75 | |
76 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
77 | |
78 Query query = session.createQuery( | |
79 "FROM SQRelation WHERE river=:river AND timeInterval=:timeInter" | |
80 ); | |
81 | |
82 query.setParameter("river", river); | |
83 query.setParameter("timeInter", timeInter); | |
84 | |
85 List<SQRelation> sq = query.list(); | |
86 | |
87 if (sq.isEmpty()) { | |
88 log.info("create new SQ relation '" + description + "'"); | |
89 | |
90 peer = new SQRelation( | |
91 river, | |
92 timeInter, | |
93 description | |
94 ); | |
95 session.save(peer); | |
96 } | |
97 else { | |
98 peer = sq.get(0); | |
99 } | |
45 } | 100 } |
46 | 101 |
47 return peer; | 102 return peer; |
103 } | |
104 | |
105 | |
106 public void setDescription(String description) { | |
107 this.description = description; | |
48 } | 108 } |
49 | 109 |
50 | 110 |
51 public void setTimeInterval(ImportTimeInterval timeInterval) { | 111 public void setTimeInterval(ImportTimeInterval timeInterval) { |
52 this.timeInterval = timeInterval; | 112 this.timeInterval = timeInterval; |