Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • dev
  • f-filesystem-cleanup
  • f-filesystem-core
  • f-filesystem-directory
  • f-filesystem-import
  • f-filesystem-link
  • f-filesystem-main
  • f-linkahead-rename
  • f-mysql8-tests
  • f-name
  • f-permission-checks-2
  • f-real-id
  • f-retrieve-history
  • keep_changes
  • main
  • t-distinct-parents
  • v2.0.30
  • v3.0
  • v4.0.0
  • v4.1.0
  • v5.0.0
  • v6.0.0
  • v6.0.1
  • v7.0.0
  • v7.0.1
  • v7.0.2
  • v8.0.0
  • v8.1.0
28 results

Target

Select target project
  • caosdb/src/caosdb-mysqlbackend
1 result
Select Git revision
Loading items
Show changes
Showing
with 837 additions and 476 deletions
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -17,28 +16,56 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
DROP PROCEDURE IF EXISTS db_5_0.insertEntityDataType;
DELIMITER //
/*
* Insert the (default) datatype of a property.
*
* Parameters
* ----------
* PropertyID : VARCHAR(255)
* The property id.
* DataTypeID : VARCHAR(255)
* The data type id (not the name!)
*/
CREATE PROCEDURE db_5_0.insertEntityDataType(in PropertyID VARCHAR(255), in DataTypeID VARCHAR(255))
BEGIN
DECLARE InternalPropertyID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalPropertyID FROM entity_ids WHERE id=PropertyID;
INSERT INTO data_type (domain_id, entity_id, property_id, datatype) SELECT 0, 0, InternalPropertyID, ( SELECT internal_id FROM entity_ids WHERE id = DataTypeID);
END;
//
DELIMITER ;
DROP PROCEDURE IF EXISTS db_5_0.getRole;
delimiter //
CREATE PROCEDURE db_5_0.getRole(in RoleName VARCHAR(255))
BEGIN
Select e.id INTO @RoleID from entities e where e.name=RoleName AND e.role=RoleName LIMIT 1;
call retrieveEntity(@RoleID);
DROP PROCEDURE IF EXISTS db_5_0.insertEntityCollection;
DELIMITER //
/*
* Insert the (default) collection type of a property.
*
* Parameters
* ----------
* PropertyID : VARCHAR(255)
* The property id.
* Collection : VARCHAR(255)
* The collection, e.g. "LIST"
*/
CREATE PROCEDURE db_5_0.insertEntityCollection(in PropertyID VARCHAR(255), in Collection VARCHAR(255))
BEGIN
DECLARE InternalPropertyID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalPropertyID FROM entity_ids WHERE id=PropertyID;
INSERT INTO collection_type (domain_id, entity_id, property_id, collection) SELECT 0, 0, InternalPropertyID, Collection;
END;
//
delimiter ;
DELIMITER ;
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale
* Copyright (C) 2020,2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020,2023 Timm Fitschen <t.fitschen@indiscale
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -19,112 +18,166 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
DROP PROCEDURE IF EXISTS db_5_0.insertEntityProperty;
delimiter //
/*
* Insert the property of an entity (level 1 and 2, only one *_data table entry at a time).
*
* Parameters
* ----------
* DomainID : VARCHAR(255)
* The domain id (0 or the entity's id for level-2-data)
* EntityID : VARCHAR(255)
* The entity id (or the property's id for level-2-data)
* PropertyID : VARCHAR(255)
* The property id (or the sub-property's id for level-2-data)
* Datatable : VARCHAR(255)
* Name of the *_data table, e.g. 'double_data'.
* PropertyValue : TEXT
* The property's value
* PropertyUnitSig : BIGINT
* The unit signature.
* PropertyStatus : VARCHAR(255)
* E.g. OBLIGATORY, FIX,...
* NameOverride : VARCHAR(255)
* The overridden name
* DescOverride : TEXT
* The overridden description
* DatatypeOverride : VARCHAR(255)
* The overridden datatype
* Collection : VARCHAR(255)
* The overridden collection (only if DatatypeOverride is present).
* PropertyIndex : INT UNSIGNED
* The property's index (for ordering of properties and values).
*/
CREATE PROCEDURE db_5_0.insertEntityProperty(
in DomainID INT UNSIGNED,
in EntityID INT UNSIGNED,
in PropertyID INT UNSIGNED,
in DomainID VARCHAR(255),
in EntityID VARCHAR(255),
in PropertyID VARCHAR(255),
in Datatable VARCHAR(255),
in PropertyValue TEXT,
in PropertyUnitSig BIGINT,
in PropertyStatus VARCHAR(255),
in NameOverride VARCHAR(255),
in DescOverride TEXT,
in DatatypeOverride INT UNSIGNED,
in DatatypeOverride VARCHAR(255),
in Collection VARCHAR(255),
in PropertyIndex INT UNSIGNED)
BEGIN
DECLARE ReferenceValueIVersion INT UNSIGNED DEFAULT NULL;
DECLARE ReferenceValue INT UNSIGNED DEFAULT NULL;
DECLARE AT_PRESENT INTEGER DEFAULT NULL;
DECLARE InternalDataTypeID INT UNSIGNED DEFAULT NULL;
DECLARE InternalPropertyID INT UNSIGNED DEFAULT NULL;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
DECLARE InternalDomainID INT UNSIGNED DEFAULT 0;
SELECT internal_id INTO InternalDomainID FROM entity_ids WHERE id = DomainID;
-- When DomainID != 0 the EntityID could possibly be a 'replacement id'
-- which are internal ids by definition (and do not have external
-- equivalents).
IF LOCATE("$", EntityID) = 1 THEN
SET InternalEntityID=SUBSTRING(EntityID, 2);
ELSE
SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
END IF;
IF LOCATE("$", PropertyID) = 1 THEN
SET InternalPropertyID=SUBSTRING(PropertyID, 2);
ELSE
SELECT internal_id INTO InternalPropertyID FROM entity_ids WHERE id = PropertyID;
END IF;
CASE Datatable
WHEN 'double_data' THEN
INSERT INTO double_data
(domain_id, entity_id, property_id, value, unit_sig, status, pidx)
VALUES
(DomainID, EntityID, PropertyID, PropertyValue, PropertyUnitSig, PropertyStatus, PropertyIndex);
(InternalDomainID, InternalEntityID, InternalPropertyID, PropertyValue, PropertyUnitSig, PropertyStatus, PropertyIndex);
WHEN 'integer_data' THEN
INSERT INTO integer_data
(domain_id, entity_id, property_id, value, unit_sig, status, pidx)
VALUES
(DomainID, EntityID, PropertyID, PropertyValue, PropertyUnitSig, PropertyStatus, PropertyIndex);
(InternalDomainID, InternalEntityID, InternalPropertyID, PropertyValue, PropertyUnitSig, PropertyStatus, PropertyIndex);
WHEN 'datetime_data' THEN
INSERT INTO datetime_data
(domain_id, entity_id, property_id, value, value_ns, status, pidx)
VALUES
(DomainID, EntityID, PropertyID, SUBSTRING_INDEX(PropertyValue, 'UTC', 1), IF(SUBSTRING_INDEX(PropertyValue, 'UTC', -1)='',NULL,SUBSTRING_INDEX(PropertyValue, 'UTC', -1)), PropertyStatus, PropertyIndex);
(InternalDomainID, InternalEntityID, InternalPropertyID, SUBSTRING_INDEX(PropertyValue, 'UTC', 1), IF(SUBSTRING_INDEX(PropertyValue, 'UTC', -1)='',NULL,SUBSTRING_INDEX(PropertyValue, 'UTC', -1)), PropertyStatus, PropertyIndex);
WHEN 'reference_data' THEN
-- special handling if versioning enabled and specific version of referenced entity is given.
SET AT_PRESENT=LOCATE("@", PropertyValue);
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") AND AT_PRESENT > 0 THEN
SET ReferenceValue = SUBSTRING_INDEX(PropertyValue, '@', 1);
SELECT internal_id INTO ReferenceValue FROM entity_ids WHERE id = SUBSTRING_INDEX(PropertyValue, '@', 1);
SET ReferenceValueIVersion = get_iversion(ReferenceValue,
SUBSTRING_INDEX(PropertyValue, '@', -1));
-- TODO raise error when @ present but iversion is null
IF ReferenceValueIVersion IS NULL THEN
-- Raise error when @ present but iversion is null
SELECT 0 from `ReferenceValueIVersion_WAS_NULL`;
END IF;
ELSEIF LOCATE("$", PropertyValue) = 1 THEN
SET ReferenceValue = SUBSTRING(PropertyValue, 2);
ELSE
SET ReferenceValue = PropertyValue;
SELECT internal_id INTO ReferenceValue FROM entity_ids WHERE id = PropertyValue;
END IF;
INSERT INTO reference_data
(domain_id, entity_id, property_id, value, value_iversion, status,
pidx)
VALUES
(DomainID, EntityID, PropertyID, ReferenceValue,
(InternalDomainID, InternalEntityID, InternalPropertyID, ReferenceValue,
ReferenceValueIVersion, PropertyStatus, PropertyIndex);
WHEN 'enum_data' THEN
INSERT INTO enum_data
(domain_id, entity_id, property_id, value, status, pidx)
VALUES
(DomainID, EntityID, PropertyID, PropertyValue, PropertyStatus, PropertyIndex);
(InternalDomainID, InternalEntityID, InternalPropertyID, PropertyValue, PropertyStatus, PropertyIndex);
WHEN 'date_data' THEN
INSERT INTO date_data
(domain_id, entity_id, property_id, value, status, pidx)
VALUES
(DomainID, EntityID, PropertyID, SUBSTRING_INDEX(PropertyValue, '.', 1), PropertyStatus, PropertyIndex);
(InternalDomainID, InternalEntityID, InternalPropertyID, SUBSTRING_INDEX(PropertyValue, '.', 1), PropertyStatus, PropertyIndex);
WHEN 'text_data' THEN
INSERT INTO text_data
(domain_id, entity_id, property_id, value, status, pidx)
VALUES
(DomainID, EntityID, PropertyID, PropertyValue, PropertyStatus, PropertyIndex);
(InternalDomainID, InternalEntityID, InternalPropertyID, PropertyValue, PropertyStatus, PropertyIndex);
WHEN 'null_data' THEN
INSERT INTO null_data
(domain_id, entity_id, property_id, status, pidx)
VALUES
(DomainID, EntityID, PropertyID, PropertyStatus, PropertyIndex);
(InternalDomainID, InternalEntityID, InternalPropertyID, PropertyStatus, PropertyIndex);
WHEN 'name_data' THEN
INSERT INTO name_data
(domain_id, entity_id, property_id, value, status, pidx)
VALUES
(DomainID, EntityID, PropertyID, PropertyValue, PropertyStatus, PropertyIndex);
(InternalDomainID, InternalEntityID, InternalPropertyID, PropertyValue, PropertyStatus, PropertyIndex);
ELSE
-- raise error
SELECT * FROM table_does_not_exist;
END CASE;
IF DatatypeOverride IS NOT NULL THEN
call overrideType(DomainID, EntityID, PropertyID, DatatypeOverride);
SELECT internal_id INTO InternalDataTypeID from entity_ids WHERE id = DatatypeOverride;
call overrideType(InternalDomainID, InternalEntityID, InternalPropertyID, InternalDataTypeID);
IF Collection IS NOT NULL THEN
INSERT INTO collection_type (domain_id, entity_id, property_id, collection) VALUES (DomainID, EntityID, PropertyID, Collection);
INSERT INTO collection_type (domain_id, entity_id, property_id, collection) VALUES (InternalDomainID, InternalEntityID, InternalPropertyID, Collection);
END IF;
END IF;
IF NameOverride IS NOT NULL THEN
call overrideName(DomainID, EntityID, PropertyID, NameOverride);
call overrideName(InternalDomainID, InternalEntityID, InternalPropertyID, NameOverride);
END IF;
IF DescOverride IS NOT NULL THEN
call overrideDesc(DomainID, EntityID, PropertyID, DescOverride);
call overrideDesc(InternalDomainID, InternalEntityID, InternalPropertyID, DescOverride);
END IF;
END;
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020,2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020,2023 Timm Fitschen <t.fitschen@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -18,8 +18,6 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
DROP PROCEDURE IF EXISTS db_5_0.insertIsa;
DELIMITER //
......@@ -33,15 +31,21 @@ DELIMITER //
* Parameters
* ==========
*
* c : UNSIGNED
* The child entity
* ChildID : VARCHAR(255)
* The child entity.
*
* p : UNSIGNED
* The parent entity
* ParentID : VARCHAR(255)
* The parent entity.
*/
CREATE PROCEDURE db_5_0.insertIsa(IN c INT UNSIGNED, IN p INT UNSIGNED)
CREATE PROCEDURE db_5_0.insertIsa(IN ChildID VARCHAR(255), IN ParentID VARCHAR(255))
insert_is_a_proc: BEGIN
DECLARE c INT UNSIGNED DEFAULT NULL;
DECLARE p INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO c FROM entity_ids WHERE id = ChildID;
SELECT internal_id INTO p FROM entity_ids WHERE id = ParentID;
INSERT INTO isa_cache (child, parent, rpath) VALUES (c, p, c);
IF p = c THEN
......@@ -69,17 +73,17 @@ insert_is_a_proc: BEGIN
INSERT IGNORE INTO isa_cache SELECT
l.child, -- Descendant as found in isa_cache
r.parent, -- Ancestor as found in isa_cache
if(l.rpath=l.child and r.rpath=c, -- if distance=1 for left and right:
IF(l.rpath=l.child AND r.rpath=c, -- if distance=1 for left and right:
c, -- rpath = current child
concat(if(l.rpath=l.child, -- if dist=1 for descendant:
concat(IF(l.rpath=l.child, -- if dist=1 for descendant:
c, -- rpath starts with c
concat(l.rpath, '>', c)), -- rpath starts with "desc.rpath > c"
if(r.rpath=c, -- if dist=1 for ancestor
IF(r.rpath=c, -- if dist=1 for ancestor
'', -- rpath is finished
concat('>', r.rpath)))) -- rpath continuees with " > ancest.rpath"
AS rpath
FROM
isa_cache as l INNER JOIN isa_cache as r
isa_cache AS l INNER JOIN isa_cache AS r
ON (l.parent = c AND c = r.child AND l.child != l.parent); -- Left: descendants of c, right: ancestors
END;
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
Drop Procedure if exists db_5_0.insertUser;
Delimiter //
Create Procedure db_5_0.insertUser(in Name VARCHAR(255), in Password VARCHAR(255))
BEGIN
INSERT INTO entities (name, role, acl) VALUES (Name, 'USER', 0);
SET @LAST_UserID = LAST_INSERT_ID();
INSERT INTO passwords VALUES (@LAST_UserID, Password);
Select @LAST_UserID as UserID;
END;
//
delimiter ;
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -17,17 +18,36 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
DROP PROCEDURE IF EXISTS db_5_0.isSubtype;
delimiter //
CREATE PROCEDURE db_5_0.isSubtype(in c INT UNSIGNED, in p INT UNSIGNED)
/*
* Return TRUE if the given Child is indeed a (direct or indirect) child of the
* given Parent.
*
* Parameters
* ----------
* ChildID : VARCHAR(255)
* The entity id of the child.
* ParentID : VARCHAR(255)
* The entity id of the parent.
*
* Returns
* -------
* ISA : BOOLEAN
*/
CREATE PROCEDURE db_5_0.isSubtype(in ChildID VARCHAR(255), in ParentID VARCHAR(255))
BEGIN
DECLARE c INT UNSIGNED DEFAULT NULL;
DECLARE p INT UNSIGNED DEFAULT NULL;
DECLARE ret BOOLEAN DEFAULT FALSE;
SELECT internal_id INTO c from entity_ids WHERE id = ChildID;
SELECT internal_id INTO p from entity_ids WHERE id = ParentID;
SELECT TRUE INTO ret FROM isa_cache AS i WHERE i.child=c AND i.parent=p LIMIT 1;
SELECT ret as ISA;
END;
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -17,8 +18,6 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
DROP PROCEDURE IF EXISTS db_5_0.overrideName;
......@@ -26,21 +25,61 @@ DROP PROCEDURE IF EXISTS db_5_0.overrideDesc;
DROP PROCEDURE IF EXISTS db_5_0.overrideType;
DELIMITER //
CREATE PROCEDURE db_5_0.overrideName(in DomainID INT UNSIGNED, in EntityID INT UNSIGNED, in PropertyID INT UNSIGNED, in Name VARCHAR(255))
/*
* Insert a name override.
*
* Parameters
* ----------
* InternalDomainID : INT UNSIGNED
* The *internal* id of the domain.
* InternalEntityID : INT UNSIGNED
* The *internal* id of the entity.
* InternalPropertyID : INT UNSIGNED
* The *internal* id of the property.
* Name : VARCHAR(255)
*/
CREATE PROCEDURE db_5_0.overrideName(in InternalDomainID INT UNSIGNED, in InternalEntityID INT UNSIGNED, in InternalPropertyID INT UNSIGNED, in Name VARCHAR(255))
BEGIN
INSERT INTO name_overrides (domain_id, entity_id, property_id, name) VALUES (DomainID, EntityID, PropertyID, Name);
INSERT INTO name_overrides (domain_id, entity_id, property_id, name) VALUES (InternalDomainID, InternalEntityID, InternalPropertyID, Name);
END;
//
CREATE PROCEDURE db_5_0.overrideDesc(in DomainID INT UNSIGNED, in EntityID INT UNSIGNED, in PropertyID INT UNSIGNED, in Description TEXT)
/*
* Insert a description override.
*
* Parameters
* ----------
* InternalDomainID : INT UNSIGNED
* The *internal* id of the domain.
* InternalEntityID : INT UNSIGNED
* The *internal* id of the entity.
* InternalPropertyID : INT UNSIGNED
* The *internal* id of the property.
* Description : TEXT
*/
CREATE PROCEDURE db_5_0.overrideDesc(in InternalDomainID INT UNSIGNED, in InternalEntityID INT UNSIGNED, in InternalPropertyID INT UNSIGNED, in Description TEXT)
BEGIN
INSERT INTO desc_overrides (domain_id, entity_id, property_id, description) VALUES (DomainID, EntityID, PropertyID, Description);
INSERT INTO desc_overrides (domain_id, entity_id, property_id, description) VALUES (InternalDomainID, InternalEntityID, InternalPropertyID, Description);
END;
//
CREATE PROCEDURE db_5_0.overrideType(in DomainID INT UNSIGNED, in EntityID INT UNSIGNED, in PropertyID INT UNSIGNED, in Datatype INT UNSIGNED)
/*
* Insert a data type override.
*
* Parameters
* ----------
* InternalDomainID : INT UNSIGNED
* The *internal* id of the domain.
* InternalEntityID : INT UNSIGNED
* The *internal* id of the entity.
* InternalPropertyID : INT UNSIGNED
* The *internal* id of the property.
* InternalDatatypeID : INT UNSIGNED
* The *internal* id of the data type.
*/
CREATE PROCEDURE db_5_0.overrideType(in InternalDomainID INT UNSIGNED, in InternalEntityID INT UNSIGNED, in InternalPropertyID INT UNSIGNED, in InternalDataTypeID INT UNSIGNED)
BEGIN
INSERT INTO data_type (domain_id, entity_id, property_id, datatype) VALUES (DomainID, EntityID, PropertyID, Datatype);
INSERT INTO data_type (domain_id, entity_id, property_id, datatype) VALUES (InternalDomainID, InternalEntityID, InternalPropertyID, InternalDataTypeID);
END;
//
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -17,8 +18,6 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
DROP PROCEDURE IF EXISTS db_5_0.applyIDFilter;
......@@ -32,71 +31,114 @@ DELIMITER //
*
* The `versioned` flag currently only has the effect that an `_iversion` column is also copied to
* the target.
*
* Parameters
* ----------
* sourceSet : VARCHAR(255)
* The name of the table from where we start.
* targetSet : VARCHAR(255)
* The name of the table where we collect all the "good" ids (or NULL or same as sourceSet).
* o : CHAR(2)
* The operator used for filtering, e.g. '=', '!=', '>', ...
* EntityID : VARCHAR(255)
* An entity id, existing or non-existing, which we use to compare the
* existing entities to using the operator.
* agg : CHAR(3)
* An aggregate function, e.g. 'max' or 'min'. This only makes sense for number-based ids.
* versioned : BOOLEAN
* The filter belongs to a version-aware query (e.g. FIND ANY VERSION OF
* ...) and hence the sourceSet and targetSet have an `_iversion` column.
*/
CREATE PROCEDURE db_5_0.applyIDFilter(in sourceSet VARCHAR(255), in targetSet VARCHAR(255),
in o CHAR(2), in vInt BIGINT, in agg CHAR(3), in versioned BOOLEAN)
in o CHAR(2), in EntityID VARCHAR(255), in agg CHAR(3), in versioned BOOLEAN)
IDFILTER_LABEL: BEGIN
DECLARE data VARCHAR(20000) DEFAULT NULL;
DECLARE aggVal VARCHAR(255) DEFAULT NULL;
DECLARE direction CHAR(4) DEFAULT NULL;
DECLARE entity_id_type VARCHAR(255) DEFAULT "eids.id ";
#-- get aggVal if possible
IF agg IS NOT NULL THEN
IF versioned THEN
-- TODO versioned queries
SELECT 1 FROM id_agg_with_versioning_not_implemented;
ELSEIF agg = "max" THEN
SET direction = "DESC";
ELSEIF agg = "min" THEN
SET direction = "ASC ";
ELSE
SELECT 1 FROM unknown_agg_parameter;
END IF;
SET @stmtIDAggValStr = CONCAT(
"SELECT ",
agg,
"(id) INTO @sAggVal FROM `",
"SELECT e.internal_id INTO @sAggVal FROM `",
sourceSet,
"`");
"` AS s LEFT JOIN entity_ids AS e ON (s.id=e.internal_id) WHERE s.id>99 ORDER BY CAST(e.id AS UNSIGNED INT) ",
direction,
" LIMIT 1");
PREPARE stmtIDAggVal FROM @stmtIDAggValStr;
EXECUTE stmtIDAggVal;
DEALLOCATE PREPARE stmtIDAggVal;
SET aggVal = @sAggVal;
END IF;
IF o = ">" OR o = ">=" OR o = "<" or o = "<=" THEN
SET entity_id_type = "CAST(eids.id AS UNSIGNED INT) ";
END IF;
#-- generate stmt string
IF targetSet IS NULL OR targetSet = sourceSet THEN
SET data = CONCAT(
"DELETE FROM `",
sourceSet,
"` WHERE ",
IF(o IS NULL OR vInt IS NULL,
IF(o IS NULL OR EntityID IS NULL,
"1=1",
CONCAT("NOT id",
CONCAT("NOT EXISTS (SELECT 1 FROM entity_ids AS eids WHERE ",
entity_id_type,
o,
vInt)),
' "',
EntityID,
'" ',
" AND eids.internal_id = `",
sourceSet,
"`.id)"
)),
IF(aggVal IS NULL,
"",
CONCAT(" AND id!=",
CONCAT(" AND `", sourceSet, "`.id!=",
aggVal)));
ELSEIF versioned AND sourceSet = "entities" THEN
-- ################# VERSIONING #####################
SET data = CONCAT(
"INSERT IGNORE INTO `",
targetSet,
'` (id, _iversion) SELECT id, _get_head_iversion(id) FROM `entities` WHERE ',
IF(o IS NULL OR vInt IS NULL,
'` (id, _iversion) SELECT e.id, _get_head_iversion(e.id) FROM `entities` AS e JOIN entity_ids AS eids ON (e.id = eids.internal_id) WHERE ',
IF(o IS NULL OR EntityID IS NULL,
"1=1",
CONCAT("id",
CONCAT(entity_id_type,
o,
vInt)),
' "',
EntityID,
'"'
)),
IF(aggVal IS NULL,
"",
CONCAT(" AND id=",
CONCAT(" AND e.id=",
aggVal)),
' UNION SELECT id, _iversion FROM `archive_entities` WHERE ',
IF(o IS NULL OR vInt IS NULL,
' UNION SELECT e.id, _iversion FROM `archive_entities` AS e JOIN entity_ids AS eids ON (e.id = eids.internal_id) WHERE ',
IF(o IS NULL OR EntityID IS NULL,
"1=1",
CONCAT("id",
CONCAT(entity_id_type,
o,
vInt)),
' "',
EntityID,
'"'
)),
IF(aggVal IS NULL,
"",
CONCAT(" AND id=",
CONCAT(" AND e.id=",
aggVal)));
-- ##################################################
......@@ -108,12 +150,15 @@ ELSE
'` (id, _iversion) SELECT data.id, data._iversion FROM `',
'` (id) SELECT data.id FROM `'),
sourceSet,
"` AS data WHERE ",
IF(o IS NULL OR vInt IS NULL,
"` AS data JOIN entity_ids AS eids ON (eids.internal_id = data.id) WHERE ",
IF(o IS NULL OR EntityID IS NULL,
"1=1",
CONCAT("data.id",
CONCAT(entity_id_type,
o,
vInt)),
' "',
EntityID,
'"'
)),
IF(aggVal IS NULL,
"",
CONCAT(" AND data.id=",
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
......@@ -17,8 +16,6 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
/* Documentation including (?) has to be checked by an expert. */
......@@ -37,30 +34,31 @@ DELIMITER //
* ----------
*
* versioned : boolean
* If True, sourceSet and targetSet have an _iversion column, otherwise that column will be
* ignored (or only HEAD will be inserted into targetSet).
* If True, sourceSet and targetSet have an _iversion column, otherwise that column will be ignored
* (or only HEAD will be inserted into targetSet).
*/
CREATE PROCEDURE db_5_0.applyPOV(in sourceSet VARCHAR(255), /* (?) Name of the table that the POV will be applied to. This can be a temporary table. */
in targetSet VARCHAR(255), /* (?) Name of the result table of this POV. */
CREATE PROCEDURE db_5_0.applyPOV(in sourceSet VARCHAR(255), /* Name of the table that the POV will be applied to. This can be a temporary table or the `entities` table */
in targetSet VARCHAR(255), /* Name of the result table of this POV. After the filter has been applied this table only contains matching
entity ids. This may be NULL or same as sourceSet. In that case the filter is applied in-place (delete non-matching). Otherwise the filter is applied by copying only the matching ids from the *source* set to the *target* set. */
in propertiesTable VARCHAR(255),
in refIdsTable VARCHAR(255),
in refIdsTable VARCHAR(255), /* Name of a tmp table that contains all ids of children of the value interpreted as entity name or id */
in o CHAR(4), /* The operator for this operation. can be one of:
0 check for "equals NULL"
!0 check for "not NULL"
-> check whether a reference exists
( (?) check for datetime intervals
!( (?) check for being outside of datetime intervals
other operators (all SQL operators (?))
( check for datetime interval (say "in")
!( check for being outside of datetime intervals (say "not in")
other operators (all valid SQL operators)
these other operators can be used either with or without an aggregation
to use an aggregation set agg to non-zero
all SQL aggregations can be used
*/
in vText VARCHAR(255), /* (?) the text value to be checked against using operator o */
in vText VARCHAR(255), /* the text value to be checked against using operator o */
in vInt INT, /* the integer value to be checked against using operator o */
in vDouble DOUBLE, /* the double value to be checked against using operator o */
in unit_sig BIGINT,
in unit_sig BIGINT, /* signatur of the unit given by the user. used when we need to convert units. */
in vDoubleStdUnit DOUBLE, /* The numeric value, converted according to the unit rules. */
in stdUnit_sig BIGINT,
in stdUnit_sig BIGINT, /* signatur of the normalized/standardized unit, e.g when unit_sig is "km/h" this might be "m/s". */
in vDateTime VARCHAR(255),
in vDateTimeDotNotation VARCHAR(255),
in agg CHAR(3), /* an SQL aggregate function or NULL when no aggregation should be used */
......@@ -84,6 +82,10 @@ POV_LABEL: BEGIN
DECLARE keepTabl VARCHAR(255) DEFAULT NULL;
DECLARE existence_op VARCHAR(255) DEFAULT "EXISTS";
#-- ######### HINT ##############
#-- first the appropriate statement is created which in the end prepared and executed
#-- #############################
IF o = '->' THEN
#-- special case: pure reference property
call applyRefPOV(sourceSet,targetSet, propertiesTable, refIdsTable, versioned);
......@@ -232,6 +234,8 @@ POV_LABEL: BEGIN
IF o = "!=" AND refIdsTable IS NOT NULL THEN
SET existence_op = "NOT EXISTS";
END IF;
/* select all entities that reference the entity or a child of the
* value interpreted as ID*/
SET sRefData = IF(vText IS NULL,
' UNION ALL SELECT DISTINCT domain_id, entity_id, property_id FROM `reference_data`',
IF(refIdsTable IS NULL,
......@@ -246,6 +250,7 @@ POV_LABEL: BEGIN
END IF;
#-- create array of statement parts (and replace null with empty string) (?)
SET data = CONCAT('(',sTextData,
IF(sNameData IS NULL, '', sNameData),
IF(sEnumData IS NULL, '', sEnumData),
......@@ -262,6 +267,7 @@ POV_LABEL: BEGIN
call createTmpTable(keepTabl, versioned);
IF versioned THEN
#-- generate statement from statement parts
#-- (versioned section)
SET @stmtPOVkeepTblStr = CONCAT(
'INSERT IGNORE INTO `', keepTabl, '` (id, _iversion) SELECT entity_id AS id, _iversion FROM ', data,
' as data', IF(propertiesTable IS NULL, '', CONCAT(
......@@ -302,7 +308,14 @@ POV_LABEL: BEGIN
DEALLOCATE PREPARE stmtPOVkeepTbl;
ELSE
#-- generate statement from statement parts
SET @stmtPOVkeepTblStr = CONCAT('INSERT IGNORE INTO `', keepTabl, '` (id) SELECT DISTINCT entity_id AS id FROM ', data, ' as data', IF(propertiesTable IS NULL, '', CONCAT(' WHERE EXISTS (Select 1 from `', propertiesTable, '` AS prop WHERE prop.id = data.property_id AND (prop.id2=data.entity_id OR prop.id2=0))')));
SET @stmtPOVkeepTblStr = CONCAT(
'INSERT IGNORE INTO `', keepTabl,
'` (id) SELECT DISTINCT entity_id AS id FROM ', data, ' as data',
IF(propertiesTable IS NULL, '',
CONCAT(' WHERE EXISTS (Select 1 from `', propertiesTable,
'` AS prop WHERE prop.id = data.property_id AND
(prop.id2=data.entity_id OR prop.id2=0))')));
#-- (unversioned section)
SET @stmtPOVStr = CONCAT(
IF(targetSet IS NULL,
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -17,17 +18,45 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
DROP PROCEDURE IF EXISTS db_5_0.applyTransactionFilter;
DELIMITER //
/*
* Apply a transaction filter to the sourceSet and collect the remaining
* entities in the targetSet.
*
* Parameters
* ----------
* sourceSet : VARCHAR(255)
* The name of the table from where we start.
* targetSet : VARCHAR(255)
* The name of the table where we collect all the "good" ids (or NULL or same as sourceSet).
* transaction : VARCHAR(255)
* The transaction's type (INSERT, UPDATE,...)
* operator_u : CHAR(2)
* The operator used for filtering by the user, e.g. '=', '!='.
* realm : VARCHAR(255)
* The user's realm (if filtering by the user).
* userName : VARCHAR(255)
* The user's name (if filtering by the user).
* ilb : BIGINT
* Inclusive Lower Bound of seconds for the transactions time.
* ilb_nanos : BIGINT
* Inclusive Lower Bound of nanoseconds for the transactions time.
* eub : BIGINT
* Exclusive Upper Bound of seconds for the transactions time.
* eub_nanos : BIGINT
* Exclusive Upper Bound of nanoseconds for the transactions time.
* operator_t : CHAR(2)
* The operator used for filtering by the transaction time, e.g. '=', '!=', '<', '>='.
*/
CREATE PROCEDURE db_5_0.applyTransactionFilter(in sourceSet VARCHAR(255), targetSet VARCHAR(255), in transaction VARCHAR(255), in operator_u CHAR(2), in realm VARCHAR(255), in userName VARCHAR(255), in ilb BIGINT, in ilb_nanos INT UNSIGNED, in eub BIGINT, in eub_nanos INT UNSIGNED, in operator_t CHAR(2))
BEGIN
DECLARE data TEXT default CONCAT('(SELECT entity_id FROM transaction_log AS t WHERE t.transaction=\'',
DECLARE data TEXT default CONCAT("(SELECT internal_id AS entity_id FROM transaction_log AS t JOIN entity_ids AS eids ON ( t.entity_id = eids.id ) WHERE t.transaction='",
transaction,
'\'',
"'",
IF(userName IS NOT NULL,
CONCAT(' AND t.realm', operator_u, '? AND t.username', operator_u, '?'),
''
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -17,27 +18,52 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
DROP PROCEDURE IF EXISTS db_5_0.initBackReference;
DELIMITER //
CREATE PROCEDURE db_5_0.initBackReference(in pid INT UNSIGNED, in pname VARCHAR(255), in entity_id INT UNSIGNED, in ename VARCHAR(255))
/*
* Create and initialize two new temporary tables.
*
* This is used to initialize the filterin for backreferences to a
* particular entity (specified by EntityID or EntityName) or using a
* particular property (specified by PropertyID or PropertyName).
*
* The propertiesTable contains all properties matching the PropertyID or
* PropertyName. The entitiesTable contains all entities matching EntityID or
* EntityName.
* Parameters
* ----------
* PropertyID : VARCHAR(255)
* The property's (external) id.
* PropertyName : VARCHAR(255)
* The property's name.
* EntityID : VARCHAR(255)
* The entity's (external) id.
* EntityName : VARCHAR(255)
* The entity's name.
*
* Select
* ------
* Tuple (propertiesTable, entitiesTable)
*/
CREATE PROCEDURE db_5_0.initBackReference(in PropertyID VARCHAR(255), in PropertyName VARCHAR(255), in EntityID VARCHAR(255), in EntityName VARCHAR(255))
BEGIN
DECLARE propertiesTable VARCHAR(255) DEFAULT NULL;
DECLARE entitiesTable VARCHAR(255) DEFAULT NULL;
IF pname IS NOT NULL THEN
IF PropertyName IS NOT NULL THEN
-- TODO versioning for properties
call createTmpTable(propertiesTable, FALSE);
call initSubEntity(pid, pname, propertiesTable);
call initSubEntity(PropertyID, PropertyName, propertiesTable);
END IF;
IF ename IS NOT NULL THEN
IF EntityName IS NOT NULL THEN
-- TODO versioning for referencing entities
call createTmpTable(entitiesTable, FALSE);
call initSubEntity(entity_id, ename, entitiesTable);
call initSubEntity(EntityID, EntityName, entitiesTable);
END IF;
SELECT propertiesTable, entitiesTable;
......
......@@ -30,7 +30,7 @@ DELIMITER //
* If `versioned` is `TRUE`, also add archived entities (for example if the name was changed in the
* past).
*/
CREATE PROCEDURE db_5_0.initEntity(in eid INT UNSIGNED, in ename VARCHAR(255),
CREATE PROCEDURE db_5_0.initEntity(in eid VARCHAR(255), in ename VARCHAR(255),
in enameLike VARCHAR(255), in enameRegexp VARCHAR(255),
in resultset VARCHAR(255), in versioned BOOLEAN)
initEntityLabel: BEGIN
......@@ -78,11 +78,12 @@ initEntityLabel: BEGIN
'INSERT IGNORE INTO `',
resultset,
IF(versioned,
'` (id, _iversion) SELECT id, _get_head_iversion(id) ',
'` (id) SELECT id '),
'FROM entities WHERE id=',eid,';');
'` (id, _iversion) SELECT eids.internal_id, _get_head_iversion(eids.internal_id) ',
'` (id) SELECT eids.internal_id '),
'FROM entity_ids AS eids WHERE eids.id=?;');
SET @query_param = eid;
PREPARE initEntityStmt FROM @initEntityStmtStr;
EXECUTE initEntityStmt;
EXECUTE initEntityStmt USING @query_param;
DEALLOCATE PREPARE initEntityStmt;
END IF;
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -17,15 +18,32 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
DELIMITER //
DROP PROCEDURE IF EXISTS db_5_0.initPOVPropertiesTable//
CREATE PROCEDURE db_5_0.initPOVPropertiesTable(in pid INT UNSIGNED, in pname VARCHAR(255), in sourceSet VARCHAR(255))
/*
* Create and initialize a new temporary table.
*
* This is used to initialize the POV filtering. The resulting table
* contains all properties matching the Property component of the POV filter.
*
* Parameters
* ----------
* PropertyID : VARCHAR(255)
* The property's (external) id.
* PropertyName : VARCHAR(255)
* The property's name.
* sourceSet : VARCHAR(255)
* The name of the table which will be filtered by the POV filter.
*
* Select
* ------
* Tuple (propertiesTable, ... and a lot of debug output)
*/
CREATE PROCEDURE db_5_0.initPOVPropertiesTable(in PropertyID VARCHAR(255), in PropertyName VARCHAR(255), in sourceSet VARCHAR(255))
BEGIN
DECLARE propertiesTable VARCHAR(255) DEFAULT NULL; /*table for property ids*/
DECLARE replTbl VARCHAR(255) DEFAULT NULL;
......@@ -38,24 +56,31 @@ BEGIN
DECLARE t6 BIGINT DEFAULT 0;
IF pname is NOT NULL THEN
IF PropertyName is NOT NULL THEN
SELECT conv( concat( substring(uid,16,3), substring(uid,10,4), substring(uid,1,8)),16,10) div 10000 - (141427 * 24 * 60 * 60 * 1000) as current_mills INTO t1 from (select uuid() uid) as alias;
call createTmpTable2(propertiesTable);
-- fill in all properties named "pname"
-- Fill in all properties (plus the domain id and entity id) named
-- "PropertyName", be it their default name or their overridden name.
-- We need *all* properties (mind, the properties of entities not
-- abstract properties) with the given name. If an abstract
-- property has the name "person" it might have the name "author" in
-- the "Article" record type. Now, if I want to collect all properties
-- of the Article named "author" I need to look into the name_overrides
-- table.
SET @initPOVPropertiesTableStmt1 = CONCAT('INSERT IGNORE INTO `', propertiesTable, '` (id, id2, domain) SELECT property_id, entity_id, domain_id from name_overrides WHERE name = ? UNION ALL SELECT entity_id, domain_id, 0 FROM name_data WHERE value = ?;');
PREPARE stmt FROM @initPOVPropertiesTableStmt1;
SET @pname = pname;
EXECUTE stmt USING @pname, @pname;
SET @PropertyName = PropertyName;
EXECUTE stmt USING @PropertyName, @PropertyName;
SET ecount = ROW_COUNT();
-- fill in all properties with id="pid"
-- fill in all properties with id="PropertyID"
SELECT conv( concat( substring(uid,16,3), substring(uid,10,4), substring(uid,1,8)),16,10) div 10000 - (141427 * 24 * 60 * 60 * 1000) as current_mills INTO t2 from (select uuid() uid) as alias;
IF pid IS NOT NULL THEN
IF PropertyID IS NOT NULL THEN
SET @initPOVPropertiesTableStmt2 = CONCAT('INSERT IGNORE INTO `', propertiesTable, '` (id, id2, domain) VALUES (?, 0, 0)');
PREPARE stmt FROM @initPOVPropertiesTableStmt2;
SET @pid = pid;
EXECUTE stmt USING @pid;
SET @PropertyID = PropertyID;
EXECUTE stmt USING @PropertyID;
SET ecount = ecount + ROW_COUNT();
END IF;
......@@ -91,15 +116,33 @@ END //
DROP PROCEDURE IF EXISTS db_5_0.initPOVRefidsTable //
CREATE PROCEDURE db_5_0.initPOVRefidsTable(in vInt INT UNSIGNED, in vText VARCHAR(255))
/*
* Create and initialize a new temporary table.
*
* This used to initialize the POV filtering. The resulting table
* contains all entities matching the Value component of the POV filter (i.e.
* the referenced entities).
*
* Parameters
* ----------
* PropertyID : VARCHAR(255)
* The property's (external) id.
* PropertyName : VARCHAR(255)
* The property's name.
*
* Select
* ------
* Tuple (refIdsTable)
*/
CREATE PROCEDURE db_5_0.initPOVRefidsTable(in PropertyID VARCHAR(255), in PropertyName VARCHAR(255))
BEGIN
DECLARE refIdsTable VARCHAR(255) DEFAULT NULL; /*table for referenced entity ids*/
#-- for reference properties: the value is interpreted as a record type name.
IF vText IS NOT NULL THEN
IF PropertyName IS NOT NULL THEN
-- TODO versioned queries
call createTmpTable(refIdsTable, FALSE);
call initSubEntity(vInt, vText, refIdsTable);
call initSubEntity(PropertyID, PropertyName, refIdsTable);
#-- now, all ids are in the refIdsTable
END IF;
SELECT refIdsTable;
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -17,20 +18,35 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
DROP PROCEDURE IF EXISTS db_5_0.initSubEntity;
DELIMITER //
CREATE PROCEDURE db_5_0.initSubEntity(in e_id INT UNSIGNED, in ename VARCHAR(255), in tableName VARCHAR(255))
/*
* Initialize a new temporary table by loading an entity (by name or by id or
* both) and all of its children into the table (i.e. their internal ids).
*
* The table name has to be provided.
*
* This is used by initPOVRefidsTable and initBackReference for sub-property filtering.
*
* Parameters
* ----------
* EntityID : VARCHAR(255)
* The entity's (external) id.
* EntityName : VARCHAR(255)
* The entity's name.
* tableName : VARCHAR(255)
* The table which is to be initialized.
*/
CREATE PROCEDURE db_5_0.initSubEntity(in EntityID VARCHAR(255), in ename VARCHAR(255), in tableName VARCHAR(255))
BEGIN
DECLARE ecount INT DEFAULT 0;
DECLARE op VARCHAR(255) DEFAULT '=';
IF LOCATE("%", ename) > 0 THEN
SET op = "LIKE";
END IF;
......@@ -47,10 +63,11 @@ BEGIN
SET ecount = ROW_COUNT();
DEALLOCATE PREPARE stmt;
IF e_id IS NOT NULL THEN
SET @stmtStr = CONCAT('INSERT IGNORE INTO `', tableName, '` (id) VALUES (', e_id, ')');
IF EntityID IS NOT NULL THEN
SET @stmtStr = CONCAT('INSERT IGNORE INTO `', tableName, '` (id) SELECT internal_id FROM entity_ids WHERE id = ?');
PREPARE stmt FROM @stmtStr;
EXECUTE stmt;
SET @eid = EntityID;
EXECUTE stmt USING @eid;
SET ecount = ecount + ROW_COUNT();
DEALLOCATE PREPARE stmt;
END IF;
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2023 IndiScale GmbH <www.indiscale.com>
* Copyright (C) 2023 Timm Fitschen <t.fitschen@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -17,33 +18,25 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
DROP PROCEDURE IF EXISTS db_5_0.registerSubdomain;
DROP PROCEDURE IF EXISTS db_5_0.registerReplacementIds;
delimiter //
CREATE PROCEDURE db_5_0.registerSubdomain(in amount INT UNSIGNED)
CREATE PROCEDURE db_5_0.registerReplacementIds(in amount INT UNSIGNED)
BEGIN
DECLARE ED INTEGER DEFAULT NULL;
SELECT COUNT(id) INTO ED FROM entities WHERE Role='DOMAIN' AND id!=0;
SELECT COUNT(id) INTO ED FROM entities WHERE Role='_REPLACEMENT' AND id!=0;
WHILE ED < amount DO
INSERT INTO entities (description, role, acl) VALUES
(NULL, 'DOMAIN', 0);
(NULL, '_REPLACEMENT', 0);
SET ED = ED + 1;
END WHILE;
SELECT id as DomainID FROM entities WHERE Role='DOMAIN' and id!=0;
SELECT CONCAT("$", e.id) as ReplacementID FROM entities AS e WHERE e.Role='_REPLACEMENT' and e.id!=0;
END;
//
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
DROP PROCEDURE IF EXISTS db_5_0.retrieveDatatype;
delimiter //
CREATE PROCEDURE db_5_0.retrieveDatatype(in DatatypeName VARCHAR(255))
BEGIN
Select e.id INTO @DatatypeID from entities e where e.name=DatatypeName AND e.role='DATATYPE' LIMIT 1;
call retrieveEntity(@DatatypeID);
END;
//
delimiter ;
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale
* Copyright (C) 2020,2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020,2023 Timm Fitschen <t.fitschen@indiscale>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -19,8 +18,6 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
......@@ -36,30 +33,40 @@ drop procedure if exists db_5_0.retrieveEntity //
*
* Parameters
* ----------
* EntityID
* EntityID : VARCHAR(255)
* The entity's id.
* Version
* Version : VARBINARY(255)
* The version id. In this procedure only, the version may also be given as
* `HEAD` for the latest version or as `HEAD~n`, which retrieves the n-th
* ancestor of `HEAD`.
*
* ResultSet
* ---------
* Tuple of (Datatype, Collection, EntityID, EntityName, EntityDesc,
* EntityRole, FileSize, FilePath, FileHash, ACL, Version)
* Tuple of (DatatypeID, DatatypeName, Collection, EntityID, EntityName,
* EntityDesc, EntityRole, FileSize, FilePath, FileHash, ACL,
* Version)
*/
create procedure db_5_0.retrieveEntity(
in EntityID INT UNSIGNED,
in EntityID VARCHAR(255),
in Version VARBINARY(255))
retrieveEntityBody: BEGIN
DECLARE FilePath VARCHAR(255) DEFAULT NULL;
DECLARE FileSize VARCHAR(255) DEFAULT NULL;
DECLARE FileHash VARCHAR(255) DEFAULT NULL;
DECLARE DatatypeID INT UNSIGNED DEFAULT NULL;
DECLARE DatatypeID VARCHAR(255) DEFAULT NULL;
DECLARE InternalDatatypeID INT UNSIGNED DEFAULT NULL;
DECLARE CollectionName VARCHAR(255) DEFAULT NULL;
DECLARE IsHead BOOLEAN DEFAULT TRUE;
DECLARE IVersion INT UNSIGNED DEFAULT NULL;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID from entity_ids WHERE id = EntityID;
IF InternalEntityID IS NULL THEN
-- RETURN EARLY - Entity does not exist.
SELECT 0 FROM entities WHERE 0 = 1;
LEAVE retrieveEntityBody;
END IF;
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
-- Find out head-ness and version
......@@ -73,7 +80,7 @@ retrieveEntityBody: BEGIN
END IF;
IF IsHead IS FALSE THEN
SET IVersion=get_iversion(EntityID, Version);
SET IVersion=get_iversion(InternalEntityID, Version);
IF IVersion IS NULL THEN
-- RETURN EARLY - Version does not exist.
......@@ -84,16 +91,16 @@ retrieveEntityBody: BEGIN
SELECT path, size, HEX(hash)
INTO FilePath, FileSize, FileHash
FROM archive_files
WHERE file_id = EntityID
WHERE file_id = InternalEntityID
AND _iversion = IVersion
LIMIT 1;
SELECT datatype
INTO DatatypeID
INTO InternalDatatypeID
FROM archive_data_type
WHERE domain_id = 0
AND entity_id = 0
AND property_id = EntityID
AND property_id = InternalEntityID
AND _iversion = IVersion
LIMIT 1;
......@@ -102,7 +109,7 @@ retrieveEntityBody: BEGIN
FROM archive_collection_type
WHERE domain_id = 0
AND entity_id = 0
AND property_id = EntityID
AND property_id = InternalEntityID
AND _iversion = IVersion
LIMIT 1;
......@@ -111,18 +118,17 @@ retrieveEntityBody: BEGIN
( SELECT value FROM
( SELECT value FROM name_data
WHERE domain_id = 0
AND entity_ID = DatatypeID
AND entity_id = InternalDatatypeID
AND property_id = 20
UNION SELECT DatatypeID AS value
) AS tmp LIMIT 1 ) AS Datatype,
) AS tmp LIMIT 1 ) AS DatatypeName,
( SELECT id FROM entity_ids WHERE internal_id=InternalDatatypeID ) AS DatatypeID,
CollectionName AS Collection,
EntityID AS EntityID,
( SELECT value FROM archive_name_data
WHERE domain_id = 0
AND entity_ID = EntityID
AND entity_ID = InternalEntityID
AND property_id = 20
AND _iversion = IVersion
-- LIMIT 1 -- TODO Remove this line if all tests pass.
) AS EntityName,
e.description AS EntityDesc,
e.role AS EntityRole,
......@@ -132,7 +138,7 @@ retrieveEntityBody: BEGIN
(SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL,
Version AS Version
FROM archive_entities AS e
WHERE e.id = EntityID
WHERE e.id = InternalEntityID
AND e._iversion = IVersion
LIMIT 1;
......@@ -145,33 +151,34 @@ retrieveEntityBody: BEGIN
SELECT path, size, hex(hash)
INTO FilePath, FileSize, FileHash
FROM files
WHERE file_id = EntityID
WHERE file_id = InternalEntityID
LIMIT 1;
SELECT datatype INTO DatatypeID
FROM data_type
WHERE domain_id=0
AND entity_id=0
AND property_id=EntityID
SELECT dt.datatype INTO InternalDatatypeID
FROM data_type as dt
WHERE dt.domain_id=0
AND dt.entity_id=0
AND dt.property_id=InternalEntityID
LIMIT 1;
SELECT collection INTO CollectionName
FROM collection_type
WHERE domain_id=0
AND entity_id=0
AND property_id=EntityID
AND property_id=InternalEntityID
LIMIT 1;
SELECT
( SELECT value FROM name_data
WHERE domain_id = 0
AND entity_ID = DatatypeID
AND property_id = 20 LIMIT 1 ) AS Datatype,
AND entity_id = InternalDatatypeID
AND property_id = 20 LIMIT 1 ) AS DatatypeName,
( SELECT id FROM entity_ids WHERE internal_id=InternalDatatypeID ) AS DatatypeID,
CollectionName AS Collection,
EntityID AS EntityID,
( SELECT value FROM name_data
WHERE domain_id = 0
AND entity_ID = EntityID
AND entity_ID = InternalEntityID
AND property_id = 20 LIMIT 1) AS EntityName,
e.description AS EntityDesc,
e.role AS EntityRole,
......@@ -180,7 +187,7 @@ retrieveEntityBody: BEGIN
FileHash AS FileHash,
(SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL,
Version AS Version
FROM entities e WHERE id = EntityID LIMIT 1;
FROM entities e WHERE id = InternalEntityID LIMIT 1;
END;
//
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 Indiscale GmbH <info@indiscale.com>
* Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com>
* Copyright (C) 2020,2023 Indiscale GmbH <info@indiscale.com>
* Copyright (C) 2020,2023 Timm Fitschen <t.fitschen@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -19,25 +18,61 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
DROP PROCEDURE IF EXISTS db_5_0.retrieveOverrides;
delimiter //
/*
* Retrieve the overridden (overriding the Abstract Property's) name, description, and datatype.
*
* Parameters
* ----------
*
* DomainID : VARCHAR(255)
* The domain id (0 or the entity'id for level-2-data)
* EntityID : VARCHAR(255)
* The entity id (or the property'id for level-2-data)
* Version : VARBINARY(255)
* The version of the entity. Optional
*
* ResultSet
* ---------
* collection_override, # e.g. LIST
* name_override, # the name
* desc_override, # the description
* type_name_override, # the datatype, e.g. DOUBLE
* type_id_override, # data type id.
* entity_id, # same as input EntityID
* InternalPropertyID, # internal property id, to be used when property_id
* # is NULL because a replacement is used.
* property_id, # the property id
*/
CREATE PROCEDURE db_5_0.retrieveOverrides(
in DomainID INT UNSIGNED,
in EntityID INT UNSIGNED,
in DomainID VARCHAR(255),
in EntityID VARCHAR(255),
in Version VARBINARY(255))
retrieveOverridesBody: BEGIN
DECLARE IVersion INT UNSIGNED DEFAULT NULL;
DECLARE IsHead BOOLEAN DEFAULT TRUE;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
DECLARE InternalDomainID INT UNSIGNED DEFAULT 0;
-- When DomainID != 0 the EntityID could possibly be a 'replacement id'
-- which are internal ids by definition (and do not have external
-- equivalents).
IF LOCATE("$", EntityID) = 1 THEN
SET InternalEntityID=SUBSTRING(EntityID, 2);
ELSE
SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
END IF;
-- DomainID != 0 are always normal (i.e. external) Entity ids.
SELECT internal_id INTO InternalDomainID from entity_ids WHERE id = DomainID;
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
IF Version IS NOT NULL THEN
IF DomainID = 0 THEN
IF InternalDomainID = 0 THEN
SELECT get_head_version(EntityID) = Version INTO IsHead;
ELSE
SELECT get_head_version(DomainID) = Version INTO IsHead;
......@@ -47,8 +82,8 @@ retrieveOverridesBody: BEGIN
IF IsHead IS FALSE THEN
SELECT e._iversion INTO IVersion
FROM entity_version as e
WHERE ((e.entity_id = EntityID AND DomainID = 0)
OR (e.entity_id = DomainID))
WHERE ((e.entity_id = InternalEntityID AND InternalDomainID = 0)
OR (e.entity_id = InternalDomainID))
AND e.version = Version;
IF IVersion IS NULL THEN
......@@ -61,12 +96,14 @@ retrieveOverridesBody: BEGIN
NULL AS collection_override,
name AS name_override,
NULL AS desc_override,
NULL AS type_override,
entity_id,
property_id
NULL AS type_name_override,
NULL AS type_id_override,
EntityID AS entity_id,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM archive_name_overrides
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
AND _iversion = IVersion
UNION ALL
......@@ -76,12 +113,14 @@ retrieveOverridesBody: BEGIN
NULL AS collection_override,
NULL AS name_override,
description AS desc_override,
NULL AS type_override,
entity_id,
property_id
NULL AS type_name_override,
NULL AS type_id_override,
EntityID AS entity_id,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM archive_desc_overrides
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
AND _iversion = IVersion
UNION ALL
......@@ -91,16 +130,18 @@ retrieveOverridesBody: BEGIN
NULL AS collection_override,
NULL AS name_override,
NULL AS desc_override,
IFNULL((SELECT value FROM name_data
(SELECT value FROM name_data
WHERE domain_id = 0
AND entity_id = datatype
AND property_id = 20
LIMIT 1), datatype) AS type_override,
entity_id,
property_id
LIMIT 1) AS type_name_override,
(SELECT id FROM entity_ids WHERE internal_id = datatype) AS type_id_override,
EntityID AS entity_id,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM archive_data_type
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
AND _iversion = IVersion
UNION ALL
......@@ -110,12 +151,14 @@ retrieveOverridesBody: BEGIN
collection AS collection_override,
NULL AS name_override,
NULL AS desc_override,
NULL AS type_override,
entity_id,
property_id
NULL AS type_name_override,
NULL AS type_id_override,
EntityID AS entity_id,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM archive_collection_type
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
AND _iversion = IVersion;
LEAVE retrieveOverridesBody;
......@@ -126,12 +169,14 @@ retrieveOverridesBody: BEGIN
NULL AS collection_override,
name AS name_override,
NULL AS desc_override,
NULL AS type_override,
entity_id,
property_id
NULL AS type_name_override,
NULL AS type_id_override,
EntityID AS entity_id,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM name_overrides
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
UNION ALL
......@@ -139,12 +184,14 @@ retrieveOverridesBody: BEGIN
NULL AS collection_override,
NULL AS name_override,
description AS desc_override,
NULL AS type_override,
entity_id,
property_id
NULL AS type_name_override,
NULL AS type_id_override,
EntityID AS entity_id,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM desc_overrides
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
UNION ALL
......@@ -152,15 +199,17 @@ retrieveOverridesBody: BEGIN
NULL AS collection_override,
NULL AS name_override,
NULL AS desc_override,
IFNULL((SELECT value FROM name_data
(SELECT value FROM name_data
WHERE domain_id = 0
AND entity_ID = datatype
AND property_id = 20 LIMIT 1), datatype) AS type_override,
entity_id,
property_id
AND property_id = 20 LIMIT 1) AS type_name_override,
(SELECT id FROM entity_ids WHERE internal_id = datatype) AS type_id_override,
EntityID AS entity_id,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM data_type
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
UNION ALL
......@@ -168,12 +217,14 @@ retrieveOverridesBody: BEGIN
collection AS collection_override,
NULL AS name_override,
NULL AS desc_override,
NULL AS type_override,
entity_id,
property_id
NULL AS type_name_override,
NULL AS type_id_override,
EntityID AS entity_id,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM collection_type
WHERE domain_id = DomainID
AND entity_id = EntityID;
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID;
END;
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com>
* Copyright (C) 2020,2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020,2023 Timm Fitschen <t.fitschen@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -19,8 +18,6 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
......@@ -28,37 +25,35 @@ DROP PROCEDURE IF EXISTS db_5_0.retrieveEntityParents;
DELIMITER //
/* Retrieve the parents of an Entity.
Parameters
==========
EntityID : UNSIGNED
Child entity for which all parental relations should be deleted.
Returns
=======
ParentID : INT UNSIGNED
Each parent's ID
ParentName :
The parent's name.
ParentDescription :
The parent's description.
ParentRole :
The parent's Role.
ACL :
Access control list something
*
* Parameters
* ----------
* EntityID : VARCHAR(255)
* Child entity for which all parental relations should be deleted.
*
* ResultSet
* ---------
* ParentID : VARCHAR(255)
* Each parent's ID
* ParentName : VARCHAR(255)
* The parent's name.
* ParentDescription : TEXT
* The parent's description.
* ParentRole : VARCHAR(255)
* The parent's Role.
* ACL : VARBINARY(65525)
* Access control list.
*/
CREATE PROCEDURE db_5_0.retrieveEntityParents(
in EntityID INT UNSIGNED,
in EntityID VARCHAR(255),
in Version VARBINARY(255))
retrieveEntityParentsBody: BEGIN
DECLARE IVersion INT UNSIGNED DEFAULT NULL;
DECLARE IsHead BOOLEAN DEFAULT TRUE;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID from entity_ids WHERE id = EntityID;
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
IF Version IS NOT NULL THEN
......@@ -68,7 +63,7 @@ retrieveEntityParentsBody: BEGIN
IF IsHead IS FALSE THEN
SELECT e._iversion INTO IVersion
FROM entity_version as e
WHERE e.entity_id = EntityID
WHERE e.entity_id = InternalEntityID
AND e.version = Version;
IF IVersion IS NULL THEN
......@@ -77,10 +72,10 @@ retrieveEntityParentsBody: BEGIN
END IF;
SELECT
i.parent AS ParentID,
( SELECT id FROM entity_ids WHERE internal_id = i.parent) AS ParentID,
( SELECT value FROM name_data
WHERE domain_id = 0
AND entity_id = ParentID
AND entity_id = i.parent
AND property_id = 20
) AS ParentName, -- This is not necessarily the name of the parent at the time of
-- IVersion but it is a good guess. Future implementations of the
......@@ -92,7 +87,7 @@ retrieveEntityParentsBody: BEGIN
(SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL
FROM archive_isa AS i JOIN entities AS e
ON (i.parent = e.id)
WHERE i.child = EntityID
WHERE i.child = InternalEntityID
AND i.child_iversion = IVersion
AND i.direct IS TRUE
;
......@@ -102,18 +97,18 @@ retrieveEntityParentsBody: BEGIN
END IF;
SELECT
i.parent AS ParentID,
( SELECT id FROM entity_ids WHERE internal_id = i.parent) AS ParentID,
( SELECT value FROM name_data
WHERE domain_id = 0
AND entity_id = ParentID
AND entity_id = i.parent
AND property_id = 20 ) AS ParentName,
e.description AS ParentDescription,
e.role AS ParentRole,
(SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL
FROM isa_cache AS i JOIN entities AS e
ON (i.parent = e.id)
WHERE i.child = EntityID
AND i.rpath = EntityID;
WHERE i.child = InternalEntityID
AND i.rpath = InternalEntityID;
END
//
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
* Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com>
* Copyright (C) 2020-2023 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2020,2023 Timm Fitschen <t.fitschen@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
......@@ -19,8 +18,6 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
......@@ -28,30 +25,70 @@ delimiter //
drop procedure if exists db_5_0.retrieveEntityProperties //
/*
* Retrieve the properties of an entity (level 1 and 2).
*
* Parameters
* ----------
*
* DomainID : VARCHAR(255)
* The domain id (0 or the entity's id for level-2-data)
* EntityID : VARCHAR(255)
* The entity id (or the property's id for level-2-data)
* Version : VARBINARY(255)
* The version of the entity. Optional
*
* ResultSet
* ---------
* InternalPropertyID
* Internal property id, to be used when PropertyID
* is NULL because a replacement is used.
* PropertyID
* The property id
* PropertyValue
* The property value
* PropertyStatus
* E.g. OBLIGATORY, FIX, ...
* PropertyIndex
* The index of the property (for ordering).
* )
*/
create procedure db_5_0.retrieveEntityProperties(
in DomainID INT UNSIGNED,
in EntityID INT UNSIGNED,
in DomainID VARCHAR(255),
in EntityID VARCHAR(255),
in Version VARBINARY(255))
retrieveEntityPropertiesBody: BEGIN
DECLARE IVersion INT UNSIGNED DEFAULT NULL;
DECLARE IsHead BOOLEAN DEFAULT TRUE;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
DECLARE InternalDomainID INT UNSIGNED DEFAULT 0;
-- When DomainID != 0 the EntityID could possibly be a 'replacement id'
-- which are internal ids by definition (and do not have external
-- equivalents).
IF LOCATE("$", EntityID) = 1 THEN
SET InternalEntityID=SUBSTRING(EntityID, 2);
ELSE
SELECT internal_id INTO InternalEntityID FROM entity_ids WHERE id = EntityID;
END IF;
-- DomainID != 0 are always normal (i.e. external) Entity ids.
SELECT internal_id INTO InternalDomainID from entity_ids WHERE id = DomainID;
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
IF Version IS NOT NULL THEN
IF DomainID = 0 THEN
IF InternalDomainID = 0 THEN
SELECT get_head_version(EntityID) = Version INTO IsHead;
ELSE
SELECT get_head_version(DomainID) = Version INTO IsHead;
END IF;
END IF;
IF IsHead IS FALSE THEN
SELECT e._iversion INTO IVersion
FROM entity_version as e
WHERE ((e.entity_id = EntityID AND DomainID = 0)
OR (e.entity_id = DomainID))
WHERE ((e.entity_id = InternalEntityID AND InternalDomainID = 0)
OR (e.entity_id = InternalDomainID))
AND e.version = Version;
IF IVersion IS NULL THEN
......@@ -61,121 +98,135 @@ retrieveEntityPropertiesBody: BEGIN
#-- double properties
SELECT
property_id AS PropertyID,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM archive_double_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
AND _iversion = IVersion
UNION ALL
#-- integer properties
SELECT
property_id AS PropertyID,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM archive_integer_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
AND _iversion = IVersion
UNION ALL
#-- date properties
SELECT
property_id AS PropertyID,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
CONCAT(value, '.NULL.NULL') AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM archive_date_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
AND _iversion = IVersion
UNION ALL
#-- datetime properties
SELECT
property_id AS PropertyID,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
CONCAT(value, 'UTC', IF(value_ns IS NULL, '', value_ns))
AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM archive_datetime_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
AND _iversion = IVersion
UNION ALL
#-- text properties
SELECT
property_id AS PropertyID,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM archive_text_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
AND _iversion = IVersion
UNION ALL
#-- enum properties
SELECT
property_id AS PropertyID,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM archive_enum_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
AND _iversion = IVersion
UNION ALL
#-- reference properties
SELECT
property_id AS PropertyID,
IF(value_iversion IS NULL, value,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
IF(value_iversion IS NULL,
IF(status = "REPLACEMENT",
CONCAT("$", value),
( SELECT id FROM entity_ids WHERE internal_id = value )),
-- make it "value@version" if necessary
CONCAT(value, "@", _get_version(value, value_iversion)))
CONCAT(
( SELECT id FROM entity_ids WHERE internal_id = value ),
"@", _get_version(value, value_iversion)))
AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM archive_reference_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
AND _iversion = IVersion
UNION ALL
#-- null properties
SELECT
property_id AS PropertyID,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
NULL AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM archive_null_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
AND _iversion = IVersion
UNION ALL
#-- name properties
SELECT
property_id AS PropertyID,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM archive_name_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
AND property_id != 20
AND _iversion = IVersion;
......@@ -185,115 +236,129 @@ retrieveEntityPropertiesBody: BEGIN
#-- double properties
SELECT
property_id AS PropertyID,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM double_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
UNION ALL
#-- integer properties
SELECT
property_id AS PropertyID,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM integer_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
UNION ALL
#-- date properties
SELECT
property_id AS PropertyID,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
CONCAT(value, '.NULL.NULL') AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM date_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
UNION ALL
#-- datetime properties
SELECT
property_id AS PropertyID,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
CONCAT(value, 'UTC', IF(value_ns IS NULL, '', value_ns))
AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM datetime_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
UNION ALL
#-- text properties
SELECT
property_id AS PropertyID,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM text_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
UNION ALL
#-- enum properties
SELECT
property_id AS PropertyID,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM enum_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
UNION ALL
#-- reference properties
SELECT
property_id AS PropertyID,
IF(value_iversion IS NULL, value,
CONCAT(value, "@", _get_version(value, value_iversion)))
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
IF(value_iversion IS NULL,
IF(status = "REPLACEMENT",
CONCAT("$", value),
( SELECT id FROM entity_ids WHERE internal_id = value )),
-- make it "value@version" if necessary
CONCAT(
( SELECT id FROM entity_ids WHERE internal_id = value ),
"@", _get_version(value, value_iversion)))
AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM reference_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
UNION ALL
#-- null properties
SELECT
property_id AS PropertyID,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
NULL AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM null_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
UNION ALL
#-- name properties
SELECT
property_id AS PropertyID,
CONCAT("$", property_id) AS InternalPropertyID,
( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue,
status AS PropertyStatus,
pidx AS PropertyIndex
FROM name_data
WHERE domain_id = DomainID
AND entity_id = EntityID
WHERE domain_id = InternalDomainID
AND entity_id = InternalEntityID
AND property_id != 20;
END;
//
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2018 Research Group Biomedical Physics,
* Max-Planck-Institute for Dynamics and Self-Organization Göttingen
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
Drop Procedure if exists db_5_0.retrieveGroup;