Mercurial > dive4elements > river
changeset 5885:09d9c14145a3
Do not import discharge tables twice if no time interval given
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Tue, 30 Apr 2013 19:03:44 +0200 (2013-04-30) |
parents | 11e74ca3229a |
children | 6a63456b99d9 |
files | backend/src/main/java/org/dive4elements/river/importer/ImportDischargeTable.java |
diffstat | 1 files changed, 33 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportDischargeTable.java Tue Apr 30 17:46:29 2013 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportDischargeTable.java Tue Apr 30 19:03:44 2013 +0200 @@ -76,34 +76,41 @@ this.timeInterval = timeInterval; } + public DischargeTable getPeer(Gauge gauge) { - if (peer == null) { - TimeInterval ti = timeInterval != null - ? timeInterval.getPeer() - : null; - Session session = ImporterSession.getInstance().getDatabaseSession(); - - Query query = session.createQuery( - "from DischargeTable where " + - "gauge.id=:gauge and kind=:kind and " + - "description=:description and timeInterval=:interval"); - query.setParameter("gauge", gauge.getId()); - query.setParameter("description", description); - query.setParameter("kind", kind); - query.setParameter("interval", ti); - - List<DischargeTable> dischargeTables = query.list(); - if (dischargeTables.isEmpty()) { - peer = new DischargeTable(gauge, description, null, kind, ti); - session.save(peer); - } - else { - peer = dischargeTables.get(0); - } - } - - return peer; + if (peer == null) { + TimeInterval ti = timeInterval != null + ? timeInterval.getPeer() + : null; + Session session = ImporterSession.getInstance().getDatabaseSession(); + + String timeIntervalQuery = ti != null + ? "timeInterval=:interval" + : "timeInterval is null"; + + Query query = session.createQuery( + "from DischargeTable where " + + "gauge.id=:gauge and kind=:kind and " + + "description=:description and " + timeIntervalQuery); + query.setParameter("gauge", gauge.getId()); + query.setParameter("description", description); + query.setParameter("kind", kind); + if (ti != null) { + query.setParameter("interval", ti); + } + + List<DischargeTable> dischargeTables = query.list(); + if (dischargeTables.isEmpty()) { + peer = new DischargeTable(gauge, description, null, kind, ti); + session.save(peer); + } + else { + peer = dischargeTables.get(0); + } + } + + return peer; }