Skip to content
Snippets Groups Projects
Verified Commit 8b6d92dd authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Revert "Revert "WIP: introduce external ids""

This reverts commit d7d9e6f6.
parent d7d9e6f6
Branches
Tags
3 merge requests!17Release 6.0,!15External String IDs,!11DRAFT: file system cleanup
-- a little bit of house keeping
DROP PROCEDURE IF EXISTS retrieveSubEntity;
DROP PROCEDURE IF EXISTS retrieveDatatype;
DROP PROCEDURE IF EXISTS retrieveGroup;
-- new entity_ids table
DROP TABLE IF EXISTS `entity_ids`;
CREATE TABLE `entity_ids` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`internal_id` int(10) unsigned NOT NULL COMMENT 'Internal ID of an entity. This id is used internally in the *_data tables and elsewhere. This ID is never exposed via the CaosDB API.',
PRIMARY KEY `entity_ids_pk` (`id`),
CONSTRAINT `entity_ids_internal_id` FOREIGN KEY (`internal_id`) REFERENCES `entities` (`id`)
) ENGINE=InnoDB;
-- fill all existing entities into the new entity_ids table.
INSERT INTO entity_ids (id, internal_id) SELECT id, id FROM entities WHERE id>0;
INSERT INTO entity_ids (id, internal_id) SELECT id, id FROM entities WHERE id=0;
UPDATE entity_ids SET id = internal_id;
-- ALTER TABLE entity_ids CHANGE id id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'External ID of an entity. This is the id of an entity which is exposed via the CaosDB API.';
#!/bin/bash
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2022 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2022 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
# 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/>.
#
# Update mysql schema to version v5.0.0
# Drop the 'rules' table.
NEW_VERSION="v5.0.1"
OLD_VERSION="v5.0.0"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="../utils"
fi
. $UTILSPATH/patch_header.sh $*
check_version $OLD_VERSION
mysql_execute_file $PATCH_DIR/create_entity_ids_table.sql
update_version $NEW_VERSION
success
/*
* ** 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 ;
...@@ -59,21 +59,29 @@ retrieveEntityBody: BEGIN ...@@ -59,21 +59,29 @@ retrieveEntityBody: BEGIN
DECLARE CollectionName VARCHAR(255) DEFAULT NULL; DECLARE CollectionName VARCHAR(255) DEFAULT NULL;
DECLARE IsHead BOOLEAN DEFAULT TRUE; DECLARE IsHead BOOLEAN DEFAULT TRUE;
DECLARE IVersion INT UNSIGNED DEFAULT NULL; 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 IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
-- Find out head-ness and version -- Find out head-ness and version
IF Version IS NULL OR UPPER(Version) = "HEAD" THEN IF Version IS NULL OR UPPER(Version) = "HEAD" THEN
SET Version = get_head_version(EntityID); SET Version = get_head_version(InternalEntityID);
ELSEIF UPPER(LEFT(Version, 5)) = "HEAD~" THEN ELSEIF UPPER(LEFT(Version, 5)) = "HEAD~" THEN
SET IsHead = FALSE; SET IsHead = FALSE;
SET Version = get_head_relative(EntityID, SUBSTR(Version, 6)); SET Version = get_head_relative(InternalEntityID, SUBSTR(Version, 6));
ELSE ELSE
SELECT get_head_version(EntityID) = Version INTO IsHead; SELECT get_head_version(InternalEntityID) = Version INTO IsHead;
END IF; END IF;
IF IsHead IS FALSE THEN IF IsHead IS FALSE THEN
SET IVersion=get_iversion(EntityID, Version); SET IVersion=get_iversion(InternalEntityID, Version);
IF IVersion IS NULL THEN IF IVersion IS NULL THEN
-- RETURN EARLY - Version does not exist. -- RETURN EARLY - Version does not exist.
...@@ -84,7 +92,7 @@ retrieveEntityBody: BEGIN ...@@ -84,7 +92,7 @@ retrieveEntityBody: BEGIN
SELECT path, size, HEX(hash) SELECT path, size, HEX(hash)
INTO FilePath, FileSize, FileHash INTO FilePath, FileSize, FileHash
FROM archive_files FROM archive_files
WHERE file_id = EntityID WHERE file_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
LIMIT 1; LIMIT 1;
...@@ -93,7 +101,7 @@ retrieveEntityBody: BEGIN ...@@ -93,7 +101,7 @@ retrieveEntityBody: BEGIN
FROM archive_data_type FROM archive_data_type
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_id = 0 AND entity_id = 0
AND property_id = EntityID AND property_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
LIMIT 1; LIMIT 1;
...@@ -102,7 +110,7 @@ retrieveEntityBody: BEGIN ...@@ -102,7 +110,7 @@ retrieveEntityBody: BEGIN
FROM archive_collection_type FROM archive_collection_type
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_id = 0 AND entity_id = 0
AND property_id = EntityID AND property_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
LIMIT 1; LIMIT 1;
...@@ -119,10 +127,9 @@ retrieveEntityBody: BEGIN ...@@ -119,10 +127,9 @@ retrieveEntityBody: BEGIN
EntityID AS EntityID, EntityID AS EntityID,
( SELECT value FROM archive_name_data ( SELECT value FROM archive_name_data
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_ID = EntityID AND entity_ID = InternalEntityID
AND property_id = 20 AND property_id = 20
AND _iversion = IVersion AND _iversion = IVersion
-- LIMIT 1 -- TODO Remove this line if all tests pass.
) AS EntityName, ) AS EntityName,
e.description AS EntityDesc, e.description AS EntityDesc,
e.role AS EntityRole, e.role AS EntityRole,
...@@ -132,7 +139,7 @@ retrieveEntityBody: BEGIN ...@@ -132,7 +139,7 @@ retrieveEntityBody: BEGIN
(SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL, (SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL,
Version AS Version Version AS Version
FROM archive_entities AS e FROM archive_entities AS e
WHERE e.id = EntityID WHERE e.id = InternalEntityID
AND e._iversion = IVersion AND e._iversion = IVersion
LIMIT 1; LIMIT 1;
...@@ -145,21 +152,21 @@ retrieveEntityBody: BEGIN ...@@ -145,21 +152,21 @@ retrieveEntityBody: BEGIN
SELECT path, size, hex(hash) SELECT path, size, hex(hash)
INTO FilePath, FileSize, FileHash INTO FilePath, FileSize, FileHash
FROM files FROM files
WHERE file_id = EntityID WHERE file_id = InternalEntityID
LIMIT 1; LIMIT 1;
SELECT datatype INTO DatatypeID SELECT datatype INTO DatatypeID
FROM data_type FROM data_type
WHERE domain_id=0 WHERE domain_id=0
AND entity_id=0 AND entity_id=0
AND property_id=EntityID AND property_id=InternalEntityID
LIMIT 1; LIMIT 1;
SELECT collection INTO CollectionName SELECT collection INTO CollectionName
FROM collection_type FROM collection_type
WHERE domain_id=0 WHERE domain_id=0
AND entity_id=0 AND entity_id=0
AND property_id=EntityID AND property_id=InternalEntityID
LIMIT 1; LIMIT 1;
SELECT SELECT
...@@ -171,7 +178,7 @@ retrieveEntityBody: BEGIN ...@@ -171,7 +178,7 @@ retrieveEntityBody: BEGIN
EntityID AS EntityID, EntityID AS EntityID,
( SELECT value FROM name_data ( SELECT value FROM name_data
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_ID = EntityID AND entity_ID = InternalEntityID
AND property_id = 20 LIMIT 1) AS EntityName, AND property_id = 20 LIMIT 1) AS EntityName,
e.description AS EntityDesc, e.description AS EntityDesc,
e.role AS EntityRole, e.role AS EntityRole,
...@@ -180,7 +187,7 @@ retrieveEntityBody: BEGIN ...@@ -180,7 +187,7 @@ retrieveEntityBody: BEGIN
FileHash AS FileHash, FileHash AS FileHash,
(SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL, (SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL,
Version AS Version Version AS Version
FROM entities e WHERE id = EntityID LIMIT 1; FROM entities e WHERE id = InternalEntityID LIMIT 1;
END; END;
// //
......
...@@ -34,21 +34,26 @@ retrieveOverridesBody: BEGIN ...@@ -34,21 +34,26 @@ retrieveOverridesBody: BEGIN
DECLARE IVersion INT UNSIGNED DEFAULT NULL; DECLARE IVersion INT UNSIGNED DEFAULT NULL;
DECLARE IsHead BOOLEAN DEFAULT TRUE; DECLARE IsHead BOOLEAN DEFAULT TRUE;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
DECLARE InternalDomainID INT UNSIGNED DEFAULT NULL;
SELECT internal_id INTO InternalEntityID from entity_ids WHERE id = EntityID;
SELECT internal_id INTO InternalDomainID from entity_ids WHERE id = DomainID;
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
IF Version IS NOT NULL THEN IF Version IS NOT NULL THEN
IF DomainID = 0 THEN IF InternalDomainID = 0 THEN
SELECT get_head_version(EntityID) = Version INTO IsHead; SELECT get_head_version(InternalEntityID) = Version INTO IsHead;
ELSE ELSE
SELECT get_head_version(DomainID) = Version INTO IsHead; SELECT get_head_version(InternalDomainID) = Version INTO IsHead;
END IF; END IF;
END IF; END IF;
IF IsHead IS FALSE THEN IF IsHead IS FALSE THEN
SELECT e._iversion INTO IVersion SELECT e._iversion INTO IVersion
FROM entity_version as e FROM entity_version as e
WHERE ((e.entity_id = EntityID AND DomainID = 0) WHERE ((e.entity_id = InternalEntityID AND InternalDomainID = 0)
OR (e.entity_id = DomainID)) OR (e.entity_id = InternalDomainID))
AND e.version = Version; AND e.version = Version;
IF IVersion IS NULL THEN IF IVersion IS NULL THEN
...@@ -62,11 +67,11 @@ retrieveOverridesBody: BEGIN ...@@ -62,11 +67,11 @@ retrieveOverridesBody: BEGIN
name AS name_override, name AS name_override,
NULL AS desc_override, NULL AS desc_override,
NULL AS type_override, NULL AS type_override,
entity_id, EntityID AS entity_id,
property_id ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM archive_name_overrides FROM archive_name_overrides
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
...@@ -77,11 +82,11 @@ retrieveOverridesBody: BEGIN ...@@ -77,11 +82,11 @@ retrieveOverridesBody: BEGIN
NULL AS name_override, NULL AS name_override,
description AS desc_override, description AS desc_override,
NULL AS type_override, NULL AS type_override,
entity_id, EntityID AS entity_id,
property_id ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM archive_desc_overrides FROM archive_desc_overrides
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
...@@ -96,11 +101,11 @@ retrieveOverridesBody: BEGIN ...@@ -96,11 +101,11 @@ retrieveOverridesBody: BEGIN
AND entity_id = datatype AND entity_id = datatype
AND property_id = 20 AND property_id = 20
LIMIT 1), datatype) AS type_override, LIMIT 1), datatype) AS type_override,
entity_id, EntityID AS entity_id,
property_id ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM archive_data_type FROM archive_data_type
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
...@@ -111,11 +116,11 @@ retrieveOverridesBody: BEGIN ...@@ -111,11 +116,11 @@ retrieveOverridesBody: BEGIN
NULL AS name_override, NULL AS name_override,
NULL AS desc_override, NULL AS desc_override,
NULL AS type_override, NULL AS type_override,
entity_id, EntityID AS entity_id,
property_id ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM archive_collection_type FROM archive_collection_type
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion; AND _iversion = IVersion;
LEAVE retrieveOverridesBody; LEAVE retrieveOverridesBody;
...@@ -127,11 +132,11 @@ retrieveOverridesBody: BEGIN ...@@ -127,11 +132,11 @@ retrieveOverridesBody: BEGIN
name AS name_override, name AS name_override,
NULL AS desc_override, NULL AS desc_override,
NULL AS type_override, NULL AS type_override,
entity_id, EntityID AS entity_id,
property_id ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM name_overrides FROM name_overrides
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
...@@ -140,11 +145,11 @@ retrieveOverridesBody: BEGIN ...@@ -140,11 +145,11 @@ retrieveOverridesBody: BEGIN
NULL AS name_override, NULL AS name_override,
description AS desc_override, description AS desc_override,
NULL AS type_override, NULL AS type_override,
entity_id, EntityID AS entity_id,
property_id ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM desc_overrides FROM desc_overrides
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
...@@ -156,11 +161,11 @@ retrieveOverridesBody: BEGIN ...@@ -156,11 +161,11 @@ retrieveOverridesBody: BEGIN
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_ID = datatype AND entity_ID = datatype
AND property_id = 20 LIMIT 1), datatype) AS type_override, AND property_id = 20 LIMIT 1), datatype) AS type_override,
entity_id, EntityID AS entity_id,
property_id ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM data_type FROM data_type
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
...@@ -169,11 +174,11 @@ retrieveOverridesBody: BEGIN ...@@ -169,11 +174,11 @@ retrieveOverridesBody: BEGIN
NULL AS name_override, NULL AS name_override,
NULL AS desc_override, NULL AS desc_override,
NULL AS type_override, NULL AS type_override,
entity_id, EntityID AS entity_id,
property_id ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS property_id
FROM collection_type FROM collection_type
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID; AND entity_id = InternalEntityID;
END; END;
......
...@@ -59,16 +59,19 @@ retrieveEntityParentsBody: BEGIN ...@@ -59,16 +59,19 @@ retrieveEntityParentsBody: BEGIN
DECLARE IVersion INT UNSIGNED DEFAULT NULL; DECLARE IVersion INT UNSIGNED DEFAULT NULL;
DECLARE IsHead BOOLEAN DEFAULT TRUE; 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 is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
IF Version IS NOT NULL THEN IF Version IS NOT NULL THEN
SELECT get_head_version(EntityID) = Version INTO IsHead; SELECT get_head_version(InternalEntityID) = Version INTO IsHead;
END IF; END IF;
IF IsHead IS FALSE THEN IF IsHead IS FALSE THEN
SELECT e._iversion INTO IVersion SELECT e._iversion INTO IVersion
FROM entity_version as e FROM entity_version as e
WHERE e.entity_id = EntityID WHERE e.entity_id = InternalEntityID
AND e.version = Version; AND e.version = Version;
IF IVersion IS NULL THEN IF IVersion IS NULL THEN
...@@ -77,10 +80,10 @@ retrieveEntityParentsBody: BEGIN ...@@ -77,10 +80,10 @@ retrieveEntityParentsBody: BEGIN
END IF; END IF;
SELECT SELECT
i.parent AS ParentID, ( SELECT id FROM entity_ids WHERE internal_id = i.parent) AS ParentID,
( SELECT value FROM name_data ( SELECT value FROM name_data
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_id = ParentID AND entity_id = i.parent
AND property_id = 20 AND property_id = 20
) AS ParentName, -- This is not necessarily the name of the parent at the time of ) 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 -- IVersion but it is a good guess. Future implementations of the
...@@ -92,7 +95,8 @@ retrieveEntityParentsBody: BEGIN ...@@ -92,7 +95,8 @@ retrieveEntityParentsBody: BEGIN
(SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL (SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL
FROM archive_isa AS i JOIN entities AS e FROM archive_isa AS i JOIN entities AS e
ON (i.parent = e.id) ON (i.parent = e.id)
WHERE i.child = EntityID WHERE i.child = InternalEntityID
AND i.rpath = InternalEntityID
AND i.child_iversion = IVersion AND i.child_iversion = IVersion
AND i.direct IS TRUE AND i.direct IS TRUE
; ;
...@@ -102,18 +106,18 @@ retrieveEntityParentsBody: BEGIN ...@@ -102,18 +106,18 @@ retrieveEntityParentsBody: BEGIN
END IF; END IF;
SELECT SELECT
i.parent AS ParentID, ( SELECT id FROM entity_ids WHERE internal_id = i.parent) AS ParentID,
( SELECT value FROM name_data ( SELECT value FROM name_data
WHERE domain_id = 0 WHERE domain_id = 0
AND entity_id = ParentID AND entity_id = i.parent
AND property_id = 20 ) AS ParentName, AND property_id = 20 ) AS ParentName,
e.description AS ParentDescription, e.description AS ParentDescription,
e.role AS ParentRole, e.role AS ParentRole,
(SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL (SELECT acl FROM entity_acl AS a WHERE a.id = e.acl) AS ACL
FROM isa_cache AS i JOIN entities AS e FROM isa_cache AS i JOIN entities AS e
ON (i.parent = e.id) ON (i.parent = e.id)
WHERE i.child = EntityID WHERE i.child = InternalEntityID
AND i.rpath = EntityID; AND i.rpath = InternalEntityID;
END END
// //
......
...@@ -36,22 +36,26 @@ retrieveEntityPropertiesBody: BEGIN ...@@ -36,22 +36,26 @@ retrieveEntityPropertiesBody: BEGIN
DECLARE IVersion INT UNSIGNED DEFAULT NULL; DECLARE IVersion INT UNSIGNED DEFAULT NULL;
DECLARE IsHead BOOLEAN DEFAULT TRUE; DECLARE IsHead BOOLEAN DEFAULT TRUE;
DECLARE InternalEntityID INT UNSIGNED DEFAULT NULL;
DECLARE InternalDomainID INT UNSIGNED DEFAULT 0;
SELECT internal_id INTO InternalEntityID from entity_ids WHERE id = EntityID;
SELECT internal_id INTO InternalDomainID from entity_ids WHERE id = DomainID;
IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN IF is_feature_config("ENTITY_VERSIONING", "ENABLED") THEN
IF Version IS NOT NULL THEN IF Version IS NOT NULL THEN
IF DomainID = 0 THEN IF InternalDomainID = 0 THEN
SELECT get_head_version(EntityID) = Version INTO IsHead; SELECT get_head_version(InternalEntityID) = Version INTO IsHead;
ELSE ELSE
SELECT get_head_version(DomainID) = Version INTO IsHead; SELECT get_head_version(InternalDomainID) = Version INTO IsHead;
END IF; END IF;
END IF; END IF;
IF IsHead IS FALSE THEN IF IsHead IS FALSE THEN
SELECT e._iversion INTO IVersion SELECT e._iversion INTO IVersion
FROM entity_version as e FROM entity_version as e
WHERE ((e.entity_id = EntityID AND DomainID = 0) WHERE ((e.entity_id = InternalEntityID AND InternalDomainID = 0)
OR (e.entity_id = DomainID)) OR (e.entity_id = InternalDomainID))
AND e.version = Version; AND e.version = Version;
IF IVersion IS NULL THEN IF IVersion IS NULL THEN
...@@ -61,121 +65,124 @@ retrieveEntityPropertiesBody: BEGIN ...@@ -61,121 +65,124 @@ retrieveEntityPropertiesBody: BEGIN
#-- double properties #-- double properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_double_data FROM archive_double_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
#-- integer properties #-- integer properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_integer_data FROM archive_integer_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
#-- date properties #-- date properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
CONCAT(value, '.NULL.NULL') AS PropertyValue, CONCAT(value, '.NULL.NULL') AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_date_data FROM archive_date_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
#-- datetime properties #-- datetime properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
CONCAT(value, 'UTC', IF(value_ns IS NULL, '', value_ns)) CONCAT(value, 'UTC', IF(value_ns IS NULL, '', value_ns))
AS PropertyValue, AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_datetime_data FROM archive_datetime_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
#-- text properties #-- text properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_text_data FROM archive_text_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
#-- enum properties #-- enum properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_enum_data FROM archive_enum_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
#-- reference properties #-- reference properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
IF(value_iversion IS NULL, value, IF(value_iversion IS NULL,
( SELECT id FROM entity_ids WHERE internal_id = value ),
-- make it "value@version" if necessary -- 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, AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_reference_data FROM archive_reference_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
#-- null properties #-- null properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
NULL AS PropertyValue, NULL AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_null_data FROM archive_null_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND _iversion = IVersion AND _iversion = IVersion
UNION ALL UNION ALL
#-- name properties #-- name properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM archive_name_data FROM archive_name_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND property_id != 20 AND property_id != 20
AND _iversion = IVersion; AND _iversion = IVersion;
...@@ -185,115 +192,118 @@ retrieveEntityPropertiesBody: BEGIN ...@@ -185,115 +192,118 @@ retrieveEntityPropertiesBody: BEGIN
#-- double properties #-- double properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM double_data FROM double_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
#-- integer properties #-- integer properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM integer_data FROM integer_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
#-- date properties #-- date properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
CONCAT(value, '.NULL.NULL') AS PropertyValue, CONCAT(value, '.NULL.NULL') AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM date_data FROM date_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
#-- datetime properties #-- datetime properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
CONCAT(value, 'UTC', IF(value_ns IS NULL, '', value_ns)) CONCAT(value, 'UTC', IF(value_ns IS NULL, '', value_ns))
AS PropertyValue, AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM datetime_data FROM datetime_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
#-- text properties #-- text properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM text_data FROM text_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
#-- enum properties #-- enum properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM enum_data FROM enum_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
#-- reference properties #-- reference properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
IF(value_iversion IS NULL, value, IF(value_iversion IS NULL,
CONCAT(value, "@", _get_version(value, value_iversion))) ( 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, AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM reference_data FROM reference_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
#-- null properties #-- null properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
NULL AS PropertyValue, NULL AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM null_data FROM null_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
UNION ALL UNION ALL
#-- name properties #-- name properties
SELECT SELECT
property_id AS PropertyID, ( SELECT id FROM entity_ids WHERE internal_id = property_id ) AS PropertyID,
value AS PropertyValue, value AS PropertyValue,
status AS PropertyStatus, status AS PropertyStatus,
pidx AS PropertyIndex pidx AS PropertyIndex
FROM name_data FROM name_data
WHERE domain_id = DomainID WHERE domain_id = InternalDomainID
AND entity_id = EntityID AND entity_id = InternalEntityID
AND property_id != 20; AND property_id != 20;
END; 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;
/*
* ** 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
*/
DELIMITER //
DROP PROCEDURE IF EXISTS db_5_0.retrieveSubEntity //
/**
CREATE PROCEDURE db_5_0.retrieveSubEntity(in EntityID INT UNSIGNED, in DomainID INT UNSIGNED)
BEGIN
DECLARE FilePath VARCHAR(255) DEFAULT NULL;
DECLARE FileSize VARCHAR(255) DEFAULT NULL;
DECLARE FileHash VARCHAR(255) DEFAULT NULL;
Select path, size, hex(hash) into FilePath, FileSize, FileHash from files where file_id = EntityID LIMIT 1;
Select DomainID as DomainID,
EntityID as EntityID,
e.name as EntityName,
e.description as EntityDesc,
e.role as EntityRole,
FileSize as FileSize,
FilePath as FilePath,
FileHash as FileHash
from entities e where id = EntityID LIMIT 1;
END;
//
**/
DELIMITER ;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment