diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/FlowNodeInstanceTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/FlowNodeInstanceTest.java index c9b3c15c78..8565a58554 100755 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/FlowNodeInstanceTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/core/process/instance/model/FlowNodeInstanceTest.java @@ -44,9 +44,8 @@ import org.bonitasoft.engine.core.process.instance.model.event.SStartEventInstance; import org.bonitasoft.engine.core.process.instance.model.event.trigger.STimerEventTriggerInstance; import org.bonitasoft.engine.persistence.PersistentObject; -import org.bonitasoft.engine.persistence.PersistentObjectId; +import org.bonitasoft.engine.persistence.PlatformPersistentObject; import org.bonitasoft.engine.persistence.QueryOptions; -import org.bonitasoft.engine.test.persistence.builder.PersistentObjectBuilder; import org.bonitasoft.engine.test.persistence.repository.FlowNodeInstanceRepository; import org.junit.Before; import org.junit.Test; @@ -116,10 +115,10 @@ public void getFlowNodeInstanceIdsToRecover_should_return_ids_of_flow_nodes_that repository .add(aUserTask().withName("normalTask1").withStateExecuting(false).withStable(true).withTerminal(false) .build()); - final SFlowNodeInstance executing = repository + repository .add(aUserTask().withName("executingTask").withStateExecuting(true).withStable(true).withTerminal(false) .build()); - final SFlowNodeInstance notStable = repository.add( + repository.add( aUserTask().withName("notStableTask").withStateExecuting(false).withStable(false).withTerminal(true) .build()); final SFlowNodeInstance terminal = repository @@ -154,9 +153,7 @@ public void getFlowNodeInstanceIdsToRecover_should_return_ids_of_flow_nodes_that // then assertThat(nodeToRestart.stream() .map(id -> repository.getSession() - .get(SFlowNodeInstance.class, - new PersistentObjectId(id, PersistentObjectBuilder.DEFAULT_TENANT_ID)) - .getName())) + .get(SFlowNodeInstance.class, id).getName())) .containsOnly("executingTask", "notStableTask", "terminalTask", "abortingBoundary", "cancellingBoundary"); } @@ -186,8 +183,7 @@ public void getGatewayInstanceIdsToRecover_should_return_ids_of_gateways_flagged // then assertThat(nodeToRestart.stream() - .map(id -> (repository.getSession().get(SFlowNodeInstance.class, - new PersistentObjectId(id, PersistentObjectBuilder.DEFAULT_TENANT_ID))).getName())) + .map(id -> (repository.getSession().get(SFlowNodeInstance.class, id)).getName())) .containsOnly( "gateway_initializing_but_finished", "gateway_completed", @@ -215,8 +211,7 @@ public void getGatewayInstanceIdsToRecover_should_return_ids_of_gateways_flagged // then assertThat(nodeToRestart.stream() - .map(id -> (repository.getSession().get(SFlowNodeInstance.class, - new PersistentObjectId(id, PersistentObjectBuilder.DEFAULT_TENANT_ID))).getName())) + .map(id -> (repository.getSession().get(SFlowNodeInstance.class, id)).getName())) .containsOnly( "gateway_completed", "gateway_aborting"); @@ -681,7 +676,7 @@ public void should_getAllChildrenOfProcessInstance() { public void should_have_loopCounter_on_loop_Activity() { // Given final SLoopActivityInstance sLoopActivityInstance = (SLoopActivityInstance) repository - .add(aLoopActivity().withLoopCounter(6).build()); + .add((PlatformPersistentObject) aLoopActivity().withLoopCounter(6).build()); repository.flush(); final int loopCounter = jdbcTemplate.queryForObject("select loop_counter from flownode_instance", Integer.class); diff --git a/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/SFlowNodeInstance.java b/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/SFlowNodeInstance.java index 5f9fd14919..0c3137444b 100644 --- a/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/SFlowNodeInstance.java +++ b/bpm/bonita-core/bonita-process-instance/src/main/java/org/bonitasoft/engine/core/process/instance/model/SFlowNodeInstance.java @@ -15,13 +15,20 @@ import java.util.Date; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.DiscriminatorColumn; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; import lombok.Data; import lombok.NoArgsConstructor; import org.bonitasoft.engine.core.process.definition.model.SFlowNodeType; -import org.bonitasoft.engine.persistence.PersistentObject; -import org.bonitasoft.engine.persistence.PersistentObjectId; +import org.bonitasoft.engine.persistence.PlatformPersistentObject; /** * @author Feng Hui @@ -33,15 +40,12 @@ @NoArgsConstructor @Entity @Table(name = "flownode_instance") -@IdClass(PersistentObjectId.class) @DiscriminatorColumn(name = "kind") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) -public abstract class SFlowNodeInstance implements PersistentObject { +public abstract class SFlowNodeInstance implements PlatformPersistentObject { @Id private long id; - @Id - private long tenantId; private long flowNodeDefinitionId; private long rootContainerId; private long parentContainerId; 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 ea38d8d759..9a3ce6246e 100644 --- a/platform/platform-resources/src/main/resources/sql/h2/createTables.sql +++ b/platform/platform-resources/src/main/resources/sql/h2/createTables.sql @@ -296,7 +296,6 @@ CREATE TABLE process_instance ( CREATE INDEX idx1_proc_inst_pdef_state ON process_instance (processdefinitionid, stateid); CREATE TABLE flownode_instance ( - tenantid BIGINT NOT NULL, id BIGINT NOT NULL, flownodeDefinitionId BIGINT NOT NULL, kind VARCHAR(25) NOT NULL, @@ -344,7 +343,7 @@ CREATE TABLE flownode_instance ( triggeredByEvent BOOLEAN, interrupting BOOLEAN, tokenCount INT NOT NULL, - PRIMARY KEY (tenantid, id) + PRIMARY KEY (id) ); CREATE INDEX idx_fni_rootcontid ON flownode_instance (rootContainerId); CREATE INDEX idx_fni_loggroup4 ON flownode_instance (logicalGroup4); @@ -456,7 +455,7 @@ CREATE INDEX idx_biz_data_inst3 ON ref_biz_data_inst (proc_inst_id); ALTER TABLE ref_biz_data_inst ADD CONSTRAINT pk_ref_biz_data_inst PRIMARY KEY (tenantid, id); ALTER TABLE ref_biz_data_inst ADD CONSTRAINT fk_ref_biz_data_proc FOREIGN KEY (proc_inst_id) REFERENCES process_instance(id) ON DELETE CASCADE; -ALTER TABLE ref_biz_data_inst ADD CONSTRAINT fk_ref_biz_data_fn FOREIGN KEY (tenantid, fn_inst_id) REFERENCES flownode_instance(tenantid, id) ON DELETE CASCADE; +ALTER TABLE ref_biz_data_inst ADD CONSTRAINT fk_ref_biz_data_fn FOREIGN KEY (fn_inst_id) REFERENCES flownode_instance(id) ON DELETE CASCADE; CREATE TABLE multi_biz_data ( tenantid BIGINT NOT NULL, 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 3bea5b65b2..ab897f50f7 100644 --- a/platform/platform-resources/src/main/resources/sql/h2/postCreateStructure.sql +++ b/platform/platform-resources/src/main/resources/sql/h2/postCreateStructure.sql @@ -15,7 +15,6 @@ ALTER TABLE document_mapping ADD CONSTRAINT fk_document_mapping_tenantId FOREIGN 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 external_identity_mapping ADD CONSTRAINT fk_external_identity_mapping_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); -ALTER TABLE flownode_instance ADD CONSTRAINT fk_flownode_instance_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE group_ ADD CONSTRAINT fk_group__tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE job_desc ADD CONSTRAINT fk_job_desc_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE job_param ADD CONSTRAINT fk_job_param_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); @@ -23,7 +22,7 @@ ALTER TABLE message_instance ADD CONSTRAINT fk_message_instance_tenantId FOREIGN ALTER TABLE custom_usr_inf_def ADD CONSTRAINT fk_custom_usr_inf_def_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE custom_usr_inf_val ADD CONSTRAINT fk_custom_usr_inf_val_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 (tenantid, activityId) REFERENCES flownode_instance(tenantid, id); +ALTER TABLE pending_mapping ADD CONSTRAINT fk_pending_mapping_flownode_instanceId FOREIGN KEY (activityId) REFERENCES flownode_instance(id); ALTER TABLE processcategorymapping ADD CONSTRAINT fk_processcategorymapping_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE process_comment ADD CONSTRAINT fk_process_comment_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE process_definition ADD CONSTRAINT fk_process_definition_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 f89f58aaec..397107817c 100644 --- a/platform/platform-resources/src/main/resources/sql/h2/preDropStructure.sql +++ b/platform/platform-resources/src/main/resources/sql/h2/preDropStructure.sql @@ -15,7 +15,6 @@ 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 external_identity_mapping DROP CONSTRAINT fk_external_identity_mapping_tenantId; -ALTER TABLE flownode_instance DROP CONSTRAINT fk_flownode_instance_tenantId; ALTER TABLE group_ DROP CONSTRAINT fk_group__tenantId; ALTER TABLE job_desc DROP CONSTRAINT fk_job_desc_tenantId; ALTER TABLE job_param DROP CONSTRAINT fk_job_param_tenantId; 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 1ab435397e..5ba2c61ab5 100644 --- a/platform/platform-resources/src/main/resources/sql/postgres/createTables.sql +++ b/platform/platform-resources/src/main/resources/sql/postgres/createTables.sql @@ -298,7 +298,6 @@ CREATE TABLE process_instance ( CREATE INDEX idx1_proc_inst_pdef_state ON process_instance (processdefinitionid, stateid); CREATE TABLE flownode_instance ( - tenantid INT8 NOT NULL, id INT8 NOT NULL, flownodeDefinitionId INT8 NOT NULL, kind VARCHAR(25) NOT NULL, @@ -346,7 +345,7 @@ CREATE TABLE flownode_instance ( triggeredByEvent BOOLEAN, interrupting BOOLEAN, tokenCount INT NOT NULL, - PRIMARY KEY (tenantid, id) + PRIMARY KEY (id) ); CREATE INDEX idx_fni_rootcontid ON flownode_instance (rootContainerId); CREATE INDEX idx_fni_loggroup4 ON flownode_instance (logicalGroup4); @@ -457,7 +456,7 @@ CREATE INDEX idx_biz_data_inst2 ON ref_biz_data_inst (fn_inst_id); CREATE INDEX idx_biz_data_inst3 ON ref_biz_data_inst (proc_inst_id); ALTER TABLE ref_biz_data_inst ADD CONSTRAINT pk_ref_biz_data_inst PRIMARY KEY (tenantid, id); ALTER TABLE ref_biz_data_inst ADD CONSTRAINT fk_ref_biz_data_proc FOREIGN KEY (proc_inst_id) REFERENCES process_instance(id) ON DELETE CASCADE; -ALTER TABLE ref_biz_data_inst ADD CONSTRAINT fk_ref_biz_data_fn FOREIGN KEY (tenantid, fn_inst_id) REFERENCES flownode_instance(tenantid, id) ON DELETE CASCADE; +ALTER TABLE ref_biz_data_inst ADD CONSTRAINT fk_ref_biz_data_fn FOREIGN KEY (fn_inst_id) REFERENCES flownode_instance(id) ON DELETE CASCADE; CREATE TABLE multi_biz_data ( tenantid INT8 NOT NULL, 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 9b9c721bbc..3ac99dab12 100644 --- a/platform/platform-resources/src/main/resources/sql/postgres/postCreateStructure.sql +++ b/platform/platform-resources/src/main/resources/sql/postgres/postCreateStructure.sql @@ -15,7 +15,6 @@ ALTER TABLE document_mapping ADD CONSTRAINT fk_document_mapping_tenantId FOREIGN 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 external_identity_mapping ADD CONSTRAINT fk_external_identity_mapping_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); -ALTER TABLE flownode_instance ADD CONSTRAINT fk_flownode_instance_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE group_ ADD CONSTRAINT fk_group__tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE job_desc ADD CONSTRAINT fk_job_desc_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE job_param ADD CONSTRAINT fk_job_param_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); @@ -23,7 +22,7 @@ ALTER TABLE message_instance ADD CONSTRAINT fk_message_instance_tenantId FOREIGN ALTER TABLE custom_usr_inf_def ADD CONSTRAINT fk_custom_usr_inf_def_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE custom_usr_inf_val ADD CONSTRAINT fk_custom_usr_inf_val_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 (tenantid, activityId) REFERENCES flownode_instance(tenantid, id); +ALTER TABLE pending_mapping ADD CONSTRAINT fk_pending_mapping_flownode_instanceId FOREIGN KEY (activityId) REFERENCES flownode_instance(id); ALTER TABLE processcategorymapping ADD CONSTRAINT fk_processcategorymapping_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE process_comment ADD CONSTRAINT fk_process_comment_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id); ALTER TABLE process_definition ADD CONSTRAINT fk_process_definition_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 42c4c631a3..11f799b784 100644 --- a/platform/platform-resources/src/main/resources/sql/postgres/preDropStructure.sql +++ b/platform/platform-resources/src/main/resources/sql/postgres/preDropStructure.sql @@ -15,7 +15,6 @@ 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 external_identity_mapping DROP CONSTRAINT fk_external_identity_mapping_tenantId; -ALTER TABLE flownode_instance DROP CONSTRAINT fk_flownode_instance_tenantId; ALTER TABLE group_ DROP CONSTRAINT fk_group__tenantId; ALTER TABLE job_desc DROP CONSTRAINT fk_job_desc_tenantId; ALTER TABLE job_param DROP CONSTRAINT fk_job_param_tenantId;