[ 1854603 ] Prepare method is being called twice
- trx management fix. - remove non-thread safe code.
This commit is contained in:
parent
ac21848e01
commit
3c059e91c8
|
@ -249,7 +249,7 @@ public final class ProcessUtil {
|
||||||
MWorkflow wf = MWorkflow.get (ctx, AD_Workflow_ID);
|
MWorkflow wf = MWorkflow.get (ctx, AD_Workflow_ID);
|
||||||
MWFProcess wfProcess = null;
|
MWFProcess wfProcess = null;
|
||||||
if (pi.isBatch())
|
if (pi.isBatch())
|
||||||
wfProcess = wf.start(pi); // may return null
|
wfProcess = wf.start(pi, null); // may return null
|
||||||
else
|
else
|
||||||
wfProcess = wf.startWait(pi); // may return null
|
wfProcess = wf.startWait(pi); // may return null
|
||||||
log.fine(pi.toString());
|
log.fine(pi.toString());
|
||||||
|
|
|
@ -125,7 +125,7 @@ public class DocWorkflowManager implements DocWorkflowMgr
|
||||||
pi.setAD_User_ID (Env.getAD_User_ID(document.getCtx()));
|
pi.setAD_User_ID (Env.getAD_User_ID(document.getCtx()));
|
||||||
pi.setAD_Client_ID(document.getAD_Client_ID());
|
pi.setAD_Client_ID(document.getAD_Client_ID());
|
||||||
//
|
//
|
||||||
if (wf.start(pi) != null)
|
if (wf.start(pi, document.get_TrxName()) != null)
|
||||||
{
|
{
|
||||||
log.config(wf.getName());
|
log.config(wf.getName());
|
||||||
m_noStarted++;
|
m_noStarted++;
|
||||||
|
|
|
@ -736,8 +736,9 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
||||||
log.info ("Node=" + getNode());
|
log.info ("Node=" + getNode());
|
||||||
m_newValue = null;
|
m_newValue = null;
|
||||||
|
|
||||||
String trxName = Trx.createTrxName("WF");
|
|
||||||
m_trx = Trx.get(trxName, true);
|
m_trx = Trx.get(Trx.createTrxName("WFA"), true);
|
||||||
|
|
||||||
//
|
//
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -759,11 +760,6 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
||||||
// Do Work
|
// Do Work
|
||||||
/**** Trx Start ****/
|
/**** Trx Start ****/
|
||||||
boolean done = performWork(m_trx);
|
boolean done = performWork(m_trx);
|
||||||
//begin vpj-cd e-evolution 03/08/2005 PostgreSQL
|
|
||||||
// Reason: When is execute setWFState create a transaction for same table is generate a clicle Trx
|
|
||||||
// is cause that PostgreSQL wait into transaction idle
|
|
||||||
//setWFState (done ? StateEngine.STATE_Completed : StateEngine.STATE_Suspended);
|
|
||||||
//end vpj-cd e-evolution 03/08/2005 PostgreSQL
|
|
||||||
|
|
||||||
/**** Trx End ****/
|
/**** Trx End ****/
|
||||||
// teo_sarca [ 1708835 ]
|
// teo_sarca [ 1708835 ]
|
||||||
|
@ -776,9 +772,9 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
||||||
m_docStatus = DocAction.STATUS_Invalid;
|
m_docStatus = DocAction.STATUS_Invalid;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
//begin vpj-cd e-evolution 03/08/2005 PostgreSQL
|
|
||||||
//Reason: setWFState moved for the first trx be finished
|
|
||||||
setWFState (done ? StateEngine.STATE_Completed : StateEngine.STATE_Suspended);
|
setWFState (done ? StateEngine.STATE_Completed : StateEngine.STATE_Suspended);
|
||||||
|
|
||||||
//end vpj-cd e-evolution 03/08/2005 PostgreSQL
|
//end vpj-cd e-evolution 03/08/2005 PostgreSQL
|
||||||
if (m_postImmediate != null)
|
if (m_postImmediate != null)
|
||||||
postImmediate();
|
postImmediate();
|
||||||
|
@ -792,6 +788,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
||||||
//
|
//
|
||||||
if (e.getCause() != null)
|
if (e.getCause() != null)
|
||||||
log.log(Level.WARNING, "Cause", e.getCause());
|
log.log(Level.WARNING, "Cause", e.getCause());
|
||||||
|
|
||||||
String processMsg = e.getLocalizedMessage();
|
String processMsg = e.getLocalizedMessage();
|
||||||
if (processMsg == null || processMsg.length() == 0)
|
if (processMsg == null || processMsg.length() == 0)
|
||||||
processMsg = e.getMessage();
|
processMsg = e.getMessage();
|
||||||
|
|
|
@ -72,11 +72,24 @@ public class MWFProcess extends X_AD_WF_Process
|
||||||
* New Constructor
|
* New Constructor
|
||||||
* @param wf workflow
|
* @param wf workflow
|
||||||
* @param pi Process Info (Record_ID)
|
* @param pi Process Info (Record_ID)
|
||||||
|
* @deprecated
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public MWFProcess (MWorkflow wf, ProcessInfo pi) throws Exception
|
public MWFProcess (MWorkflow wf, ProcessInfo pi) throws Exception
|
||||||
{
|
{
|
||||||
super (wf.getCtx(), 0, wf.get_TrxName());
|
this(wf, pi, wf.get_TrxName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New Constructor
|
||||||
|
* @param wf workflow
|
||||||
|
* @param pi Process Info (Record_ID)
|
||||||
|
* @param trxName
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public MWFProcess (MWorkflow wf, ProcessInfo pi, String trxName) throws Exception
|
||||||
|
{
|
||||||
|
super (wf.getCtx(), 0, trxName);
|
||||||
if (!TimeUtil.isValid(wf.getValidFrom(), wf.getValidTo()))
|
if (!TimeUtil.isValid(wf.getValidFrom(), wf.getValidTo()))
|
||||||
throw new IllegalStateException("Workflow not valid");
|
throw new IllegalStateException("Workflow not valid");
|
||||||
m_wf = wf;
|
m_wf = wf;
|
||||||
|
@ -251,6 +264,10 @@ public class MWFProcess extends X_AD_WF_Process
|
||||||
+ (trxName == null ? "" : "[" + trxName + "]"));
|
+ (trxName == null ? "" : "[" + trxName + "]"));
|
||||||
if (m_state.isClosed())
|
if (m_state.isClosed())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (lastPO != null && lastPO.get_ID() == this.getRecord_ID())
|
||||||
|
m_po = lastPO;
|
||||||
|
|
||||||
//
|
//
|
||||||
MWFActivity[] activities = getActivities (true, true, trxName); // requery active
|
MWFActivity[] activities = getActivities (true, true, trxName); // requery active
|
||||||
String closedState = null;
|
String closedState = null;
|
||||||
|
@ -306,7 +323,7 @@ public class MWFProcess extends X_AD_WF_Process
|
||||||
setWFState(closedState);
|
setWFState(closedState);
|
||||||
getPO();
|
getPO();
|
||||||
if (m_po != null)
|
if (m_po != null)
|
||||||
m_po.unlock(trxName);
|
m_po.unlock(null);
|
||||||
}
|
}
|
||||||
else if (suspended)
|
else if (suspended)
|
||||||
setWFState(WFSTATE_Suspended);
|
setWFState(WFSTATE_Suspended);
|
||||||
|
@ -487,7 +504,7 @@ public class MWFProcess extends X_AD_WF_Process
|
||||||
activity.run();
|
activity.run();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, "AD_WF_Node_ID=" + AD_WF_Node_ID, e);
|
log.log(Level.SEVERE, "AD_WF_Node_ID=" + AD_WF_Node_ID, e);
|
||||||
setTextMsg(e.toString());
|
setTextMsg(e.toString());
|
||||||
|
|
|
@ -119,6 +119,8 @@ public class MWorkflow extends X_AD_Workflow
|
||||||
}
|
}
|
||||||
// Look for Entry
|
// Look for Entry
|
||||||
MWorkflow[] retValue = (MWorkflow[])s_cacheDocValue.get(key);
|
MWorkflow[] retValue = (MWorkflow[])s_cacheDocValue.get(key);
|
||||||
|
//hengsin: this is not threadsafe
|
||||||
|
/*
|
||||||
//set trxName to all workflow instance
|
//set trxName to all workflow instance
|
||||||
if ( retValue != null && retValue.length > 0 )
|
if ( retValue != null && retValue.length > 0 )
|
||||||
{
|
{
|
||||||
|
@ -126,7 +128,7 @@ public class MWorkflow extends X_AD_Workflow
|
||||||
{
|
{
|
||||||
retValue[i].set_TrxName(trxName);
|
retValue[i].set_TrxName(trxName);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
return retValue;
|
return retValue;
|
||||||
} // getDocValue
|
} // getDocValue
|
||||||
|
|
||||||
|
@ -643,28 +645,50 @@ public class MWorkflow extends X_AD_Workflow
|
||||||
return success;
|
return success;
|
||||||
} // afterSave
|
} // afterSave
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Start Workflow.
|
||||||
|
* @param pi Process Info (Record_ID)
|
||||||
|
* @deprecated
|
||||||
|
* @return process
|
||||||
|
*/
|
||||||
|
public MWFProcess start (ProcessInfo pi)
|
||||||
|
{
|
||||||
|
return start(pi, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Start Workflow.
|
* Start Workflow.
|
||||||
* @param pi Process Info (Record_ID)
|
* @param pi Process Info (Record_ID)
|
||||||
* @return process
|
* @return process
|
||||||
*/
|
*/
|
||||||
public MWFProcess start (ProcessInfo pi)
|
public MWFProcess start (ProcessInfo pi, String trxName)
|
||||||
{
|
{
|
||||||
MWFProcess retValue = null;
|
MWFProcess retValue = null;
|
||||||
|
Trx localTrx = null;
|
||||||
|
if (trxName == null)
|
||||||
|
localTrx = Trx.get(Trx.createTrxName("WFP"), true);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
retValue = new MWFProcess (this, pi);
|
retValue = new MWFProcess (this, pi, trxName != null ? trxName : localTrx.getTrxName());
|
||||||
retValue.save();
|
retValue.save();
|
||||||
retValue.startWork();
|
|
||||||
pi.setSummary(Msg.getMsg(getCtx(), "Processing"));
|
pi.setSummary(Msg.getMsg(getCtx(), "Processing"));
|
||||||
|
retValue.startWork();
|
||||||
|
if (localTrx != null)
|
||||||
|
localTrx.commit(true);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
if (localTrx != null)
|
||||||
|
localTrx.rollback();
|
||||||
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||||
pi.setSummary(e.getMessage(), true);
|
pi.setSummary(e.getMessage(), true);
|
||||||
retValue = null;
|
retValue = null;
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (localTrx != null)
|
||||||
|
localTrx.close();
|
||||||
|
}
|
||||||
return retValue;
|
return retValue;
|
||||||
} // MWFProcess
|
} // MWFProcess
|
||||||
|
|
||||||
|
@ -678,7 +702,7 @@ public class MWorkflow extends X_AD_Workflow
|
||||||
final int SLEEP = 500; // 1/2 sec
|
final int SLEEP = 500; // 1/2 sec
|
||||||
final int MAXLOOPS = 30; // 15 sec
|
final int MAXLOOPS = 30; // 15 sec
|
||||||
//
|
//
|
||||||
MWFProcess process = start(pi);
|
MWFProcess process = start(pi, null);
|
||||||
if (process == null)
|
if (process == null)
|
||||||
return null;
|
return null;
|
||||||
Thread.yield();
|
Thread.yield();
|
||||||
|
|
Loading…
Reference in New Issue