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

organize imports
+ re-format
This commit is contained in:
tspc 2008-07-14 03:51:38 +00:00
parent fded7d0218
commit b4750dad0a
1 changed files with 291 additions and 288 deletions

View File

@ -15,15 +15,22 @@
*****************************************************************************/ *****************************************************************************/
package org.eevolution.model; package org.eevolution.model;
import java.util.*; import java.sql.PreparedStatement;
import java.sql.*; import java.sql.ResultSet;
import javax.swing.*; import java.sql.SQLException;
import javax.swing.tree.*; import java.util.Hashtable;
import java.util.logging.*; import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.*; import javax.swing.JOptionPane;
import org.compiere.model.*; import javax.swing.tree.DefaultMutableTreeNode;
import org.compiere.model.MProduct;
import org.compiere.model.X_M_Product;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
/** /**
* Manufacturing Order Line Model. * Manufacturing Order Line Model.
@ -39,8 +46,6 @@ import org.compiere.model.*;
public class MPPProductBOMLine extends X_PP_Product_BOMLine public class MPPProductBOMLine extends X_PP_Product_BOMLine
{ {
static private int AD_Client_ID = 0; static private int AD_Client_ID = 0;
static Hashtable<Integer, Integer> tableproduct = new Hashtable<Integer, Integer>(); static Hashtable<Integer, Integer> tableproduct = new Hashtable<Integer, Integer>();
private static CLogger s_log = CLogger.getCLogger(MPPProductBOMLine.class); private static CLogger s_log = CLogger.getCLogger(MPPProductBOMLine.class);
@ -69,8 +74,7 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
public MPPProductBOMLine(MPPProductBOM bom) public MPPProductBOMLine(MPPProductBOM bom)
{ {
super(bom.getCtx(), 0, bom.get_TableName()); super(bom.getCtx(), 0, bom.get_TableName());
if (bom.get_ID() == 0) if (bom.get_ID() == 0) throw new IllegalArgumentException("Header not saved");
throw new IllegalArgumentException("Header not saved");
setPP_Product_BOM_ID(bom.getPP_Product_BOM_ID()); // parent setPP_Product_BOM_ID(bom.getPP_Product_BOM_ID()); // parent
} }
@ -84,8 +88,6 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
super(ctx, rs, trxName); super(ctx, rs, trxName);
} // MPPProductBOMLine } // MPPProductBOMLine
/** /**
* Set Defaults from BOM. * Set Defaults from BOM.
* Does not set Parent !! * Does not set Parent !!
@ -96,20 +98,16 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
setClientOrg(bom); setClientOrg(bom);
} }
/** /**
* String Representation * String Representation
* @return info * @return info
*/ */
public String toString() public String toString()
{ {
StringBuffer sb = new StringBuffer ("MPPProductBOMLine[") StringBuffer sb = new StringBuffer("MPPProductBOMLine[").append(get_ID()).append("]");
.append(get_ID())
.append ("]");
return sb.toString(); return sb.toString();
} }
/** /**
* String Description * String Description
* @return info * @return info
@ -147,16 +145,17 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
DefaultMutableTreeNode parent = new DefaultMutableTreeNode(Integer.toString(M_Product_ID) + "|" + Integer.toString(PP_Product_BOM_ID)); DefaultMutableTreeNode parent = new DefaultMutableTreeNode(Integer.toString(M_Product_ID) + "|" + Integer.toString(PP_Product_BOM_ID));
String sql = new String("SELECT pbom.PP_Product_BOM_ID FROM PP_Product_BOM pbom WHERE pbom.IsActive = 'Y' AND pbom.AD_Client_ID= ? AND pbom.M_Product_ID = ? "); String sql = new String(
"SELECT pbom.PP_Product_BOM_ID FROM PP_Product_BOM pbom WHERE pbom.IsActive = 'Y' AND pbom.AD_Client_ID= ? AND pbom.M_Product_ID = ? ");
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, Env.getAD_Client_ID(Env.getCtx())); pstmt.setInt(1, Env.getAD_Client_ID(Env.getCtx()));
pstmt.setInt(2, M_Product_ID); pstmt.setInt(2, M_Product_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
DefaultMutableTreeNode bom = component(rs.getInt(1), M_Product_ID, parent); DefaultMutableTreeNode bom = component(rs.getInt(1), M_Product_ID, parent);
@ -166,18 +165,18 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
} }
} }
rs.close();
pstmt.close();
return parent; return parent;
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log(Level.SEVERE, "doIt - " + sql + e); s_log.log(Level.SEVERE, "doIt - " + sql + e);
} }
finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
return parent; return parent;
} }
@ -191,29 +190,32 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
private DefaultMutableTreeNode component(int M_Product_BOM_ID, int M_Product_ID, DefaultMutableTreeNode bom) private DefaultMutableTreeNode component(int M_Product_BOM_ID, int M_Product_ID, DefaultMutableTreeNode bom)
{ {
String sql = new String("SELECT pboml.M_Product_ID , pbom.Value , pboml.PP_Product_BOMLine_ID , pbom.PP_Product_BOM_ID FROM PP_Product_BOM pbom INNER JOIN PP_Product_BOMLine pboml ON (pbom.PP_Product_BOM_ID = pboml.PP_Product_BOM_ID) WHERE pbom.IsActive= 'Y' AND pboml.IsActive= 'Y' AND pbom.AD_Client_ID= ? AND pbom.PP_Product_BOM_ID = ? "); String sql = new String(
"SELECT pboml.M_Product_ID , pbom.Value , pboml.PP_Product_BOMLine_ID , pbom.PP_Product_BOM_ID FROM"
+ " PP_Product_BOM pbom INNER JOIN PP_Product_BOMLine pboml ON (pbom.PP_Product_BOM_ID = pboml.PP_Product_BOM_ID)"
+ " WHERE pbom.IsActive= 'Y' AND pboml.IsActive= 'Y' AND pbom.AD_Client_ID= ? AND pbom.PP_Product_BOM_ID = ? ");
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, Env.getAD_Client_ID(Env.getCtx())); pstmt.setInt(1, Env.getAD_Client_ID(Env.getCtx()));
pstmt.setInt(2, M_Product_BOM_ID); pstmt.setInt(2, M_Product_BOM_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
if (M_Product_ID != rs.getInt(1)) if (M_Product_ID != rs.getInt(1))
{ {
bom.add(parent(rs.getInt(1), rs.getInt(4))); bom.add(parent(rs.getInt(1), rs.getInt(4)));
} }
else else
{ {
JOptionPane.showMessageDialog(null,"Componet will be deactivated for BOM & Formula:" + rs.getString(2) + "(" + rs.getString(3) + ")", "Error Cycle BOM" , JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, "Componet will be deactivated for BOM & Formula:" + rs.getString(2) + "(" + rs.getString(3)
+ ")", "Error Cycle BOM", JOptionPane.ERROR_MESSAGE);
MPPProductBOMLine PP_Product_BOMLine = new MPPProductBOMLine(Env.getCtx(), rs.getInt(3), get_TrxName()); MPPProductBOMLine PP_Product_BOMLine = new MPPProductBOMLine(Env.getCtx(), rs.getInt(3), get_TrxName());
PP_Product_BOMLine.setIsActive(false); PP_Product_BOMLine.setIsActive(false);
PP_Product_BOMLine.save(); PP_Product_BOMLine.save();
} }
} }
if (rs.getRow() == 0) if (rs.getRow() == 0)
{ {
@ -221,20 +223,20 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
bom.add(parent); bom.add(parent);
return bom; return bom;
} }
rs.close();
pstmt.close();
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log(Level.SEVERE, "doIt - " + sql + e); s_log.log(Level.SEVERE, "doIt - " + sql + e);
} }
finally {
return null; DB.close(rs, pstmt);
rs = null;
pstmt = null;
} }
return null;
}
/** /**
* get an implotion the product * get an implotion the product
@ -247,16 +249,18 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
DefaultMutableTreeNode parent = new DefaultMutableTreeNode(Integer.toString(M_Product_ID) + "|" + Integer.toString(PP_Product_BOM_ID)); DefaultMutableTreeNode parent = new DefaultMutableTreeNode(Integer.toString(M_Product_ID) + "|" + Integer.toString(PP_Product_BOM_ID));
String sql = new String("SELECT pboml.PP_Product_BOMLine_ID FROM PP_Product_BOMLine pboml WHERE pboml.IsActive= 'Y' AND pboml.AD_Client_ID = ? AND pboml.M_Product_ID = ? "); String sql = new String(
"SELECT pboml.PP_Product_BOMLine_ID FROM PP_Product_BOMLine pboml"
+ " WHERE pboml.IsActive= 'Y' AND pboml.AD_Client_ID = ? AND pboml.M_Product_ID = ? ");
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, AD_Client_ID); pstmt.setInt(1, AD_Client_ID);
pstmt.setInt(2, M_Product_ID); pstmt.setInt(2, M_Product_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
// If not the first bom line at this level // If not the first bom line at this level
@ -271,21 +275,18 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
{ {
parent.add(bom); parent.add(bom);
} }
} }
rs.close();
pstmt.close();
return parent; return parent;
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log(Level.SEVERE, "iparent - " + sql + e); s_log.log(Level.SEVERE, "iparent - " + sql + e);
} }
finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
return parent; return parent;
} }
@ -297,15 +298,18 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
*/ */
private DefaultMutableTreeNode icomponent(int PP_Product_BOMLine_ID, int M_Product_ID, DefaultMutableTreeNode bom) throws Exception private DefaultMutableTreeNode icomponent(int PP_Product_BOMLine_ID, int M_Product_ID, DefaultMutableTreeNode bom) throws Exception
{ {
String sql = new String(
String sql = new String("SELECT pbom.M_Product_ID , pbom.Value , pbom.PP_Product_BOM_ID FROM PP_Product_BOMLine pboml INNER JOIN PP_Product_BOM pbom ON (pbom.PP_Product_BOM_ID = pboml.PP_Product_BOM_ID) WHERE pbom.IsActive= 'Y' AND pboml.IsActive= 'Y' AND pboml.AD_Client_ID =? AND pboml.PP_Product_BOMLine_ID = ? "); "SELECT pbom.M_Product_ID , pbom.Value , pbom.PP_Product_BOM_ID FROM PP_Product_BOMLine pboml"
+ "INNER JOIN PP_Product_BOM pbom ON (pbom.PP_Product_BOM_ID = pboml.PP_Product_BOM_ID)"
+ "WHERE pbom.IsActive= 'Y' AND pboml.IsActive= 'Y' AND pboml.AD_Client_ID =? AND pboml.PP_Product_BOMLine_ID = ? ");
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, AD_Client_ID); pstmt.setInt(1, AD_Client_ID);
pstmt.setInt(2, PP_Product_BOMLine_ID); pstmt.setInt(2, PP_Product_BOMLine_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
if (M_Product_ID != rs.getInt(1)) if (M_Product_ID != rs.getInt(1))
@ -327,17 +331,17 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
+ product.getValue() + "(" + product.getM_Product_ID() + ")"); + product.getValue() + "(" + product.getM_Product_ID() + ")");
throw new Exception(CLogger.retrieveError().toString()); throw new Exception(CLogger.retrieveError().toString());
} }
} }
rs.close();
pstmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
s_log.log(Level.SEVERE, "doIt - " + sql + e); s_log.log(Level.SEVERE, "doIt - " + sql + e);
} }
finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
return null; return null;
} }
@ -358,7 +362,6 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
} }
tableproduct.put(p, bom); tableproduct.put(p, bom);
return false; return false;
} }
/************************************************************************** /**************************************************************************