Mercurial > dive4elements > river
diff flys-backend/src/main/java/de/intevation/flys/importer/ImportSQRelation.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 | 4ee97d914501 |
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportSQRelation.java Tue Sep 18 15:58:28 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportSQRelation.java Wed Sep 19 10:05:36 2012 +0000 @@ -19,7 +19,6 @@ private static Logger log = Logger.getLogger(ImportSQRelation.class); - private ImportTimeInterval timeInterval; private String description; @@ -28,40 +27,38 @@ private SQRelation peer; - public ImportSQRelation() { this.values = new ArrayList<ImportSQRelationValue>(); } - - public void storeDependencies(River river) - throws SQLException, ConstraintViolationException - { + public void storeDependencies(River river) throws SQLException, + ConstraintViolationException { log.info("store dependencies"); SQRelation peer = getPeer(river); timeInterval.getPeer(); - int count = 0; + if (peer != null) { + int count = 0; - for (ImportSQRelationValue value: values) { - try { - value.storeDependencies(peer); - count++; + for (ImportSQRelationValue value : values) { + try { + value.storeDependencies(peer); + count++; + } + catch (SQLException sqle) { + log.warn("ISQ: Unable to store sq relation value.", sqle); + } + catch (ConstraintViolationException cve) { + log.warn("ISQ: Unable to store sq relation value.", cve); + } } - catch (SQLException sqle) { - log.warn("ISQ: Unable to store sq relation value.", sqle); - } - catch (ConstraintViolationException cve) { - log.warn("ISQ: Unable to store sq relation value.", cve); - } + + log.info("stored " + count + " sq relation values."); } - - log.info("stored " + count + " sq relation values."); } - public SQRelation getPeer(River river) { log.debug("getPeer()"); @@ -73,11 +70,11 @@ return null; } - Session session = ImporterSession.getInstance().getDatabaseSession(); + Session session = ImporterSession.getInstance() + .getDatabaseSession(); - Query query = session.createQuery( - "FROM SQRelation WHERE river=:river AND timeInterval=:timeInter" - ); + Query query = session + .createQuery("FROM SQRelation WHERE river=:river AND timeInterval=:timeInter"); query.setParameter("river", river); query.setParameter("timeInter", timeInter); @@ -87,11 +84,7 @@ if (sq.isEmpty()) { log.info("create new SQ relation '" + description + "'"); - peer = new SQRelation( - river, - timeInter, - description - ); + peer = new SQRelation(river, timeInter, description); session.save(peer); } else { @@ -102,17 +95,14 @@ return peer; } - public void setDescription(String description) { this.description = description; } - public void setTimeInterval(ImportTimeInterval timeInterval) { this.timeInterval = timeInterval; } - public void addValue(ImportSQRelationValue value) { if (value != null) { this.values.add(value);