IDEMPIERE-568 Review proper closing of JDBC statements and resultsets
This commit is contained in:
parent
f737c1fc87
commit
555e234496
|
@ -44,17 +44,18 @@ import org.compiere.util.DB;
|
|||
public class ApplyMigrationScripts extends SvrProcess {
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger
|
||||
.getCLogger(ApplyMigrationScripts.class);
|
||||
private static CLogger log = CLogger.getCLogger(ApplyMigrationScripts.class);
|
||||
|
||||
@Override
|
||||
protected String doIt() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
log.info("Applying migrations scripts");
|
||||
StringBuilder sql = new StringBuilder()
|
||||
.append("select ad_migrationscript_id, script, name from ad_migrationscript where isApply = 'Y' and status = 'IP' order by name, created");
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), this.get_TrxName());
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
pstmt = DB.prepareStatement(sql.toString(), this.get_TrxName());
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
byte[] scriptArray = rs.getBytes(2);
|
||||
int seqID = rs.getInt(1);
|
||||
|
@ -75,18 +76,17 @@ public class ApplyMigrationScripts extends SvrProcess {
|
|||
log.severe(e.getMessage());
|
||||
} finally {
|
||||
sql = new StringBuilder("UPDATE ad_migrationscript SET status = ? , isApply = 'N' WHERE ad_migrationscript_id = ? ");
|
||||
pstmt = DB.prepareStatement(sql.toString(), this.get_TrxName());
|
||||
PreparedStatement pstmtu = DB.prepareStatement(sql.toString(), this.get_TrxName());
|
||||
if (execOk) {
|
||||
pstmt.setString(1, "CO");
|
||||
pstmt.setInt(2, seqID);
|
||||
pstmtu.setString(1, "CO");
|
||||
pstmtu.setInt(2, seqID);
|
||||
} else {
|
||||
pstmt.setString(1, "ER");
|
||||
pstmt.setInt(2, seqID);
|
||||
pstmtu.setString(1, "ER");
|
||||
pstmtu.setInt(2, seqID);
|
||||
}
|
||||
try {
|
||||
pstmt.executeUpdate();
|
||||
pstmtu.executeUpdate();
|
||||
if (!execOk) {
|
||||
pstmt.close();
|
||||
return null;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
@ -94,17 +94,23 @@ public class ApplyMigrationScripts extends SvrProcess {
|
|||
StringBuilder msglog = new StringBuilder("Script: ").append(rs.getString(3)).append(" - ").append(e.getMessage());
|
||||
log.saveError("Error", msglog.toString());
|
||||
log.severe(e.getMessage());
|
||||
} finally {
|
||||
DB.close(pstmtu);
|
||||
pstmtu = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
} catch (SQLException e) {
|
||||
throw e;
|
||||
} finally {
|
||||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepare() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
@ -156,7 +162,8 @@ public class ApplyMigrationScripts extends SvrProcess {
|
|||
log.saveError("Error", msglog.toString());
|
||||
log.severe(e.getMessage());
|
||||
} finally {
|
||||
if (stmt != null)stmt.close();
|
||||
DB.close(stmt);
|
||||
stmt = null;
|
||||
if(execOk)
|
||||
conn.commit();
|
||||
else
|
||||
|
|
|
@ -92,9 +92,9 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
int toti = 0;
|
||||
@SuppressWarnings("unused")
|
||||
int totd = 0;
|
||||
int V_temp;
|
||||
int v_temp;
|
||||
int v_NextNo = 0;
|
||||
StringBuilder Message = new StringBuilder();
|
||||
StringBuilder message = new StringBuilder();
|
||||
//
|
||||
//Checking Prerequisites
|
||||
//PO Prices must exists
|
||||
|
@ -171,31 +171,34 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
sql.append(" AND IsCurrentVendor='Y' AND IsActive='Y' ");
|
||||
sql.append(" GROUP BY M_Product_ID ").append(" HAVING COUNT(*) > 1 ) ");
|
||||
|
||||
PreparedStatement Cur_Duplicates = null;
|
||||
Cur_Duplicates = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||
ResultSet dupl = Cur_Duplicates.executeQuery();
|
||||
while (dupl.next()) {
|
||||
PreparedStatement stmtDupl = null;
|
||||
ResultSet rsDupl = null;
|
||||
PreparedStatement stmtVendors = null;
|
||||
ResultSet rsVend = null;
|
||||
try {
|
||||
stmtDupl = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||
rsDupl = stmtDupl.executeQuery();
|
||||
while (rsDupl.next()) {
|
||||
sql = new StringBuilder("SELECT M_Product_ID ,C_BPartner_ID ");
|
||||
sql.append(" FROM M_Product_PO WHERE IsCurrentVendor = 'Y' ");
|
||||
sql.append(" AND IsActive = 'Y' ");
|
||||
sql.append(" AND M_Product_ID = ").append(dupl.getInt("M_Product_ID"));
|
||||
sql.append(" AND M_Product_ID = ").append(rsDupl.getInt("M_Product_ID"));
|
||||
sql.append(" ORDER BY PriceList DESC");
|
||||
|
||||
PreparedStatement Cur_Vendors = null;
|
||||
Cur_Vendors = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||
ResultSet Vend = Cur_Vendors.executeQuery();
|
||||
stmtVendors = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||
rsVend = stmtVendors.executeQuery();
|
||||
|
||||
//
|
||||
// Leave First
|
||||
//
|
||||
Vend.next();
|
||||
rsVend.next();
|
||||
|
||||
while (Vend.next()) {
|
||||
while (rsVend.next()) {
|
||||
sqlupd = new StringBuilder("UPDATE M_Product_PO ");
|
||||
sqlupd.append(" SET IsCurrentVendor = 'N' ");
|
||||
sqlupd.append(" WHERE M_Product_ID= ").append(Vend.getInt("M_Product_ID"));
|
||||
sqlupd.append(" WHERE M_Product_ID= ").append(rsVend.getInt("M_Product_ID"));
|
||||
sqlupd.append(" AND C_BPartner_ID= ");
|
||||
sqlupd.append(Vend.getInt("C_BPartner_ID"));
|
||||
sqlupd.append(rsVend.getInt("C_BPartner_ID"));
|
||||
|
||||
cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName());
|
||||
if (cntu == -1)
|
||||
|
@ -204,16 +207,16 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
sqlupd.toString());
|
||||
totu += cntu;
|
||||
log.fine("Updated " + cntu);
|
||||
|
||||
}
|
||||
Vend.close();
|
||||
Cur_Vendors.close();
|
||||
Cur_Vendors = null;
|
||||
|
||||
}
|
||||
dupl.close();
|
||||
Cur_Duplicates.close();
|
||||
Cur_Duplicates = null;
|
||||
} catch (SQLException e) {
|
||||
throw e;
|
||||
} finally {
|
||||
DB.close(rsDupl, stmtDupl);
|
||||
rsDupl = null; stmtDupl = null;
|
||||
DB.close(rsVend, stmtVendors);
|
||||
rsVend = null; stmtVendors = null;
|
||||
}
|
||||
|
||||
// DB.commit(true, get_TrxName());
|
||||
|
||||
|
@ -228,7 +231,7 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
if (cntd == -1)
|
||||
raiseError(" DELETE M_ProductPrice ", sqldel.toString());
|
||||
totd += cntd;
|
||||
Message = new StringBuilder("@Deleted@=").append(cntd).append(" - ");
|
||||
message = new StringBuilder("@Deleted@=").append(cntd).append(" - ");
|
||||
log.fine("Deleted " + cntd);
|
||||
}
|
||||
//
|
||||
|
@ -243,10 +246,16 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
sql.append(" AND p.C_Currency_ID = c.C_Currency_ID");
|
||||
sql.append(" AND v.M_PriceList_Version_ID = ").append(p_PriceList_Version_ID);
|
||||
|
||||
PreparedStatement curgen = null;
|
||||
curgen = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||
ResultSet v = curgen.executeQuery();
|
||||
while (v.next()) {
|
||||
PreparedStatement stmtCurgen = null;
|
||||
ResultSet rsCurgen = null;
|
||||
PreparedStatement stmtDiscountLine = null;
|
||||
ResultSet rsDiscountLine = null;
|
||||
CPreparedStatement stmt = null;
|
||||
PreparedStatement pstmt = null;
|
||||
try {
|
||||
stmtCurgen = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||
rsCurgen = stmtCurgen.executeQuery();
|
||||
while (rsCurgen.next()) {
|
||||
//
|
||||
// For All Discount Lines in Sequence
|
||||
//
|
||||
|
@ -259,13 +268,12 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
sql.append(",limit_rounding,limit_minamt,limit_maxamt,limit_fixed,group1,group2,c_conversiontype_id");
|
||||
sql.append(" FROM M_DiscountSchemaLine");
|
||||
sql.append(" WHERE M_DiscountSchema_ID=");
|
||||
sql.append(v.getInt("M_DiscountSchema_ID"));
|
||||
sql.append(rsCurgen.getInt("M_DiscountSchema_ID"));
|
||||
sql.append(" AND IsActive='Y' ORDER BY SeqNo");
|
||||
|
||||
PreparedStatement Cur_DiscountLine = null;
|
||||
Cur_DiscountLine = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||
ResultSet dl = Cur_DiscountLine.executeQuery();
|
||||
while (dl.next()) {
|
||||
stmtDiscountLine = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||
rsDiscountLine = stmtDiscountLine.executeQuery();
|
||||
while (rsDiscountLine.next()) {
|
||||
//
|
||||
//Clear Temporary Table
|
||||
//
|
||||
|
@ -280,10 +288,10 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
//
|
||||
//Create Selection in temporary table
|
||||
//
|
||||
V_temp = v.getInt("M_PriceList_Version_Base_ID");
|
||||
String dl_Group1 = dl.getString("Group1");
|
||||
String dl_Group2 = dl.getString("Group2");
|
||||
if (v.wasNull()) {
|
||||
v_temp = rsCurgen.getInt("M_PriceList_Version_Base_ID");
|
||||
String dl_Group1 = rsDiscountLine.getString("Group1");
|
||||
String dl_Group2 = rsDiscountLine.getString("Group2");
|
||||
if (rsCurgen.wasNull()) {
|
||||
//
|
||||
//Create Selection from M_Product_PO
|
||||
//
|
||||
|
@ -291,26 +299,26 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
sqlins.append( " SELECT DISTINCT ").append(m_AD_PInstance_ID).append(", po.M_Product_ID ");
|
||||
sqlins.append(" FROM M_Product p, M_Product_PO po");
|
||||
sqlins.append(" WHERE p.M_Product_ID=po.M_Product_ID ");
|
||||
sqlins.append(" AND (p.AD_Client_ID=").append(v.getInt("AD_Client_ID")).append(" OR p.AD_Client_ID=0)");
|
||||
sqlins.append(" AND (p.AD_Client_ID=").append(rsCurgen.getInt("AD_Client_ID")).append(" OR p.AD_Client_ID=0)");
|
||||
sqlins.append(" AND p.IsActive='Y' AND po.IsActive='Y' AND po.IsCurrentVendor='Y' ");
|
||||
//
|
||||
//Optional Restrictions
|
||||
//
|
||||
// globalqss - detected bug, JDBC returns zero for null values
|
||||
// so we're going to use NULLIF(value, 0)
|
||||
sqlins.append(" AND (NULLIF(").append(dl.getInt("M_Product_Category_ID")).append(",0) IS NULL");
|
||||
sqlins.append(" OR p.M_Product_Category_ID IN (").append(getSubCategoryWhereClause(dl.getInt("M_Product_Category_ID")))
|
||||
sqlins.append(" AND (NULLIF(").append(rsDiscountLine.getInt("M_Product_Category_ID")).append(",0) IS NULL");
|
||||
sqlins.append(" OR p.M_Product_Category_ID IN (").append(getSubCategoryWhereClause(rsDiscountLine.getInt("M_Product_Category_ID")))
|
||||
.append("))");
|
||||
if(dl_Group1 != null)
|
||||
sqlins.append(" AND (p.Group1=?)");
|
||||
if (dl_Group2 != null)
|
||||
sqlins.append(" AND (p.Group2=?)");
|
||||
sqlins.append(" AND (NULLIF(").append(dl.getInt("C_BPartner_ID")).append(",0) IS NULL ");
|
||||
sqlins.append(" OR po.C_BPartner_ID=").append(dl.getInt("C_BPartner_ID")).append(")");
|
||||
sqlins.append(" AND (NULLIF(").append(dl.getInt("M_Product_ID")).append(",0) IS NULL ");
|
||||
sqlins.append(" OR p.M_Product_ID=").append(dl.getInt("M_Product_ID")).append(")");
|
||||
sqlins.append(" AND (NULLIF(").append(rsDiscountLine.getInt("C_BPartner_ID")).append(",0) IS NULL ");
|
||||
sqlins.append(" OR po.C_BPartner_ID=").append(rsDiscountLine.getInt("C_BPartner_ID")).append(")");
|
||||
sqlins.append(" AND (NULLIF(").append(rsDiscountLine.getInt("M_Product_ID")).append(",0) IS NULL ");
|
||||
sqlins.append(" OR p.M_Product_ID=").append(rsDiscountLine.getInt("M_Product_ID")).append(")");
|
||||
|
||||
CPreparedStatement stmt = DB.prepareStatement(sqlins.toString(), get_TrxName());
|
||||
stmt = DB.prepareStatement(sqlins.toString(), get_TrxName());
|
||||
|
||||
int i = 1;
|
||||
|
||||
|
@ -334,19 +342,19 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
sqlins.append(" SELECT DISTINCT ").append(m_AD_PInstance_ID).append(", p.M_Product_ID");
|
||||
sqlins.append(" FROM M_Product p, M_ProductPrice pp");
|
||||
sqlins.append(" WHERE p.M_Product_ID=pp.M_Product_ID");
|
||||
sqlins.append(" AND pp.M_PriceList_Version_ID = ").append(v.getInt("M_PriceList_Version_Base_ID"));
|
||||
sqlins.append(" AND pp.M_PriceList_Version_ID = ").append(rsCurgen.getInt("M_PriceList_Version_Base_ID"));
|
||||
sqlins.append(" AND p.IsActive='Y' AND pp.IsActive='Y'");
|
||||
//
|
||||
//Optional Restrictions
|
||||
//
|
||||
sqlins.append(" AND (NULLIF(").append(dl.getInt("M_Product_Category_ID")).append(",0) IS NULL");
|
||||
sqlins.append(" OR p.M_Product_Category_ID IN (").append(getSubCategoryWhereClause(dl.getInt("M_Product_Category_ID")))
|
||||
sqlins.append(" AND (NULLIF(").append(rsDiscountLine.getInt("M_Product_Category_ID")).append(",0) IS NULL");
|
||||
sqlins.append(" OR p.M_Product_Category_ID IN (").append(getSubCategoryWhereClause(rsDiscountLine.getInt("M_Product_Category_ID")))
|
||||
.append("))");
|
||||
if(dl_Group1 != null)
|
||||
sqlins.append(" AND (p.Group1=?)");
|
||||
if (dl_Group2 != null)
|
||||
sqlins.append(" AND (p.Group2=?)");
|
||||
sqlins.append(" AND (NULLIF(").append(dl.getInt("C_BPartner_ID")).append(",0) IS NULL OR EXISTS ");
|
||||
sqlins.append(" AND (NULLIF(").append(rsDiscountLine.getInt("C_BPartner_ID")).append(",0) IS NULL OR EXISTS ");
|
||||
sqlins.append("(SELECT m_product_id,c_bpartner_id,ad_client_id,ad_org_id,isactive");
|
||||
sqlins.append(",created,createdby,updated,updatedby,iscurrentvendor,c_uom_id");
|
||||
sqlins.append(",c_currency_id,pricelist,pricepo,priceeffective,pricelastpo");
|
||||
|
@ -355,12 +363,12 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
sqlins.append(",deliverytime_promised,deliverytime_actual,qualityrating");
|
||||
sqlins.append(",royaltyamt,group1,group2");
|
||||
sqlins.append(",manufacturer FROM M_Product_PO po WHERE po.M_Product_ID=p.M_Product_ID");
|
||||
sqlins.append(" AND po.C_BPartner_ID=").append(dl.getInt("C_BPartner_ID")).append("))");
|
||||
sqlins.append(" AND (NULLIF(").append(dl.getInt("M_Product_ID")).append(",0) IS NULL ");
|
||||
sqlins.append(" OR p.M_Product_ID=").append(dl.getInt("M_Product_ID")).append(")");
|
||||
sqlins.append(" AND po.C_BPartner_ID=").append(rsDiscountLine.getInt("C_BPartner_ID")).append("))");
|
||||
sqlins.append(" AND (NULLIF(").append(rsDiscountLine.getInt("M_Product_ID")).append(",0) IS NULL ");
|
||||
sqlins.append(" OR p.M_Product_ID=").append(rsDiscountLine.getInt("M_Product_ID")).append(")");
|
||||
|
||||
|
||||
CPreparedStatement stmt = DB.prepareStatement(sqlins.toString(), get_TrxName());
|
||||
stmt = DB.prepareStatement(sqlins.toString(), get_TrxName());
|
||||
int i = 1;
|
||||
|
||||
if (dl_Group1!=null)
|
||||
|
@ -378,13 +386,13 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
|
||||
}
|
||||
|
||||
Message.append("@Selected@=").append(cnti);
|
||||
message.append("@Selected@=").append(cnti);
|
||||
|
||||
//
|
||||
//Delete Prices in Selection, so that we can insert
|
||||
//
|
||||
V_temp = v.getInt("M_PriceList_Version_Base_ID");
|
||||
if (v.wasNull() || V_temp != p_PriceList_Version_ID) {
|
||||
v_temp = rsCurgen.getInt("M_PriceList_Version_Base_ID");
|
||||
if (rsCurgen.wasNull() || v_temp != p_PriceList_Version_ID) {
|
||||
|
||||
sqldel = new StringBuilder("DELETE M_ProductPrice pp");
|
||||
sqldel.append(" WHERE pp.M_PriceList_Version_ID = ");
|
||||
|
@ -396,20 +404,20 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
if (cntd == -1)
|
||||
raiseError(" DELETE M_ProductPrice ", sqldel.toString());
|
||||
totd += cntd;
|
||||
Message.append(", @Deleted@=").append(cntd);
|
||||
message.append(", @Deleted@=").append(cntd);
|
||||
log.fine("Deleted " + cntd);
|
||||
}
|
||||
|
||||
//
|
||||
// Copy (Insert) Prices
|
||||
//
|
||||
V_temp = v.getInt("M_PriceList_Version_Base_ID");
|
||||
if (V_temp == p_PriceList_Version_ID)
|
||||
v_temp = rsCurgen.getInt("M_PriceList_Version_Base_ID");
|
||||
if (v_temp == p_PriceList_Version_ID)
|
||||
//
|
||||
// We have Prices already
|
||||
//
|
||||
;
|
||||
else if (v.wasNull())
|
||||
else if (rsCurgen.wasNull())
|
||||
//
|
||||
//Copy and Convert from Product_PO
|
||||
//
|
||||
|
@ -431,59 +439,59 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
sqlins.append(p_PriceList_Version_ID);
|
||||
sqlins.append(" ,po.M_Product_ID ");
|
||||
sqlins.append(" ,");
|
||||
sqlins.append(v.getInt("AD_Client_ID"));
|
||||
sqlins.append(rsCurgen.getInt("AD_Client_ID"));
|
||||
sqlins.append(" ,");
|
||||
sqlins.append(v.getInt("AD_Org_ID"));
|
||||
sqlins.append(rsCurgen.getInt("AD_Org_ID"));
|
||||
sqlins.append(" ,'Y'");
|
||||
sqlins.append(" ,SysDate,");
|
||||
sqlins.append(v.getInt("UpdatedBy"));
|
||||
sqlins.append(rsCurgen.getInt("UpdatedBy"));
|
||||
sqlins.append(" ,SysDate,");
|
||||
sqlins.append(v.getInt("UpdatedBy"));
|
||||
sqlins.append(rsCurgen.getInt("UpdatedBy"));
|
||||
//
|
||||
//Price List
|
||||
//
|
||||
sqlins.append(" ,COALESCE(currencyConvert(po.PriceList, po.C_Currency_ID, ");
|
||||
sqlins.append(v.getInt("C_Currency_ID"));
|
||||
sqlins.append(rsCurgen.getInt("C_Currency_ID"));
|
||||
sqlins.append(", ? , ");
|
||||
sqlins.append(dl.getInt("C_ConversionType_ID"));
|
||||
sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID"));
|
||||
sqlins.append(", ");
|
||||
sqlins.append(v.getInt("AD_Client_ID"));
|
||||
sqlins.append(rsCurgen.getInt("AD_Client_ID"));
|
||||
sqlins.append(", ");
|
||||
sqlins.append(v.getInt("AD_Org_ID"));
|
||||
sqlins.append(rsCurgen.getInt("AD_Org_ID"));
|
||||
sqlins.append("),0)");
|
||||
|
||||
// Price Std
|
||||
sqlins.append(" ,COALESCE(currencyConvert(po.PriceList, po.C_Currency_ID, ");
|
||||
sqlins.append(v.getInt("C_Currency_ID"));
|
||||
sqlins.append(rsCurgen.getInt("C_Currency_ID"));
|
||||
sqlins.append(", ? , ");
|
||||
sqlins.append(dl.getInt("C_ConversionType_ID"));
|
||||
sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID"));
|
||||
sqlins.append(", ");
|
||||
sqlins.append(v.getInt("AD_Client_ID"));
|
||||
sqlins.append(rsCurgen.getInt("AD_Client_ID"));
|
||||
sqlins.append(", ");
|
||||
sqlins.append(v.getInt("AD_Org_ID"));
|
||||
sqlins.append(rsCurgen.getInt("AD_Org_ID"));
|
||||
sqlins.append("),0)");
|
||||
|
||||
// Price Limit
|
||||
sqlins.append(" ,COALESCE(currencyConvert(po.PricePO ,po.C_Currency_ID, ");
|
||||
sqlins.append(v.getInt("C_Currency_ID"));
|
||||
sqlins.append(rsCurgen.getInt("C_Currency_ID"));
|
||||
sqlins.append(",? , ");
|
||||
sqlins.append(dl.getInt("C_ConversionType_ID"));
|
||||
sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID"));
|
||||
sqlins.append(", ");
|
||||
sqlins.append(v.getInt("AD_Client_ID"));
|
||||
sqlins.append(rsCurgen.getInt("AD_Client_ID"));
|
||||
sqlins.append(", ");
|
||||
sqlins.append(v.getInt("AD_Org_ID"));
|
||||
sqlins.append(rsCurgen.getInt("AD_Org_ID"));
|
||||
sqlins.append("),0)");
|
||||
sqlins.append(" FROM M_Product_PO po ");
|
||||
sqlins.append(" WHERE EXISTS (SELECT * FROM T_Selection s WHERE po.M_Product_ID=s.T_Selection_ID");
|
||||
sqlins.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(") ");
|
||||
sqlins.append(" AND po.IsCurrentVendor='Y' AND po.IsActive='Y'");
|
||||
|
||||
PreparedStatement pstmt = DB.prepareStatement(sqlins.toString(),
|
||||
pstmt = DB.prepareStatement(sqlins.toString(),
|
||||
ResultSet.TYPE_SCROLL_INSENSITIVE,
|
||||
ResultSet.CONCUR_UPDATABLE, get_TrxName());
|
||||
pstmt.setTimestamp(1, dl.getTimestamp("ConversionDate"));
|
||||
pstmt.setTimestamp(2, dl.getTimestamp("ConversionDate"));
|
||||
pstmt.setTimestamp(3, dl.getTimestamp("ConversionDate"));
|
||||
pstmt.setTimestamp(1, rsDiscountLine.getTimestamp("ConversionDate"));
|
||||
pstmt.setTimestamp(2, rsDiscountLine.getTimestamp("ConversionDate"));
|
||||
pstmt.setTimestamp(3, rsDiscountLine.getTimestamp("ConversionDate"));
|
||||
|
||||
cnti = pstmt.executeUpdate();
|
||||
if (cnti == -1)
|
||||
|
@ -503,59 +511,59 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
sqlins.append(" SELECT ");
|
||||
sqlins.append(p_PriceList_Version_ID);
|
||||
sqlins.append(", pp.M_Product_ID,");
|
||||
sqlins.append(v.getInt("AD_Client_ID"));
|
||||
sqlins.append(rsCurgen.getInt("AD_Client_ID"));
|
||||
sqlins.append(", ");
|
||||
sqlins.append(v.getInt("AD_Org_ID"));
|
||||
sqlins.append(rsCurgen.getInt("AD_Org_ID"));
|
||||
sqlins.append(", 'Y', SysDate, ");
|
||||
sqlins.append(v.getInt("UpdatedBy"));
|
||||
sqlins.append(rsCurgen.getInt("UpdatedBy"));
|
||||
sqlins.append(", SysDate, ");
|
||||
sqlins.append(v.getInt("UpdatedBy"));
|
||||
sqlins.append(rsCurgen.getInt("UpdatedBy"));
|
||||
sqlins.append(" ,");
|
||||
// Price List
|
||||
sqlins.append("COALESCE(currencyConvert(pp.PriceList, pl.C_Currency_ID, ");
|
||||
sqlins.append(v.getInt("C_Currency_ID"));
|
||||
sqlins.append(rsCurgen.getInt("C_Currency_ID"));
|
||||
sqlins.append(", ?, ");
|
||||
sqlins.append(dl.getInt("C_ConversionType_ID"));
|
||||
sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID"));
|
||||
sqlins.append(", ");
|
||||
sqlins.append(v.getInt("AD_Client_ID"));
|
||||
sqlins.append(rsCurgen.getInt("AD_Client_ID"));
|
||||
sqlins.append(", ");
|
||||
sqlins.append(v.getInt("AD_Org_ID"));
|
||||
sqlins.append(rsCurgen.getInt("AD_Org_ID"));
|
||||
sqlins.append("),0),");
|
||||
// Price Std
|
||||
sqlins.append("COALESCE(currencyConvert(pp.PriceStd,pl.C_Currency_ID, ");
|
||||
sqlins.append(v.getInt("C_Currency_ID"));
|
||||
sqlins.append(rsCurgen.getInt("C_Currency_ID"));
|
||||
sqlins.append(" , ? , ");
|
||||
sqlins.append(dl.getInt("C_ConversionType_ID"));
|
||||
sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID"));
|
||||
sqlins.append(", ");
|
||||
sqlins.append(v.getInt("AD_Client_ID"));
|
||||
sqlins.append(rsCurgen.getInt("AD_Client_ID"));
|
||||
sqlins.append(", ");
|
||||
sqlins.append(v.getInt("AD_Org_ID"));
|
||||
sqlins.append(rsCurgen.getInt("AD_Org_ID"));
|
||||
sqlins.append("),0),");
|
||||
//Price Limit
|
||||
sqlins.append(" COALESCE(currencyConvert(pp.PriceLimit,pl.C_Currency_ID, ");
|
||||
sqlins.append(v.getInt("C_Currency_ID"));
|
||||
sqlins.append(rsCurgen.getInt("C_Currency_ID"));
|
||||
sqlins.append(" , ? , ");
|
||||
sqlins.append(dl.getInt("C_ConversionType_ID"));
|
||||
sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID"));
|
||||
sqlins.append(", ");
|
||||
sqlins.append(v.getInt("AD_Client_ID"));
|
||||
sqlins.append(rsCurgen.getInt("AD_Client_ID"));
|
||||
sqlins.append(", ");
|
||||
sqlins.append(v.getInt("AD_Org_ID"));
|
||||
sqlins.append(rsCurgen.getInt("AD_Org_ID"));
|
||||
sqlins.append("),0)");
|
||||
sqlins.append(" FROM M_ProductPrice pp");
|
||||
sqlins.append(" INNER JOIN M_PriceList_Version plv ON (pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID)");
|
||||
sqlins.append(" INNER JOIN M_PriceList pl ON (plv.M_PriceList_ID=pl.M_PriceList_ID)");
|
||||
sqlins.append(" WHERE pp.M_PriceList_Version_ID=");
|
||||
sqlins.append(v.getInt("M_PriceList_Version_Base_ID"));
|
||||
sqlins.append(rsCurgen.getInt("M_PriceList_Version_Base_ID"));
|
||||
sqlins.append(" AND EXISTS (SELECT * FROM T_Selection s WHERE pp.M_Product_ID=s.T_Selection_ID");
|
||||
sqlins.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")");
|
||||
sqlins.append("AND pp.IsActive='Y'");
|
||||
|
||||
PreparedStatement pstmt = DB.prepareStatement(sqlins.toString(),
|
||||
pstmt = DB.prepareStatement(sqlins.toString(),
|
||||
ResultSet.TYPE_SCROLL_INSENSITIVE,
|
||||
ResultSet.CONCUR_UPDATABLE, get_TrxName());
|
||||
pstmt.setTimestamp(1, dl.getTimestamp("ConversionDate"));
|
||||
pstmt.setTimestamp(2, dl.getTimestamp("ConversionDate"));
|
||||
pstmt.setTimestamp(3, dl.getTimestamp("ConversionDate"));
|
||||
pstmt.setTimestamp(1, rsDiscountLine.getTimestamp("ConversionDate"));
|
||||
pstmt.setTimestamp(2, rsDiscountLine.getTimestamp("ConversionDate"));
|
||||
pstmt.setTimestamp(3, rsDiscountLine.getTimestamp("ConversionDate"));
|
||||
|
||||
cnti = pstmt.executeUpdate();
|
||||
|
||||
|
@ -567,19 +575,19 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
log.fine("Inserted " + cnti);
|
||||
|
||||
}
|
||||
Message.append(", @Inserted@=").append(cnti);
|
||||
message.append(", @Inserted@=").append(cnti);
|
||||
//
|
||||
// Calculation
|
||||
//
|
||||
sqlupd = new StringBuilder("UPDATE M_ProductPrice p ");
|
||||
sqlupd.append(" SET PriceList = (DECODE( '");
|
||||
sqlupd.append(dl.getString("List_Base"));
|
||||
sqlupd.append(rsDiscountLine.getString("List_Base"));
|
||||
sqlupd.append("', 'S', PriceStd, 'X', PriceLimit, PriceList)");
|
||||
sqlupd.append(" + ?) * (1 - ?/100), PriceStd = (DECODE('");
|
||||
sqlupd.append(dl.getString("Std_Base"));
|
||||
sqlupd.append(rsDiscountLine.getString("Std_Base"));
|
||||
sqlupd.append("', 'L', PriceList, 'X', PriceLimit, PriceStd) ");
|
||||
sqlupd.append(" + ?) * (1 - ?/100), ").append(" PriceLimit = (DECODE('");
|
||||
sqlupd.append(dl.getString("Limit_Base"));
|
||||
sqlupd.append(rsDiscountLine.getString("Limit_Base"));
|
||||
sqlupd.append("', 'L', PriceList, 'S', PriceStd, PriceLimit) ");
|
||||
sqlupd.append(" + ?) * (1 - ? /100) ");
|
||||
sqlupd.append(" WHERE M_PriceList_Version_ID = ");
|
||||
|
@ -592,12 +600,12 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
ResultSet.TYPE_SCROLL_INSENSITIVE,
|
||||
ResultSet.CONCUR_UPDATABLE, get_TrxName());
|
||||
|
||||
pstmu.setDouble(1, dl.getDouble("List_AddAmt"));
|
||||
pstmu.setDouble(2, dl.getDouble("List_Discount"));
|
||||
pstmu.setDouble(3, dl.getDouble("Std_AddAmt"));
|
||||
pstmu.setDouble(4, dl.getDouble("Std_Discount"));
|
||||
pstmu.setDouble(5, dl.getDouble("Limit_AddAmt"));
|
||||
pstmu.setDouble(6, dl.getDouble("Limit_Discount"));
|
||||
pstmu.setDouble(1, rsDiscountLine.getDouble("List_AddAmt"));
|
||||
pstmu.setDouble(2, rsDiscountLine.getDouble("List_Discount"));
|
||||
pstmu.setDouble(3, rsDiscountLine.getDouble("Std_AddAmt"));
|
||||
pstmu.setDouble(4, rsDiscountLine.getDouble("Std_Discount"));
|
||||
pstmu.setDouble(5, rsDiscountLine.getDouble("Limit_AddAmt"));
|
||||
pstmu.setDouble(6, rsDiscountLine.getDouble("Limit_Discount"));
|
||||
|
||||
cntu = pstmu.executeUpdate();
|
||||
|
||||
|
@ -611,7 +619,7 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
//
|
||||
sqlupd = new StringBuilder("UPDATE M_ProductPrice p ");
|
||||
sqlupd.append(" SET PriceList = DECODE('");
|
||||
sqlupd.append(dl.getString("List_Rounding")).append("',");
|
||||
sqlupd.append(rsDiscountLine.getString("List_Rounding")).append("',");
|
||||
sqlupd.append(" 'N', PriceList, ");
|
||||
sqlupd.append(" '0', ROUND(PriceList, 0),"); //Even .00
|
||||
sqlupd.append(" 'D', ROUND(PriceList, 1),"); //Dime .10
|
||||
|
@ -621,9 +629,9 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
sqlupd.append(" '9', CASE"); //Whole 9 or 5
|
||||
sqlupd.append(" WHEN MOD(ROUND(PriceList),10)<=5 THEN ROUND(PriceList)+(5-MOD(ROUND(PriceList),10))");
|
||||
sqlupd.append(" WHEN MOD(ROUND(PriceList),10)>5 THEN ROUND(PriceList)+(9-MOD(ROUND(PriceList),10)) END,");
|
||||
sqlupd.append(" ROUND(PriceList, ").append(v.getInt("StdPrecision"));
|
||||
sqlupd.append(" ROUND(PriceList, ").append(rsCurgen.getInt("StdPrecision"));
|
||||
sqlupd.append(")),");//Currency
|
||||
sqlupd.append(" PriceStd = DECODE('").append(dl.getString("Std_Rounding"));
|
||||
sqlupd.append(" PriceStd = DECODE('").append(rsDiscountLine.getString("Std_Rounding"));
|
||||
sqlupd.append("',").append(" 'N', PriceStd, ");
|
||||
sqlupd.append(" '0', ROUND(PriceStd, 0), "); //Even .00
|
||||
sqlupd.append(" 'D', ROUND(PriceStd, 1), "); //Dime .10
|
||||
|
@ -633,9 +641,9 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
sqlupd.append(" '9', CASE"); //Whole 9 or 5
|
||||
sqlupd.append(" WHEN MOD(ROUND(PriceStd),10)<=5 THEN ROUND(PriceStd)+(5-MOD(ROUND(PriceStd),10))");
|
||||
sqlupd.append(" WHEN MOD(ROUND(PriceStd),10)>5 THEN ROUND(PriceStd)+(9-MOD(ROUND(PriceStd),10)) END,");
|
||||
sqlupd.append("ROUND(PriceStd, ").append(v.getInt("StdPrecision")).append(")),"); //Currency
|
||||
sqlupd.append("ROUND(PriceStd, ").append(rsCurgen.getInt("StdPrecision")).append(")),"); //Currency
|
||||
sqlupd.append("PriceLimit = DECODE('");
|
||||
sqlupd.append(dl.getString("Limit_Rounding")).append("', ");
|
||||
sqlupd.append(rsDiscountLine.getString("Limit_Rounding")).append("', ");
|
||||
sqlupd.append(" 'N', PriceLimit, ");
|
||||
sqlupd.append(" '0', ROUND(PriceLimit, 0), "); // Even .00
|
||||
sqlupd.append(" 'D', ROUND(PriceLimit, 1), "); // Dime .10
|
||||
|
@ -645,7 +653,7 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
sqlupd.append(" '9', CASE"); //Whole 9 or 5
|
||||
sqlupd.append(" WHEN MOD(ROUND(PriceLimit),10)<=5 THEN ROUND(PriceLimit)+(5-MOD(ROUND(PriceLimit),10))");
|
||||
sqlupd.append(" WHEN MOD(ROUND(PriceLimit),10)>5 THEN ROUND(PriceLimit)+(9-MOD(ROUND(PriceLimit),10)) END,");
|
||||
sqlupd.append(" ROUND(PriceLimit, ").append(v.getInt("StdPrecision"));
|
||||
sqlupd.append(" ROUND(PriceLimit, ").append(rsCurgen.getInt("StdPrecision"));
|
||||
sqlupd.append(")) "); // Currency
|
||||
sqlupd.append(" WHERE M_PriceList_Version_ID=");
|
||||
sqlupd.append(p_PriceList_Version_ID);
|
||||
|
@ -659,20 +667,20 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
totu += cntu;
|
||||
log.fine("Updated " + cntu);
|
||||
|
||||
Message.append(", @Updated@=").append(cntu);
|
||||
message.append(", @Updated@=").append(cntu);
|
||||
//
|
||||
//Fixed Price overwrite
|
||||
//
|
||||
sqlupd = new StringBuilder("UPDATE M_ProductPrice p ");
|
||||
sqlupd.append(" SET PriceList = DECODE('");
|
||||
sqlupd.append(dl.getString("List_Base")).append("', 'F', ");
|
||||
sqlupd.append(dl.getDouble("List_Fixed")).append(", PriceList), ");
|
||||
sqlupd.append(rsDiscountLine.getString("List_Base")).append("', 'F', ");
|
||||
sqlupd.append(rsDiscountLine.getDouble("List_Fixed")).append(", PriceList), ");
|
||||
sqlupd.append(" PriceStd = DECODE('");
|
||||
sqlupd.append(dl.getString("Std_Base")).append("', 'F', ");
|
||||
sqlupd.append(dl.getDouble("Std_Fixed")).append(", PriceStd),");
|
||||
sqlupd.append(rsDiscountLine.getString("Std_Base")).append("', 'F', ");
|
||||
sqlupd.append(rsDiscountLine.getDouble("Std_Fixed")).append(", PriceStd),");
|
||||
sqlupd.append(" PriceLimit = DECODE('");
|
||||
sqlupd.append(dl.getString("Limit_Base")).append("', 'F', ");
|
||||
sqlupd.append(dl.getDouble("Limit_Fixed")).append(", PriceLimit)");
|
||||
sqlupd.append(rsDiscountLine.getString("Limit_Base")).append("', 'F', ");
|
||||
sqlupd.append(rsDiscountLine.getDouble("Limit_Fixed")).append(", PriceLimit)");
|
||||
sqlupd.append(" WHERE M_PriceList_Version_ID=");
|
||||
sqlupd.append(p_PriceList_Version_ID);
|
||||
sqlupd.append(" AND EXISTS (SELECT * FROM T_Selection s");
|
||||
|
@ -686,13 +694,9 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
log.fine("Updated " + cntu);
|
||||
|
||||
v_NextNo = v_NextNo + 1;
|
||||
addLog(0, null, null, Message.toString());
|
||||
Message = new StringBuilder();
|
||||
addLog(0, null, null, message.toString());
|
||||
message = new StringBuilder();
|
||||
}
|
||||
dl.close();
|
||||
Cur_DiscountLine.close();
|
||||
Cur_DiscountLine = null;
|
||||
|
||||
//
|
||||
// Delete Temporary Selection
|
||||
//
|
||||
|
@ -710,9 +714,18 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
// DB.commit(true, get_TrxName());
|
||||
|
||||
}
|
||||
v.close();
|
||||
curgen.close();
|
||||
curgen = null;
|
||||
} catch (SQLException e) {
|
||||
throw e;
|
||||
} finally {
|
||||
DB.close(rsCurgen, stmtCurgen);
|
||||
rsCurgen = null; stmtCurgen = null;
|
||||
DB.close(rsDiscountLine, stmtDiscountLine);
|
||||
rsDiscountLine = null; stmtDiscountLine = null;
|
||||
DB.close(stmt);
|
||||
stmt = null;
|
||||
DB.close(pstmt);
|
||||
pstmt = null;
|
||||
}
|
||||
|
||||
return "OK";
|
||||
|
||||
|
@ -734,15 +747,19 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
* It is used as restriction in MQuery.
|
||||
* @param productCategoryId
|
||||
* @return
|
||||
* @throws
|
||||
*/
|
||||
private String getSubCategoryWhereClause(int productCategoryId) throws SQLException, AdempiereSystemError{
|
||||
private String getSubCategoryWhereClause(int productCategoryId) throws SQLException, AdempiereSystemError {
|
||||
//if a node with this id is found later in the search we have a loop in the tree
|
||||
int subTreeRootParentId = 0;
|
||||
StringBuilder retString = new StringBuilder();
|
||||
String sql = " SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category";
|
||||
final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100);
|
||||
Statement stmt = DB.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(sql);
|
||||
Statement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
stmt = DB.createStatement();
|
||||
rs = stmt.executeQuery(sql);
|
||||
while (rs.next()) {
|
||||
if(rs.getInt(1)==productCategoryId) {
|
||||
subTreeRootParentId = rs.getInt(2);
|
||||
|
@ -750,8 +767,12 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2)));
|
||||
}
|
||||
retString.append(getSubCategoriesString(productCategoryId, categories, subTreeRootParentId));
|
||||
rs.close();
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
throw e;
|
||||
} finally {
|
||||
DB.close(rs, stmt);
|
||||
rs = null; stmt = null;
|
||||
}
|
||||
return retString.toString();
|
||||
}
|
||||
|
||||
|
@ -760,7 +781,7 @@ public class M_PriceList_Create extends SvrProcess {
|
|||
* @param productCategoryId
|
||||
* @param categories
|
||||
* @param loopIndicatorId
|
||||
* @return comma seperated list of category ids
|
||||
* @return comma separated list of category ids
|
||||
* @throws AdempiereSystemError if a loop is detected
|
||||
*/
|
||||
private String getSubCategoriesString(int productCategoryId, Vector<SimpleTreeNode> categories, int loopIndicatorId) throws AdempiereSystemError {
|
||||
|
|
Loading…
Reference in New Issue