MMatchPO.java:

* BF [ 1874419 ] JDBC Statement not close in a finally block
* organized imports
* removed unused variables
This commit is contained in:
teo_sarca 2008-02-18 17:15:01 +00:00
parent 5e4f59dea0
commit 5b32d5e6b2
1 changed files with 51 additions and 129 deletions

View File

@ -16,11 +16,17 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.math.*; import java.math.BigDecimal;
import java.sql.*; import java.sql.PreparedStatement;
import java.util.*; import java.sql.ResultSet;
import java.util.logging.*; import java.sql.Timestamp;
import org.compiere.util.*; import java.util.ArrayList;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
/** /**
* Match PO Model. * Match PO Model.
@ -50,31 +56,24 @@ public class MMatchPO extends X_M_MatchPO
String sql = "SELECT * FROM M_MatchPO WHERE C_OrderLine_ID=? AND C_InvoiceLine_ID=?"; String sql = "SELECT * FROM M_MatchPO WHERE C_OrderLine_ID=? AND C_InvoiceLine_ID=?";
ArrayList<MMatchPO> list = new ArrayList<MMatchPO>(); ArrayList<MMatchPO> list = new ArrayList<MMatchPO>();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxName); pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt (1, C_OrderLine_ID); pstmt.setInt (1, C_OrderLine_ID);
pstmt.setInt (2, C_InvoiceLine_ID); pstmt.setInt (2, C_InvoiceLine_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
list.add (new MMatchPO (ctx, rs, trxName)); list.add (new MMatchPO (ctx, rs, trxName));
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log(Level.SEVERE, sql, e); s_log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
MMatchPO[] retValue = new MMatchPO[list.size()]; MMatchPO[] retValue = new MMatchPO[list.size()];
list.toArray (retValue); list.toArray (retValue);
@ -99,30 +98,23 @@ public class MMatchPO extends X_M_MatchPO
+ "WHERE l.M_InOut_ID=?"; + "WHERE l.M_InOut_ID=?";
ArrayList<MMatchPO> list = new ArrayList<MMatchPO>(); ArrayList<MMatchPO> list = new ArrayList<MMatchPO>();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxName); pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt (1, M_InOut_ID); pstmt.setInt (1, M_InOut_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
list.add (new MMatchPO (ctx, rs, trxName)); list.add (new MMatchPO (ctx, rs, trxName));
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log(Level.SEVERE, sql, e); s_log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
MMatchPO[] retValue = new MMatchPO[list.size()]; MMatchPO[] retValue = new MMatchPO[list.size()];
list.toArray (retValue); list.toArray (retValue);
@ -147,30 +139,23 @@ public class MMatchPO extends X_M_MatchPO
+ "WHERE il.C_Invoice_ID=?"; + "WHERE il.C_Invoice_ID=?";
ArrayList<MMatchPO> list = new ArrayList<MMatchPO>(); ArrayList<MMatchPO> list = new ArrayList<MMatchPO>();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxName); pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt (1, C_Invoice_ID); pstmt.setInt (1, C_Invoice_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
list.add (new MMatchPO (ctx, rs, trxName)); list.add (new MMatchPO (ctx, rs, trxName));
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log(Level.SEVERE, sql, e); s_log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
MMatchPO[] retValue = new MMatchPO[list.size()]; MMatchPO[] retValue = new MMatchPO[list.size()];
list.toArray (retValue); list.toArray (retValue);
@ -193,30 +178,23 @@ public class MMatchPO extends X_M_MatchPO
String sql = "SELECT * FROM M_MatchPO WHERE C_OrderLine_ID=?"; String sql = "SELECT * FROM M_MatchPO WHERE C_OrderLine_ID=?";
ArrayList<MMatchPO> list = new ArrayList<MMatchPO>(); ArrayList<MMatchPO> list = new ArrayList<MMatchPO>();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxName); pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt (1, C_OrderLine_ID); pstmt.setInt (1, C_OrderLine_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
list.add (new MMatchPO (ctx, rs, trxName)); list.add (new MMatchPO (ctx, rs, trxName));
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log(Level.SEVERE, sql, e); s_log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
MMatchPO[] retValue = new MMatchPO[list.size()]; MMatchPO[] retValue = new MMatchPO[list.size()];
list.toArray (retValue); list.toArray (retValue);
@ -253,13 +231,13 @@ public class MMatchPO extends X_M_MatchPO
MMatchPO retValue = null; MMatchPO retValue = null;
String sql = "SELECT * FROM M_MatchPO WHERE C_OrderLine_ID=?"; String sql = "SELECT * FROM M_MatchPO WHERE C_OrderLine_ID=?";
ArrayList list = new ArrayList();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxName); pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt (1, C_OrderLine_ID); pstmt.setInt (1, C_OrderLine_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
MMatchPO mpo = new MMatchPO (ctx, rs, trxName); MMatchPO mpo = new MMatchPO (ctx, rs, trxName);
@ -303,23 +281,15 @@ public class MMatchPO extends X_M_MatchPO
break; break;
} }
} }
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log(Level.SEVERE, sql, e); s_log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
// Create New // Create New
@ -648,68 +618,27 @@ public class MMatchPO extends X_M_MatchPO
*/ */
private Timestamp getNewerDateAcct() private Timestamp getNewerDateAcct()
{ {
Timestamp orderDate = null;
Timestamp invoiceDate = null; Timestamp invoiceDate = null;
Timestamp shipDate = null; Timestamp shipDate = null;
String sql = "SELECT i.DateAcct "
+ "FROM C_InvoiceLine il"
+ " INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID) "
+ "WHERE C_InvoiceLine_ID=?";
PreparedStatement pstmt = null;
if (getC_InvoiceLine_ID() != 0) if (getC_InvoiceLine_ID() != 0)
{ {
try String sql = "SELECT i.DateAcct "
{ + "FROM C_InvoiceLine il"
pstmt = DB.prepareStatement (sql, null); + " INNER JOIN C_Invoice i ON (i.C_Invoice_ID=il.C_Invoice_ID) "
pstmt.setInt (1, getC_InvoiceLine_ID()); + "WHERE C_InvoiceLine_ID=?";
ResultSet rs = pstmt.executeQuery (); invoiceDate = DB.getSQLValueTS(null, sql, getC_InvoiceLine_ID());
if (rs.next ())
invoiceDate = rs.getTimestamp(1);
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
log.log (Level.SEVERE, sql, e);
}
} }
// //
sql = "SELECT io.DateAcct "
+ "FROM M_InOutLine iol"
+ " INNER JOIN M_InOut io ON (io.M_InOut_ID=iol.M_InOut_ID) "
+ "WHERE iol.M_InOutLine_ID=?";
if (getM_InOutLine_ID() != 0) if (getM_InOutLine_ID() != 0)
{ {
try String sql = "SELECT io.DateAcct "
{ + "FROM M_InOutLine iol"
pstmt = DB.prepareStatement (sql, null); + " INNER JOIN M_InOut io ON (io.M_InOut_ID=iol.M_InOut_ID) "
pstmt.setInt (1, getM_InOutLine_ID()); + "WHERE iol.M_InOutLine_ID=?";
ResultSet rs = pstmt.executeQuery (); shipDate = DB.getSQLValueTS(null, sql, getM_InOutLine_ID());
if (rs.next ())
shipDate = rs.getTimestamp(1);
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;
}
// Assuming that order date is always earlier // Assuming that order date is always earlier
if (invoiceDate == null) if (invoiceDate == null)
return shipDate; return shipDate;
@ -818,13 +747,14 @@ public class MMatchPO extends X_M_MatchPO
+ " AND AD_Client_ID=?" + " AND AD_Client_ID=?"
+ "ORDER BY C_OrderLine_ID, M_InOutLine_ID"; + "ORDER BY C_OrderLine_ID, M_InOutLine_ID";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
int success = 0; int success = 0;
int errors = 0; int errors = 0;
try try
{ {
pstmt = DB.prepareStatement (sql, null); pstmt = DB.prepareStatement (sql, null);
pstmt.setInt(1, Env.getAD_Client_ID(ctx)); pstmt.setInt(1, Env.getAD_Client_ID(ctx));
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
MMatchPO po1 = new MMatchPO (ctx, rs, null); MMatchPO po1 = new MMatchPO (ctx, rs, null);
@ -860,23 +790,15 @@ public class MMatchPO extends X_M_MatchPO
} }
} }
} }
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log (Level.SEVERE, sql, e); s_log.log (Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
if (errors == 0 && success == 0) if (errors == 0 && success == 0)
; ;