提交 071acf3c 编写于 作者: J Joram Barrez

ACT-1890: Multi tenancy support: historic entities

上级 a99b225c
......@@ -61,4 +61,7 @@ public interface HistoricActivityInstance {
/** Difference between {@link #getEndTime()} and {@link #getStartTime()}. */
Long getDurationInMillis();
/** Returns the tenant identifier for the historic activity */
String getTenantId();
}
......@@ -20,6 +20,7 @@ import org.activiti.engine.query.Query;
* Programmatic querying for {@link HistoricActivityInstance}s.
*
* @author Tom Baeyens
* @author Joram Barrez
*/
public interface HistoricActivityInstanceQuery extends Query<HistoricActivityInstanceQuery, HistoricActivityInstance>{
......@@ -53,6 +54,16 @@ public interface HistoricActivityInstanceQuery extends Query<HistoricActivityIns
/** Only select historic activity instances that are not finished yet. */
HistoricActivityInstanceQuery unfinished();
/** Only select historic activity instances that have the given tenant id. */
HistoricActivityInstanceQuery activityTenantId(String tenantId);
/** Only select historic activity instances with a tenant id like the given one. */
HistoricActivityInstanceQuery activityTenantIdLike(String tenantIdLike);
/** Only select historic activity instances that do not have a tenant id. */
HistoricActivityInstanceQuery activityWithoutTenantId();
// ordering /////////////////////////////////////////////////////////////////
/** Order by id (needs to be followed by {@link #asc()} or {@link #desc()}). */
......@@ -84,4 +95,8 @@ public interface HistoricActivityInstanceQuery extends Query<HistoricActivityIns
/** Order by processDefinitionId (needs to be followed by {@link #asc()} or {@link #desc()}). */
HistoricActivityInstanceQuery orderByProcessDefinitionId();
/** Order by tenant id (needs to be followed by {@link #asc()} or {@link #desc()}). */
HistoricActivityInstanceQuery orderByTenantId();
}
......@@ -67,6 +67,11 @@ public interface HistoricProcessInstance {
*/
String getSuperProcessInstanceId();
/**
* The tenant identifier for the process instance.
*/
String getTenantId();
/** Returns the process variables if requested in the process instance query */
Map<String, Object> getProcessVariables();
}
......@@ -157,6 +157,15 @@ public interface HistoricProcessInstanceQuery extends Query<HistoricProcessInsta
/** Only select historic process instance that are started by the given user. */
HistoricProcessInstanceQuery startedBy(String userId);
/** Only select process instances that have the given tenant id. */
HistoricProcessInstanceQuery processInstanceTenantId(String tenantId);
/** Only select process instances with a tenant id like the given one. */
HistoricProcessInstanceQuery processInstanceTenantIdLike(String tenantIdLike);
/** Only select process instances that do not have a tenant id. */
HistoricProcessInstanceQuery processInstanceWithoutTenantId();
/** Order by the process instance id (needs to be followed by {@link #asc()} or {@link #desc()}). */
HistoricProcessInstanceQuery orderByProcessInstanceId();
......@@ -176,6 +185,9 @@ public interface HistoricProcessInstanceQuery extends Query<HistoricProcessInsta
/** Order by the duration of the process instance (needs to be followed by {@link #asc()} or {@link #desc()}). */
HistoricProcessInstanceQuery orderByProcessInstanceDuration();
/** Order by tenant id (needs to be followed by {@link #asc()} or {@link #desc()}). */
HistoricProcessInstanceQuery orderByTenantId();
/** Only select historic process instances started by the given process
* instance. {@link ProcessInstance) ids and {@link HistoricProcessInstance}
* ids match. */
......
......@@ -87,6 +87,9 @@ public interface HistoricTaskInstance {
/** The parent task of this task, in case this task was a subtask */
String getParentTaskId();
/** Returns the tenant identifier for this historic task */
String getTenantId();
/** Returns the local task variables if requested in the task query */
Map<String, Object> getTaskLocalVariables();
......
......@@ -17,6 +17,7 @@ import java.io.Serializable;
import java.util.Date;
import java.util.List;
import org.activiti.engine.ActivitiIllegalArgumentException;
import org.activiti.engine.query.Query;
import org.activiti.engine.task.Task;
......@@ -25,6 +26,7 @@ import org.activiti.engine.task.Task;
* Allows programmatic querying for {@link HistoricTaskInstance}s.
*
* @author Tom Baeyens
* @author Joram Barrez
*/
public interface HistoricTaskInstanceQuery extends Query<HistoricTaskInstanceQuery, HistoricTaskInstance> {
......@@ -419,6 +421,15 @@ public interface HistoricTaskInstanceQuery extends Query<HistoricTaskInstanceQu
* (string%), ends with (%string) or contains (%string%). */
HistoricTaskInstanceQuery processVariableValueLike(String name, String value);
/** Only select tasks that have the given tenant id. */
HistoricTaskInstanceQuery taskTenantId(String tenantId);
/** Only select tasks with a tenant id like the given one. */
HistoricTaskInstanceQuery taskTenantIdLike(String tenantIdLike);
/** Only select tasks that do not have a tenant id. */
HistoricTaskInstanceQuery taskWithoutTenantId();
/**
* Include local task variables in the task query result
*/
......@@ -484,4 +495,8 @@ public interface HistoricTaskInstanceQuery extends Query<HistoricTaskInstanceQu
/** Order by task priority key (needs to be followed by {@link #asc()} or {@link #desc()}). */
HistoricTaskInstanceQuery orderByTaskPriority();
/** Order by tenant id (needs to be followed by {@link #asc()} or {@link #desc()}). */
HistoricTaskInstanceQuery orderByTenantId();
}
......@@ -15,6 +15,7 @@ package org.activiti.engine.impl;
import java.util.List;
import org.activiti.engine.ActivitiIllegalArgumentException;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricActivityInstanceQuery;
import org.activiti.engine.impl.interceptor.CommandContext;
......@@ -36,6 +37,9 @@ public class HistoricActivityInstanceQueryImpl extends AbstractQuery<HistoricAct
protected String activityName;
protected String activityType;
protected String assignee;
protected String tenantId;
protected String tenantIdLike;
protected boolean withoutTenantId;
protected boolean finished;
protected boolean unfinished;
......@@ -110,6 +114,28 @@ public class HistoricActivityInstanceQueryImpl extends AbstractQuery<HistoricAct
this.unfinished = true;
return this;
}
public HistoricActivityInstanceQueryImpl activityTenantId(String tenantId) {
if (tenantId == null) {
throw new ActivitiIllegalArgumentException("activity tenant id is null");
}
this.tenantId = tenantId;
return this;
}
public HistoricActivityInstanceQueryImpl activityTenantIdLike(String tenantIdLike) {
if (tenantIdLike == null) {
throw new ActivitiIllegalArgumentException("activity tenant id is null");
}
this.tenantIdLike = tenantIdLike;
return this;
}
public HistoricActivityInstanceQueryImpl activityWithoutTenantId() {
this.withoutTenantId = true;
return this;
}
// ordering /////////////////////////////////////////////////////////////////
......@@ -162,6 +188,11 @@ public class HistoricActivityInstanceQueryImpl extends AbstractQuery<HistoricAct
orderBy(HistoricActivityInstanceQueryProperty.ACTIVITY_TYPE);
return this;
}
public HistoricActivityInstanceQueryImpl orderByTenantId() {
orderBy(HistoricActivityInstanceQueryProperty.TENANT_ID);
return this;
}
public HistoricActivityInstanceQueryImpl activityInstanceId(String activityInstanceId) {
this.activityInstanceId = activityInstanceId;
......
......@@ -41,6 +41,7 @@ public class HistoricActivityInstanceQueryProperty implements QueryProperty {
public static final HistoricActivityInstanceQueryProperty START = new HistoricActivityInstanceQueryProperty("START_TIME_");
public static final HistoricActivityInstanceQueryProperty END = new HistoricActivityInstanceQueryProperty("END_TIME_");
public static final HistoricActivityInstanceQueryProperty DURATION = new HistoricActivityInstanceQueryProperty("DURATION_");
public static final HistoricActivityInstanceQueryProperty TENANT_ID = new HistoricActivityInstanceQueryProperty("TENANT_ID_");
private String name;
......
......@@ -50,6 +50,9 @@ public class HistoricProcessInstanceQueryImpl extends AbstractVariableQueryImpl<
protected Set<String> processInstanceIds;
protected String involvedUser;
protected boolean includeProcessVariables;
protected String tenantId;
protected String tenantIdLike;
protected boolean withoutTenantId;
public HistoricProcessInstanceQueryImpl() {
}
......@@ -156,6 +159,27 @@ public class HistoricProcessInstanceQueryImpl extends AbstractVariableQueryImpl<
return this;
}
public HistoricProcessInstanceQuery processInstanceTenantId(String tenantId) {
if (tenantId == null) {
throw new ActivitiIllegalArgumentException("process instance tenant id is null");
}
this.tenantId = tenantId;
return this;
}
public HistoricProcessInstanceQuery processInstanceTenantIdLike(String tenantIdLike) {
if (tenantIdLike == null) {
throw new ActivitiIllegalArgumentException("process instance tenant id is null");
}
this.tenantIdLike = tenantIdLike;
return this;
}
public HistoricProcessInstanceQuery processInstanceWithoutTenantId() {
this.withoutTenantId = true;
return this;
}
public HistoricProcessInstanceQuery orderByProcessInstanceBusinessKey() {
return orderBy(HistoricProcessInstanceQueryProperty.BUSINESS_KEY);
}
......@@ -180,6 +204,10 @@ public class HistoricProcessInstanceQueryImpl extends AbstractVariableQueryImpl<
return orderBy(HistoricProcessInstanceQueryProperty.PROCESS_INSTANCE_ID_);
}
public HistoricProcessInstanceQuery orderByTenantId() {
return orderBy(HistoricProcessInstanceQueryProperty.TENANT_ID);
}
public String getMssqlOrDB2OrderBy() {
String specialOrderBy = super.getOrderBy();
if (specialOrderBy != null && specialOrderBy.length() > 0) {
......
......@@ -36,6 +36,7 @@ public class HistoricProcessInstanceQueryProperty implements QueryProperty {
public static final HistoricProcessInstanceQueryProperty START_TIME = new HistoricProcessInstanceQueryProperty("RES.START_TIME_");
public static final HistoricProcessInstanceQueryProperty END_TIME = new HistoricProcessInstanceQueryProperty("RES.END_TIME_");
public static final HistoricProcessInstanceQueryProperty DURATION = new HistoricProcessInstanceQueryProperty("RES.DURATION_");
public static final HistoricProcessInstanceQueryProperty TENANT_ID = new HistoricProcessInstanceQueryProperty("RES.TENANT_ID_");
private String name;
......
......@@ -78,6 +78,9 @@ public class HistoricTaskInstanceQueryImpl extends AbstractVariableQueryImpl<His
protected Date completedAfterDate;
protected Date completedBeforeDate;
protected String category;
protected String tenantId;
protected String tenantIdLike;
protected boolean withoutTenantId;
protected boolean includeTaskLocalVariables = false;
protected boolean includeProcessVariables = false;
......@@ -457,6 +460,28 @@ public class HistoricTaskInstanceQueryImpl extends AbstractVariableQueryImpl<His
return this;
}
public HistoricTaskInstanceQuery taskTenantId(String tenantId) {
if (tenantId == null) {
throw new ActivitiIllegalArgumentException("task tenant id is null");
}
this.tenantId = tenantId;
return this;
}
public HistoricTaskInstanceQuery taskTenantIdLike(String tenantIdLike) {
if (tenantIdLike == null) {
throw new ActivitiIllegalArgumentException("task tenant id is null");
}
this.tenantIdLike = tenantIdLike;
return this;
}
public HistoricTaskInstanceQuery taskWithoutTenantId() {
this.withoutTenantId = true;
return this;
}
public HistoricTaskInstanceQuery includeTaskLocalVariables() {
this.includeTaskLocalVariables = true;
return this;
......@@ -555,6 +580,11 @@ public class HistoricTaskInstanceQueryImpl extends AbstractVariableQueryImpl<His
return this;
}
public HistoricTaskInstanceQuery orderByTenantId() {
orderBy(HistoricTaskInstanceQueryProperty.TENANT_ID_);
return this;
}
public String getMssqlOrDB2OrderBy() {
String specialOrderBy = super.getOrderBy();
if (specialOrderBy != null && specialOrderBy.length() > 0) {
......
......@@ -43,6 +43,7 @@ public class HistoricTaskInstanceQueryProperty implements QueryProperty {
public static final HistoricTaskInstanceQueryProperty DURATION = new HistoricTaskInstanceQueryProperty("RES.DURATION_");
public static final HistoricTaskInstanceQueryProperty TASK_PRIORITY = new HistoricTaskInstanceQueryProperty("RES.PRIORITY_");
public static final HistoricTaskInstanceQueryProperty TASK_DUE_DATE = new HistoricTaskInstanceQueryProperty("RES.DUE_DATE_");
public static final HistoricTaskInstanceQueryProperty TENANT_ID_ = new HistoricTaskInstanceQueryProperty("RES.TENANT_ID_");
private String name;
......
......@@ -21,7 +21,6 @@ import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.impl.HistoricActivityInstanceQueryImpl;
import org.activiti.engine.impl.cfg.IdGenerator;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.db.DbSqlSession;
import org.activiti.engine.impl.form.TaskFormHandler;
import org.activiti.engine.impl.identity.Authentication;
import org.activiti.engine.impl.persistence.AbstractManager;
......@@ -42,7 +41,6 @@ import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.impl.pvm.runtime.InterpretableExecution;
import org.activiti.engine.impl.util.ClockUtil;
import org.activiti.engine.task.Event;
import org.activiti.engine.task.IdentityLink;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -133,8 +131,12 @@ public void recordProcessInstanceStart(ExecutionEntity processInstance) {
Date now = ClockUtil.getCurrentTime();
historicActivityInstance.setStartTime(now);
getDbSqlSession()
.insert(historicActivityInstance);
// Inherit tenant id (if applicable)
if (processInstance.getTenantId() != null) {
historicActivityInstance.setTenantId(processInstance.getTenantId());
}
getDbSqlSession().insert(historicActivityInstance);
}
}
......@@ -206,6 +208,11 @@ public void recordActivityStart(ExecutionEntity executionEntity) {
historicActivityInstance.setActivityType((String) executionEntity.getActivity().getProperty("type"));
historicActivityInstance.setStartTime(ClockUtil.getCurrentTime());
// Inherit tenant id (if applicable)
if (executionEntity.getTenantId() != null) {
historicActivityInstance.setTenantId(executionEntity.getTenantId());
}
getDbSqlSession().insert(historicActivityInstance);
}
}
......
......@@ -21,6 +21,7 @@ import org.activiti.engine.history.HistoricActivityInstance;
/**
* @author Christian Stettler
* @author Joram Barrez
*/
public class HistoricActivityInstanceEntity extends HistoricScopeInstanceEntity implements HistoricActivityInstance {
......@@ -33,6 +34,7 @@ public class HistoricActivityInstanceEntity extends HistoricScopeInstanceEntity
protected String assignee;
protected String taskId;
protected String calledProcessInstanceId;
protected String tenantId;
public Object getPersistentState() {
Map<String, Object> persistentState = (Map<String, Object>) new HashMap<String, Object>();
......@@ -95,9 +97,17 @@ public class HistoricActivityInstanceEntity extends HistoricScopeInstanceEntity
this.calledProcessInstanceId = calledProcessInstanceId;
}
// common methods //////////////////////////////////////////////////////////
public String getTenantId() {
return tenantId;
}
@Override
public void setTenantId(String tenantId) {
this.tenantId = tenantId;
}
// common methods //////////////////////////////////////////////////////////
@Override
public String toString() {
return "HistoricActivityInstanceEntity[activityId=" + activityId + ", activityName=" + activityName + "]";
}
......
......@@ -26,6 +26,7 @@ import org.activiti.engine.impl.util.ClockUtil;
/**
* @author Tom Baeyens
* @author Christian Stettler
* @author Joram Barrez
*/
public class HistoricProcessInstanceEntity extends HistoricScopeInstanceEntity implements HistoricProcessInstance {
......@@ -36,6 +37,7 @@ public class HistoricProcessInstanceEntity extends HistoricScopeInstanceEntity i
protected String startUserId;
protected String startActivityId;
protected String superProcessInstanceId;
protected String tenantId;
protected List<HistoricVariableInstanceEntity> queryVariables;
public HistoricProcessInstanceEntity() {
......@@ -50,6 +52,11 @@ public class HistoricProcessInstanceEntity extends HistoricScopeInstanceEntity i
startUserId = Authentication.getAuthenticatedUserId();
startActivityId = processInstance.getActivityId();
superProcessInstanceId = processInstance.getSuperExecution() != null ? processInstance.getSuperExecution().getProcessInstanceId() : null;
// Inherit tenant id (if applicable)
if (processInstance.getTenantId() != null) {
tenantId = processInstance.getTenantId();
}
}
......@@ -103,7 +110,15 @@ public class HistoricProcessInstanceEntity extends HistoricScopeInstanceEntity i
this.superProcessInstanceId = superProcessInstanceId;
}
public Map<String, Object> getProcessVariables() {
public String getTenantId() {
return tenantId;
}
public void setTenantId(String tenantId) {
this.tenantId = tenantId;
}
public Map<String, Object> getProcessVariables() {
Map<String, Object> variables = new HashMap<String, Object>();
if (queryVariables != null) {
for (HistoricVariableInstanceEntity variableInstance: queryVariables) {
......
......@@ -26,6 +26,7 @@ import org.activiti.engine.impl.util.ClockUtil;
/**
* @author Tom Baeyens
* @author Joram Barrez
*/
public class HistoricTaskInstanceEntity extends HistoricScopeInstanceEntity implements HistoricTaskInstance, PersistentObject {
......@@ -43,6 +44,7 @@ public class HistoricTaskInstanceEntity extends HistoricScopeInstanceEntity impl
protected Date dueDate;
protected Date claimTime;
protected String category;
protected String tenantId;
protected List<HistoricVariableInstanceEntity> queryVariables;
public HistoricTaskInstanceEntity() {
......@@ -65,6 +67,11 @@ public class HistoricTaskInstanceEntity extends HistoricScopeInstanceEntity impl
this.setPriority(task.getPriority());
this.setDueDate(task.getDueDate());
// Inherit tenant id (if applicable)
if (task.getTenantId() != null) {
tenantId = task.getTenantId();
}
}
// persistence //////////////////////////////////////////////////////////////
......@@ -167,7 +174,13 @@ public class HistoricTaskInstanceEntity extends HistoricScopeInstanceEntity impl
public void setClaimTime(Date claimTime) {
this.claimTime = claimTime;
}
public Long getWorkTimeInMillis() {
public String getTenantId() {
return tenantId;
}
public void setTenantId(String tenantId) {
this.tenantId = tenantId;
}
public Long getWorkTimeInMillis() {
if (endTime == null || claimTime == null) {
return null;
}
......
......@@ -11,6 +11,7 @@ create table ACT_HI_PROCINST (
END_ACT_ID_ varchar(255),
SUPER_PROCESS_INSTANCE_ID_ varchar(64),
DELETE_REASON_ varchar(4000),
TENANT_ID_ varchar(255),
primary key (ID_)
);
......@@ -31,6 +32,7 @@ create table ACT_HI_ACTINST (
START_TIME_ timestamp not null,
END_TIME_ timestamp,
DURATION_ bigint,
TENANT_ID_ varchar(255),
primary key (ID_)
);
......@@ -54,6 +56,7 @@ create table ACT_HI_TASKINST (
DUE_DATE_ timestamp,
FORM_KEY_ varchar(255),
CATEGORY_ varchar(255),
TENANT_ID_ varchar(255),
primary key (ID_)
);
......
......@@ -11,6 +11,7 @@ create table ACT_HI_PROCINST (
END_ACT_ID_ varchar(255),
SUPER_PROCESS_INSTANCE_ID_ varchar(64),
DELETE_REASON_ varchar(4000),
TENANT_ID_ varchar(255),
primary key (ID_),
unique (PROC_INST_ID_)
);
......@@ -29,6 +30,7 @@ create table ACT_HI_ACTINST (
START_TIME_ timestamp not null,
END_TIME_ timestamp,
DURATION_ bigint,
TENANT_ID_ varchar(255),
primary key (ID_)
);
......@@ -52,6 +54,7 @@ create table ACT_HI_TASKINST (
DUE_DATE_ timestamp,
FORM_KEY_ varchar(255),
CATEGORY_ varchar(255),
TENANT_ID_ varchar(255),
primary key (ID_)
);
......
......@@ -11,6 +11,7 @@ create table ACT_HI_PROCINST (
END_ACT_ID_ nvarchar(255),
SUPER_PROCESS_INSTANCE_ID_ nvarchar(64),
DELETE_REASON_ nvarchar(4000),
TENANT_ID_ nvarchar(255),
primary key (ID_),
unique (PROC_INST_ID_)
);
......@@ -29,6 +30,7 @@ create table ACT_HI_ACTINST (
START_TIME_ datetime not null,
END_TIME_ datetime,
DURATION_ numeric(19,0),
TENANT_ID_ nvarchar(255),
primary key (ID_)
);
......@@ -52,6 +54,7 @@ create table ACT_HI_TASKINST (
DUE_DATE_ datetime,
FORM_KEY_ nvarchar(255),
CATEGORY_ nvarchar(255),
TENANT_ID_ nvarchar(255),
primary key (ID_)
);
......
......@@ -11,6 +11,7 @@ create table ACT_HI_PROCINST (
END_ACT_ID_ varchar(255),
SUPER_PROCESS_INSTANCE_ID_ varchar(64),
DELETE_REASON_ varchar(4000),
TENANT_ID_ varchar(255),
primary key (ID_),
unique (PROC_INST_ID_)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin;
......@@ -29,6 +30,7 @@ create table ACT_HI_ACTINST (
START_TIME_ datetime(3) not null,
END_TIME_ datetime(3),
DURATION_ bigint,
TENANT_ID_ varchar(255),
primary key (ID_)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin;
......@@ -52,6 +54,7 @@ create table ACT_HI_TASKINST (
DUE_DATE_ datetime(3),
FORM_KEY_ varchar(255),
CATEGORY_ varchar(255),
TENANT_ID_ varchar(255),
primary key (ID_)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin;
......
......@@ -11,6 +11,7 @@ create table ACT_HI_PROCINST (
END_ACT_ID_ varchar(255),
SUPER_PROCESS_INSTANCE_ID_ varchar(64),
DELETE_REASON_ varchar(4000),
TENANT_ID_ varchar(255),
primary key (ID_),
unique (PROC_INST_ID_)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin;
......@@ -29,6 +30,7 @@ create table ACT_HI_ACTINST (
START_TIME_ datetime not null,
END_TIME_ datetime,
DURATION_ bigint,
TENANT_ID_ varchar(255),
primary key (ID_)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin;
......@@ -52,6 +54,7 @@ create table ACT_HI_TASKINST (
DUE_DATE_ datetime,
FORM_KEY_ varchar(255),
CATEGORY_ varchar(255),
TENANT_ID_ varchar(255),
primary key (ID_)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin;
......
......@@ -11,6 +11,7 @@ create table ACT_HI_PROCINST (
END_ACT_ID_ NVARCHAR2(255),
SUPER_PROCESS_INSTANCE_ID_ NVARCHAR2(64),
DELETE_REASON_ NVARCHAR2(2000),
TENANT_ID_ NVARCHAR2(255),
primary key (ID_),
unique (PROC_INST_ID_)
);
......@@ -29,6 +30,7 @@ create table ACT_HI_ACTINST (
START_TIME_ TIMESTAMP(6) not null,
END_TIME_ TIMESTAMP(6),
DURATION_ NUMBER(19,0),
TENANT_ID_ NVARCHAR2(255),
primary key (ID_)
);
......@@ -52,6 +54,7 @@ create table ACT_HI_TASKINST (
DUE_DATE_ TIMESTAMP(6),
FORM_KEY_ NVARCHAR2(255),
CATEGORY_ NVARCHAR2(255),
TENANT_ID_ NVARCHAR2(255),
primary key (ID_)
);
......
......@@ -11,6 +11,7 @@ create table ACT_HI_PROCINST (
END_ACT_ID_ varchar(255),
SUPER_PROCESS_INSTANCE_ID_ varchar(64),
DELETE_REASON_ varchar(4000),
TENANT_ID_ varchar(255),
primary key (ID_),
unique (PROC_INST_ID_)
);
......@@ -29,6 +30,7 @@ create table ACT_HI_ACTINST (
START_TIME_ timestamp not null,
END_TIME_ timestamp,
DURATION_ bigint,
TENANT_ID_ varchar(255),
primary key (ID_)
);
......@@ -52,6 +54,7 @@ create table ACT_HI_TASKINST (
DUE_DATE_ timestamp,
FORM_KEY_ varchar(255),
CATEGORY_ varchar(255),
TENANT_ID_ varchar(255),
primary key (ID_)
);
......
......@@ -34,7 +34,8 @@
ASSIGNEE_,
START_TIME_,
END_TIME_,
DURATION_
DURATION_,
TENANT_ID_
) values (
#{id ,jdbcType=VARCHAR},
#{processDefinitionId, jdbcType=VARCHAR},
......@@ -48,7 +49,8 @@
#{assignee ,jdbcType=VARCHAR},
#{startTime, jdbcType=TIMESTAMP},
#{endTime, jdbcType=TIMESTAMP},
#{durationInMillis ,jdbcType=BIGINT}
#{durationInMillis ,jdbcType=BIGINT},
#{tenantId, jdbcType=VARCHAR}
)
</insert>
......@@ -85,6 +87,7 @@
<result property="startTime" column="START_TIME_" jdbcType="TIMESTAMP" />
<result property="endTime" column="END_TIME_" jdbcType="TIMESTAMP" />
<result property="durationInMillis" column="DURATION_" jdbcType="BIGINT" />
<result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
</resultMap>
<!-- HISTORIC ACTIVITY INSTANCE SELECT -->
......@@ -133,6 +136,15 @@
<if test="assignee != null">
and RES.ASSIGNEE_ = #{assignee}
</if>
<if test="tenantId != null">
and RES.TENANT_ID_ = #{tenantId}
</if>
<if test="tenantIdLike != null">
and RES.TENANT_ID_ like #{tenantIdLike}
</if>
<if test="withoutTenantId">
and RES.TENANT_ID_ is null
</if>
<if test="unfinished">
and RES.END_TIME_ is null
</if>
......
......@@ -33,7 +33,8 @@
START_ACT_ID_,
END_ACT_ID_,
SUPER_PROCESS_INSTANCE_ID_,
DELETE_REASON_
DELETE_REASON_,
TENANT_ID_
) values (
#{id ,jdbcType=VARCHAR},
#{processInstanceId, jdbcType=VARCHAR},
......@@ -46,7 +47,8 @@
#{startActivityId, jdbcType=VARCHAR},
#{endActivityId, jdbcType=VARCHAR},
#{superProcessInstanceId, jdbcType=VARCHAR},
#{deleteReason, jdbcType=VARCHAR}
#{deleteReason, jdbcType=VARCHAR},
#{tenantId, jdbcType=VARCHAR}
)
</insert>
......@@ -85,6 +87,7 @@
<result property="endActivityId" column="END_ACT_ID_" jdbcType="VARCHAR" />
<result property="superProcessInstanceId" column="SUPER_PROCESS_INSTANCE_ID_" jdbcType="VARCHAR" />
<result property="deleteReason" column="DELETE_REASON_" jdbcType="VARCHAR" />
<result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="historicProcessInstanceAndVariablesResultMap" type="org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity">
......@@ -100,6 +103,7 @@
<result property="endActivityId" column="END_ACT_ID_" jdbcType="VARCHAR" />
<result property="superProcessInstanceId" column="SUPER_PROCESS_INSTANCE_ID_" jdbcType="VARCHAR" />
<result property="deleteReason" column="DELETE_REASON_" jdbcType="VARCHAR" />
<result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
<collection property="queryVariables" column="EXECUTION_ID_" javaType="ArrayList" ofType="org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity">
<id property="id" column="VAR_ID_"/>
<result property="name" column="VAR_NAME_" javaType="String" jdbcType="VARCHAR" />
......@@ -280,6 +284,15 @@
<if test="excludeSubprocesses">
and RES.SUPER_PROCESS_INSTANCE_ID_ is null
</if>
<if test="tenantId != null">
and RES.TENANT_ID_ = #{tenantId}
</if>
<if test="tenantIdLike != null">
and RES.TENANT_ID_ like #{tenantIdLike}
</if>
<if test="withoutTenantId">
and RES.TENANT_ID_ is null
</if>
<foreach collection="queryVariableValues" index="index" item="queryVariableValue">
<if test="queryVariableValue.name != null">
<!-- Match-all variable-names when name is null -->
......
......@@ -40,7 +40,8 @@
FORM_KEY_,
PRIORITY_,
DUE_DATE_,
CATEGORY_
CATEGORY_,
TENANT_ID_
) values (
#{id ,jdbcType=VARCHAR},
#{processDefinitionId, jdbcType=VARCHAR},
......@@ -60,7 +61,8 @@
#{formKey ,jdbcType=VARCHAR},
#{priority, jdbcType=INTEGER},
#{dueDate, jdbcType=TIMESTAMP},
#{category, jdbcType=VARCHAR}
#{category, jdbcType=VARCHAR},
#{tenantId, jdbcType=VARCHAR}
)
</insert>
......@@ -114,6 +116,7 @@
<result property="priority" column="PRIORITY_" jdbcType="INTEGER" />
<result property="dueDate" column="DUE_DATE_" jdbcType="TIMESTAMP" />
<result property="category" column="CATEGORY_" jdbcType="VARCHAR" />
<result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="historicTaskInstanceAndVariablesResultMap" type="org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntity">
......@@ -136,6 +139,7 @@
<result property="priority" column="PRIORITY_" jdbcType="INTEGER" />
<result property="dueDate" column="DUE_DATE_" jdbcType="TIMESTAMP" />
<result property="category" column="CATEGORY_" jdbcType="VARCHAR" />
<result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
<collection property="queryVariables" column="TASK_ID_" javaType="ArrayList" ofType="org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntity">
<id property="id" column="VAR_ID_"/>
<result property="name" column="VAR_NAME_" javaType="String" jdbcType="VARCHAR" />
......@@ -388,6 +392,15 @@
<if test="category != null">
and RES.CATEGORY_ = #{category}
</if>
<if test="tenantId != null">
and RES.TENANT_ID_ = #{tenantId}
</if>
<if test="tenantIdLike != null">
and RES.TENANT_ID_ like #{tenantIdLike}
</if>
<if test="withoutTenantId">
and RES.TENANT_ID_ is null
</if>
<if test="candidateUser != null || candidateGroups != null">
and RES.ASSIGNEE_ is null
and HI.TYPE_ = 'candidate'
......
......@@ -15,4 +15,20 @@ alter table ACT_HI_VARINST
-- This means that for DB2 the columns will remain as they are (they won't be used)
-- alter table ACT_HI_PROCINST drop colum UNI_BUSINESS_KEY;
-- alter table ACT_HI_PROCINST drop colum UNI_PROC_DEF_ID;
-- Call Sysproc.admin_cmd ('REORG TABLE ACT_HI_PROCINST');
\ No newline at end of file
-- Call Sysproc.admin_cmd ('REORG TABLE ACT_HI_PROCINST');
alter table ACT_HI_PROCINST
add TENANT_ID_ varchar(255);
Call Sysproc.admin_cmd ('REORG TABLE ACT_HI_PROCINST');
alter table ACT_HI_ACTINST
add TENANT_ID_ varchar(255);
Call Sysproc.admin_cmd ('REORG TABLE ACT_HI_ACTINST');
alter table ACT_HI_TASKINST
add TENANT_ID_ varchar(255);
Call Sysproc.admin_cmd ('REORG TABLE ACT_HI_TASKINST');
\ No newline at end of file
......@@ -7,4 +7,13 @@ alter table ACT_HI_VARINST
add CREATE_TIME_ timestamp;
alter table ACT_HI_VARINST
add LAST_UPDATED_TIME_ timestamp;
\ No newline at end of file
add LAST_UPDATED_TIME_ timestamp;
alter table ACT_HI_PROCINST
add TENANT_ID_ varchar(255);
alter table ACT_HI_ACTINST
add TENANT_ID_ varchar(255);
alter table ACT_HI_TASKINST
add TENANT_ID_ varchar(255);
\ No newline at end of file
......@@ -8,4 +8,13 @@ alter table ACT_HI_VARINST
alter table ACT_HI_VARINST
add LAST_UPDATED_TIME_ datetime;
alter table ACT_HI_PROCINST
add TENANT_ID_ nvarchar(255);
alter table ACT_HI_ACTINST
add TENANT_ID_ nvarchar(255);
alter table ACT_HI_TASKINST
add TENANT_ID_ nvarchar(255);
\ No newline at end of file
......@@ -90,4 +90,13 @@ alter table ACT_HI_VARINST
alter table ACT_HI_VARINST
add LAST_UPDATED_TIME_ datetime(3);
alter table ACT_HI_PROCINST
add TENANT_ID_ varchar(255);
alter table ACT_HI_ACTINST
add TENANT_ID_ varchar(255);
alter table ACT_HI_TASKINST
add TENANT_ID_ varchar(255);
......@@ -11,4 +11,13 @@ alter table ACT_HI_VARINST
add CREATE_TIME_ datetime;
alter table ACT_HI_VARINST
add LAST_UPDATED_TIME_ datetime;
\ No newline at end of file
add LAST_UPDATED_TIME_ datetime;
alter table ACT_HI_PROCINST
add TENANT_ID_ varchar(255);
alter table ACT_HI_ACTINST
add TENANT_ID_ varchar(255);
alter table ACT_HI_TASKINST
add TENANT_ID_ varchar(255);
\ No newline at end of file
......@@ -7,4 +7,13 @@ alter table ACT_HI_VARINST
add CREATE_TIME_ TIMESTAMP(6);
alter table ACT_HI_VARINST
add LAST_UPDATED_TIME_ TIMESTAMP(6);
\ No newline at end of file
add LAST_UPDATED_TIME_ TIMESTAMP(6);
alter table ACT_HI_PROCINST
add TENANT_ID_ NVARCHAR2(255);
alter table ACT_HI_ACTINST
add TENANT_ID_ NVARCHAR2(255);
alter table ACT_HI_TASKINST
add TENANT_ID_ NVARCHAR2(255);
\ No newline at end of file
......@@ -7,4 +7,13 @@ alter table ACT_HI_VARINST
add CREATE_TIME_ timestamp;
alter table ACT_HI_VARINST
add LAST_UPDATED_TIME_ timestamp;
\ No newline at end of file
add LAST_UPDATED_TIME_ timestamp;
alter table ACT_HI_PROCINST
add TENANT_ID_ varchar(255);
alter table ACT_HI_ACTINST
add TENANT_ID_ varchar(255);
alter table ACT_HI_TASKINST
add TENANT_ID_ varchar(255);
\ No newline at end of file
......@@ -3,10 +3,12 @@ package org.activiti.engine.test.api.tenant;
import java.util.ArrayList;
import java.util.List;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.impl.test.PluggableActivitiTestCase;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.Model;
import org.activiti.engine.runtime.Job;
import org.activiti.engine.task.Task;
/**
* A test case for the various implications of the tenancy support (tenant id column to entities + query support)
......@@ -407,5 +409,55 @@ public class TenancyTest extends PluggableActivitiTestCase {
// clean up
repositoryService.deleteDeployment(deploymentId, true);
}
public void testHistoryTenancy() {
// Generate 3 tasks with tenant
String processDefinitionIdWithTenant = deployTestProcessWithTestTenant();
int nrOfProcessInstancesWithTenant = 3;
for (int i=0; i<nrOfProcessInstancesWithTenant; i++) {
runtimeService.startProcessInstanceById(processDefinitionIdWithTenant);
}
// Generate 2 tasks without tenant
String processDefinitionIdNoTenant = deployOneTaskTestProcess();
int nrOfProcessInstancesNoTenant = 2;
for (int i = 0; i < nrOfProcessInstancesNoTenant; i++) {
runtimeService.startProcessInstanceById(processDefinitionIdNoTenant);
}
// Complete all tasks
for (Task task : taskService.createTaskQuery().list()) {
taskService.complete(task.getId());
}
// Verify process instances
assertEquals(TEST_TENANT_ID, historyService.createHistoricProcessInstanceQuery().processDefinitionId(processDefinitionIdWithTenant).list().get(0).getTenantId());
assertEquals(null, historyService.createHistoricProcessInstanceQuery().processDefinitionId(processDefinitionIdNoTenant).list().get(0).getTenantId());
assertEquals(nrOfProcessInstancesWithTenant + nrOfProcessInstancesNoTenant, historyService.createHistoricProcessInstanceQuery().list().size());
assertEquals(nrOfProcessInstancesWithTenant, historyService.createHistoricProcessInstanceQuery().processInstanceTenantId(TEST_TENANT_ID).list().size());
assertEquals(nrOfProcessInstancesWithTenant, historyService.createHistoricProcessInstanceQuery().processInstanceTenantIdLike("%e%").list().size());
assertEquals(nrOfProcessInstancesNoTenant, historyService.createHistoricProcessInstanceQuery().processInstanceWithoutTenantId().list().size());
// verify tasks
assertEquals(TEST_TENANT_ID, historyService.createHistoricTaskInstanceQuery().processDefinitionId(processDefinitionIdWithTenant).list().get(0).getTenantId());
assertEquals(null, historyService.createHistoricTaskInstanceQuery().processDefinitionId(processDefinitionIdNoTenant).list().get(0).getTenantId());
assertEquals(nrOfProcessInstancesWithTenant + nrOfProcessInstancesNoTenant, historyService.createHistoricTaskInstanceQuery().list().size());
assertEquals(nrOfProcessInstancesWithTenant, historyService.createHistoricTaskInstanceQuery().taskTenantId(TEST_TENANT_ID).list().size());
assertEquals(nrOfProcessInstancesWithTenant, historyService.createHistoricTaskInstanceQuery().taskTenantIdLike("my%").list().size());
assertEquals(nrOfProcessInstancesNoTenant, historyService.createHistoricTaskInstanceQuery().taskWithoutTenantId().list().size());
// verify activities
List<HistoricActivityInstance> activityInstances = historyService.createHistoricActivityInstanceQuery().processDefinitionId(processDefinitionIdWithTenant).list();
for (HistoricActivityInstance historicActivityInstance : activityInstances) {
assertEquals(TEST_TENANT_ID, historicActivityInstance.getTenantId());
}
assertEquals(null, historyService.createHistoricActivityInstanceQuery().processDefinitionId(processDefinitionIdNoTenant).list().get(0).getTenantId());
assertEquals(3 * (nrOfProcessInstancesWithTenant + nrOfProcessInstancesNoTenant), historyService.createHistoricActivityInstanceQuery().list().size());
assertEquals(3 * nrOfProcessInstancesWithTenant, historyService.createHistoricActivityInstanceQuery().activityTenantId(TEST_TENANT_ID).list().size());
assertEquals(3 * nrOfProcessInstancesWithTenant, historyService.createHistoricActivityInstanceQuery().activityTenantIdLike("my%").list().size());
assertEquals(3 * nrOfProcessInstancesNoTenant, historyService.createHistoricActivityInstanceQuery().activityWithoutTenantId().list().size());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册