changeset 1126:70b51893f15b

Fix UNIQUE-constraint and respective validation. Btw. improved readability of DEFAULT definition.
author Tom Gottfried <tom@intevation.de>
date Mon, 31 Oct 2016 18:09:45 +0100
parents f9328849a53c
children 997899aba991
files db_schema/lada_schema.sql src/main/java/de/intevation/lada/validation/rules/probe/UniqueHauptprobenNr.java
diffstat 2 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/db_schema/lada_schema.sql	Mon Oct 31 17:14:49 2016 +0100
+++ b/db_schema/lada_schema.sql	Mon Oct 31 18:09:45 2016 +0100
@@ -192,7 +192,10 @@
 
 CREATE TABLE probe (
     id serial PRIMARY KEY,
-    id_alt character varying(20) DEFAULT (('sss'::text || lpad(((nextval('land.probe_probe_id_seq'::regclass))::character varying)::text, 12, '0'::text)) || 'Y'::text) NOT NULL,
+    id_alt character varying(20) UNIQUE NOT NULL
+        DEFAULT 'sss'
+            || lpad(nextval('land.probe_probe_id_seq')::varchar, 12, '0')
+            || 'Y',
     test boolean DEFAULT false NOT NULL,
     mst_id character varying(5) NOT NULL REFERENCES stammdaten.mess_stelle,
     labor_mst_id character varying(5) NOT NULL REFERENCES stammdaten.mess_stelle,
@@ -214,7 +217,7 @@
     solldatum_beginn timestamp without time zone,
     solldatum_ende timestamp without time zone,
     tree_modified timestamp without time zone DEFAULT now(),
-    UNIQUE (mst_id, hauptproben_nr, id_alt),
+    UNIQUE (mst_id, hauptproben_nr),
     CHECK(solldatum_beginn <= solldatum_ende)
 );
 CREATE TRIGGER letzte_aenderung_probe BEFORE UPDATE ON probe FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung();
--- a/src/main/java/de/intevation/lada/validation/rules/probe/UniqueHauptprobenNr.java	Mon Oct 31 17:14:49 2016 +0100
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/UniqueHauptprobenNr.java	Mon Oct 31 18:09:45 2016 +0100
@@ -42,6 +42,7 @@
             repo.entityManager("land"),
             Probe.class);
         builder.and("hauptprobenNr", probe.getHauptprobenNr());
+        builder.and("mstId", probe.getMstId());
         Response response = repo.filter(builder.getQuery(), "land");
         if (!((List<Probe>)response.getData()).isEmpty()) {
             Probe found = ((List<Probe>)response.getData()).get(0);
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)