提交 3d878342 编写于 作者: T tombaeyens

ACT-251 added HistoricVariableUpdate

上级 4f800757
......@@ -18,6 +18,8 @@ import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricActivityInstanceQuery;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricProcessInstanceQuery;
import org.activiti.engine.history.HistoricVariableUpdate;
import org.activiti.engine.history.HistoricVariableUpdateQuery;
/**
* Service exposing information about ongoing and past process instances. This is different
......@@ -37,4 +39,7 @@ public interface HistoryService {
/** Creates a new programmatic query to search for {@link HistoricActivityInstance}s. */
HistoricActivityInstanceQuery createHistoricActivityInstanceQuery();
/** Creates a new programmatic query to search for {@link HistoricVariableUpdate}s. */
HistoricVariableUpdateQuery createHistoricVariableUpdateQuery();
}
......@@ -72,6 +72,7 @@ public class ProcessEngineBuilder {
protected String mailServerSmtpPassword;
protected int mailServerSmtpPort = ProcessEngineConfiguration.DEFAULT_MAIL_SERVER_SMTP_PORT;
protected String mailServerDefaultFrom = ProcessEngineConfiguration.DEFAULT_FROM_EMAIL_ADDRESS;
protected Integer historyLevel;
public ProcessEngineBuilder setProcessEngineName(String processEngineName) {
this.processEngineName = processEngineName;
......@@ -226,6 +227,11 @@ public class ProcessEngineBuilder {
this.mailServerDefaultFrom = mailServerDefaultFrom;
}
String historyLevelText = configurationProperties.getProperty("history.level");
if (historyLevelText!=null) {
historyLevel = ProcessEngineConfiguration.parseHistoryLevel(historyLevelText);
}
return this;
}
......@@ -280,6 +286,11 @@ public class ProcessEngineBuilder {
// JOBEXECUTOR
processEngineConfiguration.setJobExecutorAutoActivate(jobExecutorAutoActivate);
// HISTORY
if (historyLevel!=null) {
processEngineConfiguration.setHistoryLevel(historyLevel);
}
// DATABASE
processEngineConfiguration.setDbSchemaStrategy(dbSchemaStrategy);
processEngineConfiguration.setJdbcDriver(jdbcDriver);
......
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.history;
import java.util.Date;
/**
* @author Tom Baeyens
*/
public interface HistoricVariableUpdate {
String getProcessInstanceId();
String getExecutionId();
String getVariableName();
String getVariableType();
Object getValue();
int getIndex();
Date getTime();
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.history;
import org.activiti.engine.query.Query;
/**
* @author Tom Baeyens
*/
public interface HistoricVariableUpdateQuery extends Query<HistoricVariableUpdateQuery, HistoricVariableUpdate> {
/** Only select historic variable updates with the given process instance.
* {@link ProcessInstance) ids and {@link HistoricProcessInstance} ids match. */
HistoricVariableUpdateQuery processInstanceId(String processInstanceId);
/** Only select historic variable updates with the given variableName. */
HistoricVariableUpdateQuery variableName(String variableName);
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.history;
import java.util.HashMap;
import java.util.Map;
import org.activiti.engine.query.QueryProperty;
/**
* @author Tom Baeyens
*/
public class HistoricVariableUpdateQueryProperty implements QueryProperty {
private static final Map<String, HistoricVariableUpdateQueryProperty> properties = new HashMap<String, HistoricVariableUpdateQueryProperty>();
public static final HistoricVariableUpdateQueryProperty PROCESS_INSTANCE_ID_ = new HistoricVariableUpdateQueryProperty("PROC_INST_ID_");
public static final HistoricVariableUpdateQueryProperty VARIABLE_NAME = new HistoricVariableUpdateQueryProperty("NAME_");
public static final HistoricVariableUpdateQueryProperty VARIABLE_TYPE = new HistoricVariableUpdateQueryProperty("TYPE_");
public static final HistoricVariableUpdateQueryProperty INDEX = new HistoricVariableUpdateQueryProperty("INDEX_");
public static final HistoricVariableUpdateQueryProperty TIME = new HistoricVariableUpdateQueryProperty("TIME_");
private String name;
public HistoricVariableUpdateQueryProperty(String name) {
this.name = name;
properties.put(name, this);
}
public String getName() {
return name;
}
public static HistoricVariableUpdateQueryProperty findByName(String propertyName) {
return properties.get(propertyName);
}
}
......@@ -39,7 +39,6 @@ public class HistoricActivityInstanceQueryImpl extends AbstractQuery<HistoricAct
protected String assignee;
protected boolean onlyOpen;
protected HistoricActivityInstanceQueryProperty orderProperty;
protected String orderBy;
public HistoricActivityInstanceQueryImpl() {
}
......
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl;
import java.util.List;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.history.HistoricVariableUpdate;
import org.activiti.engine.history.HistoricVariableUpdateQuery;
import org.activiti.engine.history.HistoricVariableUpdateQueryProperty;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.interceptor.CommandExecutor;
import org.activiti.engine.query.QueryProperty;
/**
* @author Tom Baeyens
*/
public class HistoricVariableUpdateQueryImpl extends AbstractQuery<HistoricVariableUpdateQuery, HistoricVariableUpdate> implements HistoricVariableUpdateQuery {
protected String processInstanceId;
protected String variableName;
protected HistoricVariableUpdateQueryProperty orderProperty;
public HistoricVariableUpdateQueryImpl() {
}
public HistoricVariableUpdateQueryImpl(CommandExecutor commandExecutor) {
super(commandExecutor);
}
public HistoricVariableUpdateQueryImpl processInstanceId(String processInstanceId) {
this.processInstanceId = processInstanceId;
return this;
}
public HistoricVariableUpdateQueryImpl variableName(String variableName) {
this.variableName = variableName;
return this;
}
public HistoricVariableUpdateQueryImpl asc() {
return direction(Direction.ASCENDING);
}
public HistoricVariableUpdateQueryImpl desc() {
return direction(Direction.DESCENDING);
}
public long executeCount(CommandContext commandContext) {
checkQueryOk();
return commandContext
.getHistorySession()
.findHistoricVariableUpdateCountByQueryCriteria(this);
}
public List<HistoricVariableUpdate> executeList(CommandContext commandContext, Page page) {
checkQueryOk();
return commandContext
.getHistorySession()
.findHistoricVariableUpdatesByQueryCriteria(this, page);
}
protected void checkQueryOk() {
if (orderProperty != null) {
throw new ActivitiException("Invalid query: call asc() or desc() after using orderByXX()");
}
}
public HistoricVariableUpdateQueryImpl direction(Direction direction) {
if (orderProperty==null) {
throw new ActivitiException("you should call any of the orderBy methods first before specifying a direction");
}
addOrder(orderProperty.getName(), direction.getName());
orderProperty = null;
return this;
}
public HistoricVariableUpdateQueryImpl orderBy(QueryProperty property) {
if(!(property instanceof HistoricVariableUpdateQueryProperty)) {
throw new ActivitiException("Only HistoricVariableUpdateQueryProperty can be used with orderBy");
}
this.orderProperty = (HistoricVariableUpdateQueryProperty) property;
return this;
}
// getters and setters //////////////////////////////////////////////////////
public String getProcessInstanceId() {
return processInstanceId;
}
public String getVariableName() {
return variableName;
}
}
......@@ -17,6 +17,7 @@ package org.activiti.engine.impl;
import org.activiti.engine.HistoryService;
import org.activiti.engine.history.HistoricActivityInstanceQuery;
import org.activiti.engine.history.HistoricProcessInstanceQuery;
import org.activiti.engine.history.HistoricVariableUpdateQuery;
/**
* @author Tom Baeyens
......@@ -31,4 +32,8 @@ public class HistoryServiceImpl extends ServiceImpl implements HistoryService {
public HistoricActivityInstanceQuery createHistoricActivityInstanceQuery() {
return new HistoricActivityInstanceQueryImpl(commandExecutor);
}
public HistoricVariableUpdateQuery createHistoricVariableUpdateQuery() {
return new HistoricVariableUpdateQueryImpl(commandExecutor);
}
}
......@@ -44,7 +44,7 @@ public class BpmnDeployer implements Deployer, ProcessEngineConfigurationAware {
public void configurationCompleted(ProcessEngineConfiguration processEngineConfiguration) {
this.expressionManager = processEngineConfiguration.getExpressionManager();
this.bpmnParser = new BpmnParser(expressionManager);
if (processEngineConfiguration.isHistoryEnabled()) {
if (processEngineConfiguration.getHistoryLevel()>=ProcessEngineConfiguration.HISTORYLEVEL_ACTIVITY) {
bpmnParser.getParseListeners().add(new HistoryParseListener());
}
}
......
......@@ -49,6 +49,7 @@ import org.activiti.engine.impl.bpmn.SubProcessActivity;
import org.activiti.engine.impl.bpmn.TaskActivity;
import org.activiti.engine.impl.bpmn.UserTaskActivity;
import org.activiti.engine.impl.bpmn.WebServiceActivityBehavior;
import org.activiti.engine.impl.cfg.ProcessEngineConfiguration;
import org.activiti.engine.impl.el.ActivitiValueExpression;
import org.activiti.engine.impl.el.ExpressionManager;
import org.activiti.engine.impl.el.UelMethodExpressionCondition;
......@@ -365,6 +366,11 @@ public class BpmnParse extends Parse {
processDefinition.setKey(processElement.attribute("id"));
processDefinition.setProperty("name", processElement.attribute("name"));
processDefinition.setProperty("documentation", parseDocumentation(processElement));
String historyLevelText = processElement.attribute("history");
if (historyLevelText!=null) {
processDefinition.setHistoryLevel(ProcessEngineConfiguration.parseHistoryLevel(historyLevelText));
}
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Parsing process " + processDefinition.getKey());
......
......@@ -17,8 +17,10 @@ import java.util.List;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricVariableUpdate;
import org.activiti.engine.impl.HistoricActivityInstanceQueryImpl;
import org.activiti.engine.impl.HistoricProcessInstanceQueryImpl;
import org.activiti.engine.impl.HistoricVariableUpdateQueryImpl;
import org.activiti.engine.impl.Page;
import org.activiti.engine.impl.history.HistoricActivityInstanceEntity;
import org.activiti.engine.impl.history.HistoricProcessInstanceEntity;
......@@ -41,4 +43,7 @@ public interface HistorySession {
long findHistoricActivityInstanceCountByQueryCriteria(HistoricActivityInstanceQueryImpl historicActivityInstanceQueryImpl);
List<HistoricActivityInstance> findHistoricActivityInstancesByQueryCriteria(HistoricActivityInstanceQueryImpl historicActivityInstanceQueryImpl, Page page);
long findHistoricVariableUpdateCountByQueryCriteria(HistoricVariableUpdateQueryImpl historicVariableUpdateQueryImpl);
List<HistoricVariableUpdate> findHistoricVariableUpdatesByQueryCriteria(HistoricVariableUpdateQueryImpl historicVariableUpdateQueryImpl, Page page);
}
......@@ -95,6 +95,28 @@ public class ProcessEngineConfiguration {
public static final String DBSCHEMASTRATEGY_CREATE_IF_NECESSARY = "create-if-necessary";
public static final String DBSCHEMASTRATEGY_DROP_CREATE = "drop-create";
public static final int HISTORYLEVEL_NONE = 0;
public static final int HISTORYLEVEL_ACTIVITY = 1;
public static final int HISTORYLEVEL_AUDIT = 2;
public static final int HISTORYLEVEL_FULL = 3;
public static Integer parseHistoryLevel(String historyLevelText) {
if ("none".equalsIgnoreCase(historyLevelText)) {
return HISTORYLEVEL_NONE;
}
if ("activity".equalsIgnoreCase(historyLevelText)) {
return HISTORYLEVEL_ACTIVITY;
}
if ("audit".equalsIgnoreCase(historyLevelText)) {
return HISTORYLEVEL_AUDIT;
}
if ("full".equalsIgnoreCase(historyLevelText)) {
return HISTORYLEVEL_FULL;
}
throw new ActivitiException("invalid history level: "+historyLevelText);
}
protected String processEngineName;
/** the configurable list which will be {@link #initializeInterceptorChain(List, ProcessEngineConfiguration) processed} to build the {@link #commandExecutorTxRequired} */
......@@ -139,7 +161,7 @@ public class ProcessEngineConfiguration {
protected ExpressionManager expressionManager;
protected BusinessCalendarManager businessCalendarManager;
protected boolean isHistoryEnabled = true;
protected int historyLevel = HISTORYLEVEL_AUDIT;
protected Map<String, List<TaskListener>> taskListeners;
protected boolean isConfigurationCompleted = false;
......@@ -253,7 +275,7 @@ public class ProcessEngineConfiguration {
notifyConfigurationComplete(expressionManager);
notifyConfigurationComplete(businessCalendarManager);
if (isHistoryEnabled) {
if (historyLevel>=HISTORYLEVEL_ACTIVITY) {
addTaskListener(TaskListener.EVENTNAME_ASSIGNMENT, new HistoryTaskAssignmentHandler());
}
......@@ -308,6 +330,8 @@ public class ProcessEngineConfiguration {
public DbSqlSessionFactory getDbSqlSessionFactory() {
return (DbSqlSessionFactory) sessionFactories.get(DbSqlSession.class);
}
// configuration update methods /////////////////////////////////////////////
public void addCommandInterceptorsTxRequired(CommandInterceptor commandInterceptor) {
commandInterceptorsTxRequired.add(commandInterceptor);
......@@ -316,6 +340,28 @@ public class ProcessEngineConfiguration {
public void addCommandInterceptorsTxRequiresNew(CommandInterceptor commandInterceptor) {
commandInterceptorsTxRequiresNew.add(commandInterceptor);
}
public void enableJPA(Object entityManagerFactory, boolean handleTransaction, boolean closeEntityManager) {
if(entityManagerFactory == null) {
throw new ActivitiException("entityManagerFactory is null, JPA cannot be enabled");
}
if(!sessionFactories.containsKey(EntityManagerSession.class)) {
sessionFactories.put(EntityManagerSession.class, new EntityManagerSessionFactory(entityManagerFactory, true, true));
Type jpaType = variableTypes.getVariableType(JPAEntityVariableType.TYPE_NAME);
// Add JPA-type
if(jpaType == null) {
// We try adding the variable right before SerializableType, if available
int serializableIndex = variableTypes.getTypeIndex(SerializableType.TYPE_NAME);
if(serializableIndex > -1) {
variableTypes.addType(new JPAEntityVariableType(), serializableIndex);
} else {
variableTypes.addType(new JPAEntityVariableType());
}
}
} else {
throw new ActivitiException("JPA is already enabled");
}
}
// getters and setters //////////////////////////////////////////////////////
......@@ -547,14 +593,6 @@ public class ProcessEngineConfiguration {
this.idBlockSize = idBlockSize;
}
public boolean isHistoryEnabled() {
return isHistoryEnabled;
}
public void setHistoryEnabled(boolean isHistoryEnabled) {
this.isHistoryEnabled = isHistoryEnabled;
}
public String getWsSyncFactoryClassName() {
return wsSyncFactoryClassName;
}
......@@ -637,26 +675,12 @@ public class ProcessEngineConfiguration {
return commandExecutorTxRequiresNew;
}
public int getHistoryLevel() {
return historyLevel;
}
public void enableJPA(Object entityManagerFactory, boolean handleTransaction, boolean closeEntityManager) {
if(entityManagerFactory == null) {
throw new ActivitiException("entityManagerFactory is null, JPA cannot be enabled");
}
if(!sessionFactories.containsKey(EntityManagerSession.class)) {
sessionFactories.put(EntityManagerSession.class, new EntityManagerSessionFactory(entityManagerFactory, true, true));
Type jpaType = variableTypes.getVariableType(JPAEntityVariableType.TYPE_NAME);
// Add JPA-type
if(jpaType == null) {
// We try adding the variable right before SerializableType, if available
int serializableIndex = variableTypes.getTypeIndex(SerializableType.TYPE_NAME);
if(serializableIndex > -1) {
variableTypes.addType(new JPAEntityVariableType(), serializableIndex);
} else {
variableTypes.addType(new JPAEntityVariableType());
}
}
} else {
throw new ActivitiException("JPA is already enabled");
}
public void setHistoryLevel(int historyLevel) {
this.historyLevel = historyLevel;
}
}
......@@ -44,7 +44,7 @@ public class CompleteTaskCmd implements Command<Void> {
TaskEntity task = taskSession.findTaskById(taskId);
if (variables!=null) {
task.setActivityInstanceVariables(variables);
task.setExecutionVariables(variables);
}
if (task == null) {
......
......@@ -18,6 +18,7 @@ import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.runtime.ExecutionEntity;
import org.activiti.engine.impl.runtime.VariableMap;
/**
......@@ -46,7 +47,12 @@ public class SetVariablesCmd implements Command<Object> {
throw new ActivitiException("execution "+executionId+" doesn't exist");
}
execution.setVariables(variables);
try {
VariableMap.setExternalUpdate(Boolean.TRUE);
execution.setVariables(variables);
} finally {
VariableMap.setExternalUpdate(null);
}
return null;
}
......
......@@ -20,6 +20,7 @@ import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.repository.ProcessDefinitionEntity;
import org.activiti.engine.impl.runtime.ExecutionEntity;
import org.activiti.engine.impl.runtime.VariableMap;
import org.activiti.engine.runtime.ProcessInstance;
......@@ -60,7 +61,12 @@ public class StartProcessInstanceCmd<T> implements Command<ProcessInstance> {
ExecutionEntity processInstance = processDefinition.createProcessInstance();
if (variables!=null) {
processInstance.setVariables(variables);
try {
VariableMap.setExternalUpdate(Boolean.TRUE);
processInstance.setVariables(variables);
} finally {
VariableMap.setExternalUpdate(null);
}
}
if (businessKey != null) {
......
......@@ -19,12 +19,16 @@ import java.util.Map;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricVariableUpdate;
import org.activiti.engine.impl.HistoricActivityInstanceQueryImpl;
import org.activiti.engine.impl.HistoricProcessInstanceQueryImpl;
import org.activiti.engine.impl.HistoricVariableUpdateQueryImpl;
import org.activiti.engine.impl.Page;
import org.activiti.engine.impl.cfg.HistorySession;
import org.activiti.engine.impl.history.HistoricActivityInstanceEntity;
import org.activiti.engine.impl.history.HistoricProcessInstanceEntity;
import org.activiti.engine.impl.history.HistoricVariableUpdateEntity;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.interceptor.Session;
......@@ -38,7 +42,15 @@ public class DbHistorySession extends AbstractDbSession implements HistorySessio
dbSqlSession.insert(historicProcessInstance);
}
@SuppressWarnings("unchecked")
public void deleteHistoricProcessInstance(String historicProcessInstanceId) {
List<HistoricVariableUpdateEntity> historicVariableUpdates = (List) new HistoricVariableUpdateQueryImpl()
.processInstanceId(historicProcessInstanceId)
.executeList(CommandContext.getCurrent(), null);
for (HistoricVariableUpdateEntity historicVariableUpdate: historicVariableUpdates) {
historicVariableUpdate.delete();
}
dbSqlSession.delete("deleteHistoricActivityInstancesByProcessInstanceId", historicProcessInstanceId);
dbSqlSession.delete(HistoricProcessInstanceEntity.class, historicProcessInstanceId);
}
......@@ -72,12 +84,6 @@ public class DbHistorySession extends AbstractDbSession implements HistorySessio
return dbSqlSession.selectList("selectHistoricProcessInstancesByQueryCriteria", historicProcessInstanceQuery, page);
}
public void close() {
}
public void flush() {
}
public long findHistoricActivityInstanceCountByQueryCriteria(HistoricActivityInstanceQueryImpl historicActivityInstanceQuery) {
return (Long) dbSqlSession.selectOne("selectHistoricActivityInstanceCountByQueryCriteria", historicActivityInstanceQuery);
}
......@@ -86,4 +92,19 @@ public class DbHistorySession extends AbstractDbSession implements HistorySessio
public List<HistoricActivityInstance> findHistoricActivityInstancesByQueryCriteria(HistoricActivityInstanceQueryImpl historicActivityInstanceQuery, Page page) {
return dbSqlSession.selectList("selectHistoricActivityInstancesByQueryCriteria", historicActivityInstanceQuery, page);
}
public long findHistoricVariableUpdateCountByQueryCriteria(HistoricVariableUpdateQueryImpl historicVariableUpdateQuery) {
return (Long) dbSqlSession.selectOne("selectHistoricVariableUpdateCountByQueryCriteria", historicVariableUpdateQuery);
}
@SuppressWarnings("unchecked")
public List<HistoricVariableUpdate> findHistoricVariableUpdatesByQueryCriteria(HistoricVariableUpdateQueryImpl historicVariableUpdateQuery, Page page) {
return dbSqlSession.selectList("selectHistoricVariableUpdatesByQueryCriteria", historicVariableUpdateQuery, page);
}
public void close() {
}
public void flush() {
}
}
......@@ -24,6 +24,7 @@ import org.activiti.engine.impl.HistoricProcessInstanceQueryImpl;
import org.activiti.engine.impl.Page;
import org.activiti.engine.impl.ProcessDefinitionQueryImpl;
import org.activiti.engine.impl.ProcessInstanceQueryImpl;
import org.activiti.engine.impl.cfg.ProcessEngineConfiguration;
import org.activiti.engine.impl.cfg.RepositorySession;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.interceptor.Session;
......@@ -112,8 +113,9 @@ public class DbRepositorySession implements Session, RepositorySession {
List<ProcessDefinition> processDefinitions = new ProcessDefinitionQueryImpl()
.deploymentId(deploymentId)
.executeList(commandContext, null);
boolean isHistoryEnabled = commandContext.getProcessEngineConfiguration().isHistoryEnabled();
int historyLevel = commandContext.getProcessEngineConfiguration().getHistoryLevel();
boolean isHistoryEnabled = historyLevel >= ProcessEngineConfiguration.HISTORYLEVEL_ACTIVITY;
for (ProcessDefinition processDefinition: processDefinitions) {
if (isHistoryEnabled) {
......
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl.history;
import java.util.Date;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.history.HistoricVariableUpdate;
import org.activiti.engine.impl.db.DbSqlSession;
import org.activiti.engine.impl.db.PersistentObject;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.runtime.ByteArrayEntity;
import org.activiti.engine.impl.runtime.VariableInstanceEntity;
import org.activiti.engine.impl.util.ClockUtil;
/**
* @author Tom Baeyens
*/
public class HistoricVariableUpdateEntity extends VariableInstanceEntity implements HistoricVariableUpdate, PersistentObject {
private static final long serialVersionUID = 1L;
protected int index;
protected Date time;
public HistoricVariableUpdateEntity() {
}
public HistoricVariableUpdateEntity(VariableInstanceEntity variableInstance, DbSqlSession dbSqlSession) {
this.processInstanceId = variableInstance.getProcessInstanceId();
if (processInstanceId==null) {
throw new ActivitiException("bug");
}
this.executionId = variableInstance.getExecutionId();
if (executionId==null) {
throw new ActivitiException("bug");
}
this.name = variableInstance.getName();
this.type = variableInstance.getType();
this.time = ClockUtil.getCurrentTime();
this.index = variableInstance.generateNextHistoryIndex();
if (variableInstance.getByteArrayValueId()!=null) {
// TODO test and review. name ok here?
this.byteArrayValue = new ByteArrayEntity(name, variableInstance.getByteArrayValue().getBytes());
dbSqlSession.insert(byteArrayValue);
this.byteArrayValueId = byteArrayValue.getId();
}
this.textValue = variableInstance.getTextValue();
this.textValue2 = variableInstance.getTextValue2();
this.doubleValue = variableInstance.getDoubleValue();
this.longValue = variableInstance.getLongValue();
}
public void delete() {
DbSqlSession dbSqlSession = CommandContext
.getCurrent()
.getDbSqlSession();
dbSqlSession.delete(HistoricVariableUpdateEntity.class, id);
if (byteArrayValueId != null) {
// the next apparently useless line is probably to ensure consistency in the DbSqlSession
// cache, but should be checked and docced here (or removed if it turns out to be unnecessary)
// @see also HistoricVariableInstanceEntity
getByteArrayValue();
dbSqlSession.delete(ByteArrayEntity.class, byteArrayValueId);
}
}
public Object getPersistentState() {
// HistoricVariableUpdateEntity is immutable, so always the same object is returned
return HistoricVariableUpdateEntity.class;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public Date getTime() {
return time;
}
public void setTime(Date time) {
this.time = time;
}
public String getVariableName() {
return name;
}
public String getVariableType() {
return type.getTypeName();
}
}
......@@ -36,6 +36,7 @@ public class ProcessDefinitionEntity extends ProcessDefinitionImpl implements Pr
protected String deploymentId;
protected String resourceName;
protected String startFormResourceKey;
protected Integer historyLevel;
public ProcessDefinitionEntity() {
super(null);
......@@ -135,4 +136,12 @@ public class ProcessDefinitionEntity extends ProcessDefinitionImpl implements Pr
public void setStartFormResourceKey(String startFormResourceKey) {
this.startFormResourceKey = startFormResourceKey;
}
public Integer getHistoryLevel() {
return historyLevel;
}
public void setHistoryLevel(Integer historyLevel) {
this.historyLevel = historyLevel;
}
}
......@@ -15,6 +15,7 @@ package org.activiti.engine.impl.runtime;
import java.io.Serializable;
import org.activiti.engine.impl.db.PersistentObject;
import org.activiti.engine.impl.history.HistoricVariableUpdateEntity;
import org.activiti.engine.impl.variable.ByteArrayType;
/**
......
......@@ -46,12 +46,14 @@ public class VariableInstanceEntity implements Serializable, PersistentObject {
protected ByteArrayEntity byteArrayValue;
protected String byteArrayValueId;
protected int historyNextIndex;
protected Object cachedValue;
protected Type type;
// Default constructor for SQL mapping
VariableInstanceEntity() {
protected VariableInstanceEntity() {
}
public static VariableInstanceEntity createAndInsert(String name, Type type, Object value) {
......@@ -69,6 +71,7 @@ public class VariableInstanceEntity implements Serializable, PersistentObject {
VariableInstanceEntity variableInstance = new VariableInstanceEntity();
variableInstance.name = name;
variableInstance.type = type;
variableInstance.historyNextIndex = 0;
variableInstance.setValue(value);
return variableInstance;
......@@ -88,15 +91,19 @@ public class VariableInstanceEntity implements Serializable, PersistentObject {
}
public void delete() {
// delete variable
DbSqlSession dbSqlSession = CommandContext
.getCurrent()
.getDbSqlSession();
dbSqlSession.delete(VariableInstanceEntity.class, id);
if (byteArrayValueId != null) {
ByteArrayEntity byteArrayValue = getByteArrayValue();
dbSqlSession.delete(ByteArrayEntity.class, byteArrayValue.getId());
// the next apparently useless line is probably to ensure consistency in the DbSqlSession
// cache, but should be checked and docced here (or removed if it turns out to be unnecessary)
// @see also HistoricVariableUpdateEntity
getByteArrayValue();
dbSqlSession.delete(ByteArrayEntity.class, byteArrayValueId);
}
}
......@@ -153,15 +160,23 @@ public class VariableInstanceEntity implements Serializable, PersistentObject {
}
return byteArrayValue;
}
public int generateNextHistoryIndex() {
return historyNextIndex++;
}
// type /////////////////////////////////////////////////////////////////////
public Object getValue() {
return type.getValue(this);
if (!type.isCachable() || cachedValue==null) {
cachedValue = type.getValue(this);
}
return cachedValue;
}
public void setValue(Object value) {
type.setValue(value, this);
cachedValue = value;
}
// getters and setters //////////////////////////////////////////////////////
......@@ -232,4 +247,10 @@ public class VariableInstanceEntity implements Serializable, PersistentObject {
public void setTextValue2(String textValue2) {
this.textValue2 = textValue2;
}
public int getHistoryNextIndex() {
return historyNextIndex;
}
public void setHistoryNextIndex(int historyNextIndex) {
this.historyNextIndex = historyNextIndex;
}
}
......@@ -21,7 +21,9 @@ import java.util.Map;
import java.util.Set;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.cfg.ProcessEngineConfiguration;
import org.activiti.engine.impl.db.DbSqlSession;
import org.activiti.engine.impl.history.HistoricVariableUpdateEntity;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.variable.Type;
import org.activiti.engine.impl.variable.VariableTypes;
......@@ -38,12 +40,17 @@ public class VariableMap implements Map<String, Object> , Serializable {
protected String executionId;
protected String processInstanceId;
protected Map<String, VariableInstanceEntity> variableInstances = null;
protected static ThreadLocal<Boolean> isExternalUpdateThreadLocal = new ThreadLocal<Boolean>();
public VariableMap(String executionId, String processInstanceId) {
this.executionId = executionId;
this.processInstanceId = processInstanceId;
}
public static void setExternalUpdate(Boolean isExternalUpdate) {
isExternalUpdateThreadLocal.set(isExternalUpdate);
}
/** returns an initialized empty variable map */
public static VariableMap createNewInitialized(String executionId, String processInstanceId) {
VariableMap variableMap = new VariableMap(executionId, processInstanceId);
......@@ -98,9 +105,9 @@ public class VariableMap implements Map<String, Object> , Serializable {
remove(key);
variableInstance = null;
}
CommandContext commandContext = CommandContext.getCurrent();
if (variableInstance == null) {
VariableTypes variableTypes = CommandContext
.getCurrent()
VariableTypes variableTypes = commandContext
.getProcessEngineConfiguration()
.getVariableTypes();
......@@ -112,6 +119,16 @@ public class VariableMap implements Map<String, Object> , Serializable {
}
variableInstance.setValue(value);
int historyLevel = commandContext.getProcessEngineConfiguration().getHistoryLevel();
if ( (historyLevel>=ProcessEngineConfiguration.HISTORYLEVEL_AUDIT)
&& (Boolean.TRUE.equals(isExternalUpdateThreadLocal.get()))
) {
DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
HistoricVariableUpdateEntity historicVariableUpdate = new HistoricVariableUpdateEntity(variableInstance, dbSqlSession);
dbSqlSession.insert(historicVariableUpdate);
}
variableInstances.put(key, variableInstance);
return null;
}
......@@ -120,16 +137,7 @@ public class VariableMap implements Map<String, Object> , Serializable {
ensureInitialized();
VariableInstanceEntity variableInstance = variableInstances.remove(key);
if (variableInstance != null) {
// delete variable
DbSqlSession dbSqlSession = CommandContext
.getCurrent()
.getDbSqlSession();
dbSqlSession.delete(VariableInstanceEntity.class, variableInstance.getId());
if (variableInstance.getByteArrayValueId()!=null) {
dbSqlSession.delete(ByteArrayEntity.class, variableInstance.getByteArrayValueId());
}
variableInstance.delete();
}
return null;
}
......
......@@ -25,6 +25,7 @@ import java.util.Set;
import org.activiti.engine.impl.db.PersistentObject;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.runtime.ExecutionEntity;
import org.activiti.engine.impl.runtime.VariableMap;
import org.activiti.engine.impl.util.ClockUtil;
import org.activiti.engine.task.IdentityLinkType;
import org.activiti.engine.task.Task;
......@@ -210,9 +211,14 @@ public class TaskEntity implements Task, Serializable, PersistentObject {
return Collections.EMPTY_MAP;
}
public void setActivityInstanceVariables(Map<String, Object> parameters) {
public void setExecutionVariables(Map<String, Object> parameters) {
if (getExecution()!=null) {
execution.setVariables(parameters);
try {
VariableMap.setExternalUpdate(Boolean.TRUE);
execution.setVariables(parameters);
} finally {
VariableMap.setExternalUpdate(null);
}
}
}
......
......@@ -27,6 +27,10 @@ public class ByteArrayType implements Type {
return "bytes";
}
public boolean isCachable() {
return true;
}
public Object getValue(VariableInstanceEntity variableInstanceEntity) {
if (variableInstanceEntity.getByteArrayValueId()==null) {
return null;
......
......@@ -26,6 +26,10 @@ public class DateType implements Type {
return "date";
}
public boolean isCachable() {
return true;
}
public boolean isAbleToStore(Object value) {
if (value==null) {
return true;
......
......@@ -26,6 +26,10 @@ public class DoubleType implements Type {
return "double";
}
public boolean isCachable() {
return true;
}
public Object getValue(VariableInstanceEntity variableInstanceEntity) {
return variableInstanceEntity.getDoubleValue();
}
......
......@@ -26,6 +26,10 @@ public class IntegerType implements Type {
return "integer";
}
public boolean isCachable() {
return true;
}
public Object getValue(VariableInstanceEntity variableInstanceEntity) {
return new Integer(variableInstanceEntity.getLongValue().intValue());
}
......
......@@ -35,6 +35,10 @@ public class JPAEntityVariableType implements Type {
return TYPE_NAME;
}
public boolean isCachable() {
return false;
}
public boolean isAbleToStore(Object value) {
return mappings.isJPAEntity(value);
}
......
......@@ -26,6 +26,10 @@ public class LongType implements Type {
return "long";
}
public boolean isCachable() {
return true;
}
public Object getValue(VariableInstanceEntity variableInstanceEntity) {
return variableInstanceEntity.getLongValue();
}
......
......@@ -26,6 +26,10 @@ public class NullType implements Type {
return "null";
}
public boolean isCachable() {
return true;
}
public Object getValue(VariableInstanceEntity variableInstanceEntity) {
return null;
}
......
......@@ -26,6 +26,10 @@ public class ShortType implements Type {
return "short";
}
public boolean isCachable() {
return true;
}
public Object getValue(VariableInstanceEntity variableInstanceEntity) {
return new Short(variableInstanceEntity.getLongValue().shortValue());
}
......
......@@ -26,6 +26,10 @@ public class StringType implements Type {
return "string";
}
public boolean isCachable() {
return true;
}
public Object getValue(VariableInstanceEntity variableInstanceEntity) {
return variableInstanceEntity.getTextValue();
}
......
......@@ -21,6 +21,7 @@ import org.activiti.engine.impl.runtime.VariableInstanceEntity;
public interface Type {
String getTypeName();
boolean isCachable();
boolean isAbleToStore(Object value);
void setValue(Object value, VariableInstanceEntity variableInstanceEntity);
Object getValue(VariableInstanceEntity variableInstanceEntity);
......
......@@ -169,6 +169,24 @@ create table ACT_HI_ACT_INST (
primary key (ID_)
);
create table ACT_HI_VAR_UPDATE (
ID_ varchar(64) not null,
PROC_INST_ID_ varchar(64) not null,
EXECUTION_ID_ varchar(64) not null,
TASK_ID_ varchar(64),
TYPE_ varchar(255) not null,
NAME_ varchar(255) not null,
INDEX_ integer,
TIME_ timestamp not null,
BYTEARRAY_ID_ varchar(64),
DATE_ timestamp,
DOUBLE_ double,
LONG_ bigint,
TEXT1_ varchar(255),
TEXT2_ varchar(255),
primary key (ID_)
);
alter table ACT_GE_BYTEARRAY
add constraint FK_BYTEARR_DEPL
foreign key (DEPLOYMENT_ID_)
......
......@@ -171,6 +171,24 @@ create table ACT_HI_ACT_INST (
primary key (ID_)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin;
create table ACT_HI_VAR_UPDATE (
ID_ varchar(64) not null,
PROC_INST_ID_ varchar(64) not null,
EXECUTION_ID_ varchar(64) not null,
TASK_ID_ varchar(64),
TYPE_ varchar(255) not null,
NAME_ varchar(255) not null,
INDEX_ integer,
TIME_ datetime not null,
BYTEARRAY_ID_ varchar(64),
DATE_ datetime,
DOUBLE_ double,
LONG_ bigint,
TEXT1_ varchar(255),
TEXT2_ varchar(255),
primary key (ID_)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin;
alter table ACT_GE_BYTEARRAY
add constraint FK_BYTEARR_DEPL
foreign key (DEPLOYMENT_ID_)
......
......@@ -169,7 +169,26 @@ create table ACT_HI_ACT_INST (
primary key (ID_)
);
alter table ACT_GE_BYTEARRAY
create table ACT_HI_VAR_UPDATE (
ID_ varchar(64) not null,
PROC_INST_ID_ NVARCHAR2(64) not null,
EXECUTION_ID_ NVARCHAR2(64) not null,
TASK_ID_ NVARCHAR2(64),
TYPE_ NVARCHAR2(255) not null,
NAME_ NVARCHAR2(255) not null,
INDEX_ INTEGER,
TIME_ TIMESTAMP(6) not null,
BYTEARRAY_ID_ NVARCHAR2(64),
DATE_ TIMESTAMP(6),
DOUBLE_ NUMBER(*,10),
LONG_ NUMBER(19,0),
TEXT1_ NVARCHAR2(255),
TEXT2_ NVARCHAR2(255),
primary key (ID_)
);
alter table ACT_GE_BYTEARRAY
add constraint FK_BYTEARR_DEPL
foreign key (DEPLOYMENT_ID_)
references ACT_RE_DEPLOYMENT (ID_);
......
......@@ -172,6 +172,24 @@ create table ACT_HI_ACT_INST (
primary key (ID_)
);
create table ACT_HI_VAR_UPDATE (
ID_ varchar(64) not null,
PROC_INST_ID_ varchar(64) not null,
EXECUTION_ID_ varchar(64) not null,
TASK_ID_ varchar(64),
TYPE_ varchar(255) not null,
NAME_ varchar(255) not null,
INDEX_ integer,
TIME_ timestamp not null,
BYTEARRAY_ID_ varchar(64),
DATE_ timestamp,
DOUBLE_ double precision,
LONG_ bigint,
TEXT1_ varchar(255),
TEXT2_ varchar(255),
primary key (ID_)
);
alter table ACT_GE_BYTEARRAY
add constraint FK_BYTEARR_DEPL
foreign key (DEPLOYMENT_ID_)
......
......@@ -63,3 +63,4 @@ drop table ACT_RU_IDENTITY_LINK if exists;
drop table ACT_RU_VARIABLE if exists;
drop table ACT_HI_PROC_INST if exists;
drop table ACT_HI_ACT_INST if exists;
drop table ACT_HI_VAR_UPDATE if exists;
......@@ -57,4 +57,5 @@ alter table ACT_RU_JOB
drop table if exists ACT_RU_JOB;
drop table if exists ACT_HI_PROC_INST;
drop table if exists ACT_HI_ACT_INST;
drop table if exists ACT_HI_VAR_UPDATE;
\ No newline at end of file
......@@ -56,4 +56,5 @@ drop table ACT_ID_GROUP;
drop table ACT_ID_USER;
drop table ACT_RU_JOB;
drop table ACT_HI_PROC_INST;
drop table ACT_HI_ACT_INST;
\ No newline at end of file
drop table ACT_HI_ACT_INST;
drop table ACT_HI_VAR_UPDATE;
\ No newline at end of file
......@@ -57,3 +57,4 @@ drop table ACT_RU_IDENTITY_LINK;
drop table ACT_RU_VARIABLE;
drop table ACT_HI_PROC_INST;
drop table ACT_HI_ACT_INST;
drop table ACT_HI_VAR_UPDATE;
......@@ -224,4 +224,78 @@
</where>
</sql>
<!-- HISTORIC VARIABLE UPDATE INSERT -->
<insert id="insertHistoricVariableUpdate" parameterType="org.activiti.engine.impl.history.HistoricVariableUpdateEntity">
insert into ACT_HI_VAR_UPDATE (ID_, PROC_INST_ID_, EXECUTION_ID_, TASK_ID_, NAME_, TYPE_, INDEX_, TIME_, BYTEARRAY_ID_, DOUBLE_, LONG_ , TEXT1_, TEXT2_)
values (
#{id, jdbcType=VARCHAR},
#{processInstanceId, jdbcType=VARCHAR},
#{executionId, jdbcType=VARCHAR},
#{taskId, jdbcType=VARCHAR},
#{variableName, jdbcType=VARCHAR},
#{variableType, jdbcType=VARCHAR },
#{index, jdbcType=INTEGER },
#{time, jdbcType=TIMESTAMP },
#{byteArrayValueId, jdbcType=VARCHAR},
#{doubleValue, jdbcType=DOUBLE},
#{longValue, jdbcType=BIGINT},
#{textValue, jdbcType=VARCHAR},
#{textValue2, jdbcType=VARCHAR}
)
</insert>
<!-- HISTORIC VARIABLE UPDATE DELETE -->
<delete id="deleteHistoricVariableUpdate">
delete from ACT_HI_VAR_UPDATE where ID_ = #{historicVariableUpdateId}
</delete>
<!-- HISTORIC VARIABLE UPDATE RESULTMAP -->
<resultMap id="historicVariableUpdateResultMap" type="org.activiti.engine.impl.history.HistoricVariableUpdateEntity">
<id property="id" column="ID_" jdbcType="VARCHAR" />
<result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR" />
<result property="executionId" column="EXECUTION_ID_" jdbcType="VARCHAR" />
<result property="taskId" column="TASK_ID_" jdbcType="VARCHAR" />
<result property="name" column="NAME_" javaType="String" jdbcType="VARCHAR" />
<result property="type" column="TYPE_" javaType="org.activiti.engine.impl.variable.Type" jdbcType="VARCHAR"/>
<result property="activityId" column="ACTIVITY_ID_" jdbcType="VARCHAR" />
<result property="index" column="INDEX_" jdbcType="INTEGER" />
<result property="time" column="TIME_" jdbcType="TIMESTAMP" />
<result property="activityId" column="ACTIVITY_ID_" jdbcType="VARCHAR" />
<result property="byteArrayValueId" column="BYTEARRAY_ID_" />
<result property="doubleValue" column="DOUBLE_" />
<result property="textValue" column="TEXT1_" />
<result property="textValue2" column="TEXT2_" />
<result property="longValue" column="LONG_" />
</resultMap>
<!-- HISTORIC VARIABLE UPDATE SELECT -->
<select id="selectHistoricVariableUpdatesByQueryCriteria" parameterType="org.activiti.engine.impl.HistoricVariableUpdateQueryImpl" resultMap="historicVariableUpdateResultMap">
select *
<include refid="selectHistoricVariableUpdatesByQueryCriteriaSql"/>
<if test="orderBy != null">
order by ${orderBy}
</if>
</select>
<select id="selectHistoricVariableUpdateCountByQueryCriteria" parameterType="org.activiti.engine.impl.HistoricVariableUpdateQueryImpl" resultType="long">
select count(*)
<include refid="selectHistoricVariableUpdatesByQueryCriteriaSql"/>
</select>
<sql id="selectHistoricVariableUpdatesByQueryCriteriaSql">
from ACT_HI_VAR_UPDATE HVU
<where>
<if test="processInstanceId != null">
HVU.PROC_INST_ID_ = #{processInstanceId}
</if>
<if test="variableName != null">
and HVU.NAME_ = #{variableName}
</if>
</where>
</sql>
</mapper>
......@@ -7,12 +7,13 @@
<!-- VARIABLE INSTANCE INSERT -->
<insert id="insertVariableInstance" parameterType="org.activiti.engine.impl.runtime.VariableInstanceEntity">
insert into ACT_RU_VARIABLE (ID_, REV_, TYPE_, NAME_, EXECUTION_ID_, TASK_ID_, BYTEARRAY_ID_, DOUBLE_, LONG_ , TEXT1_, TEXT2_)
insert into ACT_RU_VARIABLE (ID_, REV_, TYPE_, NAME_, PROC_INST_ID_, EXECUTION_ID_, TASK_ID_, BYTEARRAY_ID_, DOUBLE_, LONG_ , TEXT1_, TEXT2_)
values (
#{id, jdbcType=VARCHAR},
1,
#{type, jdbcType=VARCHAR },
#{name, jdbcType=VARCHAR},
#{processInstanceId, jdbcType=VARCHAR},
#{executionId, jdbcType=VARCHAR},
#{taskId, jdbcType=VARCHAR},
#{byteArrayValueId, jdbcType=VARCHAR},
......@@ -51,7 +52,8 @@
<result property="revision" column="REV_" jdbcType="INTEGER"/>
<result property="type" column="TYPE_" javaType="org.activiti.engine.impl.variable.Type" jdbcType="VARCHAR"/>
<result property="name" column="NAME_" javaType="String" jdbcType="VARCHAR" />
<result property="processDefinitionId" column="PROC_DEF_ID_" jdbcType="VARCHAR" />
<result property="processInstanceId" column="PROC_INST_ID_" jdbcType="VARCHAR" />
<result property="executionId" column="EXECUTION_ID_" jdbcType="VARCHAR" />
<result property="activityId" column="ACTIVITY_ID_" jdbcType="VARCHAR" />
<result property="isActive" column="IS_ACTIVE_" jdbcType="BOOLEAN" />
<result property="isConcurrencyScope" column="IS_CONCURRENCY_SCOPE_" jdbcType="BOOLEAN" />
......
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.test.history;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.activiti.engine.history.HistoricVariableUpdate;
import org.activiti.engine.history.HistoricVariableUpdateQueryProperty;
import org.activiti.engine.impl.test.ActivitiInternalTestCase;
import org.activiti.engine.test.Deployment;
/**
* @author Tom Baeyens
*/
public class HistoricVariableUpdateTest extends ActivitiInternalTestCase {
@Deployment
public void testHistoricVariableUpdates() {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("startFormParamA", "one");
variables.put("startFormParamB", new Long(234));
variables.put("startFormParamC", new SerializableVariable("contents"));
runtimeService.startProcessInstanceByKey("HistoricVariableUpdateProcess", variables);
List<HistoricVariableUpdate> historicVariableUpdates = historyService
.createHistoricVariableUpdateQuery()
.orderBy(HistoricVariableUpdateQueryProperty.INDEX).asc()
.list();
// HistoricVariableUpdate historicVariableUpdate = historicVariableUpdates.get(0);
// assertEquals(expected, historicVariableUpdate.getProcessInstanceId());
// assertEquals(expected, historicVariableUpdate.getExecutionId());
// assertEquals(expected, historicVariableUpdate.getIndex());
// assertEquals(expected, historicVariableUpdate.getTime());
// assertEquals(expected, historicVariableUpdate.getVariableName());
// assertEquals(expected, historicVariableUpdate.getVariableType());
// assertEquals(expected, historicVariableUpdate.getValue());
System.out.println(historicVariableUpdates);
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.test.history;
import java.io.Serializable;
/**
* @author Tom Baeyens
*/
public class SerializableVariable implements Serializable {
private static final long serialVersionUID = 1L;
public String text;
public SerializableVariable(String text) {
super();
this.text = text;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((text == null) ? 0 : text.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SerializableVariable other = (SerializableVariable) obj;
if (text == null) {
if (other.text != null)
return false;
} else if (!text.equals(other.text))
return false;
return true;
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.test.history;
import org.activiti.pvm.activity.ActivityBehavior;
import org.activiti.pvm.activity.ActivityExecution;
/**
* @author Tom Baeyens
*/
public class VariableSetter implements ActivityBehavior {
public void execute(ActivityExecution execution) throws Exception {
execution.setVariable("internalVar1", "this should not be part of default history level audit");
execution.setVariable("internalVar2", "this neither");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:activiti="http://activiti.org/bpmn-extensions"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
targetNamespace="http://www.activiti.org/bpmn2.0">
<process id="HistoricVariableUpdateProcess">
<startEvent id="start" />
<sequenceFlow id="flow1" sourceRef="start" targetRef="setVariables" />
<serviceTask id="setVariables" activiti:class="org.activiti.engine.test.history.VariableSetter" />
<sequenceFlow id="flow2" sourceRef="setVariables" targetRef="task" />
<userTask id="task" name="Schedule meeting" activiti:assignee="kermit" />
<sequenceFlow id="flow3" sourceRef="task" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册