# HG changeset patch # User Sascha L. Teichmann # Date 1367859189 -7200 # Node ID 8bdb84aa95412ed385ee0ad4eb50ef7d966a0f87 # Parent e76fceaf84fc66f697ba67e4f680c3743e9fdf87# Parent 8025cb45c31a49d44973e6665b2613521ff17962 Merged diff -r 8025cb45c31a -r 8bdb84aa9541 backend/src/main/java/org/dive4elements/river/importer/ImportMainValue.java --- 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 values = query.list(); if (values.isEmpty()) { - peer = new MainValue(g, n, value, null); + peer = new MainValue(g, n, value, t); session.save(peer); } else {