MRMA, MRMALine - apply best practices:
BF [ 2791635 ] Use saveEx whenever is possible https://sourceforge.net/tracker/?func=detail&atid=879335&aid=2791635&group_id=176962 BF [ 1874419 ] JDBC Statement not close in a finally block https://sourceforge.net/tracker/?func=detail&atid=879332&aid=1874419&group_id=176962
This commit is contained in:
parent
c01fc5e457
commit
29832d9081
|
@ -18,9 +18,9 @@ package org.compiere.model;
|
|||
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
@ -90,39 +90,15 @@ public class MRMA extends X_M_RMA implements DocAction
|
|||
*/
|
||||
public MRMALine[] getLines (boolean requery)
|
||||
{
|
||||
if (m_lines != null && !requery) {
|
||||
if (m_lines != null && !requery)
|
||||
{
|
||||
set_TrxName(m_lines, get_TrxName());
|
||||
return m_lines;
|
||||
}
|
||||
ArrayList<MRMALine> list = new ArrayList<MRMALine>();
|
||||
|
||||
String sql = "SELECT * FROM M_RMALine WHERE M_RMA_ID=?";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||
pstmt.setInt (1, getM_RMA_ID());
|
||||
ResultSet rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
list.add (new MRMALine(getCtx(), rs, get_TrxName()));
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (pstmt != null)
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
pstmt = null;
|
||||
}
|
||||
List<MRMALine> list = new Query(getCtx(), MRMALine.Table_Name, "M_RMA_ID=?", get_TrxName())
|
||||
.setParameters(new Object[]{getM_RMA_ID()})
|
||||
.setOrderBy(MRMALine.COLUMNNAME_Line)
|
||||
.list();
|
||||
|
||||
m_lines = new MRMALine[list.size ()];
|
||||
list.toArray (m_lines);
|
||||
|
@ -175,7 +151,7 @@ public class MRMA extends X_M_RMA implements DocAction
|
|||
else
|
||||
{
|
||||
String sqlStmt = "SELECT C_Invoice_ID FROM C_Invoice WHERE C_Order_ID=?";
|
||||
invId = DB.getSQLValue(null, sqlStmt, shipment.getC_Order_ID());
|
||||
invId = DB.getSQLValueEx(null, sqlStmt, shipment.getC_Order_ID());
|
||||
}
|
||||
|
||||
if (invId <= 0)
|
||||
|
@ -491,7 +467,7 @@ public class MRMA extends X_M_RMA implements DocAction
|
|||
//
|
||||
counter.setAD_Org_ID(counterAD_Org_ID);
|
||||
counter.setC_BPartner_ID(counterC_BPartner_ID);
|
||||
counter.save(get_TrxName());
|
||||
counter.saveEx(get_TrxName());
|
||||
|
||||
// Update copied lines
|
||||
MRMALine[] counterLines = counter.getLines(true);
|
||||
|
@ -500,7 +476,7 @@ public class MRMA extends X_M_RMA implements DocAction
|
|||
MRMALine counterLine = counterLines[i];
|
||||
counterLine.setClientOrg(counter);
|
||||
//
|
||||
counterLine.save(get_TrxName());
|
||||
counterLine.saveEx(get_TrxName());
|
||||
}
|
||||
|
||||
log.fine(counter.toString());
|
||||
|
@ -512,7 +488,7 @@ public class MRMA extends X_M_RMA implements DocAction
|
|||
{
|
||||
counter.setDocAction(counterDT.getDocAction());
|
||||
counter.processIt(counterDT.getDocAction());
|
||||
counter.save(get_TrxName());
|
||||
counter.saveEx(get_TrxName());
|
||||
}
|
||||
}
|
||||
return counter;
|
||||
|
@ -563,12 +539,11 @@ public class MRMA extends X_M_RMA implements DocAction
|
|||
if (peer.getRef_InOut_ID() != 0)
|
||||
to.setInOut_ID(peer.getRef_InOut_ID());
|
||||
}
|
||||
to.set_Value("Ref_RMA_ID", from.getM_RMA_ID());
|
||||
to.setRef_RMA_ID(from.getM_RMA_ID());
|
||||
|
||||
if (!to.save(trxName))
|
||||
throw new IllegalStateException("Could not create RMA");
|
||||
to.saveEx(trxName);
|
||||
if (counter)
|
||||
from.set_Value("Ref_RMA_ID", to.getM_RMA_ID());
|
||||
from.setRef_RMA_ID(to.getM_RMA_ID());
|
||||
|
||||
if (to.copyLinesFrom(from, counter) == 0)
|
||||
throw new IllegalStateException("Could not create RMA Lines");
|
||||
|
@ -599,10 +574,10 @@ public class MRMA extends X_M_RMA implements DocAction
|
|||
else
|
||||
PO.copyValues(fromLine, line, fromLine.getAD_Client_ID(), fromLine.getAD_Org_ID());
|
||||
line.setM_RMA_ID(getM_RMA_ID());
|
||||
line.set_ValueNoCheck ("M_RMALine_ID", I_ZERO); // new
|
||||
line.set_ValueNoCheck (MRMALine.COLUMNNAME_M_RMALine_ID, I_ZERO); // new
|
||||
if (counter)
|
||||
{
|
||||
line.set_Value("Ref_RMALine_ID", fromLine.getM_RMALine_ID());
|
||||
line.setRef_RMALine_ID(fromLine.getM_RMALine_ID());
|
||||
if (fromLine.getM_InOutLine_ID() != 0)
|
||||
{
|
||||
MInOutLine peer = new MInOutLine (getCtx(), fromLine.getM_InOutLine_ID(), get_TrxName());
|
||||
|
@ -617,8 +592,8 @@ public class MRMA extends X_M_RMA implements DocAction
|
|||
// Cross Link
|
||||
if (counter)
|
||||
{
|
||||
fromLine.set_Value("Ref_RMALine_ID", line.getM_RMALine_ID());
|
||||
fromLine.save(get_TrxName());
|
||||
fromLine.setRef_RMALine_ID(line.getM_RMALine_ID());
|
||||
fromLine.saveEx(get_TrxName());
|
||||
}
|
||||
}
|
||||
if (fromLines.length != count)
|
||||
|
@ -645,11 +620,7 @@ public class MRMA extends X_M_RMA implements DocAction
|
|||
rmaLine.addDescription(Msg.getMsg(getCtx(), "Voided") + " (" + rmaLine.getQty() + ")");
|
||||
rmaLine.setQty(Env.ZERO);
|
||||
rmaLine.setAmt(Env.ZERO);
|
||||
|
||||
if (!rmaLine.save())
|
||||
{
|
||||
m_processMsg = "Could not update line";
|
||||
}
|
||||
rmaLine.saveEx();
|
||||
}
|
||||
|
||||
addDescription(Msg.getMsg(getCtx(), "Voided"));
|
||||
|
@ -753,12 +724,11 @@ public class MRMA extends X_M_RMA implements DocAction
|
|||
public void setProcessed (boolean processed)
|
||||
{
|
||||
super.setProcessed (processed);
|
||||
if (get_ID() == 0)
|
||||
if (get_ID() <= 0)
|
||||
return;
|
||||
String set = "SET Processed='"
|
||||
+ (processed ? "Y" : "N")
|
||||
+ "' WHERE M_RMA_ID=" + getM_RMA_ID();
|
||||
int noLine = DB.executeUpdate("UPDATE M_RMALine " + set, get_TrxName());
|
||||
int noLine = DB.executeUpdateEx("UPDATE M_RMALine SET Processed=? WHERE M_RMA_ID=?",
|
||||
new Object[]{processed, get_ID()},
|
||||
get_TrxName());
|
||||
m_lines = null;
|
||||
log.fine("setProcessed - " + processed + " - Lines=" + noLine);
|
||||
} // setProcessed
|
||||
|
|
|
@ -90,7 +90,7 @@ public class MRMALine extends X_M_RMALine
|
|||
+ "AND IsTaxExempt='Y' AND ValidFrom < SYSDATE ORDER BY IsDefault DESC";
|
||||
|
||||
// Set tax for charge as exempt
|
||||
taxId = DB.getSQLValue(null, sql, Env.getAD_Client_ID(getCtx()));
|
||||
taxId = DB.getSQLValueEx(null, sql, Env.getAD_Client_ID(getCtx()));
|
||||
m_ioLine = null;
|
||||
}
|
||||
else
|
||||
|
@ -124,7 +124,7 @@ public class MRMALine extends X_M_RMALine
|
|||
}
|
||||
else if (getC_Charge_ID() != 0)
|
||||
{
|
||||
MCharge charge = new MCharge(this.getCtx(), getC_Charge_ID(), null);
|
||||
MCharge charge = MCharge.get(this.getCtx(), getC_Charge_ID());
|
||||
unitAmount = charge.getChargeAmt();
|
||||
}
|
||||
}
|
||||
|
@ -167,18 +167,10 @@ public class MRMALine extends X_M_RMALine
|
|||
*/
|
||||
private int getInvoiceLineId()
|
||||
{
|
||||
String whereClause = "M_InOutLine_ID=" + getM_InOutLine_ID();
|
||||
|
||||
int invoiceLineIds[] = MInvoiceLine.getAllIDs(MInvoiceLine.Table_Name, whereClause, null);
|
||||
|
||||
if (invoiceLineIds.length == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return invoiceLineIds[0];
|
||||
}
|
||||
int invoiceLine_ID = new Query(getCtx(), MInvoiceLine.Table_Name, "M_InOutLine_ID=?", get_TrxName())
|
||||
.setParameters(new Object[]{getM_InOutLine_ID()})
|
||||
.firstIdOnly();
|
||||
return invoiceLine_ID <= 0 ? 0 : invoiceLine_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -223,11 +215,7 @@ public class MRMALine extends X_M_RMALine
|
|||
return (getInvoiceLineId() != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
* @param newRecord new
|
||||
* @return save
|
||||
*/
|
||||
@Override
|
||||
protected boolean beforeSave(boolean newRecord)
|
||||
{
|
||||
if (newRecord && getParent().isComplete()) {
|
||||
|
@ -272,9 +260,9 @@ public class MRMALine extends X_M_RMALine
|
|||
// Set default amount for charge and qty
|
||||
if (this.getC_Charge_ID() != 0 && this.getQty().doubleValue() <= 0)
|
||||
{
|
||||
if (Env.ZERO.compareTo(getQty()) == 0)
|
||||
this.setQty(new BigDecimal(1));
|
||||
if (Env.ZERO.compareTo(getAmt()) == 0)
|
||||
if (getQty().signum() == 0)
|
||||
this.setQty(Env.ONE);
|
||||
if (getAmt().signum() == 0)
|
||||
this.setAmt(getUnitAmt());
|
||||
}
|
||||
|
||||
|
@ -283,7 +271,7 @@ public class MRMALine extends X_M_RMALine
|
|||
{
|
||||
this.setAmt(getUnitAmt());
|
||||
|
||||
if (newRecord && Env.ZERO.compareTo(getQty()) == 0)
|
||||
if (newRecord && getQty().signum() == 0)
|
||||
{
|
||||
this.setQty(originalQty);
|
||||
}
|
||||
|
@ -294,12 +282,7 @@ public class MRMALine extends X_M_RMALine
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* After Save
|
||||
* @param newRecord new
|
||||
* @param success success
|
||||
* @return true if can be saved
|
||||
*/
|
||||
@Override
|
||||
protected boolean afterSave(boolean newRecord, boolean success)
|
||||
{
|
||||
if (!success)
|
||||
|
|
Loading…
Reference in New Issue