[Dive4elements-commits] [PATCH 1 of 2] Importer: Store id of time interval in main values

Wald Commits scm-commit at wald.intevation.org
Mon May 6 18:53:13 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1367859123 -7200
# Node ID e76fceaf84fc66f697ba67e4f680c3743e9fdf87
# Parent  0c61dba8c0de53707b45c28643b7c9801b226819
Importer: Store id of time interval in main values.

diff -r 0c61dba8c0de -r e76fceaf84fc backend/src/main/java/org/dive4elements/river/importer/ImportMainValue.java
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportMainValue.java	Mon May 06 17:53:22 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportMainValue.java	Mon May 06 18:52:03 2013 +0200
@@ -72,22 +72,36 @@
     public MainValue getPeer(River river) {
         if (peer == null) {
             Session session = ImporterSession.getInstance().getDatabaseSession();
-            Query query = session.createQuery("from MainValue where "
-                + "gauge.id=:gauge_id and mainValue.id=:name_id "
-                + "and timeInterval = :time "
-                + "and value=:value");
+
+            Query query;
+
+            TimeInterval t = timeInterval != null
+                ? timeInterval.getPeer()
+                : null;
+
+            if (t != null) {
+                query = session.createQuery("from MainValue where "
+                    + "gauge.id=:gauge_id and mainValue.id=:name_id "
+                    + "and timeInterval = :time "
+                    + "and value=:value");
+                query.setParameter("time", t);
+            }
+            else {
+                query = session.createQuery("from MainValue where "
+                    + "gauge.id=:gauge_id and mainValue.id=:name_id "
+                    + "and timeInterval is null "
+                    + "and value=:value");
+            }
+
             Gauge          g = gauge.getPeer(river);
             NamedMainValue n = mainValue.getPeer();
-            TimeInterval   t = timeInterval != null
-                ? timeInterval.getPeer()
-                : null;
             query.setParameter("gauge_id", g.getId());
             query.setParameter("name_id",  n.getId());
             query.setParameter("value",    value);
-            query.setParameter("time",     t);
+
             List<MainValue> values = query.list();
             if (values.isEmpty()) {
-                peer = new MainValue(g, n, value, null);
+                peer = new MainValue(g, n, value, t);
                 session.save(peer);
             }
             else {


More information about the Dive4elements-commits mailing list