diff --git a/base/src/org/compiere/model/MOrder.java b/base/src/org/compiere/model/MOrder.java index 347b5f4c1c..a92f1f3adb 100644 --- a/base/src/org/compiere/model/MOrder.java +++ b/base/src/org/compiere/model/MOrder.java @@ -16,14 +16,21 @@ *****************************************************************************/ package org.compiere.model; -import java.io.*; -import java.math.*; -import java.sql.*; -import java.util.*; -import java.util.logging.*; -import org.compiere.print.*; -import org.compiere.process.*; -import org.compiere.util.*; +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.Properties; +import java.util.logging.Level; + +import org.compiere.print.ReportEngine; +import org.compiere.process.DocAction; +import org.compiere.process.DocumentEngine; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.compiere.util.Msg; /** * Order Model. @@ -601,35 +608,27 @@ public class MOrder extends X_C_Order implements DocAction if (orderClause != null) sql.append(" ").append(orderClause); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); pstmt.setInt(1, getC_Order_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { MOrderLine ol = new MOrderLine(getCtx(), rs, get_TrxName()); ol.setHeaderInfo (this); list.add(ol); } - rs.close(); - pstmt.close(); - pstmt = null; - } + } catch (Exception e) { log.log(Level.SEVERE, sql.toString(), e); } finally { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} - pstmt = null; + DB.close(rs, pstmt); + rs = null; pstmt = null; } // MOrderLine[] lines = new MOrderLine[list.size ()]; @@ -762,31 +761,23 @@ public class MOrder extends X_C_Order implements DocAction "WHERE o.C_Order_ID=? " + "ORDER BY i.Created DESC"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getC_Order_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MInvoice(getCtx(), rs, get_TrxName())); - rs.close(); - pstmt.close(); - pstmt = null; - } + } catch (Exception e) { log.log(Level.SEVERE, sql, e); } finally { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} - pstmt = null; + DB.close(rs, pstmt); + rs = null; pstmt = null; } // MInvoice[] retValue = new MInvoice[list.size()]; @@ -801,36 +792,27 @@ public class MOrder extends X_C_Order implements DocAction public int getC_Invoice_ID() { int C_Invoice_ID = 0; - ArrayList list = new ArrayList(); - String sql = "SELECT C_Invoice_ID FROM C_Invoice " + String sql = "SELECT C_Invoice_ID FROM C_Invoice " + "WHERE C_Order_ID=? AND DocStatus IN ('CO','CL') " + "ORDER BY Created DESC"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getC_Order_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) C_Invoice_ID = rs.getInt(1); - rs.close(); - pstmt.close(); - pstmt = null; - } + } catch (Exception e) { log.log(Level.SEVERE, "getC_Invoice_ID", e); } finally { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} - pstmt = null; + DB.close(rs, pstmt); + rs = null; pstmt = null; } return C_Invoice_ID; } // getC_Invoice_ID @@ -851,31 +833,23 @@ public class MOrder extends X_C_Order implements DocAction "ORDER BY io.Created DESC"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getC_Order_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MInOut(getCtx(), rs, get_TrxName())); - rs.close(); - pstmt.close(); - pstmt = null; - } + } catch (Exception e) { log.log(Level.SEVERE, sql, e); } finally { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} - pstmt = null; + DB.close(rs, pstmt); + rs = null; pstmt = null; } // MInOut[] retValue = new MInOut[list.size()];