Skip to content
Snippets Groups Projects
Commit be9383c4 authored by felmer's avatar felmer
Browse files

LMS-835 fix some broken test. Adapt function and migration script.

SVN: 10608
parent 35c7d889
No related branches found
No related tags found
No related merge requests found
...@@ -78,6 +78,7 @@ CREATE OR REPLACE FUNCTION SAMPLE_CODE_UNIQUENESS_CHECK() RETURNS trigger AS $$ ...@@ -78,6 +78,7 @@ CREATE OR REPLACE FUNCTION SAMPLE_CODE_UNIQUENESS_CHECK() RETURNS trigger AS $$
DECLARE DECLARE
counter INTEGER; counter INTEGER;
BEGIN BEGIN
LOCK TABLE samples IN EXCLUSIVE MODE;
IF (NEW.samp_id_part_of is NULL) THEN IF (NEW.samp_id_part_of is NULL) THEN
IF (NEW.dbin_id is not NULL) THEN IF (NEW.dbin_id is not NULL) THEN
SELECT count(*) into counter FROM samples SELECT count(*) into counter FROM samples
......
...@@ -57,5 +57,49 @@ DROP TABLE procedure_types; ...@@ -57,5 +57,49 @@ DROP TABLE procedure_types;
DROP SEQUENCE procedure_id_seq; DROP SEQUENCE procedure_id_seq;
DROP SEQUENCE procedure_type_id_seq; DROP SEQUENCE procedure_type_id_seq;
------------------------------------------------------------------------------------
-- Purpose: Replace trigger SAMPLE_CODE_UNIQUENESS_CHECK
------------------------------------------------------------------------------------
DROP FUNCTION SAMPLE_CODE_UNIQUENESS_CHECK();
CREATE OR REPLACE FUNCTION SAMPLE_CODE_UNIQUENESS_CHECK() RETURNS trigger AS $$
DECLARE
counter INTEGER;
BEGIN
LOCK TABLE samples IN EXCLUSIVE MODE;
IF (NEW.samp_id_part_of is NULL) THEN
IF (NEW.dbin_id is not NULL) THEN
SELECT count(*) into counter FROM samples
where id != NEW.id and code = NEW.code and samp_id_part_of is NULL and dbin_id = NEW.dbin_id;
IF (counter > 0) THEN
RAISE EXCEPTION 'Insert/Update of Sample (Code: %) failed because database instance sample with the same code already exists.', NEW.code;
END IF;
ELSIF (NEW.grou_id is not NULL) THEN
SELECT count(*) into counter FROM samples
where id != NEW.id and code = NEW.code and samp_id_part_of is NULL and grou_id = NEW.grou_id;
IF (counter > 0) THEN
RAISE EXCEPTION 'Insert/Update of Sample (Code: %) failed because group sample with the same code already exists.', NEW.code;
END IF;
END IF;
ELSE
IF (NEW.dbin_id is not NULL) THEN
SELECT count(*) into counter FROM samples
where id != NEW.id and code = NEW.code and samp_id_part_of = NEW.samp_id_part_of and dbin_id = NEW.dbin_id;
IF (counter > 0) THEN
RAISE EXCEPTION 'Insert/Update of Sample (Code: %) failed because database instance sample with the same code and being the part of the same parent already exists.', NEW.code;
END IF;
ELSIF (NEW.grou_id is not NULL) THEN
SELECT count(*) into counter FROM samples
where id != NEW.id and code = NEW.code and samp_id_part_of = NEW.samp_id_part_of and grou_id = NEW.grou_id;
IF (counter > 0) THEN
RAISE EXCEPTION 'Insert/Update of Sample (Code: %) failed because group sample with the same code and being the part of the same parent already exists.', NEW.code;
END IF;
END IF;
END IF;
RETURN NEW;
END;
$$ LANGUAGE 'plpgsql';
...@@ -68,7 +68,7 @@ public final class PackageBasedIndexedEntityFinderTest ...@@ -68,7 +68,7 @@ public final class PackageBasedIndexedEntityFinderTest
final PackageBasedIndexedEntityFinder entityFinder = final PackageBasedIndexedEntityFinder entityFinder =
new PackageBasedIndexedEntityFinder("ch.systemsx.cisd.openbis.generic.shared.dto"); new PackageBasedIndexedEntityFinder("ch.systemsx.cisd.openbis.generic.shared.dto");
final Set<Class<?>> entities = entityFinder.getIndexedEntities(); final Set<Class<?>> entities = entityFinder.getIndexedEntities();
assertEquals(5, entities.size()); assertEquals(4, entities.size());
assertTrue(entities.contains(SamplePE.class)); assertTrue(entities.contains(SamplePE.class));
assertTrue(entities.contains(ExperimentPE.class)); assertTrue(entities.contains(ExperimentPE.class));
assertTrue(entities.contains(MaterialPE.class)); assertTrue(entities.contains(MaterialPE.class));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment