# HG changeset patch # User Tom Gottfried # Date 1429275342 -7200 # Node ID bfca77cbf3536b248344469891b94082b7269516 # Parent 11c88a2f695af4a5a6da841a1b87777e9c4c0f21 (issue1750) There can be only one SQ-relation of a parameter for a time range (given by sq_relation_id) per station and some other attributes might be null. diff -r 11c88a2f695a -r bfca77cbf353 backend/doc/schema/postgresql-minfo.sql --- a/backend/doc/schema/postgresql-minfo.sql Fri Apr 17 14:50:08 2015 +0200 +++ b/backend/doc/schema/postgresql-minfo.sql Fri Apr 17 14:55:42 2015 +0200 @@ -399,6 +399,7 @@ cferguson NUMERIC, cduan NUMERIC, PRIMARY KEY (id), + UNIQUE(sq_relation_id, measurement_station_id, parameter), CONSTRAINT fk_sqr_id FOREIGN KEY (sq_relation_id) REFERENCES sq_relation(id) ON DELETE CASCADE, CONSTRAINT fk_mstation_id FOREIGN KEY (measurement_station_id) diff -r 11c88a2f695a -r bfca77cbf353 backend/src/main/java/org/dive4elements/river/importer/ImportSQRelationValue.java --- a/backend/src/main/java/org/dive4elements/river/importer/ImportSQRelationValue.java Fri Apr 17 14:50:08 2015 +0200 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportSQRelationValue.java Fri Apr 17 14:55:42 2015 +0200 @@ -77,29 +77,17 @@ public SQRelationValue getPeer(SQRelation owner) { if (peer == null) { Session session = ImporterSession.getInstance().getDatabaseSession(); - Query query2 = session.createQuery( + Query query = session.createQuery( "from SQRelationValue " + " where sqRelation=:owner " + - " and parameter=:parameter" + " and measurementStation=:measurementStation" + - " and a=:a" + - " and b=:b" + - " and qMax=:qMax" + - " and rSQ=:rSQ" + - " and cFerguson=:cFerguson" + - " and cDuan=:cDuan"); + " and parameter=:parameter"); - query2.setParameter("owner", owner); - query2.setString("parameter", parameter); - query2.setParameter("measurementStation", station); - query2.setBigDecimal("a", toBigDecimal(a)); - query2.setBigDecimal("b", toBigDecimal(b)); - query2.setBigDecimal("qMax", toBigDecimal(qMax)); - query2.setBigDecimal("rSQ", toBigDecimal(rSQ)); - query2.setBigDecimal("cFerguson", toBigDecimal(cFerguson)); - query2.setBigDecimal("cDuan", toBigDecimal(cDuan)); + query.setParameter("owner", owner); + query.setParameter("measurementStation", station); + query.setString("parameter", parameter); - List values = query2.list(); + List values = query.list(); if (values.isEmpty()) { peer = new SQRelationValue(