changeset 5907:e76fceaf84fc

Importer: Store id of time interval in main values.
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 06 May 2013 18:52:03 +0200
parents 0c61dba8c0de
children 8bdb84aa9541
files backend/src/main/java/org/dive4elements/river/importer/ImportMainValue.java
diffstat 1 files changed, 23 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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 {

http://dive4elements.wald.intevation.org