Skip to content

Commit

Permalink
chore(MTR): remove tenantId from SFlownodeInstance (#3281)
Browse files Browse the repository at this point in the history
MTR = Multi-tenancy removal

Relates to https://bonitasoft.atlassian.net/browse/PROD-379
  • Loading branch information
educhastenier authored Dec 16, 2024
1 parent 346ef4f commit 8641831
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ 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);
ALTER TABLE message_instance ADD CONSTRAINT fk_message_instance_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id);
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ 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);
ALTER TABLE message_instance ADD CONSTRAINT fk_message_instance_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id);
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8641831

Please sign in to comment.