1. Reorganize Imports

2. Remove deprecated CalloutActive sets
3. BF [ 1874419 ] JDBC Statement not close in a finally block

tested with single POS order, export pricelist, patio BP, invalid complete due to no cash book, change to Std Order, completes ok.

committing for review
This commit is contained in:
Redhuan D. Oon 2008-02-03 03:28:55 +00:00
parent 0a15b4a374
commit 0ad10e90d3
1 changed files with 65 additions and 51 deletions

View File

@ -16,13 +16,20 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.math.*; import java.math.BigDecimal;
import java.sql.*; import java.sql.PreparedStatement;
import java.text.SimpleDateFormat; import java.sql.ResultSet;
import java.util.*; import java.sql.SQLException;
import java.util.Date; import java.sql.Timestamp;
import java.util.logging.*; import java.util.Properties;
import org.compiere.util.*; import java.util.logging.Level;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Ini;
import org.compiere.util.Msg;
/** /**
* Order Callouts. * Order Callouts.
@ -72,6 +79,8 @@ public class CalloutOrder extends CalloutEngine
+ "FROM C_DocType d, AD_Sequence s " + "FROM C_DocType d, AD_Sequence s "
+ "WHERE C_DocType_ID=?" // #1 + "WHERE C_DocType_ID=?" // #1
+ " AND d.DocNoSequence_ID=s.AD_Sequence_ID(+)"; + " AND d.DocNoSequence_ID=s.AD_Sequence_ID(+)";
PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
int AD_Sequence_ID = 0; int AD_Sequence_ID = 0;
@ -79,18 +88,15 @@ public class CalloutOrder extends CalloutEngine
// Get old AD_SeqNo for comparison // Get old AD_SeqNo for comparison
if (!newDocNo && oldC_DocType_ID.intValue() != 0) if (!newDocNo && oldC_DocType_ID.intValue() != 0)
{ {
PreparedStatement pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, oldC_DocType_ID.intValue()); pstmt.setInt(1, oldC_DocType_ID.intValue());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
AD_Sequence_ID = rs.getInt(7); AD_Sequence_ID = rs.getInt(7);
rs.close();
pstmt.close();
} }
pstmt = DB.prepareStatement(sql, null);
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, C_DocType_ID.intValue()); pstmt.setInt(1, C_DocType_ID.intValue());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
String DocSubTypeSO = ""; String DocSubTypeSO = "";
boolean IsSOTrx = true; boolean IsSOTrx = true;
if (rs.next()) // we found document type if (rs.next()) // we found document type
@ -132,6 +138,7 @@ public class CalloutOrder extends CalloutEngine
// Set Context: // Set Context:
Env.setContext(ctx, WindowNo, "HasCharges", rs.getString(2)); Env.setContext(ctx, WindowNo, "HasCharges", rs.getString(2));
// DocumentNo // DocumentNo
if (rs.getString(4).equals("Y")) // IsDocNoControlled if (rs.getString(4).equals("Y")) // IsDocNoControlled
{ {
@ -157,8 +164,6 @@ public class CalloutOrder extends CalloutEngine
} }
} }
} }
rs.close();
pstmt.close();
// When BPartner is changed, the Rules are not set if // When BPartner is changed, the Rules are not set if
// it is a POS or Credit Order (i.e. defaults from Standard BPartner) // it is a POS or Credit Order (i.e. defaults from Standard BPartner)
// This re-reads the Rules and applies them. // This re-reads the Rules and applies them.
@ -211,16 +216,19 @@ public class CalloutOrder extends CalloutEngine
if (s != null && s.length() != 0) if (s != null && s.length() != 0)
mTab.setValue("DeliveryViaRule", s); mTab.setValue("DeliveryViaRule", s);
} }
rs.close(); }
pstmt.close(); // re-read customer rules
} // re-read customer rules
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
return e.getLocalizedMessage(); return e.getLocalizedMessage();
} }
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return ""; return "";
} // docType } // docType
@ -247,8 +255,6 @@ public class CalloutOrder extends CalloutEngine
Integer C_BPartner_ID = (Integer)value; Integer C_BPartner_ID = (Integer)value;
if (C_BPartner_ID == null || C_BPartner_ID.intValue() == 0) if (C_BPartner_ID == null || C_BPartner_ID.intValue() == 0)
return ""; return "";
setCalloutActive(true);
String sql = "SELECT p.AD_Language,p.C_PaymentTerm_ID," String sql = "SELECT p.AD_Language,p.C_PaymentTerm_ID,"
+ " COALESCE(p.M_PriceList_ID,g.M_PriceList_ID) AS M_PriceList_ID, p.PaymentRule,p.POReference," + " COALESCE(p.M_PriceList_ID,g.M_PriceList_ID) AS M_PriceList_ID, p.PaymentRule,p.POReference,"
+ " p.SO_Description,p.IsDiscountPrinted," + " p.SO_Description,p.IsDiscountPrinted,"
@ -266,12 +272,13 @@ public class CalloutOrder extends CalloutEngine
+ "WHERE p.C_BPartner_ID=? AND p.IsActive='Y'"; // #1 + "WHERE p.C_BPartner_ID=? AND p.IsActive='Y'"; // #1
boolean IsSOTrx = "Y".equals(Env.getContext(ctx, WindowNo, "IsSOTrx")); boolean IsSOTrx = "Y".equals(Env.getContext(ctx, WindowNo, "IsSOTrx"));
PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, C_BPartner_ID.intValue()); pstmt.setInt(1, C_BPartner_ID.intValue());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
// Sales Rep - If BP has a default SalesRep then default it // Sales Rep - If BP has a default SalesRep then default it
@ -411,16 +418,17 @@ public class CalloutOrder extends CalloutEngine
mTab.setValue("DeliveryViaRule", s); mTab.setValue("DeliveryViaRule", s);
} }
} }
rs.close();
pstmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
setCalloutActive(false);
return e.getLocalizedMessage(); return e.getLocalizedMessage();
} }
setCalloutActive(false); finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return ""; return "";
} // bPartner } // bPartner
@ -463,12 +471,13 @@ public class CalloutOrder extends CalloutEngine
+ "WHERE p.C_BPartner_ID=? AND p.IsActive='Y'"; // #1 + "WHERE p.C_BPartner_ID=? AND p.IsActive='Y'"; // #1
boolean IsSOTrx = "Y".equals(Env.getContext(ctx, WindowNo, "IsSOTrx")); boolean IsSOTrx = "Y".equals(Env.getContext(ctx, WindowNo, "IsSOTrx"));
PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, bill_BPartner_ID.intValue()); pstmt.setInt(1, bill_BPartner_ID.intValue());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
// PriceList (indirect: IsTaxIncluded & Currency) // PriceList (indirect: IsTaxIncluded & Currency)
@ -570,15 +579,17 @@ public class CalloutOrder extends CalloutEngine
mTab.setValue("InvoiceRule", s); mTab.setValue("InvoiceRule", s);
} }
} }
rs.close();
pstmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, "bPartnerBill", e); log.log(Level.SEVERE, "bPartnerBill", e);
return e.getLocalizedMessage(); return e.getLocalizedMessage();
} }
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return ""; return "";
} // bPartnerBill } // bPartnerBill
@ -605,7 +616,8 @@ public class CalloutOrder extends CalloutEngine
if (M_PriceList_ID == null || M_PriceList_ID.intValue()== 0) if (M_PriceList_ID == null || M_PriceList_ID.intValue()== 0)
return ""; return "";
if (steps) log.warning("init"); if (steps) log.warning("init");
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "SELECT pl.IsTaxIncluded,pl.EnforcePriceLimit,pl.C_Currency_ID,c.StdPrecision," String sql = "SELECT pl.IsTaxIncluded,pl.EnforcePriceLimit,pl.C_Currency_ID,c.StdPrecision,"
+ "plv.M_PriceList_Version_ID,plv.ValidFrom " + "plv.M_PriceList_Version_ID,plv.ValidFrom "
+ "FROM M_PriceList pl,C_Currency c,M_PriceList_Version plv " + "FROM M_PriceList pl,C_Currency c,M_PriceList_Version plv "
@ -616,9 +628,9 @@ public class CalloutOrder extends CalloutEngine
// Use newest price list - may not be future // Use newest price list - may not be future
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, M_PriceList_ID.intValue()); pstmt.setInt(1, M_PriceList_ID.intValue());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
// Tax Included // Tax Included
@ -631,14 +643,17 @@ public class CalloutOrder extends CalloutEngine
// PriceList Version // PriceList Version
Env.setContext(ctx, WindowNo, "M_PriceList_Version_ID", rs.getInt(5)); Env.setContext(ctx, WindowNo, "M_PriceList_Version_ID", rs.getInt(5));
} }
rs.close();
pstmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
return e.getLocalizedMessage(); return e.getLocalizedMessage();
} }
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
if (steps) log.warning("fini"); if (steps) log.warning("fini");
return ""; return "";
@ -664,7 +679,6 @@ public class CalloutOrder extends CalloutEngine
Integer M_Product_ID = (Integer)value; Integer M_Product_ID = (Integer)value;
if (M_Product_ID == null || M_Product_ID.intValue() == 0) if (M_Product_ID == null || M_Product_ID.intValue() == 0)
return ""; return "";
setCalloutActive(true);
if (steps) log.warning("init"); if (steps) log.warning("init");
// //
mTab.setValue("C_Charge_ID", null); mTab.setValue("C_Charge_ID", null);
@ -755,7 +769,6 @@ public class CalloutOrder extends CalloutEngine
} }
} }
// //
setCalloutActive(false);
if (steps) log.warning("fini"); if (steps) log.warning("fini");
return tax (ctx, WindowNo, mTab, mField, value); return tax (ctx, WindowNo, mTab, mField, value);
} // product } // product
@ -789,11 +802,13 @@ public class CalloutOrder extends CalloutEngine
Env.setContext(ctx, WindowNo, "DiscountSchema", "N"); Env.setContext(ctx, WindowNo, "DiscountSchema", "N");
String sql = "SELECT ChargeAmt FROM C_Charge WHERE C_Charge_ID=?"; String sql = "SELECT ChargeAmt FROM C_Charge WHERE C_Charge_ID=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, C_Charge_ID.intValue()); pstmt.setInt(1, C_Charge_ID.intValue());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
mTab.setValue ("PriceEntered", rs.getBigDecimal (1)); mTab.setValue ("PriceEntered", rs.getBigDecimal (1));
@ -802,14 +817,18 @@ public class CalloutOrder extends CalloutEngine
mTab.setValue ("PriceList", Env.ZERO); mTab.setValue ("PriceList", Env.ZERO);
mTab.setValue ("Discount", Env.ZERO); mTab.setValue ("Discount", Env.ZERO);
} }
rs.close();
pstmt.close();
} }
catch (SQLException e) catch (SQLException e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
return e.getLocalizedMessage(); return e.getLocalizedMessage();
} }
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// //
return tax (ctx, WindowNo, mTab, mField, value); return tax (ctx, WindowNo, mTab, mField, value);
} // charge } // charge
@ -910,7 +929,6 @@ public class CalloutOrder extends CalloutEngine
{ {
if (isCalloutActive() || value == null) if (isCalloutActive() || value == null)
return ""; return "";
setCalloutActive(true);
if (steps) log.warning("init"); if (steps) log.warning("init");
int C_UOM_To_ID = Env.getContextAsInt(ctx, WindowNo, "C_UOM_ID"); int C_UOM_To_ID = Env.getContextAsInt(ctx, WindowNo, "C_UOM_ID");
@ -1057,7 +1075,6 @@ public class CalloutOrder extends CalloutEngine
log.info("LineNetAmt=" + LineNetAmt); log.info("LineNetAmt=" + LineNetAmt);
mTab.setValue("LineNetAmt", LineNetAmt); mTab.setValue("LineNetAmt", LineNetAmt);
// //
setCalloutActive(false);
return ""; return "";
} // amt } // amt
@ -1076,8 +1093,6 @@ public class CalloutOrder extends CalloutEngine
{ {
if (isCalloutActive() || value == null) if (isCalloutActive() || value == null)
return ""; return "";
setCalloutActive(true);
int M_Product_ID = Env.getContextAsInt(ctx, WindowNo, "M_Product_ID"); int M_Product_ID = Env.getContextAsInt(ctx, WindowNo, "M_Product_ID");
if (steps) log.warning("init - M_Product_ID=" + M_Product_ID + " - " ); if (steps) log.warning("init - M_Product_ID=" + M_Product_ID + " - " );
BigDecimal QtyOrdered = Env.ZERO; BigDecimal QtyOrdered = Env.ZERO;
@ -1218,7 +1233,6 @@ public class CalloutOrder extends CalloutEngine
} }
} }
// //
setCalloutActive(false);
return ""; return "";
} // qty } // qty