changeset 5908:8bdb84aa9541

Merged
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 06 May 2013 18:53:09 +0200
parents e76fceaf84fc (diff) 8025cb45c31a (current diff)
children 6dfd967dcae9
files
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 18:43:13 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportMainValue.java	Mon May 06 18:53:09 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