[ 2608617 ] Error when I want to delete a PO document

https://sourceforge.net/tracker/index.php?func=detail&aid=2608617&group_id=176962&atid=879332

* better exception handling
* use new Query API - extensively tested by us
This commit is contained in:
teo_sarca 2009-02-17 11:14:44 +00:00
parent 133edfb2db
commit 26cc12bf8a
2 changed files with 32 additions and 43 deletions

View File

@ -18,12 +18,10 @@ package org.compiere.model;
import java.io.File;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.process.DocAction;
import org.compiere.process.DocumentEngine;
@ -40,9 +38,16 @@ import org.compiere.util.Msg;
* <li> FR [ 2520591 ] Support multiples calendar for Org
* @see http://sourceforge.net/tracker2/?func=detail&atid=879335&aid=2520591&group_id=176962
* @version $Id: MRequisition.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
* @author red1
* <li>FR [ 2214883 ] Remove SQL code and Replace for Query
*/
public class MRequisition extends X_M_Requisition implements DocAction
{
/**
*
*/
private static final long serialVersionUID = -4111474920471624816L;
/**
* Standard Constructor
* @param ctx context
@ -93,34 +98,14 @@ public class MRequisition extends X_M_Requisition implements DocAction
return m_lines;
}
ArrayList<MRequisitionLine> list = new ArrayList<MRequisitionLine>();
String sql = "SELECT * FROM M_RequisitionLine WHERE M_Requisition_ID=? ORDER BY Line";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setInt (1, getM_Requisition_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new MRequisitionLine (getCtx(), rs, get_TrxName()));
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, "getLines", e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
//red1 - FR: [ 2214883 ] Remove SQL code and Replace for Query
String whereClause = MRequisitionLine.COLUMNNAME_M_Requisition_ID+"=?";
List <MRequisitionLine> list = new Query(getCtx(), MRequisitionLine.Table_Name, whereClause, get_TrxName())
.setParameters(new Object[]{get_ID()})
.setOrderBy(MRequisitionLine.COLUMNNAME_Line)
.list();
// red1 - end -
m_lines = new MRequisitionLine[list.size ()];
list.toArray (m_lines);
return m_lines;
@ -286,14 +271,14 @@ public class MRequisition extends X_M_Requisition implements DocAction
if (lineNet.compareTo(line.getLineNetAmt()) != 0)
{
line.setLineNetAmt(lineNet);
line.save();
line.saveEx();
}
totalLines = totalLines.add (line.getLineNetAmt());
}
if (totalLines.compareTo(getTotalLines()) != 0)
{
setTotalLines(totalLines);
save();
saveEx();
}
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_PREPARE);
@ -442,14 +427,14 @@ public class MRequisition extends X_M_Requisition implements DocAction
line.setDescription(description);
line.setQty(finalQty);
line.setLineNetAmt();
line.save();
line.saveEx();
}
totalLines = totalLines.add (line.getLineNetAmt());
}
if (totalLines.compareTo(getTotalLines()) != 0)
{
setTotalLines(totalLines);
save();
saveEx();
}
// After Close
m_processMsg = ModelValidationEngine.get().fireDocValidate(this,ModelValidator.TIMING_AFTER_CLOSE);

View File

@ -33,10 +33,14 @@ import org.compiere.util.Env;
*
* @author Teo Sarca, www.arhipac.ro
* <li>BF [ 2419978 ] Voiding PO, requisition don't set on NULL
* <li>BF [ 2608617 ] Error when I want to delete a PO document
*/
public class MRequisitionLine extends X_M_RequisitionLine
{
private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 6288086509043522278L;
/**
* Get corresponding Requisition Line for given Order Line
@ -73,18 +77,19 @@ public class MRequisitionLine extends X_M_RequisitionLine
/**
* Get corresponding Requisition Line for given Order Line
* Get corresponding Requisition Line(s) for given Order Line
* @param ctx
* @param C_OrderLine_ID order line
* @param trxName
* @return Requisition Line
* @return array of Requisition Line(s)
*/
public static MRequisitionLine forC_OrderLine_ID(Properties ctx, int C_OrderLine_ID, String trxName)
public static MRequisitionLine[] forC_OrderLine_ID(Properties ctx, int C_OrderLine_ID, String trxName)
{
final String whereClause = COLUMNNAME_C_OrderLine_ID+"=?";
return new Query(ctx, MRequisitionLine.Table_Name, whereClause, trxName)
List<MRequisitionLine> list = new Query(ctx, MRequisitionLine.Table_Name, whereClause, trxName)
.setParameters(new Object[]{C_OrderLine_ID})
.firstOnly();
.list();
return list.toArray(new MRequisitionLine[list.size()]);
}
/**
@ -95,8 +100,7 @@ public class MRequisitionLine extends X_M_RequisitionLine
*/
public static void unlinkC_OrderLine_ID(Properties ctx, int C_OrderLine_ID, String trxName)
{
MRequisitionLine line = forC_OrderLine_ID(ctx, C_OrderLine_ID, trxName);
if (line != null)
for (MRequisitionLine line : forC_OrderLine_ID(ctx, C_OrderLine_ID, trxName))
{
line.setC_OrderLine_ID(0);
line.saveEx();