[ 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
|
@ -34,38 +34,31 @@ public class MMenu extends X_AD_Menu
|
||||||
* Get menues with where clause
|
* Get menues with where clause
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
* @param whereClause where clause w/o the actual WHERE
|
* @param whereClause where clause w/o the actual WHERE
|
||||||
|
* @param trxName transaction
|
||||||
* @return MMenu
|
* @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";
|
String sql = "SELECT * FROM AD_Menu";
|
||||||
if (whereClause != null && whereClause.length() > 0)
|
if (whereClause != null && whereClause.length() > 0)
|
||||||
sql += " WHERE " + whereClause;
|
sql += " WHERE " + whereClause;
|
||||||
ArrayList<MMenu> list = new ArrayList<MMenu>();
|
ArrayList<MMenu> list = new ArrayList<MMenu>();
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement (sql, null);
|
pstmt = DB.prepareStatement (sql, trxName);
|
||||||
ResultSet rs = pstmt.executeQuery ();
|
rs = pstmt.executeQuery ();
|
||||||
while (rs.next ())
|
while (rs.next ())
|
||||||
list.add (new MMenu (ctx, rs, null));
|
list.add (new MMenu (ctx, rs, trxName));
|
||||||
rs.close ();
|
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
s_log.log(Level.SEVERE, sql, e);
|
s_log.log(Level.SEVERE, sql, e);
|
||||||
}
|
}
|
||||||
try
|
finally {
|
||||||
{
|
DB.close(rs, pstmt);
|
||||||
if (pstmt != null)
|
rs = null; pstmt = null;
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
MMenu[] retValue = new MMenu[list.size()];
|
MMenu[] retValue = new MMenu[list.size()];
|
||||||
list.toArray (retValue);
|
list.toArray (retValue);
|
||||||
|
|
|
@ -382,7 +382,7 @@ public class MProcess extends X_AD_Process
|
||||||
else if (is_ValueChanged("IsActive") || is_ValueChanged("Name")
|
else if (is_ValueChanged("IsActive") || is_ValueChanged("Name")
|
||||||
|| is_ValueChanged("Description") || is_ValueChanged("Help"))
|
|| 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++)
|
for (int i = 0; i < menues.length; i++)
|
||||||
{
|
{
|
||||||
menues[i].setIsActive(isActive());
|
menues[i].setIsActive(isActive());
|
||||||
|
@ -390,7 +390,7 @@ public class MProcess extends X_AD_Process
|
||||||
menues[i].setDescription(getDescription());
|
menues[i].setDescription(getDescription());
|
||||||
menues[i].save();
|
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++)
|
for (int i = 0; i < nodes.length; i++)
|
||||||
{
|
{
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
|
|
|
@ -144,7 +144,7 @@ public class MWindow extends X_AD_Window
|
||||||
else if (is_ValueChanged("IsActive") || is_ValueChanged("Name")
|
else if (is_ValueChanged("IsActive") || is_ValueChanged("Name")
|
||||||
|| is_ValueChanged("Description") || is_ValueChanged("Help"))
|
|| 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++)
|
for (int i = 0; i < menues.length; i++)
|
||||||
{
|
{
|
||||||
menues[i].setName(getName());
|
menues[i].setName(getName());
|
||||||
|
@ -153,7 +153,7 @@ public class MWindow extends X_AD_Window
|
||||||
menues[i].save();
|
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++)
|
for (int i = 0; i < nodes.length; i++)
|
||||||
{
|
{
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
|
@ -182,38 +182,31 @@ public class MWindow extends X_AD_Window
|
||||||
* Is here as MWFNode is in base
|
* Is here as MWFNode is in base
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
* @param whereClause where clause w/o the actual WHERE
|
* @param whereClause where clause w/o the actual WHERE
|
||||||
|
* @param trxName transaction
|
||||||
* @return nodes
|
* @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";
|
String sql = "SELECT * FROM AD_WF_Node";
|
||||||
if (whereClause != null && whereClause.length() > 0)
|
if (whereClause != null && whereClause.length() > 0)
|
||||||
sql += " WHERE " + whereClause;
|
sql += " WHERE " + whereClause;
|
||||||
ArrayList<X_AD_WF_Node> list = new ArrayList<X_AD_WF_Node>();
|
ArrayList<X_AD_WF_Node> list = new ArrayList<X_AD_WF_Node>();
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement (sql, null);
|
pstmt = DB.prepareStatement (sql, trxName);
|
||||||
ResultSet rs = pstmt.executeQuery ();
|
rs = pstmt.executeQuery ();
|
||||||
while (rs.next ())
|
while (rs.next ())
|
||||||
list.add (new X_AD_WF_Node (ctx, rs, null));
|
list.add (new X_AD_WF_Node (ctx, rs, trxName));
|
||||||
rs.close ();
|
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
s_log.log(Level.SEVERE, sql, e);
|
s_log.log(Level.SEVERE, sql, e);
|
||||||
}
|
}
|
||||||
try
|
finally {
|
||||||
{
|
DB.close(rs, pstmt);
|
||||||
if (pstmt != null)
|
rs = null; pstmt = null;
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
X_AD_WF_Node[] retValue = new X_AD_WF_Node[list.size()];
|
X_AD_WF_Node[] retValue = new X_AD_WF_Node[list.size()];
|
||||||
list.toArray (retValue);
|
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 */
|
/** Quote */
|
||||||
private static final char 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")
|
else if (is_ValueChanged("IsActive") || is_ValueChanged("Name")
|
||||||
|| is_ValueChanged("Description") || is_ValueChanged("Help"))
|
|| 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++)
|
for (int i = 0; i < menues.length; i++)
|
||||||
{
|
{
|
||||||
menues[i].setIsActive(isActive());
|
menues[i].setIsActive(isActive());
|
||||||
|
@ -619,7 +619,7 @@ public class MWorkflow extends X_AD_Workflow
|
||||||
menues[i].setDescription(getDescription());
|
menues[i].setDescription(getDescription());
|
||||||
menues[i].save();
|
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++)
|
for (int i = 0; i < nodes.length; i++)
|
||||||
{
|
{
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
|
|
Loading…
Reference in New Issue