Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
开发团队
Flowable Engine
提交
af5d4490
F
Flowable Engine
项目概览
开发团队
/
Flowable Engine
通知
9
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
Flowable Engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
af5d4490
编写于
4月 28, 2014
作者:
M
martin.grofcik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Entity created Event for sub process is fired twice.
上级
84231016
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
101 addition
and
65 deletion
+101
-65
modules/activiti-engine/src/main/java/org/activiti/engine/impl/db/DbSqlSession.java
...c/main/java/org/activiti/engine/impl/db/DbSqlSession.java
+65
-8
modules/activiti-engine/src/main/java/org/activiti/engine/impl/persistence/entity/ExecutionEntity.java
...iviti/engine/impl/persistence/entity/ExecutionEntity.java
+0
-21
modules/activiti-engine/src/main/java/org/activiti/engine/impl/persistence/entity/TaskEntity.java
...g/activiti/engine/impl/persistence/entity/TaskEntity.java
+0
-21
modules/activiti-engine/src/test/java/org/activiti/engine/test/api/event/VariableEventsTest.java
...rg/activiti/engine/test/api/event/VariableEventsTest.java
+36
-15
未找到文件。
modules/activiti-engine/src/main/java/org/activiti/engine/impl/db/DbSqlSession.java
100644 → 100755
浏览文件 @
af5d4490
...
...
@@ -36,6 +36,9 @@ import org.activiti.engine.ActivitiOptimisticLockingException;
import
org.activiti.engine.ActivitiWrongDbException
;
import
org.activiti.engine.ProcessEngine
;
import
org.activiti.engine.ProcessEngineConfiguration
;
import
org.activiti.engine.delegate.event.ActivitiEventType
;
import
org.activiti.engine.delegate.event.ActivitiVariableEvent
;
import
org.activiti.engine.delegate.event.impl.ActivitiEventBuilder
;
import
org.activiti.engine.impl.DeploymentQueryImpl
;
import
org.activiti.engine.impl.ExecutionQueryImpl
;
import
org.activiti.engine.impl.GroupQueryImpl
;
...
...
@@ -480,7 +483,8 @@ public class DbSqlSession implements Session {
// flush ////////////////////////////////////////////////////////////////////
public
void
flush
()
{
removeUnnecessaryOperations
();
List
<
DeleteOperation
>
removedOperations
=
removeUnnecessaryOperations
();
flushDeserializedObjects
();
List
<
PersistentObject
>
updatedObjects
=
getUpdatedObjects
();
...
...
@@ -500,15 +504,16 @@ public class DbSqlSession implements Session {
flushInserts
();
flushUpdates
(
updatedObjects
);
flushDeletes
();
flushDeletes
(
removedOperations
);
}
/**
* Clears all deleted and inserted objects from the cache,
* and removes inserts and deletes that cancel each other.
*/
protected
void
removeUnnecessaryOperations
()
{
protected
List
<
DeleteOperation
>
removeUnnecessaryOperations
()
{
List
<
DeleteOperation
>
removedDeleteOperations
=
new
ArrayList
<
DeleteOperation
>();
for
(
Iterator
<
DeleteOperation
>
deleteIt
=
deleteOperations
.
iterator
();
deleteIt
.
hasNext
();)
{
DeleteOperation
deleteOperation
=
deleteIt
.
next
();
...
...
@@ -520,6 +525,8 @@ public class DbSqlSession implements Session {
// remove the insert and the delete, they cancel each other
insertIt
.
remove
();
deleteIt
.
remove
();
// add removed operations to be able to fire events
removedDeleteOperations
.
add
(
deleteOperation
);
}
}
...
...
@@ -530,7 +537,8 @@ public class DbSqlSession implements Session {
for
(
PersistentObject
insertedObject:
insertedObjects
)
{
cacheRemove
(
insertedObject
.
getClass
(),
insertedObject
.
getId
());
}
return
removedDeleteOperations
;
}
protected
void
flushDeserializedObjects
()
{
...
...
@@ -629,12 +637,61 @@ public class DbSqlSession implements Session {
updatedObjects
.
clear
();
}
protected
void
flushDeletes
()
{
for
(
DeleteOperation
delete:
deleteOperations
)
{
protected
void
flushDeletes
(
List
<
DeleteOperation
>
removedOperations
)
{
boolean
dispatchEvent
=
Context
.
getProcessEngineConfiguration
().
getEventDispatcher
()
.
isEnabled
();
flushRegularDeletes
(
dispatchEvent
);
if
(
dispatchEvent
)
{
dispatchEventsForRemovedOperations
(
removedOperations
);
}
deleteOperations
.
clear
();
}
protected
void
dispatchEventsForRemovedOperations
(
List
<
DeleteOperation
>
removedOperations
)
{
for
(
DeleteOperation
delete
:
removedOperations
)
{
// dispatch removed delete events
if
(
delete
instanceof
CheckedDeleteOperation
)
{
CheckedDeleteOperation
checkedDeleteOperation
=
(
CheckedDeleteOperation
)
delete
;
PersistentObject
persistentObject
=
checkedDeleteOperation
.
getPersistentObject
();
if
(
persistentObject
instanceof
VariableInstanceEntity
)
{
VariableInstanceEntity
variableInstance
=
(
VariableInstanceEntity
)
persistentObject
;
Context
.
getProcessEngineConfiguration
().
getEventDispatcher
().
dispatchEvent
(
createVariableDeleteEvent
(
variableInstance
)
);
}
}
}
}
protected
static
ActivitiVariableEvent
createVariableDeleteEvent
(
VariableInstanceEntity
variableInstance
)
{
return
ActivitiEventBuilder
.
createVariableEvent
(
ActivitiEventType
.
VARIABLE_DELETED
,
variableInstance
.
getName
(),
null
,
variableInstance
.
getTaskId
(),
variableInstance
.
getExecutionId
(),
variableInstance
.
getProcessInstanceId
(),
null
);
}
protected
void
flushRegularDeletes
(
boolean
dispatchEvent
)
{
for
(
DeleteOperation
delete
:
deleteOperations
)
{
log
.
debug
(
"executing: {}"
,
delete
);
delete
.
execute
();
// fire event for variable delete operation. (BulkDeleteOperation is not taken into account)
if
(
dispatchEvent
)
{
// prepare delete event to fire for variable delete operation. (BulkDeleteOperation is not taken into account)
if
(
delete
instanceof
CheckedDeleteOperation
)
{
CheckedDeleteOperation
checkedDeleteOperation
=
(
CheckedDeleteOperation
)
delete
;
PersistentObject
persistentObject
=
checkedDeleteOperation
.
getPersistentObject
();
if
(
persistentObject
instanceof
VariableInstanceEntity
)
{
VariableInstanceEntity
variableInstance
=
(
VariableInstanceEntity
)
persistentObject
;
Context
.
getProcessEngineConfiguration
().
getEventDispatcher
().
dispatchEvent
(
createVariableDeleteEvent
(
variableInstance
)
);
}
}
}
}
deleteOperations
.
clear
();
}
public
void
close
()
{
...
...
modules/activiti-engine/src/main/java/org/activiti/engine/impl/persistence/entity/ExecutionEntity.java
浏览文件 @
af5d4490
...
...
@@ -1091,27 +1091,6 @@ public class ExecutionEntity extends VariableScopeImpl implements ActivityExecut
variableInstance
.
getExecutionId
(),
getProcessInstanceId
(),
getProcessDefinitionId
()));
}
}
@Override
protected
void
deleteVariableInstanceForExplicitUserCall
(
VariableInstanceEntity
variableInstance
,
ExecutionEntity
sourceActivityExecution
)
{
boolean
dispatchEvent
=
Context
.
getProcessEngineConfiguration
().
getEventDispatcher
()
.
isEnabled
();
Object
oldValue
=
null
;
if
(
dispatchEvent
)
{
oldValue
=
variableInstance
.
getValue
();
}
super
.
deleteVariableInstanceForExplicitUserCall
(
variableInstance
,
sourceActivityExecution
);
if
(
dispatchEvent
)
{
if
(
dispatchEvent
)
{
Context
.
getProcessEngineConfiguration
().
getEventDispatcher
().
dispatchEvent
(
ActivitiEventBuilder
.
createVariableEvent
(
ActivitiEventType
.
VARIABLE_DELETED
,
variableInstance
.
getName
(),
oldValue
,
variableInstance
.
getTaskId
(),
variableInstance
.
getExecutionId
(),
getProcessInstanceId
(),
getProcessDefinitionId
()));
}
}
}
// persistent state /////////////////////////////////////////////////////////
...
...
modules/activiti-engine/src/main/java/org/activiti/engine/impl/persistence/entity/TaskEntity.java
100644 → 100755
浏览文件 @
af5d4490
...
...
@@ -307,27 +307,6 @@ public class TaskEntity extends VariableScopeImpl implements Task, DelegateTask,
variableInstance
.
getExecutionId
(),
getProcessInstanceId
(),
getProcessDefinitionId
()));
}
}
@Override
protected
void
deleteVariableInstanceForExplicitUserCall
(
VariableInstanceEntity
variableInstance
,
ExecutionEntity
sourceActivityExecution
)
{
boolean
dispatchEvent
=
Context
.
getProcessEngineConfiguration
().
getEventDispatcher
()
.
isEnabled
();
Object
oldValue
=
null
;
if
(
dispatchEvent
)
{
oldValue
=
variableInstance
.
getValue
();
}
super
.
deleteVariableInstanceForExplicitUserCall
(
variableInstance
,
sourceActivityExecution
);
if
(
dispatchEvent
)
{
if
(
dispatchEvent
)
{
Context
.
getProcessEngineConfiguration
().
getEventDispatcher
().
dispatchEvent
(
ActivitiEventBuilder
.
createVariableEvent
(
ActivitiEventType
.
VARIABLE_DELETED
,
variableInstance
.
getName
(),
oldValue
,
variableInstance
.
getTaskId
(),
variableInstance
.
getExecutionId
(),
getProcessInstanceId
(),
getProcessDefinitionId
()));
}
}
}
// execution ////////////////////////////////////////////////////////////////
...
...
modules/activiti-engine/src/test/java/org/activiti/engine/test/api/event/VariableEventsTest.java
100644 → 100755
浏览文件 @
af5d4490
...
...
@@ -12,9 +12,6 @@
*/
package
org.activiti.engine.test.api.event
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.activiti.engine.delegate.event.ActivitiEvent
;
import
org.activiti.engine.delegate.event.ActivitiEventType
;
import
org.activiti.engine.delegate.event.ActivitiVariableEvent
;
...
...
@@ -25,6 +22,9 @@ import org.activiti.engine.runtime.ProcessInstance;
import
org.activiti.engine.task.Task
;
import
org.activiti.engine.test.Deployment
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* Test case for all {@link ActivitiEvent}s related to variables.
*
...
...
@@ -74,12 +74,14 @@ public class VariableEventsTest extends PluggableActivitiTestCase {
assertEquals
(
1
,
listener
.
getEventsReceived
().
size
());
event
=
(
ActivitiVariableEvent
)
listener
.
getEventsReceived
().
get
(
0
);
assertEquals
(
ActivitiEventType
.
VARIABLE_DELETED
,
event
.
getType
());
assertEquals
(
processInstance
.
getProcessDefinitionId
(),
event
.
getProcessDefinitionId
());
// process definition Id can't be recognized in DB flush
assertEquals
(
null
,
event
.
getProcessDefinitionId
());
assertEquals
(
processInstance
.
getId
(),
event
.
getExecutionId
());
assertEquals
(
processInstance
.
getId
(),
event
.
getProcessInstanceId
());
assertNull
(
event
.
getTaskId
());
assertEquals
(
"testVariable"
,
event
.
getVariableName
());
assertEquals
(
"Updated value"
,
event
.
getVariableValue
());
// deleted variable value is always null
assertEquals
(
null
,
event
.
getVariableValue
());
listener
.
clearEventsReceived
();
// Create, update and delete multiple variables
...
...
@@ -103,10 +105,25 @@ public class VariableEventsTest extends PluggableActivitiTestCase {
runtimeService
.
removeVariable
(
processInstance
.
getId
(),
"unexistingVariable"
);
assertTrue
(
listener
.
getEventsReceived
().
isEmpty
());
}
/**
* Test create event of variables when process is started with variables passed in.
*/
@Deployment
(
resources
=
{
"org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"
})
public
void
testStartEndProcessInstanceVariableEvents
()
throws
Exception
{
Map
<
String
,
Object
>
variables
=
new
HashMap
<
String
,
Object
>();
variables
.
put
(
"var1"
,
"value1"
);
ProcessInstance
processInstance
=
runtimeService
.
startProcessInstanceByKey
(
"oneTaskProcess"
,
variables
);
assertEquals
(
1
,
listener
.
getEventsReceived
().
size
());
assertEquals
(
ActivitiEventType
.
VARIABLE_CREATED
,
listener
.
getEventsReceived
().
get
(
0
).
getType
());
Task
task
=
taskService
.
createTaskQuery
().
processInstanceId
(
processInstance
.
getId
()).
singleResult
();
taskService
.
complete
(
task
.
getId
());
assertEquals
(
2
,
listener
.
getEventsReceived
().
size
());
assertEquals
(
ActivitiEventType
.
VARIABLE_DELETED
,
listener
.
getEventsReceived
().
get
(
1
).
getType
());
}
/**
* Test create event of variables when process is started with variables passed in.
*/
@Deployment
(
resources
=
{
"org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"
})
public
void
testProcessInstanceVariableEventsOnStart
()
throws
Exception
{
...
...
@@ -156,7 +173,7 @@ public class VariableEventsTest extends PluggableActivitiTestCase {
* Test variable events when done within a process (eg. execution-listener)
*/
@Deployment
public
void
testProcessInstanceVariableEventsWithinProcess
()
throws
Exception
{
public
void
ActivitiEventType
()
throws
Exception
{
ProcessInstance
processInstance
=
runtimeService
.
startProcessInstanceByKey
(
"variableProcess"
);
assertNotNull
(
processInstance
);
...
...
@@ -231,12 +248,13 @@ public class VariableEventsTest extends PluggableActivitiTestCase {
event
=
(
ActivitiVariableEvent
)
listener
.
getEventsReceived
().
get
(
2
);
assertEquals
(
ActivitiEventType
.
VARIABLE_DELETED
,
event
.
getType
());
assertEquals
(
processInstance
.
getProcessDefinitionId
(),
event
.
getProcessDefinitionId
());
assertEquals
(
null
,
event
.
getProcessDefinitionId
());
// process definition Id is set to null
assertEquals
(
processInstance
.
getId
(),
event
.
getExecutionId
());
assertEquals
(
processInstance
.
getId
(),
event
.
getProcessInstanceId
());
assertEquals
(
task
.
getId
(),
event
.
getTaskId
());
assertEquals
(
"testVariable"
,
event
.
getVariableName
());
assertEquals
(
"Updated value"
,
event
.
getVariableValue
());
// deleted values are always null
assertEquals
(
null
,
event
.
getVariableValue
());
listener
.
clearEventsReceived
();
}
...
...
@@ -277,12 +295,14 @@ public class VariableEventsTest extends PluggableActivitiTestCase {
// Check delete event
event
=
(
ActivitiVariableEvent
)
listener
.
getEventsReceived
().
get
(
2
);
assertEquals
(
ActivitiEventType
.
VARIABLE_DELETED
,
event
.
getType
());
assertEquals
(
processInstance
.
getProcessDefinitionId
(),
event
.
getProcessDefinitionId
());
// process definition Id can't be recognized in DB flush
assertEquals
(
null
,
event
.
getProcessDefinitionId
());
assertEquals
(
processInstance
.
getId
(),
event
.
getExecutionId
());
assertEquals
(
processInstance
.
getId
(),
event
.
getProcessInstanceId
());
assertEquals
(
task
.
getId
(),
event
.
getTaskId
());
assertEquals
(
"variable"
,
event
.
getVariableName
());
assertEquals
(
456
,
event
.
getVariableValue
());
// deleted variable value is always null
assertEquals
(
null
,
event
.
getVariableValue
());
}
/**
...
...
@@ -323,7 +343,8 @@ public class VariableEventsTest extends PluggableActivitiTestCase {
assertNull
(
event
.
getProcessInstanceId
());
assertEquals
(
newTask
.
getId
(),
event
.
getTaskId
());
assertEquals
(
"testVariable"
,
event
.
getVariableName
());
assertEquals
(
456
,
event
.
getVariableValue
());
// deleted variable value is always null
assertEquals
(
null
,
event
.
getVariableValue
());
}
finally
{
// Cleanup task and history to ensure a clean DB after test success/failure
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录