FR [ 1841834 ] PrintFormatUtil: work in transaction

BF [ 1874419 ] JDBC Statement not close in a finally block - only for PrintFormatUtil.java
This commit is contained in:
teo_sarca 2008-01-24 09:11:46 +00:00
parent 2c4be7b8bc
commit 002c1948c3
2 changed files with 26 additions and 27 deletions

View File

@ -41,7 +41,7 @@ public class MigrateData
// Update existing Print Format // Update existing Print Format
PrintFormatUtil pfu = new PrintFormatUtil (Env.getCtx()); PrintFormatUtil pfu = new PrintFormatUtil (Env.getCtx());
pfu.addMissingColumns(); pfu.addMissingColumns((String)null);
} // MigrateData } // MigrateData
/** Logger */ /** Logger */

View File

@ -27,6 +27,9 @@ import org.compiere.util.*;
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: PrintFormatUtil.java,v 1.2 2006/07/30 00:53:02 jjanke Exp $ * @version $Id: PrintFormatUtil.java,v 1.2 2006/07/30 00:53:02 jjanke Exp $
*
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>FR [ 1841834 ] PrintFormatUtil: work in transaction
*/ */
public class PrintFormatUtil public class PrintFormatUtil
{ {
@ -47,37 +50,37 @@ public class PrintFormatUtil
/** /**
* Add Missing Columns for all Print Format * @deprecated use {@link #addMissingColumns(String)}
*/ */
public void addMissingColumns () public void addMissingColumns ()
{
addMissingColumns((String)null);
}
/**
* Add Missing Columns for all Print Format
*/
public void addMissingColumns (String trxName)
{ {
int total = 0; int total = 0;
String sql = "SELECT * FROM AD_PrintFormat pf " String sql = "SELECT * FROM AD_PrintFormat pf "
+ "ORDER BY Name"; + "ORDER BY Name";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, trxName);
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
total += addMissingColumns(new MPrintFormat (m_ctx, rs, null)); total += addMissingColumns(new MPrintFormat (m_ctx, rs, trxName));
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(); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
log.info ("Total = " + total); log.info ("Total = " + total);
} // addMissingColumns } // addMissingColumns
@ -103,13 +106,14 @@ public class PrintFormatUtil
+ " AND c.AD_Table_ID=? " // 2 + " AND c.AD_Table_ID=? " // 2
+ "ORDER BY 1"; + "ORDER BY 1";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
int counter = 0; int counter = 0;
try try
{ {
pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, pf.get_TrxName());
pstmt.setInt(1, pf.getAD_PrintFormat_ID()); pstmt.setInt(1, pf.getAD_PrintFormat_ID());
pstmt.setInt(2, pf.getAD_Table_ID()); pstmt.setInt(2, pf.getAD_Table_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) while (rs.next())
{ {
int AD_Column_ID = rs.getInt(1); int AD_Column_ID = rs.getInt(1);
@ -128,15 +132,10 @@ public class PrintFormatUtil
{ {
log.log(Level.SEVERE, sql, e); 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 (counter == 0) if (counter == 0)
log.fine("None" log.fine("None"
@ -161,7 +160,7 @@ public class PrintFormatUtil
org.compiere.Adempiere.startupEnvironment(true); org.compiere.Adempiere.startupEnvironment(true);
// //
PrintFormatUtil pfu = new PrintFormatUtil (Env.getCtx()); PrintFormatUtil pfu = new PrintFormatUtil (Env.getCtx());
pfu.addMissingColumns(); pfu.addMissingColumns((String)null);
} // main } // main
} // PrintFormatUtils } // PrintFormatUtils