Fix bug [ 1854603 ] Prepare method is being called twice

great team work on IRC between tobi42, MCalderon, hengsin and me
:-)  Thanks
This commit is contained in:
Carlos Ruiz 2008-01-24 19:16:07 +00:00
parent a1cc40c5b6
commit 9667f26ad9
2 changed files with 29 additions and 10 deletions

View File

@ -41,7 +41,7 @@ import org.compiere.util.*;
public class MWFActivity extends X_AD_WF_Activity implements Runnable
{
/**
* Get Activities for table/tecord
* Get Activities for table/record
* @param ctx context
* @param AD_Table_ID table
* @param Record_ID record
@ -182,6 +182,22 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
m_process = process;
} // MWFActivity
/**
* Parent Contructor
* @param process process
* @param AD_WF_Node_ID start node
* @param lastPO PO from the previously executed node
*/
public MWFActivity(MWFProcess process, int next_ID, PO lastPO) {
this(process, next_ID);
if (lastPO != null) {
// Compare if the last PO is the same type and record needed here, if yes, use it
if (lastPO.get_Table_ID() == getAD_Table_ID() && lastPO.get_ID() == getRecord_ID()) {
m_po = lastPO;
}
}
}
/** State Machine */
private StateEngine m_state = null;
/** Workflow Node */
@ -238,7 +254,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
if (m_process == null)
m_process = new MWFProcess (getCtx(), getAD_WF_Process_ID(),
m_trx == null ? null : m_trx.getTrxName());
m_process.checkActivities(m_trx == null ? null : m_trx.getTrxName());
m_process.checkActivities(m_trx == null ? null : m_trx.getTrxName(), m_po);
}
else
{
@ -307,8 +323,9 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
*/
public PO getPO (Trx trx)
{
if (m_po != null)
if (m_po != null) {
return m_po;
}
MTable table = MTable.get (getCtx(), getAD_Table_ID());
if (trx != null)

View File

@ -97,7 +97,7 @@ public class MWFProcess extends X_AD_WF_Process
// Lock Entity
getPO();
if (m_po != null)
m_po.lock();
m_po.lock();
} // MWFProcess
/** State Machine */
@ -227,7 +227,7 @@ public class MWFProcess extends X_AD_WF_Process
* - start new activity
* @param trxName transaction
*/
public void checkActivities(String trxName)
public void checkActivities(String trxName, PO lastPO)
{
log.info("(" + getAD_Workflow_ID() + ") - " + getWFState()
+ (trxName == null ? "" : "[" + trxName + "]"));
@ -246,7 +246,7 @@ public class MWFProcess extends X_AD_WF_Process
// Completed - Start Next
if (activityState.isCompleted())
{
if (startNext (activity, activities))
if (startNext (activity, activities, lastPO))
continue;
}
//
@ -303,7 +303,7 @@ public class MWFProcess extends X_AD_WF_Process
* @param activities all activities
* @return true if there is a next activity
*/
private boolean startNext (MWFActivity last, MWFActivity[] activities)
private boolean startNext (MWFActivity last, MWFActivity[] activities, PO lastPO)
{
log.fine("Last=" + last);
// transitions from the last processed node
@ -331,9 +331,11 @@ public class MWFProcess extends X_AD_WF_Process
if (!transitions[i].isValidFor(last))
continue;
// Start new Activity
MWFActivity activity = new MWFActivity (this, transitions[i].getAD_WF_Next_ID());
new Thread(activity).start();
// Start new Activity...
MWFActivity activity = new MWFActivity (this, transitions[i].getAD_WF_Next_ID(), lastPO);
//new Thread(activity).start();
//..but not in another thread
activity.run();
// only the first valid if XOR
if (MWFNode.SPLITELEMENT_XOR.equals(split))