[Dive4elements-commits] [PATCH] Do not import discharge tables twice if no time interval given

Wald Commits scm-commit at wald.intevation.org
Tue Apr 30 19:03:48 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1367341424 -7200
# Node ID 09d9c14145a30527329623e610f8ace4782a9cb4
# Parent  11e74ca3229a60511a46a66a2c6d108048c2508f
Do not import discharge tables twice if no time interval given

diff -r 11e74ca3229a -r 09d9c14145a3 backend/src/main/java/org/dive4elements/river/importer/ImportDischargeTable.java
--- 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;
     }
 
 


More information about the Dive4elements-commits mailing list