Integrate contribution [ 1886164 ] Posting Doc_Issue from Expense Report

from Ivan Popov (johnniepop)

BF [ 1874419 ] JDBC Statement not close in a finally block
This commit is contained in:
Carlos Ruiz 2008-02-07 03:48:58 +00:00
parent 931881e153
commit d812e54ea8
1 changed files with 46 additions and 20 deletions

View File

@ -22,6 +22,7 @@ import java.sql.*;
import org.compiere.model.*; import org.compiere.model.*;
import java.util.*; import java.util.*;
import java.util.logging.*; import java.util.logging.*;
import org.compiere.util.*; import org.compiere.util.*;
/** /**
@ -113,7 +114,7 @@ public class Doc_ProjectIssue extends Doc
Fact fact = new Fact(this, as, Fact.POST_Actual); Fact fact = new Fact(this, as, Fact.POST_Actual);
setC_Currency_ID (as.getC_Currency_ID()); setC_Currency_ID (as.getC_Currency_ID());
MProject project = new MProject (getCtx(), m_issue.getC_Project_ID(), null); MProject project = new MProject (getCtx(), m_issue.getC_Project_ID(), getTrxName());
String ProjectCategory = project.getProjectCategory(); String ProjectCategory = project.getProjectCategory();
MProduct product = MProduct.get(getCtx(), m_issue.getM_Product_ID()); MProduct product = MProduct.get(getCtx(), m_issue.getM_Product_ID());
@ -168,14 +169,15 @@ public class Doc_ProjectIssue extends Doc
+ " INNER JOIN C_Order o ON (o.C_Order_ID=ol.C_Order_ID) " + " INNER JOIN C_Order o ON (o.C_Order_ID=ol.C_Order_ID) "
+ "WHERE iol.M_InOutLine_ID=?"; + "WHERE iol.M_InOutLine_ID=?";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, getTrxName());
pstmt.setInt(1, as.getC_Currency_ID()); pstmt.setInt(1, as.getC_Currency_ID());
pstmt.setInt(2, getAD_Client_ID()); pstmt.setInt(2, getAD_Client_ID());
pstmt.setInt(3, getAD_Org_ID()); pstmt.setInt(3, getAD_Org_ID());
pstmt.setInt(4, m_issue.getM_InOutLine_ID()); pstmt.setInt(4, m_issue.getM_InOutLine_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
retValue = rs.getBigDecimal(1); retValue = rs.getBigDecimal(1);
@ -183,23 +185,15 @@ public class Doc_ProjectIssue extends Doc
} }
else else
log.warning("Not found for M_InOutLine_ID=" + m_issue.getM_InOutLine_ID()); log.warning("Not found for M_InOutLine_ID=" + m_issue.getM_InOutLine_ID());
rs.close();
pstmt.close();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close(); pstmt = null; rs = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
return retValue; return retValue;
} // getPOCost(); } // getPOCost();
@ -209,13 +203,45 @@ public class Doc_ProjectIssue extends Doc
* @param as Account Schema * @param as Account Schema
* @return Unit Labor Cost * @return Unit Labor Cost
*/ */
private BigDecimal getLaborCost(MAcctSchema as) private BigDecimal getLaborCost(MAcctSchema as)
{ {
BigDecimal retValue = null; // Todor Lulov 30.01.2008
BigDecimal retValue = Env.ZERO;
BigDecimal qty = Env.ZERO;
/** TODO Labor Cost */ String sql = "SELECT ConvertedAmt, Qty FROM S_TimeExpenseLine " +
" WHERE S_TimeExpenseLine.S_TimeExpenseLine_ID = ?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql.toString (), getTrxName());
pstmt.setInt(1, m_issue.getS_TimeExpenseLine_ID());
rs = pstmt.executeQuery();
if (rs.next())
{
retValue = rs.getBigDecimal(1);
qty = rs.getBigDecimal(2);
retValue = retValue.multiply(qty);
log.fine("ExpLineCost = " + retValue);
}
else
log.warning("Not found for S_TimeExpenseLine_ID=" + m_issue.getS_TimeExpenseLine_ID());
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, sql.toString(), e);
}
finally
{
DB.close(rs, pstmt);
pstmt = null; rs = null;
}
return retValue; return retValue;
} // getLaborCost } // getLaborCost
} // DocProjectIssue } // DocProjectIssue