Author: alex.guizar(a)jboss.com
Date: 2010-12-01 20:32:15 -0500 (Wed, 01 Dec 2010)
New Revision: 6855
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/exe/Token.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/svc/Services.java
Log:
skip id assignment during root token construction, process instance is saved shortly
afterwards
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/exe/Token.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/exe/Token.java 2010-12-01
23:05:01 UTC (rev 6854)
+++
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/graph/exe/Token.java 2010-12-02
01:32:15 UTC (rev 6855)
@@ -98,7 +98,8 @@
this.isTerminationImplicit =
processInstance.getProcessDefinition().isTerminationImplicit();
// assign an id to this token before events get fired
- Services.assignId(this);
+ // skip, process instance is saved shortly after constructing root token
+ // Services.assignId(this);
}
/**
@@ -121,10 +122,8 @@
// operations
// ///////////////////////////////////////////////////////////////////////////
- void addChild(Token token) {
- if (children == null) {
- children = new HashMap();
- }
+ private void addChild(Token token) {
+ if (children == null) children = new HashMap();
children.put(token.getName(), token);
}
@@ -136,10 +135,12 @@
if (node == null) {
throw new JbpmException(this + " is not positioned in a node");
}
+
Transition defaultTransition = node.getDefaultLeavingTransition();
if (defaultTransition == null) {
throw new JbpmException(node + " has no default transition");
}
+
signal(defaultTransition, new ExecutionContext(this));
}
@@ -182,7 +183,7 @@
signal(node.getDefaultLeavingTransition(), executionContext);
}
- void signal(Transition transition, ExecutionContext executionContext) {
+ private void signal(Transition transition, ExecutionContext executionContext) {
if (transition == null) {
throw new JbpmException("transition is null");
}
@@ -224,8 +225,7 @@
* resolves to true.
*/
public Set getAvailableTransitions() {
- if (node == null)
- return Collections.EMPTY_SET;
+ if (node == null) return Collections.EMPTY_SET;
Set availableTransitions = new HashSet();
addAvailableTransitionsOfNode(node, availableTransitions);
@@ -245,14 +245,16 @@
if (conditionExpression != null) {
Boolean result = (Boolean)
JbpmExpressionEvaluator.evaluate(conditionExpression,
new ExecutionContext(this), Boolean.class);
- if (Boolean.TRUE.equals(result))
+ if (Boolean.TRUE.equals(result)) {
availableTransitions.add(transition);
+ }
}
else {
availableTransitions.add(transition);
}
}
}
+
if (currentNode.getSuperState() != null) {
addAvailableTransitionsOfNode(currentNode.getSuperState(), availableTransitions);
}
@@ -278,8 +280,7 @@
public void end(boolean verifyParentTermination) {
// if already ended, do nothing
if (end != null) {
- if (parent != null)
- log.warn(this + " has ended already");
+ if (parent != null) log.warn(this + " has ended already");
return;
}
@@ -294,8 +295,9 @@
if (children != null) {
for (Iterator iter = children.values().iterator(); iter.hasNext();) {
Token child = (Token) iter.next();
- if (!child.hasEnded())
+ if (!child.hasEnded()) {
child.end();
+ }
}
}
@@ -313,8 +315,7 @@
// if there are tasks associated to this token,
// remove signaling capabilities
TaskMgmtInstance taskMgmtInstance = processInstance.getTaskMgmtInstance();
- if (taskMgmtInstance != null)
- taskMgmtInstance.removeSignalling(this);
+ if (taskMgmtInstance != null) taskMgmtInstance.removeSignalling(this);
if (verifyParentTermination) {
// if this is the last active token of the parent,
@@ -330,8 +331,7 @@
}
public void addComment(Comment comment) {
- if (comments == null)
- comments = new ArrayList();
+ if (comments == null) comments = new ArrayList();
comments.add(comment);
comment.setToken(this);
}
@@ -345,7 +345,7 @@
/**
* notifies a parent that one of its nodeMap has ended.
*/
- void notifyParentOfTokenEnd() {
+ private void notifyParentOfTokenEnd() {
if (isRoot()) {
processInstance.end();
}
@@ -362,8 +362,7 @@
if (children != null) {
for (Iterator iter = children.values().iterator(); iter.hasNext();) {
Token child = (Token) iter.next();
- if (!child.hasEnded())
- return true;
+ if (!child.hasEnded()) return true;
}
}
return false;
@@ -399,8 +398,7 @@
*/
public void endCompositeLog() {
LoggingInstance loggingInstance = processInstance.getLoggingInstance();
- if (loggingInstance != null)
- loggingInstance.endCompositeLog();
+ if (loggingInstance != null) loggingInstance.endCompositeLog();
}
// various information extraction methods ///////////////////////////////////
@@ -443,14 +441,14 @@
return foundChildren;
}
- void getChildrenAtNode(Node aNode, List foundTokens) {
+ private void getChildrenAtNode(Node aNode, List foundTokens) {
if (aNode.equals(node)) {
foundTokens.add(this);
}
- else if (children != null && !children.isEmpty()) {
+ else if (children != null) {
for (Iterator it = children.values().iterator(); it.hasNext();) {
- Token aChild = (Token) it.next();
- aChild.getChildrenAtNode(aNode, foundTokens);
+ Token child = (Token) it.next();
+ child.getChildrenAtNode(aNode, foundTokens);
}
}
}
@@ -507,14 +505,12 @@
public void checkImplicitTermination() {
if (isTerminationImplicit && node.hasNoLeavingTransitions()) {
end();
- if (processInstance.isTerminatedImplicitly())
- processInstance.end();
+ if (processInstance.isTerminatedImplicitly()) processInstance.end();
}
}
public boolean isTerminatedImplicitly() {
- if (end != null)
- return true;
+ if (end != null) return true;
Map leavingTransitions = node.getLeavingTransitionsMap();
if (leavingTransitions != null && !leavingTransitions.isEmpty()) {
@@ -525,8 +521,7 @@
// loop over all active child tokens
for (Iterator iter = getActiveChildren().values().iterator(); iter.hasNext();) {
Token child = (Token) iter.next();
- if (!child.isTerminatedImplicitly())
- return false;
+ if (!child.isTerminatedImplicitly()) return false;
}
// if none of the above, this token is terminated implicitly
return true;
@@ -554,19 +549,17 @@
}
}
- void suspendJobs() {
+ private void suspendJobs() {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
if (jbpmContext != null) {
JobSession jobSession = jbpmContext.getJobSession();
- if (jobSession != null)
- jobSession.suspendJobs(this);
+ if (jobSession != null) jobSession.suspendJobs(this);
}
}
- void suspendTaskInstances() {
+ private void suspendTaskInstances() {
TaskMgmtInstance taskMgmtInstance = processInstance.getTaskMgmtInstance();
- if (taskMgmtInstance != null)
- taskMgmtInstance.suspend(this);
+ if (taskMgmtInstance != null) taskMgmtInstance.suspend(this);
}
/**
@@ -587,32 +580,27 @@
}
}
- void resumeJobs() {
+ private void resumeJobs() {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
if (jbpmContext != null) {
JobSession jobSession = jbpmContext.getJobSession();
- if (jobSession != null)
- jobSession.resumeJobs(this);
+ if (jobSession != null) jobSession.resumeJobs(this);
}
}
- void resumeTaskInstances() {
+ private void resumeTaskInstances() {
TaskMgmtInstance taskMgmtInstance = processInstance.getTaskMgmtInstance();
- if (taskMgmtInstance != null)
- taskMgmtInstance.resume(this);
+ if (taskMgmtInstance != null) taskMgmtInstance.resume(this);
}
// equals ///////////////////////////////////////////////////////////////////
public boolean equals(Object o) {
- if (o == this)
- return true;
- if (!(o instanceof Token))
- return false;
+ if (o == this) return true;
+ if (!(o instanceof Token)) return false;
Token other = (Token) o;
- if (id != 0 && id == other.getId())
- return true;
+ if (id != 0 && id == other.getId()) return true;
return (name != null ? name.equals(other.getName()) : other.getName() == null)
&& (parent != null ? parent.equals(other.getParent())
@@ -649,13 +637,11 @@
* @see #unlock(String)
*/
public void lock(String lockOwner) {
- if (lockOwner == null)
- throw new JbpmException("lock owner is null");
+ if (lockOwner == null) throw new JbpmException("lock owner is null");
if (lock == null) {
lock = lockOwner;
- if (log.isDebugEnabled())
- log.debug('\'' + lockOwner + "' locked " + this);
+ if (log.isDebugEnabled()) log.debug('\'' + lockOwner + "'
locked " + this);
}
else if (!lock.equals(lockOwner)) {
throw new JbpmException('\'' + lockOwner + "' cannot lock
" + this + " because '" + lock
@@ -674,8 +660,7 @@
}
lock = null;
- if (log.isDebugEnabled())
- log.debug('\'' + lockOwner + "' unlocked " + this);
+ if (log.isDebugEnabled()) log.debug('\'' + lockOwner + "'
unlocked " + this);
}
else {
log.warn(this + " was already unlocked");
@@ -704,8 +689,7 @@
public void forceUnlock() {
if (lock != null) {
lock = null;
- if (log.isDebugEnabled())
- log.debug("forcefully unlocked " + this);
+ if (log.isDebugEnabled()) log.debug("forcefully unlocked " + this);
}
else {
log.warn(this + " was unlocked already");
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/svc/Services.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/svc/Services.java 2010-12-01
23:05:01 UTC (rev 6854)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/svc/Services.java 2010-12-02
01:32:15 UTC (rev 6855)
@@ -32,6 +32,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.jbpm.JbpmContext;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.logging.LoggingService;
@@ -45,7 +46,6 @@
import org.jbpm.security.AuthorizationService;
import org.jbpm.svc.save.CascadeSaveOperation;
import org.jbpm.svc.save.CheckUnpersistableVariablesOperation;
-import org.jbpm.svc.save.HibernateSaveOperation;
import org.jbpm.svc.save.SaveLogsOperation;
import org.jbpm.svc.save.SaveOperation;
import org.jbpm.tx.TxService;