BF [ 1801842 ] DB connection fix & improvements for concurrent threads

* error when try to manage a WF activity
This commit is contained in:
teo_sarca 2007-10-26 08:14:19 +00:00
parent fb081de3ff
commit 3486276cbd
2 changed files with 49 additions and 27 deletions

View File

@ -291,7 +291,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
{ {
if (m_audit != null) if (m_audit != null)
return m_audit; return m_audit;
MWFEventAudit[] events = MWFEventAudit.get(getCtx(), getAD_WF_Process_ID(), getAD_WF_Node_ID()); MWFEventAudit[] events = MWFEventAudit.get(getCtx(), getAD_WF_Process_ID(), getAD_WF_Node_ID(), get_TrxName());
if (events == null || events.length == 0) if (events == null || events.length == 0)
m_audit = new MWFEventAudit(this); m_audit = new MWFEventAudit(this);
else else
@ -1557,7 +1557,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
{ {
SimpleDateFormat format = DisplayType.getDateFormat(DisplayType.DateTime); SimpleDateFormat format = DisplayType.getDateFormat(DisplayType.DateTime);
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
MWFEventAudit[] events = MWFEventAudit.get(getCtx(), getAD_WF_Process_ID()); MWFEventAudit[] events = MWFEventAudit.get(getCtx(), getAD_WF_Process_ID(), get_TrxName());
for (int i = 0; i < events.length; i++) for (int i = 0; i < events.length; i++)
{ {
MWFEventAudit audit = events[i]; MWFEventAudit audit = events[i];

View File

@ -27,17 +27,34 @@ import org.compiere.util.*;
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: MWFEventAudit.java,v 1.3 2006/07/30 00:51:06 jjanke Exp $ * @version $Id: MWFEventAudit.java,v 1.3 2006/07/30 00:51:06 jjanke Exp $
*
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>BF [ 1801842 ] DB connection fix & improvements for concurrent threads
*/ */
public class MWFEventAudit extends X_AD_WF_EventAudit public class MWFEventAudit extends X_AD_WF_EventAudit
{ {
/** /**
* Get Event Audit for node * Get Event Audit for node
* @param ctx context * @param ctx context
* @param AD_WF_Process_ID process * @param AD_WF_Process_ID process
* @param AD_WF_Node_ID optional node * @param AD_WF_Node_ID optional node
* @return event audit or null * @return event audit or null
* @deprecated Deprecated since 3.4.0. Use instead {@link #get(Properties, int, int, String)}
*/ */
public static MWFEventAudit[] get (Properties ctx, int AD_WF_Process_ID, int AD_WF_Node_ID) public static MWFEventAudit[] get (Properties ctx, int AD_WF_Process_ID, int AD_WF_Node_ID)
{
return get(ctx, AD_WF_Process_ID, AD_WF_Node_ID, null);
}
/**
* Get Event Audit for node
* @param ctx context
* @param AD_WF_Process_ID process
* @param AD_WF_Node_ID optional node
* @param trxName
* @return event audit or null
*/
public static MWFEventAudit[] get (Properties ctx, int AD_WF_Process_ID, int AD_WF_Node_ID, String trxName)
{ {
ArrayList<MWFEventAudit> list = new ArrayList<MWFEventAudit>(); ArrayList<MWFEventAudit> list = new ArrayList<MWFEventAudit>();
String sql = "SELECT * FROM AD_WF_EventAudit " String sql = "SELECT * FROM AD_WF_EventAudit "
@ -46,32 +63,24 @@ public class MWFEventAudit extends X_AD_WF_EventAudit
sql += " AND AD_WF_Node_ID=?"; sql += " AND AD_WF_Node_ID=?";
sql += " ORDER BY AD_WF_EventAudit_ID"; sql += " ORDER BY AD_WF_EventAudit_ID";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, null); pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt (1, AD_WF_Process_ID); pstmt.setInt (1, AD_WF_Process_ID);
if (AD_WF_Node_ID > 0) if (AD_WF_Node_ID > 0)
pstmt.setInt (2, AD_WF_Node_ID); pstmt.setInt (2, AD_WF_Node_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
list.add (new MWFEventAudit (ctx, rs, null)); list.add (new MWFEventAudit (ctx, rs, trxName));
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log(Level.SEVERE, "get", e); s_log.log(Level.SEVERE, "get", e);
} }
try finally {
{ DB.close(rs, pstmt);
if (pstmt != null) rs = null; pstmt = null;
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
// //
MWFEventAudit[] retValue = new MWFEventAudit[list.size()]; MWFEventAudit[] retValue = new MWFEventAudit[list.size()];
@ -80,14 +89,27 @@ public class MWFEventAudit extends X_AD_WF_EventAudit
} // get } // get
/** /**
* Get Event Audit for node * Get Event Audit for node
* @param ctx context * @param ctx context
* @param AD_WF_Process_ID process * @param AD_WF_Process_ID process
* @return event audit or null * @return event audit or null
* @deprecated Deprecated since 3.4.0. Use instead {@link #get(Properties, int, String)}
*/ */
public static MWFEventAudit[] get (Properties ctx, int AD_WF_Process_ID) public static MWFEventAudit[] get (Properties ctx, int AD_WF_Process_ID)
{ {
return get(ctx, AD_WF_Process_ID, 0); return get(ctx, AD_WF_Process_ID, null);
}
/**
* Get Event Audit for node
* @param ctx context
* @param AD_WF_Process_ID process
* @param trxName
* @return event audit or null
*/
public static MWFEventAudit[] get (Properties ctx, int AD_WF_Process_ID, String trxName)
{
return get(ctx, AD_WF_Process_ID, 0, trxName);
} // get } // get