[ 1854603 ] Prepare method is being called twice
- trx management fix.
This commit is contained in:
parent
2beae9081c
commit
c6e4203274
|
@ -278,8 +278,8 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
||||||
// Inform Process
|
// Inform Process
|
||||||
if (m_process == null)
|
if (m_process == null)
|
||||||
m_process = new MWFProcess (getCtx(), getAD_WF_Process_ID(),
|
m_process = new MWFProcess (getCtx(), getAD_WF_Process_ID(),
|
||||||
m_trx == null ? null : m_trx.getTrxName());
|
this.get_TrxName());
|
||||||
m_process.checkActivities(m_trx == null ? null : m_trx.getTrxName(), m_po);
|
m_process.checkActivities(this.get_TrxName(), m_po);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -735,6 +735,12 @@ 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);
|
||||||
|
//
|
||||||
|
try
|
||||||
|
{
|
||||||
if (!m_state.isValidAction(StateEngine.ACTION_Start))
|
if (!m_state.isValidAction(StateEngine.ACTION_Start))
|
||||||
{
|
{
|
||||||
setTextMsg("State=" + getWFState() + " - cannot start");
|
setTextMsg("State=" + getWFState() + " - cannot start");
|
||||||
|
@ -743,10 +749,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
setWFState(StateEngine.STATE_Running);
|
setWFState(StateEngine.STATE_Running);
|
||||||
m_trx = Trx.get(Trx.createTrxName("WF"), true);
|
|
||||||
//
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (getNode().get_ID() == 0)
|
if (getNode().get_ID() == 0)
|
||||||
{
|
{
|
||||||
setTextMsg("Node not found - AD_WF_Node_ID=" + getAD_WF_Node_ID());
|
setTextMsg("Node not found - AD_WF_Node_ID=" + getAD_WF_Node_ID());
|
||||||
|
@ -767,8 +770,6 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
||||||
// Reason: if the commit fails the document should be put in Invalid state
|
// Reason: if the commit fails the document should be put in Invalid state
|
||||||
try {
|
try {
|
||||||
m_trx.commit(true);
|
m_trx.commit(true);
|
||||||
m_trx.close();
|
|
||||||
m_trx = null;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// If we have a DocStatus, change it to Invalid, and throw the exception to the next level
|
// If we have a DocStatus, change it to Invalid, and throw the exception to the next level
|
||||||
if (m_docStatus != null)
|
if (m_docStatus != null)
|
||||||
|
@ -787,8 +788,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
||||||
log.log(Level.WARNING, "" + getNode(), e);
|
log.log(Level.WARNING, "" + getNode(), e);
|
||||||
/**** Trx Rollback ****/
|
/**** Trx Rollback ****/
|
||||||
m_trx.rollback();
|
m_trx.rollback();
|
||||||
m_trx.close();
|
|
||||||
m_trx = null;
|
|
||||||
//
|
//
|
||||||
if (e.getCause() != null)
|
if (e.getCause() != null)
|
||||||
log.log(Level.WARNING, "Cause", e.getCause());
|
log.log(Level.WARNING, "Cause", e.getCause());
|
||||||
|
@ -807,7 +807,14 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
||||||
m_po.save();
|
m_po.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (m_trx != null)
|
||||||
|
{
|
||||||
|
m_trx.close();
|
||||||
|
}
|
||||||
m_trx = null;
|
m_trx = null;
|
||||||
|
}
|
||||||
} // run
|
} // run
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -133,6 +133,17 @@ public class MWFProcess extends X_AD_WF_Process
|
||||||
* @return array of activities
|
* @return array of activities
|
||||||
*/
|
*/
|
||||||
public MWFActivity[] getActivities (boolean requery, boolean onlyActive)
|
public MWFActivity[] getActivities (boolean requery, boolean onlyActive)
|
||||||
|
{
|
||||||
|
return getActivities(requery, onlyActive, get_TrxName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get active Activities of Process
|
||||||
|
* @param requery if true requery
|
||||||
|
* @param onlyActive only active activities
|
||||||
|
* @return array of activities
|
||||||
|
*/
|
||||||
|
public MWFActivity[] getActivities (boolean requery, boolean onlyActive, String trxName)
|
||||||
{
|
{
|
||||||
if (!requery && m_activities != null)
|
if (!requery && m_activities != null)
|
||||||
return m_activities;
|
return m_activities;
|
||||||
|
@ -145,11 +156,11 @@ public class MWFProcess extends X_AD_WF_Process
|
||||||
sql += " AND Processed='N'";
|
sql += " AND Processed='N'";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
pstmt = DB.prepareStatement (sql, trxName);
|
||||||
pstmt.setInt (1, getAD_WF_Process_ID());
|
pstmt.setInt (1, getAD_WF_Process_ID());
|
||||||
rs = pstmt.executeQuery ();
|
rs = pstmt.executeQuery ();
|
||||||
while (rs.next ())
|
while (rs.next ())
|
||||||
list.add (new MWFActivity(getCtx(), rs, get_TrxName()));
|
list.add (new MWFActivity(getCtx(), rs, trxName));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -241,7 +252,7 @@ public class MWFProcess extends X_AD_WF_Process
|
||||||
if (m_state.isClosed())
|
if (m_state.isClosed())
|
||||||
return;
|
return;
|
||||||
//
|
//
|
||||||
MWFActivity[] activities = getActivities (true, true); // requery active
|
MWFActivity[] activities = getActivities (true, true, trxName); // requery active
|
||||||
String closedState = null;
|
String closedState = null;
|
||||||
boolean suspended = false;
|
boolean suspended = false;
|
||||||
boolean running = false;
|
boolean running = false;
|
||||||
|
@ -253,7 +264,7 @@ public class MWFProcess extends X_AD_WF_Process
|
||||||
// Completed - Start Next
|
// Completed - Start Next
|
||||||
if (activityState.isCompleted())
|
if (activityState.isCompleted())
|
||||||
{
|
{
|
||||||
if (startNext (activity, activities, lastPO))
|
if (startNext (activity, activities, lastPO, trxName))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
@ -310,7 +321,7 @@ public class MWFProcess extends X_AD_WF_Process
|
||||||
* @param activities all activities
|
* @param activities all activities
|
||||||
* @return true if there is a next activity
|
* @return true if there is a next activity
|
||||||
*/
|
*/
|
||||||
private boolean startNext (MWFActivity last, MWFActivity[] activities, PO lastPO)
|
private boolean startNext (MWFActivity last, MWFActivity[] activities, PO lastPO, String trxName)
|
||||||
{
|
{
|
||||||
log.fine("Last=" + last);
|
log.fine("Last=" + last);
|
||||||
// transitions from the last processed node
|
// transitions from the last processed node
|
||||||
|
@ -340,6 +351,7 @@ public class MWFProcess extends X_AD_WF_Process
|
||||||
|
|
||||||
// Start new Activity...
|
// Start new Activity...
|
||||||
MWFActivity activity = new MWFActivity (this, transitions[i].getAD_WF_Next_ID(), lastPO);
|
MWFActivity activity = new MWFActivity (this, transitions[i].getAD_WF_Next_ID(), lastPO);
|
||||||
|
activity.set_TrxName(trxName);
|
||||||
activity.run();
|
activity.run();
|
||||||
|
|
||||||
// only the first valid if XOR
|
// only the first valid if XOR
|
||||||
|
|
Loading…
Reference in New Issue