From 68d2e733cc306ea89eb6dd76e8f5b48b2b04dcc9 Mon Sep 17 00:00:00 2001 From: "emmanuel.duchastenier@bonitasoft.com" Date: Mon, 20 Jan 2025 15:37:42 +0100 Subject: [PATCH] feat(MTR): remove tenantid from message/event/trigger (#3323) Multi-tenancy removal for tables: * event_trigger_instance * waiting_event * message_instance relates to https://bonitasoft.atlassian.net/browse/BPM-347 --- .../model/event/handling/SMessageEventCouple.java | 10 ++-------- .../model/event/handling/SMessageInstance.java | 12 +++++------- .../model/event/handling/SWaitingEvent.java | 15 ++++++++------- .../event/trigger/STimerEventTriggerInstance.java | 12 +++++------- .../src/main/resources/sql/h2/createTables.sql | 9 +++------ .../main/resources/sql/h2/postCreateStructure.sql | 3 --- .../main/resources/sql/h2/preDropStructure.sql | 3 --- .../main/resources/sql/postgres/createTables.sql | 9 +++------ .../sql/postgres/postCreateStructure.sql | 3 --- .../resources/sql/postgres/preDropStructure.sql | 3 --- 10 files changed, 26 insertions(+), 53 deletions(-) diff --git a/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/event/handling/SMessageEventCouple.java b/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/event/handling/SMessageEventCouple.java index 02aadc1b4dd..cc39f18d702 100644 --- a/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/event/handling/SMessageEventCouple.java +++ b/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/event/handling/SMessageEventCouple.java @@ -15,14 +15,14 @@ import lombok.Data; import lombok.NoArgsConstructor; -import org.bonitasoft.engine.persistence.PersistentObject; +import org.bonitasoft.engine.persistence.PlatformPersistentObject; /** * @author Elias Ricken de Medeiros */ @Data @NoArgsConstructor -public class SMessageEventCouple implements PersistentObject { +public class SMessageEventCouple implements PlatformPersistentObject { private long waitingMessageId; private SBPMEventType waitingMessageEventType; @@ -44,10 +44,4 @@ public long getId() { public void setId(final long id) { throw new IllegalArgumentException(); } - - @Override - public void setTenantId(final long id) { - throw new IllegalArgumentException(); - } - } diff --git a/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/event/handling/SMessageInstance.java b/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/event/handling/SMessageInstance.java index 314204fb423..aef0bcf5493 100644 --- a/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/event/handling/SMessageInstance.java +++ b/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/event/handling/SMessageInstance.java @@ -13,12 +13,13 @@ **/ package org.bonitasoft.engine.core.process.instance.model.event.handling; -import javax.persistence.*; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; import lombok.Data; import lombok.NoArgsConstructor; -import org.bonitasoft.engine.persistence.PersistentObject; -import org.bonitasoft.engine.persistence.PersistentObjectId; +import org.bonitasoft.engine.persistence.PlatformPersistentObject; /** * @author Elias Ricken de Medeiros @@ -26,14 +27,11 @@ @Data @NoArgsConstructor @Entity -@IdClass(PersistentObjectId.class) @Table(name = "message_instance") -public class SMessageInstance implements PersistentObject { +public class SMessageInstance implements PlatformPersistentObject { @Id private long id; - @Id - private long tenantId; private String messageName; private String targetProcess; private String targetFlowNode; diff --git a/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/event/handling/SWaitingEvent.java b/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/event/handling/SWaitingEvent.java index 0f019e11df6..35d74b21429 100644 --- a/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/event/handling/SWaitingEvent.java +++ b/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/event/handling/SWaitingEvent.java @@ -13,14 +13,18 @@ **/ package org.bonitasoft.engine.core.process.instance.model.event.handling; -import javax.persistence.*; +import javax.persistence.DiscriminatorColumn; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.Id; +import javax.persistence.Table; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import org.bonitasoft.engine.core.process.definition.model.event.trigger.SEventTriggerType; -import org.bonitasoft.engine.persistence.PersistentObject; -import org.bonitasoft.engine.persistence.PersistentObjectId; +import org.bonitasoft.engine.persistence.PlatformPersistentObject; /** * @author Zhao Na @@ -31,15 +35,12 @@ @NoArgsConstructor @AllArgsConstructor @Entity -@IdClass(PersistentObjectId.class) @Table(name = "waiting_event") @DiscriminatorColumn(name = "kind") -public abstract class SWaitingEvent implements PersistentObject { +public abstract class SWaitingEvent implements PlatformPersistentObject { @Id private long id; - @Id - private long tenantId; @Enumerated(EnumType.STRING) private SBPMEventType eventType; private String processName; diff --git a/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/event/trigger/STimerEventTriggerInstance.java b/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/event/trigger/STimerEventTriggerInstance.java index df5283001d2..01ff7542123 100644 --- a/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/event/trigger/STimerEventTriggerInstance.java +++ b/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/event/trigger/STimerEventTriggerInstance.java @@ -13,12 +13,13 @@ **/ package org.bonitasoft.engine.core.process.instance.model.event.trigger; -import javax.persistence.*; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; import lombok.Data; import lombok.NoArgsConstructor; -import org.bonitasoft.engine.persistence.PersistentObject; -import org.bonitasoft.engine.persistence.PersistentObjectId; +import org.bonitasoft.engine.persistence.PlatformPersistentObject; /** * @author Elias Ricken de Medeiros @@ -26,16 +27,13 @@ @Data @NoArgsConstructor @Entity -@IdClass(PersistentObjectId.class) @Table(name = "event_trigger_instance") -public class STimerEventTriggerInstance implements PersistentObject { +public class STimerEventTriggerInstance implements PlatformPersistentObject { public static final String EXECUTION_DATE = "executionDate"; @Id private long id; - @Id - private long tenantId; private long eventInstanceId; /** diff --git a/platform/platform-resources/src/main/resources/sql/h2/createTables.sql b/platform/platform-resources/src/main/resources/sql/h2/createTables.sql index 6c8ce27bf3c..8d90a9ee3ec 100644 --- a/platform/platform-resources/src/main/resources/sql/h2/createTables.sql +++ b/platform/platform-resources/src/main/resources/sql/h2/createTables.sql @@ -360,17 +360,15 @@ CREATE TABLE connector_instance ( CREATE INDEX idx_ci_container_activation ON connector_instance (containerId, containerType, activationEvent); CREATE TABLE event_trigger_instance ( - tenantid BIGINT NOT NULL, id BIGINT NOT NULL, eventInstanceId BIGINT NOT NULL, eventInstanceName VARCHAR(50), executionDate BIGINT, jobTriggerName VARCHAR(255), - PRIMARY KEY (tenantid, id) + CONSTRAINT pk_event_trigger_instance PRIMARY KEY (id) ); CREATE TABLE waiting_event ( - tenantid BIGINT NOT NULL, id BIGINT NOT NULL, kind VARCHAR(15) NOT NULL, eventType VARCHAR(50), @@ -394,13 +392,12 @@ CREATE TABLE waiting_event ( correlation3 VARCHAR(128), correlation4 VARCHAR(128), correlation5 VARCHAR(128), - PRIMARY KEY (tenantid, id) + CONSTRAINT pk_waiting_event PRIMARY KEY (id) ); CREATE INDEX idx_waiting_event ON waiting_event (progress, kind, locked, active); CREATE INDEX idx_waiting_event_correl ON waiting_event (correlation1, correlation2, correlation3, correlation4, correlation5); CREATE TABLE message_instance ( - tenantid BIGINT NOT NULL, id BIGINT NOT NULL, messageName VARCHAR(255) NOT NULL, targetProcess VARCHAR(255) NOT NULL, @@ -415,7 +412,7 @@ CREATE TABLE message_instance ( correlation4 VARCHAR(128), correlation5 VARCHAR(128), creationDate BIGINT NOT NULL, - PRIMARY KEY (tenantid, id) + CONSTRAINT pk_message_instance PRIMARY KEY (id) ); CREATE INDEX idx_message_instance ON message_instance (messageName, targetProcess, correlation1, correlation2, correlation3); CREATE INDEX idx_message_instance_correl ON message_instance (correlation1, correlation2, correlation3, correlation4, correlation5); diff --git a/platform/platform-resources/src/main/resources/sql/h2/postCreateStructure.sql b/platform/platform-resources/src/main/resources/sql/h2/postCreateStructure.sql index c896e28aab5..e69b00b47ec 100644 --- a/platform/platform-resources/src/main/resources/sql/h2/postCreateStructure.sql +++ b/platform/platform-resources/src/main/resources/sql/h2/postCreateStructure.sql @@ -5,14 +5,11 @@ ALTER TABLE data_instance ADD CONSTRAINT fk_data_instance_tenantId FOREIGN KEY ( ALTER TABLE document ADD CONSTRAINT fk_document_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE document_mapping ADD CONSTRAINT fk_document_mapping_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE document_mapping ADD CONSTRAINT fk_docmap_docid FOREIGN KEY (tenantid, documentid) REFERENCES document(tenantid, id) ON DELETE CASCADE; -ALTER TABLE event_trigger_instance ADD CONSTRAINT fk_event_trigger_instance_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); -ALTER TABLE message_instance ADD CONSTRAINT fk_message_instance_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE pending_mapping ADD CONSTRAINT fk_pending_mapping_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE pending_mapping ADD CONSTRAINT fk_pending_mapping_flownode_instanceId FOREIGN KEY (activityId) REFERENCES flownode_instance(id); ALTER TABLE profilemember ADD CONSTRAINT fk_profilemember_tenantId FOREIGN KEY (tenantId) REFERENCES tenant(id); ALTER TABLE multi_biz_data ADD CONSTRAINT fk_multi_biz_data_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE ref_biz_data_inst ADD CONSTRAINT fk_ref_biz_data_inst_tenantId FOREIGN KEY (tenantId) REFERENCES tenant(id); -ALTER TABLE waiting_event ADD CONSTRAINT fk_waiting_event_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); -- ------------------------ Foreign Keys to disable if archiving is on another BD ------------------ ALTER TABLE arch_document_mapping ADD CONSTRAINT fk_arch_document_mapping_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); diff --git a/platform/platform-resources/src/main/resources/sql/h2/preDropStructure.sql b/platform/platform-resources/src/main/resources/sql/h2/preDropStructure.sql index 7b2690d32bf..dda89adbd5c 100644 --- a/platform/platform-resources/src/main/resources/sql/h2/preDropStructure.sql +++ b/platform/platform-resources/src/main/resources/sql/h2/preDropStructure.sql @@ -6,8 +6,6 @@ ALTER TABLE data_instance DROP CONSTRAINT fk_data_instance_tenantId; ALTER TABLE document DROP CONSTRAINT fk_document_tenantId; ALTER TABLE document_mapping DROP CONSTRAINT fk_document_mapping_tenantId; ALTER TABLE document_mapping DROP CONSTRAINT fk_docmap_docid; -ALTER TABLE event_trigger_instance DROP CONSTRAINT fk_event_trigger_instance_tenantId; -ALTER TABLE message_instance DROP CONSTRAINT fk_message_instance_tenantId; ALTER TABLE pending_mapping DROP CONSTRAINT fk_pending_mapping_tenantId; ALTER TABLE pending_mapping DROP CONSTRAINT fk_pending_mapping_flownode_instanceId; ALTER TABLE process_definition DROP CONSTRAINT fk_process_definition_content_id; @@ -15,7 +13,6 @@ ALTER TABLE profile DROP CONSTRAINT fk_profile_tenantId; ALTER TABLE profilemember DROP CONSTRAINT fk_profilemember_tenantId; ALTER TABLE multi_biz_data DROP CONSTRAINT fk_multi_biz_data_tenantId; ALTER TABLE ref_biz_data_inst DROP CONSTRAINT fk_ref_biz_data_inst_tenantId; -ALTER TABLE waiting_event DROP CONSTRAINT fk_waiting_event_tenantId; ALTER TABLE profilemember DROP CONSTRAINT fk_profilemember_profileid; diff --git a/platform/platform-resources/src/main/resources/sql/postgres/createTables.sql b/platform/platform-resources/src/main/resources/sql/postgres/createTables.sql index 2ff4af20a31..578dfb8eb2e 100644 --- a/platform/platform-resources/src/main/resources/sql/postgres/createTables.sql +++ b/platform/platform-resources/src/main/resources/sql/postgres/createTables.sql @@ -360,17 +360,15 @@ CREATE TABLE connector_instance ( CREATE INDEX idx_ci_container_activation ON connector_instance (containerId, containerType, activationEvent); CREATE TABLE event_trigger_instance ( - tenantid INT8 NOT NULL, id INT8 NOT NULL, eventInstanceId INT8 NOT NULL, eventInstanceName VARCHAR(50), executionDate INT8, jobTriggerName VARCHAR(255), - PRIMARY KEY (tenantid, id) + CONSTRAINT pk_event_trigger_instance PRIMARY KEY (id) ); CREATE TABLE waiting_event ( - tenantid INT8 NOT NULL, id INT8 NOT NULL, kind VARCHAR(15) NOT NULL, eventType VARCHAR(50), @@ -394,13 +392,12 @@ CREATE TABLE waiting_event ( correlation3 VARCHAR(128), correlation4 VARCHAR(128), correlation5 VARCHAR(128), - PRIMARY KEY (tenantid, id) + CONSTRAINT pk_waiting_event PRIMARY KEY (id) ); CREATE INDEX idx_waiting_event ON waiting_event (progress, kind, locked, active); CREATE INDEX idx_waiting_event_correl ON waiting_event (correlation1, correlation2, correlation3, correlation4, correlation5); CREATE TABLE message_instance ( - tenantid INT8 NOT NULL, id INT8 NOT NULL, messageName VARCHAR(255) NOT NULL, targetProcess VARCHAR(255) NOT NULL, @@ -415,7 +412,7 @@ CREATE TABLE message_instance ( correlation4 VARCHAR(128), correlation5 VARCHAR(128), creationDate INT8 NOT NULL, - PRIMARY KEY (tenantid, id) + CONSTRAINT pk_message_instance PRIMARY KEY (id) ); CREATE INDEX idx_message_instance ON message_instance (messageName, targetProcess, correlation1, correlation2, correlation3); CREATE INDEX idx_message_instance_correl ON message_instance (correlation1, correlation2, correlation3, correlation4, correlation5); diff --git a/platform/platform-resources/src/main/resources/sql/postgres/postCreateStructure.sql b/platform/platform-resources/src/main/resources/sql/postgres/postCreateStructure.sql index c896e28aab5..e69b00b47ec 100644 --- a/platform/platform-resources/src/main/resources/sql/postgres/postCreateStructure.sql +++ b/platform/platform-resources/src/main/resources/sql/postgres/postCreateStructure.sql @@ -5,14 +5,11 @@ ALTER TABLE data_instance ADD CONSTRAINT fk_data_instance_tenantId FOREIGN KEY ( ALTER TABLE document ADD CONSTRAINT fk_document_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE document_mapping ADD CONSTRAINT fk_document_mapping_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE document_mapping ADD CONSTRAINT fk_docmap_docid FOREIGN KEY (tenantid, documentid) REFERENCES document(tenantid, id) ON DELETE CASCADE; -ALTER TABLE event_trigger_instance ADD CONSTRAINT fk_event_trigger_instance_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); -ALTER TABLE message_instance ADD CONSTRAINT fk_message_instance_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE pending_mapping ADD CONSTRAINT fk_pending_mapping_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE pending_mapping ADD CONSTRAINT fk_pending_mapping_flownode_instanceId FOREIGN KEY (activityId) REFERENCES flownode_instance(id); ALTER TABLE profilemember ADD CONSTRAINT fk_profilemember_tenantId FOREIGN KEY (tenantId) REFERENCES tenant(id); ALTER TABLE multi_biz_data ADD CONSTRAINT fk_multi_biz_data_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE ref_biz_data_inst ADD CONSTRAINT fk_ref_biz_data_inst_tenantId FOREIGN KEY (tenantId) REFERENCES tenant(id); -ALTER TABLE waiting_event ADD CONSTRAINT fk_waiting_event_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); -- ------------------------ Foreign Keys to disable if archiving is on another BD ------------------ ALTER TABLE arch_document_mapping ADD CONSTRAINT fk_arch_document_mapping_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); diff --git a/platform/platform-resources/src/main/resources/sql/postgres/preDropStructure.sql b/platform/platform-resources/src/main/resources/sql/postgres/preDropStructure.sql index 4cd64f76110..5c20ee3ee02 100644 --- a/platform/platform-resources/src/main/resources/sql/postgres/preDropStructure.sql +++ b/platform/platform-resources/src/main/resources/sql/postgres/preDropStructure.sql @@ -6,8 +6,6 @@ ALTER TABLE data_instance DROP CONSTRAINT fk_data_instance_tenantId; ALTER TABLE document DROP CONSTRAINT fk_document_tenantId; ALTER TABLE document_mapping DROP CONSTRAINT fk_document_mapping_tenantId; ALTER TABLE document_mapping DROP CONSTRAINT fk_docmap_docid; -ALTER TABLE event_trigger_instance DROP CONSTRAINT fk_event_trigger_instance_tenantId; -ALTER TABLE message_instance DROP CONSTRAINT fk_message_instance_tenantId; ALTER TABLE pending_mapping DROP CONSTRAINT fk_pending_mapping_tenantId; ALTER TABLE pending_mapping DROP CONSTRAINT fk_pending_mapping_flownode_instanceId; ALTER TABLE process_definition DROP CONSTRAINT fk_process_definition_content_id; @@ -15,7 +13,6 @@ ALTER TABLE profile DROP CONSTRAINT fk_profile_tenantId; ALTER TABLE profilemember DROP CONSTRAINT fk_profilemember_tenantId; ALTER TABLE multi_biz_data DROP CONSTRAINT fk_multi_biz_data_tenantId; ALTER TABLE ref_biz_data_inst DROP CONSTRAINT fk_ref_biz_data_inst_tenantId; -ALTER TABLE waiting_event DROP CONSTRAINT fk_waiting_event_tenantId; ALTER TABLE profilemember DROP CONSTRAINT fk_profilemember_profileid;