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,11 +46,9 @@ 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);
/** /**
* Default Constructor * Default Constructor
@ -51,9 +56,9 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
* @param PP_Product_BOMLine BOM line to load * @param PP_Product_BOMLine BOM line to load
* @param Transaction Line * @param Transaction Line
*/ */
public MPPProductBOMLine(Properties ctx, int PP_Product_BOMLine,String trxName) public MPPProductBOMLine(Properties ctx, int PP_Product_BOMLine, String trxName)
{ {
super (ctx, PP_Product_BOMLine,trxName); super(ctx, PP_Product_BOMLine, trxName);
} // MPPProductBOMLine } // MPPProductBOMLine
/** /**
@ -68,10 +73,9 @@ 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
} }
/** /**
@ -79,37 +83,31 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
* @param ctx context * @param ctx context
* @param rs result set record * @param rs result set record
*/ */
public MPPProductBOMLine(Properties ctx, ResultSet rs,String trxName) public MPPProductBOMLine(Properties ctx, ResultSet rs, String trxName)
{ {
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 !!
* @param BOM BOM * @param BOM BOM
*/ */
public void setMPPProductBOM (MPPProductBOM bom) public void setMPPProductBOM(MPPProductBOM bom)
{ {
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()) return sb.toString();
.append ("]");
return sb.toString ();
} }
/** /**
* String Description * String Description
* @return info * @return info
@ -145,39 +143,40 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
private DefaultMutableTreeNode parent(int M_Product_ID, int PP_Product_BOM_ID) private DefaultMutableTreeNode parent(int M_Product_ID, int PP_Product_BOM_ID)
{ {
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);
if (bom != null) if (bom != null)
{ {
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 ,"doIt - " + sql + e); s_log.log(Level.SEVERE, "doIt - " + sql + e);
} }
finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
return parent; return parent;
} }
@ -188,32 +187,35 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
* @param DefaultMutableTreeNode Tree BOM * @param DefaultMutableTreeNode Tree BOM
* @return DefaultMutableTreeNode Tree with all components product * @return DefaultMutableTreeNode Tree with all components product
*/ */
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)
MPPProductBOMLine PP_Product_BOMLine = new MPPProductBOMLine(Env.getCtx(), rs.getInt(3),get_TrxName()); + ")", "Error Cycle BOM", JOptionPane.ERROR_MESSAGE);
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,71 +223,70 @@ 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 {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
return null; return null;
} }
/** /**
* get an implotion the product * get an implotion the product
* @param ID Product * @param ID Product
* @param ID BOM * @param ID BOM
* @return DefaultMutableTreeNode Tree with all parent product * @return DefaultMutableTreeNode Tree with all parent product
*/ */
private DefaultMutableTreeNode iparent(int M_Product_ID , int PP_Product_BOM_ID) throws Exception private DefaultMutableTreeNode iparent(int M_Product_ID, int PP_Product_BOM_ID) throws Exception
{ {
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
if(rs.getRow() > 1) if (rs.getRow() > 1)
{ {
//need to reset tableproduct cache //need to reset tableproduct cache
tableproduct.clear(); tableproduct.clear();
tableproduct.put(M_Product_ID, PP_Product_BOM_ID); //insert parent into cache tableproduct.put(M_Product_ID, PP_Product_BOM_ID); //insert parent into cache
} }
DefaultMutableTreeNode bom = icomponent(rs.getInt(1), M_Product_ID , parent); DefaultMutableTreeNode bom = icomponent(rs.getInt(1), M_Product_ID, parent);
if (bom != null) if (bom != null)
{ {
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;
} }
@ -295,24 +296,27 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
* @param ID BOM * @param ID BOM
* @return DefaultMutableTreeNode Tree with all parent product * @return DefaultMutableTreeNode Tree with all parent product
*/ */
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))
{ {
//BOM Loop Error //BOM Loop Error
if(!tableproduct(rs.getInt(1),rs.getInt(3))) if (!tableproduct(rs.getInt(1), rs.getInt(3)))
bom.add(iparent(rs.getInt(1),rs.getInt(3))); bom.add(iparent(rs.getInt(1), rs.getInt(3)));
else else
{ {
s_log.saveError("Error", "Cycle BOM & Formula:" + rs.getString(2) + "(" + rs.getString(3) + ")"); s_log.saveError("Error", "Cycle BOM & Formula:" + rs.getString(2) + "(" + rs.getString(3) + ")");
@ -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;
} }
@ -356,9 +360,8 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
{ {
return true; return true;
} }
tableproduct.put(p , bom); tableproduct.put(p, bom);
return false; return false;
} }
/************************************************************************** /**************************************************************************