[ 1801842 ] DB connection fix & improvements for concurrent threads
- fix issue when saving a process/window/wf and the depending elements should be updated (menu) - added convenient DB.close(ResultSet rs, Statement st)
This commit is contained in:
parent
d2d443500a
commit
4277f7fa6b
|
@ -31,41 +31,34 @@ public class MMenu extends X_AD_Menu
|
|||
{
|
||||
|
||||
/**
|
||||
* Get menues with where clause
|
||||
* @param ctx context
|
||||
* @param whereClause where clause w/o the actual WHERE
|
||||
* @return MMenu
|
||||
* Get menues with where clause
|
||||
* @param ctx context
|
||||
* @param whereClause where clause w/o the actual WHERE
|
||||
* @param trxName transaction
|
||||
* @return MMenu
|
||||
*/
|
||||
public static MMenu[] get (Properties ctx, String whereClause)
|
||||
public static MMenu[] get (Properties ctx, String whereClause, String trxName)
|
||||
{
|
||||
String sql = "SELECT * FROM AD_Menu";
|
||||
if (whereClause != null && whereClause.length() > 0)
|
||||
sql += " WHERE " + whereClause;
|
||||
ArrayList<MMenu> list = new ArrayList<MMenu>();
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
pstmt = DB.prepareStatement (sql, trxName);
|
||||
rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
list.add (new MMenu (ctx, rs, null));
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
list.add (new MMenu (ctx, rs, trxName));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
finally {
|
||||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
MMenu[] retValue = new MMenu[list.size()];
|
||||
list.toArray (retValue);
|
||||
|
|
|
@ -382,7 +382,7 @@ public class MProcess extends X_AD_Process
|
|||
else if (is_ValueChanged("IsActive") || is_ValueChanged("Name")
|
||||
|| is_ValueChanged("Description") || is_ValueChanged("Help"))
|
||||
{
|
||||
MMenu[] menues = MMenu.get(getCtx(), "AD_Process_ID=" + getAD_Process_ID());
|
||||
MMenu[] menues = MMenu.get(getCtx(), "AD_Process_ID=" + getAD_Process_ID(), get_TrxName());
|
||||
for (int i = 0; i < menues.length; i++)
|
||||
{
|
||||
menues[i].setIsActive(isActive());
|
||||
|
@ -390,7 +390,7 @@ public class MProcess extends X_AD_Process
|
|||
menues[i].setDescription(getDescription());
|
||||
menues[i].save();
|
||||
}
|
||||
X_AD_WF_Node[] nodes = MWindow.getWFNodes(getCtx(), "AD_Process_ID=" + getAD_Process_ID());
|
||||
X_AD_WF_Node[] nodes = MWindow.getWFNodes(getCtx(), "AD_Process_ID=" + getAD_Process_ID(), get_TrxName());
|
||||
for (int i = 0; i < nodes.length; i++)
|
||||
{
|
||||
boolean changed = false;
|
||||
|
|
|
@ -144,7 +144,7 @@ public class MWindow extends X_AD_Window
|
|||
else if (is_ValueChanged("IsActive") || is_ValueChanged("Name")
|
||||
|| is_ValueChanged("Description") || is_ValueChanged("Help"))
|
||||
{
|
||||
MMenu[] menues = MMenu.get(getCtx(), "AD_Window_ID=" + getAD_Window_ID());
|
||||
MMenu[] menues = MMenu.get(getCtx(), "AD_Window_ID=" + getAD_Window_ID(), get_TrxName());
|
||||
for (int i = 0; i < menues.length; i++)
|
||||
{
|
||||
menues[i].setName(getName());
|
||||
|
@ -153,7 +153,7 @@ public class MWindow extends X_AD_Window
|
|||
menues[i].save();
|
||||
}
|
||||
//
|
||||
X_AD_WF_Node[] nodes = getWFNodes(getCtx(), "AD_Window_ID=" + getAD_Window_ID());
|
||||
X_AD_WF_Node[] nodes = getWFNodes(getCtx(), "AD_Window_ID=" + getAD_Window_ID(), get_TrxName());
|
||||
for (int i = 0; i < nodes.length; i++)
|
||||
{
|
||||
boolean changed = false;
|
||||
|
@ -178,42 +178,35 @@ public class MWindow extends X_AD_Window
|
|||
|
||||
|
||||
/**
|
||||
* Get workflow nodes with where clause.
|
||||
* Is here as MWFNode is in base
|
||||
* @param ctx context
|
||||
* @param whereClause where clause w/o the actual WHERE
|
||||
* @return nodes
|
||||
* Get workflow nodes with where clause.
|
||||
* Is here as MWFNode is in base
|
||||
* @param ctx context
|
||||
* @param whereClause where clause w/o the actual WHERE
|
||||
* @param trxName transaction
|
||||
* @return nodes
|
||||
*/
|
||||
public static X_AD_WF_Node[] getWFNodes (Properties ctx, String whereClause)
|
||||
public static X_AD_WF_Node[] getWFNodes (Properties ctx, String whereClause, String trxName)
|
||||
{
|
||||
String sql = "SELECT * FROM AD_WF_Node";
|
||||
if (whereClause != null && whereClause.length() > 0)
|
||||
sql += " WHERE " + whereClause;
|
||||
ArrayList<X_AD_WF_Node> list = new ArrayList<X_AD_WF_Node>();
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
pstmt = DB.prepareStatement (sql, trxName);
|
||||
rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
list.add (new X_AD_WF_Node (ctx, rs, null));
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
list.add (new X_AD_WF_Node (ctx, rs, trxName));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
s_log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
finally {
|
||||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
X_AD_WF_Node[] retValue = new X_AD_WF_Node[list.size()];
|
||||
list.toArray (retValue);
|
||||
|
|
|
@ -1636,6 +1636,18 @@ public final class DB
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* convenient method to close result set and statement
|
||||
* @param rs result set
|
||||
* @param st statement
|
||||
* @see #close(ResultSet)
|
||||
* @see #close(Statement)
|
||||
*/
|
||||
public static void close(ResultSet rs, Statement st) {
|
||||
close(rs);
|
||||
close(st);
|
||||
}
|
||||
|
||||
/** Quote */
|
||||
private static final char QUOTE = '\'';
|
||||
|
||||
|
|
|
@ -611,7 +611,7 @@ public class MWorkflow extends X_AD_Workflow
|
|||
else if (is_ValueChanged("IsActive") || is_ValueChanged("Name")
|
||||
|| is_ValueChanged("Description") || is_ValueChanged("Help"))
|
||||
{
|
||||
MMenu[] menues = MMenu.get(getCtx(), "AD_Workflow_ID=" + getAD_Workflow_ID());
|
||||
MMenu[] menues = MMenu.get(getCtx(), "AD_Workflow_ID=" + getAD_Workflow_ID(), get_TrxName());
|
||||
for (int i = 0; i < menues.length; i++)
|
||||
{
|
||||
menues[i].setIsActive(isActive());
|
||||
|
@ -619,7 +619,7 @@ public class MWorkflow extends X_AD_Workflow
|
|||
menues[i].setDescription(getDescription());
|
||||
menues[i].save();
|
||||
}
|
||||
X_AD_WF_Node[] nodes = MWindow.getWFNodes(getCtx(), "AD_Workflow_ID=" + getAD_Workflow_ID());
|
||||
X_AD_WF_Node[] nodes = MWindow.getWFNodes(getCtx(), "AD_Workflow_ID=" + getAD_Workflow_ID(), get_TrxName());
|
||||
for (int i = 0; i < nodes.length; i++)
|
||||
{
|
||||
boolean changed = false;
|
||||
|
|
Loading…
Reference in New Issue