61 lines
1.7 KiB
SQL
61 lines
1.7 KiB
SQL
DROP PROCEDURE IF EXISTS mocha_create_instance_of;
|
|
|
|
CREATE PROCEDURE mocha_create_instance_of
|
|
(
|
|
IN p_tenant_id INT,
|
|
IN p_class_index INT,
|
|
IN p_global_identifier CHAR(32), -- the desired global identifier for the newly created instance
|
|
IN p_user_inst_id INT,
|
|
IN p_effective_date DATETIME
|
|
)
|
|
BEGIN
|
|
|
|
DECLARE next_inst_id INT;
|
|
DECLARE z_global_identifier CHAR(32);
|
|
DECLARE z_effective_date DATETIME;
|
|
|
|
SET next_inst_id=mocha_get_next_inst_id(p_class_index);
|
|
|
|
IF p_effective_date IS NULL THEN
|
|
SET z_effective_date = NOW();
|
|
ELSE
|
|
SET z_effective_date = p_effective_date;
|
|
END IF;
|
|
|
|
IF p_global_identifier IS NULL THEN
|
|
SET z_global_identifier=mocha_uuid_v4();
|
|
ELSE
|
|
SET z_global_identifier=p_global_identifier;
|
|
END IF;
|
|
|
|
-- insert record first
|
|
INSERT INTO mocha_instances
|
|
(tenant_id, class_id, inst_id, global_identifier)
|
|
VALUES
|
|
(p_tenant_id, p_class_index, next_inst_id, z_global_identifier);
|
|
|
|
SELECT LAST_INSERT_ID();
|
|
|
|
-- then update relationship: Class.has Instance
|
|
CALL mocha_assign_relationship
|
|
(
|
|
p_tenant_id,
|
|
mocha_get_instance_by_key(1, p_class_index),
|
|
mocha_get_instance_by_global_identifier('7EB41D3C2AE9488483A4E59441BCAEFB'),
|
|
mocha_get_instance_by_key(p_class_index, next_inst_id),
|
|
p_user_inst_id,
|
|
z_effective_date
|
|
);
|
|
-- then update relationship: Instance.for Class
|
|
CALL mocha_assign_relationship
|
|
(
|
|
p_tenant_id,
|
|
mocha_get_instance_by_key(p_class_index, next_inst_id),
|
|
mocha_get_instance_by_global_identifier('494D5A6D04BE477B8763E3F57D0DD8C8'),
|
|
mocha_get_instance_by_key(1, p_class_index),
|
|
p_user_inst_id,
|
|
z_effective_date
|
|
);
|
|
|
|
END;
|