BF [ 1874419 ] JDBC Statement not close in a finally block

This commit is contained in:
Heng Sin Low 2008-02-14 23:00:57 +00:00
parent 09a3263b6c
commit cd0d76a388
1 changed files with 66 additions and 154 deletions

View File

@ -680,36 +680,28 @@ public final class MRole extends X_AD_Role
*/ */
private void loadOrgAccessUser(ArrayList<OrgAccess> list) private void loadOrgAccessUser(ArrayList<OrgAccess> list)
{ {
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "SELECT * FROM AD_User_OrgAccess " String sql = "SELECT * FROM AD_User_OrgAccess "
+ "WHERE AD_User_ID=? AND IsActive='Y'"; + "WHERE AD_User_ID=? AND IsActive='Y'";
try try
{ {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getAD_User_ID()); pstmt.setInt(1, getAD_User_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
MUserOrgAccess oa = new MUserOrgAccess(getCtx(), rs, get_TrxName()); MUserOrgAccess oa = new MUserOrgAccess(getCtx(), rs, get_TrxName());
loadOrgAccessAdd (list, new OrgAccess(oa.getAD_Client_ID(), oa.getAD_Org_ID(), oa.isReadOnly())); loadOrgAccessAdd (list, new OrgAccess(oa.getAD_Client_ID(), oa.getAD_Org_ID(), oa.isReadOnly()));
} }
rs.close();
pstmt.close();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
} // loadOrgAccessRole } // loadOrgAccessRole
@ -719,36 +711,28 @@ public final class MRole extends X_AD_Role
*/ */
private void loadOrgAccessRole(ArrayList<OrgAccess> list) private void loadOrgAccessRole(ArrayList<OrgAccess> list)
{ {
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "SELECT * FROM AD_Role_OrgAccess " String sql = "SELECT * FROM AD_Role_OrgAccess "
+ "WHERE AD_Role_ID=? AND IsActive='Y'"; + "WHERE AD_Role_ID=? AND IsActive='Y'";
try try
{ {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getAD_Role_ID()); pstmt.setInt(1, getAD_Role_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
MRoleOrgAccess oa = new MRoleOrgAccess(getCtx(), rs, get_TrxName()); MRoleOrgAccess oa = new MRoleOrgAccess(getCtx(), rs, get_TrxName());
loadOrgAccessAdd (list, new OrgAccess(oa.getAD_Client_ID(), oa.getAD_Org_ID(), oa.isReadOnly())); loadOrgAccessAdd (list, new OrgAccess(oa.getAD_Client_ID(), oa.getAD_Org_ID(), oa.isReadOnly()));
} }
rs.close();
pstmt.close();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
} // loadOrgAccessRole } // loadOrgAccessRole
@ -811,33 +795,25 @@ public final class MRole extends X_AD_Role
if (m_tableAccess != null && !reload) if (m_tableAccess != null && !reload)
return; return;
ArrayList<MTableAccess> list = new ArrayList<MTableAccess>(); ArrayList<MTableAccess> list = new ArrayList<MTableAccess>();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "SELECT * FROM AD_Table_Access " String sql = "SELECT * FROM AD_Table_Access "
+ "WHERE AD_Role_ID=? AND IsActive='Y'"; + "WHERE AD_Role_ID=? AND IsActive='Y'";
try try
{ {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getAD_Role_ID()); pstmt.setInt(1, getAD_Role_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
list.add(new MTableAccess(getCtx(), rs, get_TrxName())); list.add(new MTableAccess(getCtx(), rs, get_TrxName()));
rs.close();
pstmt.close();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
m_tableAccess = new MTableAccess[list.size()]; m_tableAccess = new MTableAccess[list.size()];
list.toArray(m_tableAccess); list.toArray(m_tableAccess);
@ -856,14 +832,15 @@ public final class MRole extends X_AD_Role
m_tableName = new HashMap<String,Integer>(300); m_tableName = new HashMap<String,Integer>(300);
m_viewName = new HashSet<String>(300); m_viewName = new HashSet<String>(300);
m_tableIdName = new HashMap<String,String>(300); m_tableIdName = new HashMap<String,String>(300);
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "SELECT AD_Table_ID, AccessLevel, TableName, IsView, " String sql = "SELECT AD_Table_ID, AccessLevel, TableName, IsView, "
+ "(SELECT ColumnName FROM AD_COLUMN WHERE AD_COLUMN.AD_TABLE_ID = AD_TABLE.AD_TABLE_ID AND AD_COLUMN.COLUMNNAME = AD_TABLE.TABLENAME || '_ID') " + "(SELECT ColumnName FROM AD_COLUMN WHERE AD_COLUMN.AD_TABLE_ID = AD_TABLE.AD_TABLE_ID AND AD_COLUMN.COLUMNNAME = AD_TABLE.TABLENAME || '_ID') "
+ "FROM AD_Table WHERE IsActive='Y'"; + "FROM AD_Table WHERE IsActive='Y'";
try try
{ {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
Integer ii = new Integer(rs.getInt(1)); Integer ii = new Integer(rs.getInt(1));
@ -881,23 +858,14 @@ public final class MRole extends X_AD_Role
m_tableIdName.put(tableName.toUpperCase(), idColumn); m_tableIdName.put(tableName.toUpperCase(), idColumn);
} }
} }
rs.close();
pstmt.close();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
log.fine("#" + m_tableAccessLevel.size()); log.fine("#" + m_tableAccessLevel.size());
} // loadTableAccessLevel } // loadTableAccessLevel
@ -928,33 +896,25 @@ public final class MRole extends X_AD_Role
if (m_columnAccess != null && !reload) if (m_columnAccess != null && !reload)
return; return;
ArrayList<MColumnAccess> list = new ArrayList<MColumnAccess>(); ArrayList<MColumnAccess> list = new ArrayList<MColumnAccess>();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "SELECT * FROM AD_Column_Access " String sql = "SELECT * FROM AD_Column_Access "
+ "WHERE AD_Role_ID=? AND IsActive='Y'"; + "WHERE AD_Role_ID=? AND IsActive='Y'";
try try
{ {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getAD_Role_ID()); pstmt.setInt(1, getAD_Role_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
list.add(new MColumnAccess(getCtx(), rs, get_TrxName())); list.add(new MColumnAccess(getCtx(), rs, get_TrxName()));
rs.close();
pstmt.close();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
m_columnAccess = new MColumnAccess[list.size()]; m_columnAccess = new MColumnAccess[list.size()];
list.toArray(m_columnAccess); list.toArray(m_columnAccess);
@ -971,14 +931,15 @@ public final class MRole extends X_AD_Role
return; return;
ArrayList<MRecordAccess> list = new ArrayList<MRecordAccess>(); ArrayList<MRecordAccess> list = new ArrayList<MRecordAccess>();
ArrayList<MRecordAccess> dependent = new ArrayList<MRecordAccess>(); ArrayList<MRecordAccess> dependent = new ArrayList<MRecordAccess>();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "SELECT * FROM AD_Record_Access " String sql = "SELECT * FROM AD_Record_Access "
+ "WHERE AD_Role_ID=? AND IsActive='Y' ORDER BY AD_Table_ID"; + "WHERE AD_Role_ID=? AND IsActive='Y' ORDER BY AD_Table_ID";
try try
{ {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getAD_Role_ID()); pstmt.setInt(1, getAD_Role_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
MRecordAccess ra = new MRecordAccess(getCtx(), rs, get_TrxName()); MRecordAccess ra = new MRecordAccess(getCtx(), rs, get_TrxName());
@ -986,23 +947,14 @@ public final class MRole extends X_AD_Role
if (ra.isDependentEntities()) if (ra.isDependentEntities())
dependent.add(ra); dependent.add(ra);
} }
rs.close();
pstmt.close();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
m_recordAccess = new MRecordAccess[list.size()]; m_recordAccess = new MRecordAccess[list.size()];
list.toArray(m_recordAccess); list.toArray(m_recordAccess);
@ -1505,31 +1457,23 @@ public final class MRole extends X_AD_Role
+ " AND ce.AD_Field_ID IS NULL " + " AND ce.AD_Field_ID IS NULL "
+ " AND ce.ASP_Status = 'H')"; // Hide + " AND ce.ASP_Status = 'H')"; // Hide
String sql = "SELECT AD_Window_ID, IsReadWrite FROM AD_Window_Access WHERE AD_Role_ID=? AND IsActive='Y'" + ASPFilter; String sql = "SELECT AD_Window_ID, IsReadWrite FROM AD_Window_Access WHERE AD_Role_ID=? AND IsActive='Y'" + ASPFilter;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getAD_Role_ID()); pstmt.setInt(1, getAD_Role_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
m_windowAccess.put(new Integer(rs.getInt(1)), new Boolean("Y".equals(rs.getString(2)))); m_windowAccess.put(new Integer(rs.getInt(1)), new Boolean("Y".equals(rs.getString(2))));
rs.close();
pstmt.close();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
log.fine("#" + m_windowAccess.size()); log.fine("#" + m_windowAccess.size());
} // reload } // reload
@ -1584,31 +1528,23 @@ public final class MRole extends X_AD_Role
+ " AND ce.AD_Process_Para_ID IS NULL " + " AND ce.AD_Process_Para_ID IS NULL "
+ " AND ce.ASP_Status = 'H')"; // Hide + " AND ce.ASP_Status = 'H')"; // Hide
String sql = "SELECT AD_Process_ID, IsReadWrite FROM AD_Process_Access WHERE AD_Role_ID=? AND IsActive='Y'" + ASPFilter; String sql = "SELECT AD_Process_ID, IsReadWrite FROM AD_Process_Access WHERE AD_Role_ID=? AND IsActive='Y'" + ASPFilter;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getAD_Role_ID()); pstmt.setInt(1, getAD_Role_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
m_processAccess.put(new Integer(rs.getInt(1)), new Boolean("Y".equals(rs.getString(2)))); m_processAccess.put(new Integer(rs.getInt(1)), new Boolean("Y".equals(rs.getString(2))));
rs.close();
pstmt.close();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
} // reload } // reload
return (Boolean)m_processAccess.get(new Integer(AD_Process_ID)); return (Boolean)m_processAccess.get(new Integer(AD_Process_ID));
@ -1657,31 +1593,23 @@ public final class MRole extends X_AD_Role
+ " AND ce.AD_Task_ID IS NOT NULL " + " AND ce.AD_Task_ID IS NOT NULL "
+ " AND ce.ASP_Status = 'H')"; // Hide + " AND ce.ASP_Status = 'H')"; // Hide
String sql = "SELECT AD_Task_ID, IsReadWrite FROM AD_Task_Access WHERE AD_Role_ID=? AND IsActive='Y'" + ASPFilter; String sql = "SELECT AD_Task_ID, IsReadWrite FROM AD_Task_Access WHERE AD_Role_ID=? AND IsActive='Y'" + ASPFilter;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getAD_Role_ID()); pstmt.setInt(1, getAD_Role_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
m_taskAccess.put(new Integer(rs.getInt(1)), new Boolean("Y".equals(rs.getString(2)))); m_taskAccess.put(new Integer(rs.getInt(1)), new Boolean("Y".equals(rs.getString(2))));
rs.close();
pstmt.close();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
} // reload } // reload
return (Boolean)m_taskAccess.get(new Integer(AD_Task_ID)); return (Boolean)m_taskAccess.get(new Integer(AD_Task_ID));
@ -1731,31 +1659,23 @@ public final class MRole extends X_AD_Role
+ " AND ce.AD_Form_ID IS NOT NULL " + " AND ce.AD_Form_ID IS NOT NULL "
+ " AND ce.ASP_Status = 'H')"; // Hide + " AND ce.ASP_Status = 'H')"; // Hide
String sql = "SELECT AD_Form_ID, IsReadWrite FROM AD_Form_Access WHERE AD_Role_ID=? AND IsActive='Y'" + ASPFilter; String sql = "SELECT AD_Form_ID, IsReadWrite FROM AD_Form_Access WHERE AD_Role_ID=? AND IsActive='Y'" + ASPFilter;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getAD_Role_ID()); pstmt.setInt(1, getAD_Role_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
m_formAccess.put(new Integer(rs.getInt(1)), new Boolean("Y".equals(rs.getString(2)))); m_formAccess.put(new Integer(rs.getInt(1)), new Boolean("Y".equals(rs.getString(2))));
rs.close();
pstmt.close();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
} // reload } // reload
return (Boolean)m_formAccess.get(new Integer(AD_Form_ID)); return (Boolean)m_formAccess.get(new Integer(AD_Form_ID));
@ -1804,31 +1724,23 @@ public final class MRole extends X_AD_Role
+ " AND ce.AD_Workflow_ID IS NOT NULL " + " AND ce.AD_Workflow_ID IS NOT NULL "
+ " AND ce.ASP_Status = 'H')"; // Hide + " AND ce.ASP_Status = 'H')"; // Hide
String sql = "SELECT AD_Workflow_ID, IsReadWrite FROM AD_Workflow_Access WHERE AD_Role_ID=? AND IsActive='Y'" + ASPFilter; String sql = "SELECT AD_Workflow_ID, IsReadWrite FROM AD_Workflow_Access WHERE AD_Role_ID=? AND IsActive='Y'" + ASPFilter;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getAD_Role_ID()); pstmt.setInt(1, getAD_Role_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
m_workflowAccess.put(new Integer(rs.getInt(1)), new Boolean("Y".equals(rs.getString(2)))); m_workflowAccess.put(new Integer(rs.getInt(1)), new Boolean("Y".equals(rs.getString(2))));
rs.close();
pstmt.close();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
} // reload } // reload
return (Boolean)m_workflowAccess.get(new Integer(AD_Workflow_ID)); return (Boolean)m_workflowAccess.get(new Integer(AD_Workflow_ID));