From 9b0c13b9f54d6ca210fedf0e3b26cb3544ec3ab7 Mon Sep 17 00:00:00 2001 From: Richard Morales Date: Tue, 19 Feb 2013 16:08:13 -0500 Subject: [PATCH] IDEMPIERE-568 Review proper closing of JDBC statements and resultsets --- .../src/org/compiere/impexp/ImpFormat.java | 71 +++++++++++------ .../src/org/compiere/impexp/MImpFormat.java | 16 ++-- .../src/org/compiere/model/GridField.java | 30 +++---- .../src/org/compiere/model/GridTab.java | 69 +++++++++++----- .../src/org/compiere/model/GridTabVO.java | 16 ++-- .../src/org/compiere/model/GridWorkbench.java | 28 +++++-- .../src/org/compiere/model/MArchive.java | 33 ++++---- .../src/org/compiere/model/MBPGroup.java | 34 +++----- .../src/org/compiere/model/MBPartner.java | 78 ++++++------------- .../src/org/compiere/model/MBPartnerInfo.java | 16 ++-- .../compiere/model/MBankAccountProcessor.java | 14 +++- .../compiere/model/MBankStatementMatcher.java | 16 ++-- .../src/org/compiere/model/MCStage.java | 18 ++--- .../src/org/compiere/model/MCashPlan.java | 3 - .../src/org/compiere/model/MClick.java | 33 +++----- .../src/org/compiere/model/MClickCount.java | 17 ++-- .../src/org/compiere/model/MClient.java | 14 +++- .../src/org/compiere/model/MClientInfo.java | 17 ++-- .../src/org/compiere/model/MClientShare.java | 32 +++----- .../src/org/compiere/model/MColumn.java | 14 +++- .../src/org/compiere/model/MColumnAccess.java | 16 ++-- .../org/compiere/model/MConversionRate.java | 18 ++--- .../src/org/compiere/model/MCostQueue.java | 32 +++----- .../src/org/compiere/model/MCountry.java | 14 +++- .../src/org/compiere/model/MDesktop.java | 28 +++++-- .../org/compiere/model/MDiscountSchema.java | 32 +++----- .../org/compiere/model/MDistributionList.java | 16 ++-- .../org/compiere/model/MDistributionRun.java | 16 ++-- .../model/MDistributionRunDetail.java | 16 ++-- .../org/compiere/model/MDocTypeCounter.java | 16 ++-- .../src/org/compiere/model/MDunningLevel.java | 16 ++-- .../src/org/compiere/model/MDunningRun.java | 16 ++-- .../org/compiere/model/MDunningRunEntry.java | 32 +++----- .../org/compiere/model/MEXPFormatLine.java | 15 ++-- .../src/org/compiere/model/MEXPProcessor.java | 17 ++-- .../src/org/compiere/model/MGLCategory.java | 16 ++-- .../src/org/compiere/model/MIMPProcessor.java | 48 ++++-------- .../src/org/compiere/model/MInterestArea.java | 16 ++-- .../src/org/compiere/model/MInvoice.java | 3 - .../src/org/compiere/model/MInvoiceBatch.java | 16 ++-- .../src/org/compiere/model/MInvoiceLine.java | 30 ++----- .../compiere/model/MInvoicePaySchedule.java | 16 ++-- .../src/org/compiere/model/MIssueProject.java | 16 ++-- .../src/org/compiere/model/MIssueSystem.java | 18 ++--- .../src/org/compiere/model/MIssueUser.java | 16 ++-- .../src/org/compiere/model/MJournalBatch.java | 17 ++-- .../src/org/compiere/model/MLandedCost.java | 16 ++-- .../compiere/model/MLandedCostAllocation.java | 16 ++-- .../src/org/compiere/model/MLocation.java | 14 +++- .../src/org/compiere/model/MLookup.java | 14 +++- .../src/org/compiere/model/MLookupInfo.java | 28 +++++-- .../src/org/compiere/model/MMailText.java | 17 ++-- .../src/org/compiere/model/MMeasureCalc.java | 16 ++-- .../src/org/compiere/model/MMedia.java | 16 ++-- .../src/org/compiere/model/MMessage.java | 16 ++-- .../org/compiere/model/MMovementConfirm.java | 16 ++-- .../org/compiere/model/MMovementLineMA.java | 16 ++-- .../src/org/compiere/model/MNewsChannel.java | 16 ++-- .../src/org/compiere/model/MOrderLine.java | 16 ++-- .../org/compiere/model/MOrderPaySchedule.java | 16 ++-- .../src/org/compiere/model/MOrderTax.java | 32 +++----- .../src/org/compiere/model/MPInstance.java | 16 +--- .../src/org/compiere/model/MPOSKeyLayout.java | 16 ++-- .../compiere/model/MPaySelectionCheck.java | 47 +++++------ .../src/org/compiere/model/MPayment.java | 2 - .../org/compiere/model/MPaymentLookup.java | 3 - .../src/org/compiere/model/MPaymentTerm.java | 16 ++-- .../org/compiere/model/MPrivateAccess.java | 18 ++--- .../org/compiere/model/MProductCategory.java | 16 ++-- .../org/compiere/model/MProductDownload.java | 16 ++-- .../src/org/compiere/model/MProduction.java | 5 +- .../src/org/compiere/model/MProjectPhase.java | 17 ++-- .../src/org/compiere/model/MProjectType.java | 17 ++-- .../org/compiere/model/MProjectTypePhase.java | 17 ++-- .../src/org/compiere/model/MRMATax.java | 32 +++----- .../src/org/compiere/model/MRecordAccess.java | 32 +++----- .../src/org/compiere/model/MRefList.java | 6 -- .../src/org/compiere/model/MRegion.java | 14 +++- .../src/org/compiere/model/MRegistration.java | 32 +++----- .../model/MRegistrationAttribute.java | 16 ++-- .../org/compiere/model/MRequestProcessor.java | 48 ++++-------- .../src/org/compiere/model/MRequestType.java | 32 +++----- .../src/org/compiere/model/MRfQLine.java | 16 ++-- .../src/org/compiere/model/MRfQLineQty.java | 16 ++-- .../src/org/compiere/model/MRfQResponse.java | 16 ++-- .../org/compiere/model/MRfQResponseLine.java | 16 ++-- .../src/org/compiere/model/MRfQTopic.java | 16 ++-- .../compiere/model/MRfQTopicSubscriber.java | 16 ++-- .../org/compiere/model/MRoleOrgAccess.java | 32 +++----- .../src/org/compiere/model/MSLACriteria.java | 16 ++-- .../src/org/compiere/model/MSLAGoal.java | 16 ++-- .../src/org/compiere/model/MStatus.java | 34 +++----- .../org/compiere/model/MStatusCategory.java | 32 +++----- .../src/org/compiere/model/MStore.java | 63 +++++---------- .../pipo2/handler/ColumnElementHandler.java | 25 ++---- .../compiere/apps/form/VAttributeGrid.java | 34 ++++---- .../org/compiere/grid/ed/VLocatorDialog.java | 14 +++- .../org/compiere/grid/CreateFromInvoice.java | 30 ++++--- .../org/compiere/grid/CreateFromShipment.java | 8 +- .../src/org/compiere/install/Translation.java | 68 +++++++++++----- .../install/TranslationController.java | 42 +++++++--- 101 files changed, 927 insertions(+), 1347 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/impexp/ImpFormat.java b/org.adempiere.base/src/org/compiere/impexp/ImpFormat.java index c0f785dadc..5ff0c397bd 100644 --- a/org.adempiere.base/src/org/compiere/impexp/ImpFormat.java +++ b/org.adempiere.base/src/org/compiere/impexp/ImpFormat.java @@ -118,23 +118,29 @@ public final class ImpFormat String sql = "SELECT t.TableName,c.ColumnName " + "FROM AD_Table t INNER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID AND c.IsKey='Y') " + "WHERE t.AD_Table_ID=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_Table_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { m_tableName = rs.getString(1); m_tablePK = rs.getString(2); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, "ImpFormat.setTable", e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } if (m_tableName == null || m_tablePK == null) log.log(Level.SEVERE, "Data not found for AD_Table_ID=" + AD_Table_ID); @@ -269,11 +275,13 @@ public final class ImpFormat ImpFormat retValue = null; String sql = "SELECT * FROM AD_ImpFormat WHERE Name=?"; int ID = 0; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setString (1, name); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { retValue = new ImpFormat (name, rs.getInt("AD_Table_ID"), rs.getString("FormatType")); @@ -282,14 +290,18 @@ public final class ImpFormat retValue.setSeparatorChar(rs.getString(I_AD_ImpFormat.COLUMNNAME_SeparatorChar)); } } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); return null; } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } loadRows (retValue, ID); return retValue; } // getFormat @@ -306,11 +318,13 @@ public final class ImpFormat + "FROM AD_ImpFormat_Row f,AD_Column c " + "WHERE f.AD_ImpFormat_ID=? AND f.AD_Column_ID=c.AD_Column_ID AND f.IsActive='Y'" + "ORDER BY f.SeqNo"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt (1, ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { ImpFormatRow row = new ImpFormatRow (rs.getInt(1), @@ -322,13 +336,17 @@ public final class ImpFormat // format.addRow (row); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } // loadLines /************************************************************************* @@ -560,28 +578,33 @@ public final class ImpFormat sql.append(find).append(")"); int count = 0; int ID = 0; - try + if (find.length() > 0) { - if (find.length() > 0) + PreparedStatement pstmt = null; + ResultSet rs = null; + try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), trxName); - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(sql.toString(), trxName); + rs = pstmt.executeQuery(); if (rs.next()) { count = rs.getInt(1); if (count == 1) ID = rs.getInt(2); } - rs.close(); - pstmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql.toString(), e); + return false; + } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; } } - catch (SQLException e) - { - log.log(Level.SEVERE, sql.toString(), e); - return false; - } - // Insert Basic Record ----------------------------------------------- if (ID == 0) diff --git a/org.adempiere.base/src/org/compiere/impexp/MImpFormat.java b/org.adempiere.base/src/org/compiere/impexp/MImpFormat.java index d47008e1df..7360e08bd3 100644 --- a/org.adempiere.base/src/org/compiere/impexp/MImpFormat.java +++ b/org.adempiere.base/src/org/compiere/impexp/MImpFormat.java @@ -73,29 +73,23 @@ public class MImpFormat extends X_AD_ImpFormat + "WHERE AD_ImpFormat_ID=? " + "ORDER BY SeqNo"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getAD_ImpFormat_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add(new MImpFormatRow (getCtx(), rs, get_TrxName())); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, "getRows", e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } MImpFormatRow[] retValue = new MImpFormatRow[list.size ()]; diff --git a/org.adempiere.base/src/org/compiere/model/GridField.java b/org.adempiere.base/src/org/compiere/model/GridField.java index d339464ed6..85344a7139 100644 --- a/org.adempiere.base/src/org/compiere/model/GridField.java +++ b/org.adempiere.base/src/org/compiere/model/GridField.java @@ -581,21 +581,27 @@ public class GridField } else { + PreparedStatement stmt = null; + ResultSet rs = null; try { - PreparedStatement stmt = DB.prepareStatement(sql, null); - ResultSet rs = stmt.executeQuery(); + stmt = DB.prepareStatement(sql, null); + rs = stmt.executeQuery(); if (rs.next()) defStr = rs.getString(1); else log.log(Level.WARNING, "(" + m_vo.ColumnName + ") - no Result: " + sql); - rs.close(); - stmt.close(); } catch (SQLException e) { log.log(Level.WARNING, "(" + m_vo.ColumnName + ") " + sql, e); } + finally + { + DB.close(rs, stmt); + rs = null; + stmt = null; + } } if (defStr != null && defStr.length() > 0) { @@ -1721,33 +1727,27 @@ public class GridField String sql = GridFieldVO.getSQL(ctx); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_Tab_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { GridFieldVO vo = GridFieldVO.create(ctx, WindowNo, TabNo, AD_Window_ID, AD_Tab_ID, readOnly, rs); listVO.add(vo); } - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.base/src/org/compiere/model/GridTab.java b/org.adempiere.base/src/org/compiere/model/GridTab.java index f376da7e4b..74f2cdc23d 100644 --- a/org.adempiere.base/src/org/compiere/model/GridTab.java +++ b/org.adempiere.base/src/org/compiere/model/GridTab.java @@ -794,21 +794,27 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable + " INNER JOIN AD_Column cc ON (r.AD_Key=cc.AD_Column_ID) " + "WHERE c.AD_Reference_ID IN (18,30)" // Table/Search + " AND c.ColumnName=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setString(1, colName); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) refColName = rs.getString(1); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, "(ref) - Column=" + colName, e); return query.getWhereClause(); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Reference Column found if (refColName != null) { @@ -834,21 +840,24 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable + " WHERE cc.AD_Table_ID=t.AD_Table_ID AND cc.ColumnName=?)"; // #2 Tab Key Column try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setString(1, colName); pstmt.setString(2, tabKeyColumn); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) tableName = rs.getString(1); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, "Column=" + colName + ", Key=" + tabKeyColumn, e); return null; } - + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Special Reference Handling if (tabKeyColumn.equals("AD_Reference_ID")) { @@ -1290,20 +1299,26 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable else { String SQL = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(SQL, null); + pstmt = DB.prepareStatement(SQL, null); pstmt.setInt(1, m_vo.AD_Column_ID); // Parent Link Column - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) m_linkColumnName = rs.getString(1); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, "", e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } log.fine("AD_Column_ID=" + m_vo.AD_Column_ID + " - " + m_linkColumnName); } } @@ -1759,11 +1774,13 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable + "FROM C_InvoiceBatchLine " + "WHERE C_InvoiceBatch_ID=? AND IsActive='Y'"; // + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, Record_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { // {0} - Number of lines @@ -1777,13 +1794,17 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable arguments[2] = total; filled = true; } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, m_vo.TableName + "\nSQL=" + sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } if (filled) return mf.format (arguments); return " "; @@ -2095,28 +2116,34 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable + "FROM AD_Private_Access " + "WHERE AD_User_ID=? AND AD_Table_ID=? AND IsActive='Y' " + "ORDER BY Record_ID"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { if (m_Lock == null) m_Lock = new ArrayList(); else m_Lock.clear(); - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_User_ID); pstmt.setInt(2, m_vo.AD_Table_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { Integer key = new Integer(rs.getInt(1)); m_Lock.add(key); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } log.fine("#" + m_Lock.size()); } // loadLooks diff --git a/org.adempiere.base/src/org/compiere/model/GridTabVO.java b/org.adempiere.base/src/org/compiere/model/GridTabVO.java index b28844e410..963ffe0f4d 100644 --- a/org.adempiere.base/src/org/compiere/model/GridTabVO.java +++ b/org.adempiere.base/src/org/compiere/model/GridTabVO.java @@ -285,11 +285,13 @@ public class GridTabVO implements Evaluatee, Serializable mTabVO.Fields = new ArrayList(); String sql = GridFieldVO.getSQL(mTabVO.ctx); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, mTabVO.AD_Tab_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { GridFieldVO voF = GridFieldVO.create (mTabVO.ctx, @@ -299,16 +301,18 @@ public class GridTabVO implements Evaluatee, Serializable if (voF != null) mTabVO.Fields.add(voF); } - rs.close(); - pstmt.close(); } catch (Exception e) { CLogger.get().log(Level.SEVERE, "", e); return false; } - - + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } mTabVO.initFields = true; diff --git a/org.adempiere.base/src/org/compiere/model/GridWorkbench.java b/org.adempiere.base/src/org/compiere/model/GridWorkbench.java index 080ce9544e..0b756d91fa 100644 --- a/org.adempiere.base/src/org/compiere/model/GridWorkbench.java +++ b/org.adempiere.base/src/org/compiere/model/GridWorkbench.java @@ -112,11 +112,13 @@ public class GridWorkbench implements Serializable + " AND w.AD_Workbench_ID=t.AD_Workbench_ID" + " AND t.AD_Language='" + Env.getAD_Language(m_ctx) + "'" + " AND w.AD_Column_ID=c.AD_Column_ID"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_Workbench_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { Name = rs.getString(1); @@ -135,13 +137,17 @@ public class GridWorkbench implements Serializable } else AD_Workbench_ID = 0; - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } if (AD_Workbench_ID == 0) return false; @@ -268,11 +274,13 @@ public class GridWorkbench implements Serializable + "FROM AD_WorkbenchWindow " + "WHERE AD_Workbench_ID=? AND IsActive='Y'" + "ORDER BY SeqNo"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_Workbench_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { int AD_Window_ID = rs.getInt(1); @@ -289,14 +297,18 @@ public class GridWorkbench implements Serializable else if (AD_Task_ID > 0) m_windows.add (new WBWindow(TYPE_TASK, AD_Task_ID)); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); return false; } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return true; } // initWorkbenchWindows diff --git a/org.adempiere.base/src/org/compiere/model/MArchive.java b/org.adempiere.base/src/org/compiere/model/MArchive.java index f328e681db..f5cf47594d 100644 --- a/org.adempiere.base/src/org/compiere/model/MArchive.java +++ b/org.adempiere.base/src/org/compiere/model/MArchive.java @@ -52,29 +52,25 @@ public class MArchive extends X_AD_Archive { */ public static MArchive[] get(Properties ctx, String whereClause) { ArrayList list = new ArrayList(); - PreparedStatement pstmt = null; StringBuilder sql = new StringBuilder("SELECT * FROM AD_Archive WHERE AD_Client_ID=?"); if (whereClause != null && whereClause.length() > 0) sql.append(whereClause); sql.append(" ORDER BY Created"); - + PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql.toString(), null); pstmt.setInt(1, Env.getAD_Client_ID(ctx)); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MArchive(ctx, rs, null)); - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, sql.toString(), e); } - try { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } catch (Exception e) { + finally + { + DB.close(rs, pstmt); + rs = null; pstmt = null; } if (list.size() == 0) @@ -206,23 +202,20 @@ public class MArchive extends X_AD_Archive { String name = "?"; String sql = "SELECT Name FROM AD_User WHERE AD_User_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, getCreatedBy()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) name = rs.getString(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) { + finally + { + DB.close(rs, pstmt); + rs = null; pstmt = null; } return name; diff --git a/org.adempiere.base/src/org/compiere/model/MBPGroup.java b/org.adempiere.base/src/org/compiere/model/MBPGroup.java index 918e58794c..ee6f9f8e24 100644 --- a/org.adempiere.base/src/org/compiere/model/MBPGroup.java +++ b/org.adempiere.base/src/org/compiere/model/MBPGroup.java @@ -71,37 +71,31 @@ public class MBPGroup extends X_C_BP_Group if (retValue != null) return retValue; - PreparedStatement pstmt = null; String sql = "SELECT * FROM C_BP_Group g " + "WHERE IsDefault='Y' AND AD_Client_ID=? " + "ORDER BY IsActive DESC"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, AD_Client_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) { retValue = new MBPGroup (ctx, rs, null); if (retValue.get_ID () != 0) s_cacheDefault.put (key, retValue); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } if (retValue == null) @@ -119,6 +113,7 @@ public class MBPGroup extends X_C_BP_Group { MBPGroup retValue = null; PreparedStatement pstmt = null; + ResultSet rs = null; String sql = "SELECT * FROM C_BP_Group g " + "WHERE EXISTS (SELECT * FROM C_BPartner p " + "WHERE p.C_BPartner_ID=? AND p.C_BP_Group_ID=g.C_BP_Group_ID)"; @@ -126,7 +121,7 @@ public class MBPGroup extends X_C_BP_Group { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, C_BPartner_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) { retValue = new MBPGroup (ctx, rs, null); @@ -134,22 +129,15 @@ public class MBPGroup extends X_C_BP_Group if (retValue.get_ID () != 0) s_cache.put (key, retValue); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.base/src/org/compiere/model/MBPartner.java b/org.adempiere.base/src/org/compiere/model/MBPartner.java index 7e891cf618..ae322565e6 100644 --- a/org.adempiere.base/src/org/compiere/model/MBPartner.java +++ b/org.adempiere.base/src/org/compiere/model/MBPartner.java @@ -150,29 +150,23 @@ public class MBPartner extends X_C_BPartner + " INNER JOIN C_Order o ON (ol.C_Order_ID=o.C_Order_ID) " + "WHERE o.IsSOTrx='Y' AND Bill_BPartner_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, C_BPartner_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = rs.getBigDecimal(1); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } return retValue; @@ -314,11 +308,12 @@ public class MBPartner extends X_C_BPartner String sql = "SELECT * FROM C_BPartner " + "WHERE C_BPartner_ID IN (SELECT C_BPartnerCashTrx_ID FROM AD_ClientInfo WHERE AD_Client_ID=?)"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) success = load (rs); else @@ -327,9 +322,6 @@ public class MBPartner extends X_C_BPartner success = false; log.severe ("None found"); } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { @@ -337,13 +329,8 @@ public class MBPartner extends X_C_BPartner } finally { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} + DB.close(rs, pstmt); + rs = null; pstmt = null; } setStandardDefaults(); @@ -492,16 +479,14 @@ public class MBPartner extends X_C_BPartner ArrayList list = new ArrayList(); String sql = "SELECT * FROM C_BP_BankAccount WHERE C_BPartner_ID=? AND IsActive='Y'"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getC_BPartner_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MBPBankAccount (getCtx(), rs, get_TrxName())); - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { @@ -509,13 +494,8 @@ public class MBPartner extends X_C_BPartner } finally { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} + DB.close(rs, pstmt); + rs = null; pstmt = null; } @@ -689,32 +669,26 @@ public class MBPartner extends X_C_BPartner + "FROM C_BPartner bp " + "WHERE C_BPartner_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getC_BPartner_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) { SO_CreditUsed = rs.getBigDecimal(1); TotalOpenBalance = rs.getBigDecimal(2); } - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // @@ -739,29 +713,23 @@ public class MBPartner extends X_C_BPartner + "FROM C_BPartner bp " + "WHERE C_BPartner_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getC_BPartner_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) ActualLifeTimeValue = rs.getBigDecimal(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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } if (ActualLifeTimeValue != null) diff --git a/org.adempiere.base/src/org/compiere/model/MBPartnerInfo.java b/org.adempiere.base/src/org/compiere/model/MBPartnerInfo.java index e4990afcab..fa08a0e123 100644 --- a/org.adempiere.base/src/org/compiere/model/MBPartnerInfo.java +++ b/org.adempiere.base/src/org/compiere/model/MBPartnerInfo.java @@ -100,6 +100,7 @@ public class MBPartnerInfo extends X_RV_BPartner "RV_BPartner", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO); ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(finalSQL, null); @@ -116,25 +117,18 @@ public class MBPartnerInfo extends X_RV_BPartner pstmt.setString(index++, Phone); if (City != null) pstmt.setString(index++, City); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MBPartnerInfo (ctx, rs, null)); - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, "find - " + finalSQL, e); } - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // Return diff --git a/org.adempiere.base/src/org/compiere/model/MBankAccountProcessor.java b/org.adempiere.base/src/org/compiere/model/MBankAccountProcessor.java index 1609d8e279..d10a02434e 100644 --- a/org.adempiere.base/src/org/compiere/model/MBankAccountProcessor.java +++ b/org.adempiere.base/src/org/compiere/model/MBankAccountProcessor.java @@ -94,23 +94,29 @@ public class MBankAccountProcessor extends X_C_BankAccount_Processor { sql.append(" AND bap.AcceptCORPORATE='Y'"); sql.append(" ORDER BY ba.IsDefault DESC "); // + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), trxName); + pstmt = DB.prepareStatement(sql.toString(), trxName); pstmt.setInt(1, AD_Client_ID); pstmt.setInt(2, C_Currency_ID); pstmt.setBigDecimal(3, Amt); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MBankAccountProcessor (ctx, rs, trxName)); - rs.close(); - pstmt.close(); } catch (SQLException e) { s_log.log(Level.SEVERE, "find - " + sql, e); return null; } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // if (list.size() == 0) s_log.warning("find - not found - AD_Client_ID=" + AD_Client_ID diff --git a/org.adempiere.base/src/org/compiere/model/MBankStatementMatcher.java b/org.adempiere.base/src/org/compiere/model/MBankStatementMatcher.java index d7f6ff8f5e..72fa4ef0eb 100644 --- a/org.adempiere.base/src/org/compiere/model/MBankStatementMatcher.java +++ b/org.adempiere.base/src/org/compiere/model/MBankStatementMatcher.java @@ -55,28 +55,22 @@ public class MBankStatementMatcher extends X_C_BankStatementMatcher @SuppressWarnings("unused") int AD_Client_ID = Env.getAD_Client_ID(ctx); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, trxName); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add (new MBankStatementMatcher(ctx, rs, trxName)); - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // Convert diff --git a/org.adempiere.base/src/org/compiere/model/MCStage.java b/org.adempiere.base/src/org/compiere/model/MCStage.java index 8bf187e87c..b512702684 100644 --- a/org.adempiere.base/src/org/compiere/model/MCStage.java +++ b/org.adempiere.base/src/org/compiere/model/MCStage.java @@ -48,33 +48,27 @@ public class MCStage extends X_CM_CStage public static MCStage[] getStages (MWebProject project) { ArrayList list = new ArrayList(); - PreparedStatement pstmt = null; String sql = "SELECT * FROM CM_CStage WHERE CM_WebProject_ID=? ORDER BY CM_CStage_ID"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, project.get_TrxName()); pstmt.setInt (1, project.getCM_WebProject_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { list.add (new MCStage (project.getCtx(), rs, project.get_TrxName())); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } MCStage[] retValue = new MCStage[list.size ()]; diff --git a/org.adempiere.base/src/org/compiere/model/MCashPlan.java b/org.adempiere.base/src/org/compiere/model/MCashPlan.java index 8a4b54a75d..69650cbeef 100644 --- a/org.adempiere.base/src/org/compiere/model/MCashPlan.java +++ b/org.adempiere.base/src/org/compiere/model/MCashPlan.java @@ -118,9 +118,6 @@ public class MCashPlan extends X_C_CashPlan MCashPlanLine il = new MCashPlanLine(getCtx(), rs, get_TrxName()); list.add(il); } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { diff --git a/org.adempiere.base/src/org/compiere/model/MClick.java b/org.adempiere.base/src/org/compiere/model/MClick.java index b696762bd4..9af7f449ab 100644 --- a/org.adempiere.base/src/org/compiere/model/MClick.java +++ b/org.adempiere.base/src/org/compiere/model/MClick.java @@ -52,31 +52,25 @@ public class MClick extends X_W_Click ArrayList list = new ArrayList (); String sql = "SELECT * FROM W_Click WHERE AD_Client_ID=? AND Processed = 'N'"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, Env.getAD_Client_ID(ctx)); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { list.add (new MClick (ctx, rs, null)); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // @@ -199,12 +193,13 @@ public class MClick extends X_W_Click int W_ClickCount_ID = 0; int exactW_ClickCount_ID = 0; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); StringBuilder msgstr = new StringBuilder("%").append(url).append("%"); pstmt.setString(1, msgstr.toString()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { W_ClickCount_ID = rs.getInt(1); @@ -214,23 +209,17 @@ public class MClick extends X_W_Click break; } } - rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException ex) { log.log(Level.SEVERE, sql, ex); } - try + finally { - if (pstmt != null) - pstmt.close(); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - pstmt = null; // Set Click Count if (exactW_ClickCount_ID != 0) W_ClickCount_ID = exactW_ClickCount_ID; diff --git a/org.adempiere.base/src/org/compiere/model/MClickCount.java b/org.adempiere.base/src/org/compiere/model/MClickCount.java index 4b9dcec07c..7f2981c421 100644 --- a/org.adempiere.base/src/org/compiere/model/MClickCount.java +++ b/org.adempiere.base/src/org/compiere/model/MClickCount.java @@ -114,11 +114,12 @@ public class MClickCount extends X_W_ClickCount .append("GROUP BY TRUNC(Created, '").append(DateFormat).append("')"); // PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql.toString(), null); pstmt.setInt(1, getW_ClickCount_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { String value = m_dateFormat.format(rs.getTimestamp(1)); @@ -126,23 +127,17 @@ public class MClickCount extends X_W_ClickCount ValueNamePair pp = new ValueNamePair (value, name); list.add(pp); } - rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException ex) { log.log(Level.SEVERE, sql.toString(), ex); } - try + finally { - if (pstmt != null) - pstmt.close(); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - pstmt = null; // ValueNamePair[] retValue = new ValueNamePair[list.size()]; list.toArray(retValue); diff --git a/org.adempiere.base/src/org/compiere/model/MClient.java b/org.adempiere.base/src/org/compiere/model/MClient.java index 9fe61d72e9..51bfe68ee2 100644 --- a/org.adempiere.base/src/org/compiere/model/MClient.java +++ b/org.adempiere.base/src/org/compiere/model/MClient.java @@ -303,10 +303,12 @@ public class MClient extends X_AD_Client AD_Tree_Campaign_ID=0, AD_Tree_Activity_ID=0; boolean success = false; + PreparedStatement stmt = null; + ResultSet rs = null; try { - PreparedStatement stmt = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet rs = stmt.executeQuery(); + stmt = DB.prepareStatement(sql.toString(), get_TrxName()); + rs = stmt.executeQuery(); MTree_Base tree = null; while (rs.next()) { @@ -374,13 +376,17 @@ public class MClient extends X_AD_Client break; } } - rs.close(); - stmt.close(); } catch (SQLException e1) { log.log(Level.SEVERE, "Trees", e1); success = false; + } + finally + { + DB.close(rs, stmt); + rs = null; + stmt = null; } if (!success) diff --git a/org.adempiere.base/src/org/compiere/model/MClientInfo.java b/org.adempiere.base/src/org/compiere/model/MClientInfo.java index 6e2833b758..49e44cd991 100644 --- a/org.adempiere.base/src/org/compiere/model/MClientInfo.java +++ b/org.adempiere.base/src/org/compiere/model/MClientInfo.java @@ -68,34 +68,29 @@ public class MClientInfo extends X_AD_ClientInfo // String sql = "SELECT * FROM AD_ClientInfo WHERE AD_Client_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, trxName); pstmt.setInt (1, AD_Client_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) { info = new MClientInfo (ctx, rs, null); if (trxName == null) s_cache.put (key, info); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (SQLException ex) { s_log.log(Level.SEVERE, sql, ex); } - try + finally { - if (pstmt != null) - pstmt.close (); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - pstmt = null; // return info; } // get diff --git a/org.adempiere.base/src/org/compiere/model/MClientShare.java b/org.adempiere.base/src/org/compiere/model/MClientShare.java index 663aa1949e..fe20921514 100644 --- a/org.adempiere.base/src/org/compiere/model/MClientShare.java +++ b/org.adempiere.base/src/org/compiere/model/MClientShare.java @@ -80,10 +80,11 @@ public class MClientShare extends X_AD_ClientShare String sql = "SELECT AD_Client_ID, AD_Table_ID, ShareType " + "FROM AD_ClientShare WHERE ShareType<>'x' AND IsActive='Y'"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { int Client_ID = rs.getInt(1); @@ -95,22 +96,15 @@ public class MClientShare extends X_AD_ClientShare else if (ShareType.equals(SHARETYPE_OrgNotShared)) s_shares.put(key.toString(), Boolean.FALSE); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } if (s_shares.isEmpty()) // put in something @@ -249,11 +243,12 @@ public class MClientShare extends X_AD_ClientShare + " AND c.ColumnName IN (SELECT ColumnName FROM AD_Column cc " + "WHERE cc.IsKey='Y' AND cc.AD_Table_ID=?))"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, getAD_Table_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { //int AD_Table_ID = rs.getInt(1); @@ -262,22 +257,15 @@ public class MClientShare extends X_AD_ClientShare info.append(", "); info.append(TableName); } - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } log.info(info.toString()); diff --git a/org.adempiere.base/src/org/compiere/model/MColumn.java b/org.adempiere.base/src/org/compiere/model/MColumn.java index 5f3e764fcf..1ffbbcb11d 100644 --- a/org.adempiere.base/src/org/compiere/model/MColumn.java +++ b/org.adempiere.base/src/org/compiere/model/MColumn.java @@ -558,22 +558,28 @@ public class MColumn extends X_AD_Column int retValue = 0; String SQL = "SELECT AD_Column_ID FROM AD_Column WHERE AD_Table_ID = ? AND columnname = ?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(SQL, null); + pstmt = DB.prepareStatement(SQL, null); pstmt.setInt(1, m_table_id); pstmt.setString(2, columnName); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) retValue = rs.getInt(1); - rs.close(); - pstmt.close(); } catch (SQLException e) { s_log.log(Level.SEVERE, SQL, e); retValue = -1; } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return retValue; } //end vpj-cd e-evolution diff --git a/org.adempiere.base/src/org/compiere/model/MColumnAccess.java b/org.adempiere.base/src/org/compiere/model/MColumnAccess.java index c5ce061657..111a3ea82c 100644 --- a/org.adempiere.base/src/org/compiere/model/MColumnAccess.java +++ b/org.adempiere.base/src/org/compiere/model/MColumnAccess.java @@ -126,11 +126,12 @@ public class MColumnAccess extends X_AD_Column_Access + "FROM AD_Table t INNER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID) " + "WHERE AD_Column_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getAD_Column_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { m_tableName = rs.getString(1); @@ -138,22 +139,15 @@ public class MColumnAccess extends X_AD_Column_Access if (rs.getInt(3) != getAD_Table_ID()) log.log(Level.SEVERE, "AD_Table_ID inconsistent - Access=" + getAD_Table_ID() + " - Table=" + rs.getInt(3)); } - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // Get Clear Text diff --git a/org.adempiere.base/src/org/compiere/model/MConversionRate.java b/org.adempiere.base/src/org/compiere/model/MConversionRate.java index 14e3daf0b2..49db829f30 100644 --- a/org.adempiere.base/src/org/compiere/model/MConversionRate.java +++ b/org.adempiere.base/src/org/compiere/model/MConversionRate.java @@ -226,6 +226,7 @@ public class MConversionRate extends X_C_Conversion_Rate + "ORDER BY AD_Client_ID DESC, AD_Org_ID DESC, ValidFrom DESC"; BigDecimal retValue = null; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); @@ -235,27 +236,20 @@ public class MConversionRate extends X_C_Conversion_Rate pstmt.setTimestamp(4, ConvDate); pstmt.setInt(5, AD_Client_ID); pstmt.setInt(6, AD_Org_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) retValue = rs.getBigDecimal(1); - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, "getRate", e); } - try + finally { - if (pstmt != null) - pstmt.close(); + DB.close(rs, pstmt); + rs = null; pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } + } if (retValue == null) s_log.info ("getRate - not found - CurFrom=" + CurFrom_ID + ", CurTo=" + CurTo_ID diff --git a/org.adempiere.base/src/org/compiere/model/MCostQueue.java b/org.adempiere.base/src/org/compiere/model/MCostQueue.java index b91c38575d..b4c8057126 100644 --- a/org.adempiere.base/src/org/compiere/model/MCostQueue.java +++ b/org.adempiere.base/src/org/compiere/model/MCostQueue.java @@ -63,6 +63,7 @@ public class MCostQueue extends X_M_CostQueue + " AND M_CostType_ID=? AND C_AcctSchema_ID=?" + " AND M_CostElement_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, trxName); @@ -73,25 +74,18 @@ public class MCostQueue extends X_M_CostQueue pstmt.setInt (5, as.getM_CostType_ID()); pstmt.setInt (6, as.getC_AcctSchema_ID()); pstmt.setInt (7, M_CostElement_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) costQ = new MCostQueue (product.getCtx(), rs, trxName); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // New @@ -127,6 +121,7 @@ public class MCostQueue extends X_M_CostQueue if (!ce.isFifo()) sql.append("DESC"); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql.toString(), trxName); @@ -138,25 +133,18 @@ public class MCostQueue extends X_M_CostQueue pstmt.setInt (6, ce.getM_CostElement_ID()); if (M_ASI_ID != 0) pstmt.setInt (7, M_ASI_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add(new MCostQueue (product.getCtx(), rs, trxName)); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql.toString(), e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } MCostQueue[] costQ = new MCostQueue[list.size()]; diff --git a/org.adempiere.base/src/org/compiere/model/MCountry.java b/org.adempiere.base/src/org/compiere/model/MCountry.java index 5920ceeb5b..2f1b0f1a3d 100644 --- a/org.adempiere.base/src/org/compiere/model/MCountry.java +++ b/org.adempiere.base/src/org/compiere/model/MCountry.java @@ -113,10 +113,12 @@ public final class MCountry extends X_C_Country // s_countries = new CCache(Table_Name, 250); String sql = "SELECT * FROM C_Country WHERE IsActive='Y'"; + Statement stmt = null; + ResultSet rs = null; try { - Statement stmt = DB.createStatement(); - ResultSet rs = stmt.executeQuery(sql); + stmt = DB.createStatement(); + rs = stmt.executeQuery(sql); while(rs.next()) { MCountry c = new MCountry (ctx, rs, null); @@ -127,13 +129,17 @@ public final class MCountry extends X_C_Country if (c.getC_Country_ID() == COUNTRY_US) // USA usa = c; } - rs.close(); - stmt.close(); } catch (SQLException e) { s_log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, stmt); + rs = null; + stmt = null; + } if (s_default == null) s_default = usa; s_log.fine("#" + s_countries.size() diff --git a/org.adempiere.base/src/org/compiere/model/MDesktop.java b/org.adempiere.base/src/org/compiere/model/MDesktop.java index 6af38950ad..98f0eb066e 100644 --- a/org.adempiere.base/src/org/compiere/model/MDesktop.java +++ b/org.adempiere.base/src/org/compiere/model/MDesktop.java @@ -85,11 +85,13 @@ public class MDesktop .append("WHERE w.AD_Desktop_ID=? AND w.IsActive='Y'") .append(" AND w.AD_Desktop_ID=t.AD_Desktop_ID") .append(" AND t.AD_Language='").append(Env.getAD_Language(m_ctx)).append("'"); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), null); pstmt.setInt(1, AD_Desktop_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { Name = rs.getString(1); @@ -107,13 +109,17 @@ public class MDesktop } else AD_Desktop_ID = 0; - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } if (AD_Desktop_ID == 0) return false; @@ -207,24 +213,30 @@ public class MDesktop + "FROM AD_DesktopWorkbench " + "WHERE AD_Desktop_ID=? AND IsActive='Y' " + "ORDER BY SeqNo"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_Desktop_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { int AD_Workbench_ID = rs.getInt(1); m_workbenches.add (new Integer(AD_Workbench_ID)); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, "MWorkbench.initDesktopWorkbenches", e); return false; } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return true; } // initDesktopWorkbenches diff --git a/org.adempiere.base/src/org/compiere/model/MDiscountSchema.java b/org.adempiere.base/src/org/compiere/model/MDiscountSchema.java index cbeef15962..f5f560f83a 100644 --- a/org.adempiere.base/src/org/compiere/model/MDiscountSchema.java +++ b/org.adempiere.base/src/org/compiere/model/MDiscountSchema.java @@ -115,29 +115,23 @@ public class MDiscountSchema extends X_M_DiscountSchema String sql = "SELECT * FROM M_DiscountSchemaBreak WHERE M_DiscountSchema_ID=? ORDER BY SeqNo"; ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getM_DiscountSchema_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add(new MDiscountSchemaBreak(getCtx(), rs, get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } m_breaks = new MDiscountSchemaBreak[list.size ()]; @@ -160,29 +154,23 @@ public class MDiscountSchema extends X_M_DiscountSchema String sql = "SELECT * FROM M_DiscountSchemaLine WHERE M_DiscountSchema_ID=? ORDER BY SeqNo"; ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getM_DiscountSchema_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add(new MDiscountSchemaLine(getCtx(), rs, get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } m_lines = new MDiscountSchemaLine[list.size ()]; diff --git a/org.adempiere.base/src/org/compiere/model/MDistributionList.java b/org.adempiere.base/src/org/compiere/model/MDistributionList.java index 654d1a51c8..9c0f2cdac7 100644 --- a/org.adempiere.base/src/org/compiere/model/MDistributionList.java +++ b/org.adempiere.base/src/org/compiere/model/MDistributionList.java @@ -73,11 +73,12 @@ public class MDistributionList extends X_M_DistributionList // String sql = "SELECT * FROM M_DistributionListLine WHERE M_DistributionList_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getM_DistributionList_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MDistributionListLine line = new MDistributionListLine(getCtx(), rs, get_TrxName()); @@ -86,22 +87,15 @@ public class MDistributionList extends X_M_DistributionList if (ratio != null) ratioTotal = ratioTotal.add(ratio); } - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // Update Ratio diff --git a/org.adempiere.base/src/org/compiere/model/MDistributionRun.java b/org.adempiere.base/src/org/compiere/model/MDistributionRun.java index 3bbfcde204..7ab8adafda 100644 --- a/org.adempiere.base/src/org/compiere/model/MDistributionRun.java +++ b/org.adempiere.base/src/org/compiere/model/MDistributionRun.java @@ -79,29 +79,23 @@ public class MDistributionRun extends X_M_DistributionRun + "WHERE M_DistributionRun_ID=? AND IsActive='Y' AND TotalQty IS NOT NULL AND TotalQty<> 0 ORDER BY Line"; ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getM_DistributionRun_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MDistributionRunLine(getCtx(), rs, get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } m_lines = new MDistributionRunLine[list.size()]; diff --git a/org.adempiere.base/src/org/compiere/model/MDistributionRunDetail.java b/org.adempiere.base/src/org/compiere/model/MDistributionRunDetail.java index d730ddcb8a..a4590e2b9f 100644 --- a/org.adempiere.base/src/org/compiere/model/MDistributionRunDetail.java +++ b/org.adempiere.base/src/org/compiere/model/MDistributionRunDetail.java @@ -58,29 +58,23 @@ public class MDistributionRunDetail extends X_T_DistributionRunDetail else sql.append("ORDER BY M_DistributionRunLine_ID"); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql.toString(), trxName); pstmt.setInt (1, M_DistributionRun_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add(new MDistributionRunDetail(ctx, rs, trxName)); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, sql.toString(), e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } MDistributionRunDetail[] retValue = new MDistributionRunDetail[list.size()]; diff --git a/org.adempiere.base/src/org/compiere/model/MDocTypeCounter.java b/org.adempiere.base/src/org/compiere/model/MDocTypeCounter.java index f22ac3ce18..d56805ccfb 100644 --- a/org.adempiere.base/src/org/compiere/model/MDocTypeCounter.java +++ b/org.adempiere.base/src/org/compiere/model/MDocTypeCounter.java @@ -99,11 +99,12 @@ public class MDocTypeCounter extends X_C_DocTypeCounter MDocTypeCounter temp = null; String sql = "SELECT * FROM C_DocTypeCounter WHERE C_DocType_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, C_DocType_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next () && retValue == null) { retValue = new MDocTypeCounter (ctx, rs, null); @@ -113,22 +114,15 @@ public class MDocTypeCounter extends X_C_DocTypeCounter retValue = null; } } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, "getCounterDocType", e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } if (retValue != null) // valid diff --git a/org.adempiere.base/src/org/compiere/model/MDunningLevel.java b/org.adempiere.base/src/org/compiere/model/MDunningLevel.java index 46aafd7b7c..bbbc60c574 100644 --- a/org.adempiere.base/src/org/compiere/model/MDunningLevel.java +++ b/org.adempiere.base/src/org/compiere/model/MDunningLevel.java @@ -88,31 +88,25 @@ public class MDunningLevel extends X_C_DunningLevel ArrayList list = new ArrayList(); String sql = "SELECT * FROM C_DunningLevel WHERE C_Dunning_ID=? AND DaysAfterDue+DaysBetweenDunning list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getC_DunningRun_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MDunningRunEntry thisEntry = new MDunningRunEntry(getCtx(), rs, get_TrxName()); if (!(onlyInvoices && thisEntry.hasInvoices())) list.add (new MDunningRunEntry(getCtx(), rs, get_TrxName())); } - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } m_entries = new MDunningRunEntry[list.size ()]; diff --git a/org.adempiere.base/src/org/compiere/model/MDunningRunEntry.java b/org.adempiere.base/src/org/compiere/model/MDunningRunEntry.java index 30a7a47fa3..114be9a27e 100644 --- a/org.adempiere.base/src/org/compiere/model/MDunningRunEntry.java +++ b/org.adempiere.base/src/org/compiere/model/MDunningRunEntry.java @@ -204,29 +204,23 @@ public class MDunningRunEntry extends X_C_DunningRunEntry if (onlyInvoices) sql.append(" AND C_Invoice_ID IS NOT NULL"); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); pstmt.setInt(1, get_ID ()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MDunningRunLine(getCtx(), rs, get_TrxName())); - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, sql.toString(), e); } - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } @@ -245,34 +239,28 @@ public class MDunningRunEntry extends X_C_DunningRunEntry boolean retValue = false; String sql = "SELECT COUNT(*) FROM C_DunningRunLine WHERE C_DunningRunEntry_ID=? AND C_Invoice_ID IS NOT NULL"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, get_ID ()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { if (rs.getInt(1) > 0) retValue = true; } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } - try + finally { - if (pstmt != null) - pstmt.close(); + DB.close(rs, pstmt); + rs = null; pstmt = null; } - catch (Exception e) - { - pstmt = null; - } return retValue; } // hasInvoices diff --git a/org.adempiere.base/src/org/compiere/model/MEXPFormatLine.java b/org.adempiere.base/src/org/compiere/model/MEXPFormatLine.java index 2ceb8632ce..bc02c71cea 100644 --- a/org.adempiere.base/src/org/compiere/model/MEXPFormatLine.java +++ b/org.adempiere.base/src/org/compiere/model/MEXPFormatLine.java @@ -78,25 +78,22 @@ public class MEXPFormatLine extends X_EXP_FormatLine { .append(" AND ").append(X_EXP_Format.COLUMNNAME_EXP_Format_ID).append(" = ?") ; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql.toString(), trxName); pstmt.setString(1, value); pstmt.setInt(2, EXP_Format_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if ( rs.next() ) { result = new MEXPFormatLine (ctx, rs, trxName); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (SQLException e) { s_log.log(Level.SEVERE, sql.toString(), e); throw e; - } finally { - try { - if (pstmt != null) pstmt.close (); - pstmt = null; - } catch (Exception e) { pstmt = null; } + } finally{ + DB.close(rs, pstmt); + rs = null; + pstmt = null; } return result; diff --git a/org.adempiere.base/src/org/compiere/model/MEXPProcessor.java b/org.adempiere.base/src/org/compiere/model/MEXPProcessor.java index c300207d61..f592011f97 100644 --- a/org.adempiere.base/src/org/compiere/model/MEXPProcessor.java +++ b/org.adempiere.base/src/org/compiere/model/MEXPProcessor.java @@ -84,27 +84,24 @@ public class MEXPProcessor extends X_EXP_Processor { .append(" AND IsActive = ?") // # 2 //.append(" ORDER BY ").append(X_EXP_ProcessorParameter.COLUMNNAME_) ; - PreparedStatement pstmt = null; X_EXP_ProcessorParameter processorParameter = null; + PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql.toString(), trxName); pstmt.setInt(1, getEXP_Processor_ID()); pstmt.setString(2, "Y"); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while ( rs.next() ) { processorParameter = new X_EXP_ProcessorParameter (getCtx(), rs, trxName); resultList.add(processorParameter); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (SQLException e) { s_log.log(Level.SEVERE, sql.toString(), e); - } finally { - try { - if (pstmt != null) pstmt.close (); - pstmt = null; - } catch (Exception e) { pstmt = null; } + } finally{ + DB.close(rs, pstmt); + rs = null; + pstmt = null; } X_EXP_ProcessorParameter[] result = (X_EXP_ProcessorParameter[])resultList.toArray( new X_EXP_ProcessorParameter[0]); parameters = result; diff --git a/org.adempiere.base/src/org/compiere/model/MGLCategory.java b/org.adempiere.base/src/org/compiere/model/MGLCategory.java index 66b5df5697..af392f5d7e 100644 --- a/org.adempiere.base/src/org/compiere/model/MGLCategory.java +++ b/org.adempiere.base/src/org/compiere/model/MGLCategory.java @@ -70,11 +70,12 @@ public class MGLCategory extends X_GL_Category String sql = "SELECT * FROM GL_Category " + "WHERE AD_Client_ID=? AND IsDefault='Y'"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, Env.getAD_Client_ID(ctx)); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MGLCategory temp = new MGLCategory (ctx, rs, null); @@ -86,22 +87,15 @@ public class MGLCategory extends X_GL_Category if (retValue == null) retValue = temp; } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } return retValue; diff --git a/org.adempiere.base/src/org/compiere/model/MIMPProcessor.java b/org.adempiere.base/src/org/compiere/model/MIMPProcessor.java index 87eb9ec3ff..6be1c040be 100644 --- a/org.adempiere.base/src/org/compiere/model/MIMPProcessor.java +++ b/org.adempiere.base/src/org/compiere/model/MIMPProcessor.java @@ -96,29 +96,23 @@ public class MIMPProcessor + "WHERE " + X_IMP_Processor.COLUMNNAME_IMP_Processor_ID + "=? " // # 1 + "ORDER BY Created DESC"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getIMP_Processor_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MIMPProcessorLog (getCtx(), rs, get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } MIMPProcessorLog[] retValue = new MIMPProcessorLog[list.size ()]; @@ -156,26 +150,23 @@ public class MIMPProcessor //.append(" ORDER BY ").append(X_EXP_ProcessorParameter.COLUMNNAME_) ; PreparedStatement pstmt = null; + ResultSet rs = null; X_IMP_ProcessorParameter processorParameter = null; try { pstmt = DB.prepareStatement (sql.toString(), trxName); pstmt.setInt(1, getIMP_Processor_ID()); pstmt.setString(2, "Y"); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while ( rs.next() ) { processorParameter = new X_IMP_ProcessorParameter (getCtx(), rs, trxName); resultList.add(processorParameter); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (SQLException e) { s_log.log(Level.SEVERE, sql.toString(), e); - } finally { - try { - if (pstmt != null) pstmt.close (); - pstmt = null; - } catch (Exception e) { pstmt = null; } + } finally{ + DB.close(rs, pstmt); + rs = null; + pstmt = null; } X_IMP_ProcessorParameter[] result = (X_IMP_ProcessorParameter[])resultList.toArray( new X_IMP_ProcessorParameter[0]); return result; @@ -186,28 +177,23 @@ public class MIMPProcessor ArrayList list = new ArrayList(); String sql = "SELECT * FROM "+X_IMP_Processor.Table_Name+" WHERE IsActive='Y'"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MIMPProcessor (ctx, rs, null)); - rs.close (); - pstmt.close (); - pstmt = null; + } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.base/src/org/compiere/model/MInterestArea.java b/org.adempiere.base/src/org/compiere/model/MInterestArea.java index 99a343c859..d6eb1ff970 100644 --- a/org.adempiere.base/src/org/compiere/model/MInterestArea.java +++ b/org.adempiere.base/src/org/compiere/model/MInterestArea.java @@ -54,31 +54,25 @@ public class MInterestArea extends X_R_InterestArea ArrayList list = new ArrayList(); String sql = "SELECT * FROM R_InterestArea WHERE IsActive='Y'"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MInterestArea ia = new MInterestArea (ctx, rs, null); list.add (ia); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } MInterestArea[] retValue = new MInterestArea[list.size ()]; diff --git a/org.adempiere.base/src/org/compiere/model/MInvoice.java b/org.adempiere.base/src/org/compiere/model/MInvoice.java index b3762172b9..68c7068317 100644 --- a/org.adempiere.base/src/org/compiere/model/MInvoice.java +++ b/org.adempiere.base/src/org/compiere/model/MInvoice.java @@ -1112,9 +1112,6 @@ public class MInvoice extends X_C_Invoice implements DocAction { retValue = rs.getBigDecimal(1); } - rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException e) { diff --git a/org.adempiere.base/src/org/compiere/model/MInvoiceBatch.java b/org.adempiere.base/src/org/compiere/model/MInvoiceBatch.java index 8f734e8205..ed4d445d73 100644 --- a/org.adempiere.base/src/org/compiere/model/MInvoiceBatch.java +++ b/org.adempiere.base/src/org/compiere/model/MInvoiceBatch.java @@ -93,31 +93,25 @@ public class MInvoiceBatch extends X_C_InvoiceBatch String sql = "SELECT * FROM C_InvoiceBatchLine WHERE C_InvoiceBatch_ID=? ORDER BY Line"; ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getC_InvoiceBatch_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { list.add (new MInvoiceBatchLine (getCtx(), rs, get_TrxName())); } - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // diff --git a/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java b/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java index 2200e75a67..271bd4a0ba 100644 --- a/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java +++ b/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java @@ -726,16 +726,14 @@ public class MInvoiceLine extends X_C_InvoiceLine + " LEFT OUTER JOIN C_Charge C ON (il.C_Charge_ID=c.C_Charge_ID) " + "WHERE C_InvoiceLine_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getC_InvoiceLine_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) m_name = rs.getString(1); - rs.close(); - pstmt.close(); - pstmt = null; if (m_name == null) m_name = "??"; } @@ -745,13 +743,8 @@ public class MInvoiceLine extends X_C_InvoiceLine } finally { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} + DB.close(rs, pstmt); + rs = null; pstmt = null; } } @@ -1238,19 +1231,17 @@ public class MInvoiceLine extends X_C_InvoiceLine if (whereClause != null) sql += whereClause; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getC_InvoiceLine_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { MLandedCost lc = new MLandedCost(getCtx(), rs, get_TrxName()); list.add(lc); } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { @@ -1258,13 +1249,8 @@ public class MInvoiceLine extends X_C_InvoiceLine } finally { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.base/src/org/compiere/model/MInvoicePaySchedule.java b/org.adempiere.base/src/org/compiere/model/MInvoicePaySchedule.java index ce4e2a2a98..f8ee35109f 100644 --- a/org.adempiere.base/src/org/compiere/model/MInvoicePaySchedule.java +++ b/org.adempiere.base/src/org/compiere/model/MInvoicePaySchedule.java @@ -63,6 +63,7 @@ public class MInvoicePaySchedule extends X_C_InvoicePaySchedule // ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql.toString(), trxName); @@ -70,27 +71,20 @@ public class MInvoicePaySchedule extends X_C_InvoicePaySchedule pstmt.setInt(1, C_Invoice_ID); else pstmt.setInt(1, C_InvoicePaySchedule_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { list.add (new MInvoicePaySchedule(ctx, rs, trxName)); } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, "getInvoicePaySchedule", e); } - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.base/src/org/compiere/model/MIssueProject.java b/org.adempiere.base/src/org/compiere/model/MIssueProject.java index c55265e418..89754b37d3 100644 --- a/org.adempiere.base/src/org/compiere/model/MIssueProject.java +++ b/org.adempiere.base/src/org/compiere/model/MIssueProject.java @@ -50,29 +50,23 @@ public class MIssueProject extends X_R_IssueProject MIssueProject pj = null; String sql = "SELECT * FROM R_IssueProject WHERE Name=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setString (1, issue.getName()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) pj = new MIssueProject(issue.getCtx(), rs, null); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // New diff --git a/org.adempiere.base/src/org/compiere/model/MIssueSystem.java b/org.adempiere.base/src/org/compiere/model/MIssueSystem.java index 127d08030d..5f2fbfe858 100644 --- a/org.adempiere.base/src/org/compiere/model/MIssueSystem.java +++ b/org.adempiere.base/src/org/compiere/model/MIssueSystem.java @@ -47,31 +47,25 @@ public class MIssueSystem extends X_R_IssueSystem if (issue.getDBAddress() == null) return null; MIssueSystem system = null; - PreparedStatement pstmt = null; String sql = "SELECT * FROM R_IssueSystem WHERE DBAddress=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setString (1, issue.getDBAddress()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) system = new MIssueSystem(issue.getCtx(), rs, null); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // New diff --git a/org.adempiere.base/src/org/compiere/model/MIssueUser.java b/org.adempiere.base/src/org/compiere/model/MIssueUser.java index a20b6370ca..b9b3762f6f 100644 --- a/org.adempiere.base/src/org/compiere/model/MIssueUser.java +++ b/org.adempiere.base/src/org/compiere/model/MIssueUser.java @@ -50,29 +50,23 @@ public class MIssueUser extends X_R_IssueUser // Find Issue User String sql = "SELECT * FROM R_IssueUser WHERE UserName=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setString (1, issue.getUserName()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) user = new MIssueUser (issue.getCtx(), rs, null); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.base/src/org/compiere/model/MJournalBatch.java b/org.adempiere.base/src/org/compiere/model/MJournalBatch.java index 95a7921e7d..bf03822a72 100644 --- a/org.adempiere.base/src/org/compiere/model/MJournalBatch.java +++ b/org.adempiere.base/src/org/compiere/model/MJournalBatch.java @@ -195,30 +195,25 @@ public class MJournalBatch extends X_GL_JournalBatch implements DocAction ArrayList list = new ArrayList(); String sql = "SELECT * FROM GL_Journal WHERE GL_JournalBatch_ID=? ORDER BY DocumentNo"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getGL_JournalBatch_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MJournal (getCtx(), rs, get_TrxName())); - rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException ex) { log.log(Level.SEVERE, sql, ex); } - try + finally { - if (pstmt != null) - pstmt.close(); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - pstmt = null; // MJournal[] retValue = new MJournal[list.size()]; list.toArray(retValue); diff --git a/org.adempiere.base/src/org/compiere/model/MLandedCost.java b/org.adempiere.base/src/org/compiere/model/MLandedCost.java index 65025d78bb..9159368221 100644 --- a/org.adempiere.base/src/org/compiere/model/MLandedCost.java +++ b/org.adempiere.base/src/org/compiere/model/MLandedCost.java @@ -49,31 +49,25 @@ public class MLandedCost extends X_C_LandedCost ArrayList list = new ArrayList (); String sql = "SELECT * FROM C_LandedCost WHERE C_InvoiceLine_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, il.get_TrxName()); pstmt.setInt (1, il.getC_InvoiceLine_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { list.add (new MLandedCost (il.getCtx(), rs, il.get_TrxName())); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // diff --git a/org.adempiere.base/src/org/compiere/model/MLandedCostAllocation.java b/org.adempiere.base/src/org/compiere/model/MLandedCostAllocation.java index b6aa246a19..ff4495cfa2 100644 --- a/org.adempiere.base/src/org/compiere/model/MLandedCostAllocation.java +++ b/org.adempiere.base/src/org/compiere/model/MLandedCostAllocation.java @@ -53,29 +53,23 @@ public class MLandedCostAllocation extends X_C_LandedCostAllocation ArrayList list = new ArrayList(); String sql = "SELECT * FROM C_LandedCostAllocation WHERE C_InvoiceLine_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, trxName); pstmt.setInt (1, C_InvoiceLine_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MLandedCostAllocation (ctx, rs, trxName)); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } MLandedCostAllocation[] retValue = new MLandedCostAllocation[list.size ()]; diff --git a/org.adempiere.base/src/org/compiere/model/MLocation.java b/org.adempiere.base/src/org/compiere/model/MLocation.java index bce8c7112e..36be3669ea 100644 --- a/org.adempiere.base/src/org/compiere/model/MLocation.java +++ b/org.adempiere.base/src/org/compiere/model/MLocation.java @@ -101,21 +101,27 @@ public class MLocation extends X_C_Location implements Comparator MLocation loc = null; String sql = "SELECT * FROM C_Location l " + "WHERE C_Location_ID IN (SELECT C_Location_ID FROM C_BPartner_Location WHERE C_BPartner_Location_ID=?)"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, trxName); + pstmt = DB.prepareStatement(sql, trxName); pstmt.setInt(1, C_BPartner_Location_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) loc = new MLocation (ctx, rs, trxName); - rs.close(); - pstmt.close(); } catch (SQLException e) { s_log.log(Level.SEVERE, sql + " - " + C_BPartner_Location_ID, e); loc = null; } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return loc; } // getBPLocation diff --git a/org.adempiere.base/src/org/compiere/model/MLookup.java b/org.adempiere.base/src/org/compiere/model/MLookup.java index 4af0858f21..be8d7ff1be 100644 --- a/org.adempiere.base/src/org/compiere/model/MLookup.java +++ b/org.adempiere.base/src/org/compiere/model/MLookup.java @@ -485,15 +485,17 @@ public final class MLookup extends Lookup implements Serializable log.finer(m_info.KeyColumn + ": " + key + ", SaveInCache=" + saveInCache + ",Local=" + cacheLocal); boolean isNumber = m_info.KeyColumn.endsWith("_ID"); + PreparedStatement pstmt = null; + ResultSet rs = null; try { // SELECT Key, Value, Name FROM ... - PreparedStatement pstmt = DB.prepareStatement(m_info.QueryDirect, null); + pstmt = DB.prepareStatement(m_info.QueryDirect, null); if (isNumber) pstmt.setInt(1, Integer.parseInt(key.toString())); else pstmt.setString(1, key.toString()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { String name = rs.getString(3); @@ -523,8 +525,6 @@ public final class MLookup extends Lookup implements Serializable directValue = null; } - rs.close(); - pstmt.close(); if (CLogMgt.isLevelFinest()) log.finest(m_info.KeyColumn + ": " + directValue + " - " + m_info); } @@ -533,6 +533,12 @@ public final class MLookup extends Lookup implements Serializable log.log(Level.SEVERE, m_info.KeyColumn + ": SQL=" + m_info.QueryDirect + "; Key=" + key, e); directValue = null; } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Cache Local if not added to R/W cache if (cacheLocal && !saveInCache && directValue != null) { diff --git a/org.adempiere.base/src/org/compiere/model/MLookupInfo.java b/org.adempiere.base/src/org/compiere/model/MLookupInfo.java index 65a3362786..530c3b0639 100644 --- a/org.adempiere.base/src/org/compiere/model/MLookupInfo.java +++ b/org.adempiere.base/src/org/compiere/model/MLookupInfo.java @@ -46,11 +46,13 @@ public class MLookupInfo implements Serializable, Cloneable int retValue = 0; String sql = "SELECT AD_Reference_ID,Name,ValidationType,IsActive " + "FROM AD_Reference WHERE Name LIKE ?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setString(1, referenceName); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); // int i = 0; int id = 0; @@ -69,13 +71,17 @@ public class MLookupInfo implements Serializable, Cloneable "AD_Reference Name=").append(refName).append(", ID=").append(id).append(", Type=").append(validationType).append(", Active=").append(isActive); CLogger.get().config(msgconf.toString()); } - rs.close(); - pstmt.close(); } catch (SQLException e) { CLogger.get().log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return retValue; } // getAD_Reference_ID @@ -92,11 +98,13 @@ public class MLookupInfo implements Serializable, Cloneable String sql = "SELECT c.AD_Column_ID,c.ColumnName,t.TableName " + "FROM AD_Column c, AD_Table t " + "WHERE c.ColumnName LIKE ? AND c.AD_Table_ID=t.AD_Table_ID"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setString(1, columnName); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); // int i = 0; int id = 0; @@ -112,13 +120,17 @@ public class MLookupInfo implements Serializable, Cloneable StringBuilder msgconf = new StringBuilder("Name=").append(colName).append(", ID=").append(id).append(", Table=").append(tabName); CLogger.get().config(msgconf.toString()); } - rs.close(); - pstmt.close(); } catch (SQLException e) { CLogger.get().log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return retValue; } // getAD_Column_ID diff --git a/org.adempiere.base/src/org/compiere/model/MMailText.java b/org.adempiere.base/src/org/compiere/model/MMailText.java index 7d954b6b15..394ba91375 100644 --- a/org.adempiere.base/src/org/compiere/model/MMailText.java +++ b/org.adempiere.base/src/org/compiere/model/MMailText.java @@ -339,13 +339,14 @@ public class MMailText extends X_R_MailText { MMailTextTrl trl = null; PreparedStatement pstmt = null; + ResultSet rs = null; String sql = "SELECT * FROM R_MailText_Trl WHERE R_MailText_ID=? AND AD_Language=?"; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, getR_MailText_ID()); pstmt.setString(2, AD_Language); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next()) { trl = new MMailTextTrl(); @@ -355,24 +356,18 @@ public class MMailText extends X_R_MailText trl.MailText2 = rs.getString("MailText2"); trl.MailText3 = rs.getString("MailText3"); } - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } + return trl; } // getTranslation diff --git a/org.adempiere.base/src/org/compiere/model/MMeasureCalc.java b/org.adempiere.base/src/org/compiere/model/MMeasureCalc.java index c328e95574..8f86fa39c5 100644 --- a/org.adempiere.base/src/org/compiere/model/MMeasureCalc.java +++ b/org.adempiere.base/src/org/compiere/model/MMeasureCalc.java @@ -238,10 +238,11 @@ public class MMeasureCalc extends X_PA_MeasureCalc // Execute StringBuilder where = new StringBuilder(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (finalSQL, null); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { int id = rs.getInt(1); @@ -249,22 +250,15 @@ public class MMeasureCalc extends X_PA_MeasureCalc where.append(","); where.append(id); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { log.log (Level.SEVERE, finalSQL, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } if (where.length() == 0) diff --git a/org.adempiere.base/src/org/compiere/model/MMedia.java b/org.adempiere.base/src/org/compiere/model/MMedia.java index 910c6523e5..1dcf01f089 100644 --- a/org.adempiere.base/src/org/compiere/model/MMedia.java +++ b/org.adempiere.base/src/org/compiere/model/MMedia.java @@ -50,32 +50,26 @@ public class MMedia extends X_CM_Media { ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; String sql = "SELECT * FROM CM_Media WHERE CM_WebProject_ID=? ORDER BY CM_Media_ID"; try { pstmt = DB.prepareStatement (sql, project.get_TrxName()); pstmt.setInt (1, project.getCM_WebProject_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { list.add (new MMedia (project.getCtx(), rs, project.get_TrxName())); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } MMedia[] retValue = new MMedia[list.size ()]; diff --git a/org.adempiere.base/src/org/compiere/model/MMessage.java b/org.adempiere.base/src/org/compiere/model/MMessage.java index 59decbbc5b..057e085cf6 100644 --- a/org.adempiere.base/src/org/compiere/model/MMessage.java +++ b/org.adempiere.base/src/org/compiere/model/MMessage.java @@ -54,29 +54,23 @@ public class MMessage extends X_AD_Message { String sql = "SELECT * FROM AD_Message WHERE Value=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setString(1, Value); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) retValue = new MMessage (ctx, rs, null); - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, "get", e); } - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } if (retValue != null) diff --git a/org.adempiere.base/src/org/compiere/model/MMovementConfirm.java b/org.adempiere.base/src/org/compiere/model/MMovementConfirm.java index a21a4bb9bb..cf28d208fa 100644 --- a/org.adempiere.base/src/org/compiere/model/MMovementConfirm.java +++ b/org.adempiere.base/src/org/compiere/model/MMovementConfirm.java @@ -146,29 +146,23 @@ public class MMovementConfirm extends X_M_MovementConfirm implements DocAction + "WHERE M_MovementConfirm_ID=?"; ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getM_MovementConfirm_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add(new MMovementLineConfirm(getCtx(), rs, get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } m_lines = new MMovementLineConfirm[list.size ()]; diff --git a/org.adempiere.base/src/org/compiere/model/MMovementLineMA.java b/org.adempiere.base/src/org/compiere/model/MMovementLineMA.java index 5972f4d489..ac5acced3c 100644 --- a/org.adempiere.base/src/org/compiere/model/MMovementLineMA.java +++ b/org.adempiere.base/src/org/compiere/model/MMovementLineMA.java @@ -52,31 +52,25 @@ public class MMovementLineMA extends X_M_MovementLineMA ArrayList list = new ArrayList(); String sql = "SELECT * FROM M_MovementLineMA WHERE M_MovementLine_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, trxName); pstmt.setInt (1, M_MovementLine_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { list.add (new MMovementLineMA (ctx, rs, trxName)); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.base/src/org/compiere/model/MNewsChannel.java b/org.adempiere.base/src/org/compiere/model/MNewsChannel.java index 0fd201f172..f97bfa3d86 100644 --- a/org.adempiere.base/src/org/compiere/model/MNewsChannel.java +++ b/org.adempiere.base/src/org/compiere/model/MNewsChannel.java @@ -75,29 +75,23 @@ public class MNewsChannel extends X_CM_NewsChannel sql += " AND " + where; sql += " ORDER BY pubDate DESC"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, this.get_TrxName()); pstmt.setInt (1, this.get_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add(new MNewsItem(this.getCtx(), rs, this.get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } MNewsItem[] retValue = new MNewsItem[list.size ()]; diff --git a/org.adempiere.base/src/org/compiere/model/MOrderLine.java b/org.adempiere.base/src/org/compiere/model/MOrderLine.java index d95b52a6f9..8167fefd94 100644 --- a/org.adempiere.base/src/org/compiere/model/MOrderLine.java +++ b/org.adempiere.base/src/org/compiere/model/MOrderLine.java @@ -82,6 +82,7 @@ public class MOrderLine extends X_C_OrderLine sql += " AND M_AttributeSetInstance_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); @@ -90,25 +91,18 @@ public class MOrderLine extends X_C_OrderLine pstmt.setInt (3, excludeC_OrderLine_ID); if (M_AttributeSetInstance_ID != 0) pstmt.setInt (4, M_AttributeSetInstance_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = rs.getBigDecimal(1); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } if (retValue == null) diff --git a/org.adempiere.base/src/org/compiere/model/MOrderPaySchedule.java b/org.adempiere.base/src/org/compiere/model/MOrderPaySchedule.java index aee979ef70..ca029cec63 100644 --- a/org.adempiere.base/src/org/compiere/model/MOrderPaySchedule.java +++ b/org.adempiere.base/src/org/compiere/model/MOrderPaySchedule.java @@ -63,6 +63,7 @@ public class MOrderPaySchedule extends X_C_OrderPaySchedule // ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, trxName); @@ -70,27 +71,20 @@ public class MOrderPaySchedule extends X_C_OrderPaySchedule pstmt.setInt(1, C_Order_ID); else pstmt.setInt(1, C_OrderPaySchedule_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { list.add (new MOrderPaySchedule(ctx, rs, trxName)); } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, "getOrderPaySchedule", e); } - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.base/src/org/compiere/model/MOrderTax.java b/org.adempiere.base/src/org/compiere/model/MOrderTax.java index 47ec0fecf1..61de671d03 100644 --- a/org.adempiere.base/src/org/compiere/model/MOrderTax.java +++ b/org.adempiere.base/src/org/compiere/model/MOrderTax.java @@ -77,30 +77,24 @@ public class MOrderTax extends X_C_OrderTax String sql = "SELECT * FROM C_OrderTax WHERE C_Order_ID=? AND C_Tax_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, trxName); pstmt.setInt (1, line.getC_Order_ID()); pstmt.setInt (2, C_Tax_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = new MOrderTax (line.getCtx(), rs, trxName); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } if (retValue != null) @@ -212,12 +206,13 @@ public class MOrderTax extends X_C_OrderTax // String sql = "SELECT LineNetAmt FROM C_OrderLine WHERE C_Order_ID=? AND C_Tax_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getC_Order_ID()); pstmt.setInt (2, getC_Tax_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { BigDecimal baseAmt = rs.getBigDecimal(1); @@ -226,23 +221,16 @@ public class MOrderTax extends X_C_OrderTax if (!documentLevel) // calculate line tax taxAmt = taxAmt.add(tax.calculateTax(baseAmt, isTaxIncluded(), getPrecision())); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, get_TrxName(), e); taxBaseAmt = null; } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // diff --git a/org.adempiere.base/src/org/compiere/model/MPInstance.java b/org.adempiere.base/src/org/compiere/model/MPInstance.java index 12f1414cc4..ccd31d089b 100644 --- a/org.adempiere.base/src/org/compiere/model/MPInstance.java +++ b/org.adempiere.base/src/org/compiere/model/MPInstance.java @@ -152,18 +152,16 @@ public class MPInstance extends X_AD_PInstance m_log.clear(); String sql = "SELECT * FROM AD_PInstance_Log WHERE AD_PInstance_ID=? ORDER BY Log_ID"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, getAD_PInstance_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { m_log.add(new MPInstanceLog(rs)); } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { @@ -171,16 +169,10 @@ public class MPInstance extends X_AD_PInstance } finally { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} + DB.close(rs, pstmt); + rs = null; pstmt = null; } - MPInstanceLog[] retValue = new MPInstanceLog[m_log.size()]; m_log.toArray(retValue); return retValue; diff --git a/org.adempiere.base/src/org/compiere/model/MPOSKeyLayout.java b/org.adempiere.base/src/org/compiere/model/MPOSKeyLayout.java index 2ee18ec660..7e39faa9fd 100644 --- a/org.adempiere.base/src/org/compiere/model/MPOSKeyLayout.java +++ b/org.adempiere.base/src/org/compiere/model/MPOSKeyLayout.java @@ -97,29 +97,23 @@ public class MPOSKeyLayout extends X_C_POSKeyLayout ArrayList list = new ArrayList(); String sql = "SELECT * FROM C_POSKey WHERE C_POSKeyLayout_ID=? AND IsActive = 'Y' ORDER BY SeqNo"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getC_POSKeyLayout_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add(new MPOSKey(getCtx(), rs, get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.base/src/org/compiere/model/MPaySelectionCheck.java b/org.adempiere.base/src/org/compiere/model/MPaySelectionCheck.java index d8c6d07113..4d5ac3117a 100644 --- a/org.adempiere.base/src/org/compiere/model/MPaySelectionCheck.java +++ b/org.adempiere.base/src/org/compiere/model/MPaySelectionCheck.java @@ -57,11 +57,12 @@ public final class MPaySelectionCheck extends X_C_PaySelectionCheck String sql = "SELECT * FROM C_PaySelectionCheck WHERE C_Payment_ID=?"; int count = 0; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, trxName); pstmt.setInt (1, C_Payment_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MPaySelectionCheck psc = new MPaySelectionCheck (ctx, rs, trxName); @@ -71,22 +72,15 @@ public final class MPaySelectionCheck extends X_C_PaySelectionCheck retValue = psc; count++; } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } if (count > 1) @@ -215,12 +209,14 @@ public final class MPaySelectionCheck extends X_C_PaySelectionCheck int docNo = startDocumentNo; String sql = "SELECT * FROM C_PaySelectionCheck " + "WHERE C_PaySelection_ID=? AND PaymentRule=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, trxName); + pstmt = DB.prepareStatement(sql, trxName); pstmt.setInt(1, C_PaySelection_ID); pstmt.setString(2, PaymentRule); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { MPaySelectionCheck check = new MPaySelectionCheck (Env.getCtx(), rs, trxName); @@ -229,14 +225,17 @@ public final class MPaySelectionCheck extends X_C_PaySelectionCheck check.saveEx(); list.add(check); } - rs.close(); - pstmt.close(); } catch (SQLException e) { s_log.log(Level.SEVERE, sql, e); } - + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // convert to Array MPaySelectionCheck[] retValue = new MPaySelectionCheck[list.size()]; list.toArray(retValue); @@ -543,29 +542,23 @@ public final class MPaySelectionCheck extends X_C_PaySelectionCheck ArrayList list = new ArrayList(); String sql = "SELECT * FROM C_PaySelectionLine WHERE C_PaySelectionCheck_ID=? ORDER BY Line"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getC_PaySelectionCheck_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MPaySelectionLine(getCtx(), rs, get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // diff --git a/org.adempiere.base/src/org/compiere/model/MPayment.java b/org.adempiere.base/src/org/compiere/model/MPayment.java index a2a07df839..a415869aed 100644 --- a/org.adempiere.base/src/org/compiere/model/MPayment.java +++ b/org.adempiere.base/src/org/compiere/model/MPayment.java @@ -2283,8 +2283,6 @@ public final class MPayment extends X_C_Payment if (alloc.get_ID() == 0 && !alloc.save(get_TrxName())) { log.log(Level.SEVERE, "Could not create Allocation Hdr"); - rs.close(); - pstmt.close(); return false; } MAllocationLine aLine = null; diff --git a/org.adempiere.base/src/org/compiere/model/MPaymentLookup.java b/org.adempiere.base/src/org/compiere/model/MPaymentLookup.java index 9d0610145b..f56131ac13 100644 --- a/org.adempiere.base/src/org/compiere/model/MPaymentLookup.java +++ b/org.adempiere.base/src/org/compiere/model/MPaymentLookup.java @@ -142,9 +142,6 @@ public class MPaymentLookup extends Lookup implements Serializable { rs = pstmt.executeQuery(); while (rs.next()) list.add(new ValueNamePair(rs.getString(1), rs.getString(2))); - rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException e) { diff --git a/org.adempiere.base/src/org/compiere/model/MPaymentTerm.java b/org.adempiere.base/src/org/compiere/model/MPaymentTerm.java index c9e54d79c3..e964bf2ae6 100644 --- a/org.adempiere.base/src/org/compiere/model/MPaymentTerm.java +++ b/org.adempiere.base/src/org/compiere/model/MPaymentTerm.java @@ -96,33 +96,27 @@ public class MPaymentTerm extends X_C_PaymentTerm String sql = "SELECT * FROM C_PaySchedule WHERE C_PaymentTerm_ID=? AND IsActive='Y' ORDER BY NetDays"; ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getC_PaymentTerm_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { MPaySchedule ps = new MPaySchedule(getCtx(), rs, get_TrxName()); ps.setParent(this); list.add (ps); } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, "getSchedule", e); } - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.base/src/org/compiere/model/MPrivateAccess.java b/org.adempiere.base/src/org/compiere/model/MPrivateAccess.java index 2c66557267..cc75c46764 100644 --- a/org.adempiere.base/src/org/compiere/model/MPrivateAccess.java +++ b/org.adempiere.base/src/org/compiere/model/MPrivateAccess.java @@ -48,33 +48,27 @@ public class MPrivateAccess extends X_AD_Private_Access public static MPrivateAccess get (Properties ctx, int AD_User_ID, int AD_Table_ID, int Record_ID) { MPrivateAccess retValue = null; - PreparedStatement pstmt = null; String sql = "SELECT * FROM AD_Private_Access WHERE AD_User_ID=? AND AD_Table_ID=? AND Record_ID=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_User_ID); pstmt.setInt(2, AD_Table_ID); pstmt.setInt(3, Record_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) retValue = new MPrivateAccess (ctx, rs, null); - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, "MPrivateAccess", e); } - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } return retValue; diff --git a/org.adempiere.base/src/org/compiere/model/MProductCategory.java b/org.adempiere.base/src/org/compiere/model/MProductCategory.java index 011001eb91..2a817bb1d8 100644 --- a/org.adempiere.base/src/org/compiere/model/MProductCategory.java +++ b/org.adempiere.base/src/org/compiere/model/MProductCategory.java @@ -77,29 +77,23 @@ public class MProductCategory extends X_M_Product_Category String sql = "SELECT M_Product_Category_ID FROM M_Product WHERE M_Product_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, M_Product_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) category = new Integer(rs.getInt(1)); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } if (category != null) diff --git a/org.adempiere.base/src/org/compiere/model/MProductDownload.java b/org.adempiere.base/src/org/compiere/model/MProductDownload.java index fbe3a6350c..e983330097 100644 --- a/org.adempiere.base/src/org/compiere/model/MProductDownload.java +++ b/org.adempiere.base/src/org/compiere/model/MProductDownload.java @@ -58,10 +58,11 @@ public class MProductDownload extends X_M_ProductDownload + "FROM M_Product " + "WHERE DownloadURL IS NOT NULL"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { int AD_Client_ID = rs.getInt(1); @@ -86,22 +87,15 @@ public class MProductDownload extends X_M_ProductDownload else s_log.warning("Product Download not created M_Product_ID=" + M_Product_ID); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } s_log.info("#" + count); diff --git a/org.adempiere.base/src/org/compiere/model/MProduction.java b/org.adempiere.base/src/org/compiere/model/MProduction.java index b4f3f52d0c..9a2efa7f02 100644 --- a/org.adempiere.base/src/org/compiere/model/MProduction.java +++ b/org.adempiere.base/src/org/compiere/model/MProduction.java @@ -61,9 +61,6 @@ public class MProduction extends X_M_Production { rs = pstmt.executeQuery(); while (rs.next()) list.add( new MProductionLine( getCtx(), rs.getInt(1), get_TrxName() ) ); - rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException ex) { @@ -72,6 +69,8 @@ public class MProduction extends X_M_Production { finally { DB.close(rs, pstmt); + rs = null; + pstmt = null; } MProductionLine[] retValue = new MProductionLine[list.size()]; diff --git a/org.adempiere.base/src/org/compiere/model/MProjectPhase.java b/org.adempiere.base/src/org/compiere/model/MProjectPhase.java index c4ef54abd3..730b5e4fe7 100644 --- a/org.adempiere.base/src/org/compiere/model/MProjectPhase.java +++ b/org.adempiere.base/src/org/compiere/model/MProjectPhase.java @@ -113,30 +113,25 @@ public class MProjectPhase extends X_C_ProjectPhase ArrayList list = new ArrayList(); String sql = "SELECT * FROM C_ProjectTask WHERE C_ProjectPhase_ID=? ORDER BY SeqNo"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getC_ProjectPhase_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MProjectTask (getCtx(), rs, get_TrxName())); - rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException ex) { log.log(Level.SEVERE, sql, ex); } - try + finally { - if (pstmt != null) - pstmt.close(); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - pstmt = null; // MProjectTask[] retValue = new MProjectTask[list.size()]; list.toArray(retValue); diff --git a/org.adempiere.base/src/org/compiere/model/MProjectType.java b/org.adempiere.base/src/org/compiere/model/MProjectType.java index 8713802820..e86701589d 100644 --- a/org.adempiere.base/src/org/compiere/model/MProjectType.java +++ b/org.adempiere.base/src/org/compiere/model/MProjectType.java @@ -116,30 +116,25 @@ public class MProjectType extends X_C_ProjectType ArrayList list = new ArrayList(); String sql = "SELECT * FROM C_Phase WHERE C_ProjectType_ID=? ORDER BY SeqNo"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getC_ProjectType_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MProjectTypePhase (getCtx(), rs, get_TrxName())); - rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException ex) { log.log(Level.SEVERE, sql, ex); } - try + finally { - if (pstmt != null) - pstmt.close(); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - pstmt = null; // MProjectTypePhase[] retValue = new MProjectTypePhase[list.size()]; list.toArray(retValue); diff --git a/org.adempiere.base/src/org/compiere/model/MProjectTypePhase.java b/org.adempiere.base/src/org/compiere/model/MProjectTypePhase.java index d748d3270a..b0fd34caf7 100644 --- a/org.adempiere.base/src/org/compiere/model/MProjectTypePhase.java +++ b/org.adempiere.base/src/org/compiere/model/MProjectTypePhase.java @@ -78,30 +78,25 @@ public class MProjectTypePhase extends X_C_Phase ArrayList list = new ArrayList(); String sql = "SELECT * FROM C_Task WHERE C_Phase_ID=? ORDER BY SeqNo"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getC_Phase_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MProjectTypeTask (getCtx(), rs, get_TrxName())); - rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException ex) { log.log(Level.SEVERE, sql, ex); } - try + finally { - if (pstmt != null) - pstmt.close(); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - pstmt = null; // MProjectTypeTask[] retValue = new MProjectTypeTask[list.size()]; list.toArray(retValue); diff --git a/org.adempiere.base/src/org/compiere/model/MRMATax.java b/org.adempiere.base/src/org/compiere/model/MRMATax.java index dd1d433cf3..9f59b2aa3f 100644 --- a/org.adempiere.base/src/org/compiere/model/MRMATax.java +++ b/org.adempiere.base/src/org/compiere/model/MRMATax.java @@ -72,30 +72,24 @@ public class MRMATax extends X_M_RMATax String sql = "SELECT * FROM M_RMATax WHERE M_RMA_ID=? AND C_Tax_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, trxName); pstmt.setInt (1, line.getM_RMA_ID()); pstmt.setInt (2, C_Tax_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = new MRMATax (line.getCtx(), rs, trxName); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } if (retValue != null) @@ -205,12 +199,13 @@ public class MRMATax extends X_M_RMATax // String sql = "SELECT LineNetAmt FROM M_RMALine WHERE M_RMA_ID=? AND C_Tax_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getM_RMA_ID()); pstmt.setInt (2, getC_Tax_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { BigDecimal baseAmt = rs.getBigDecimal(1); @@ -219,23 +214,16 @@ public class MRMATax extends X_M_RMATax if (!documentLevel) // calculate line tax taxAmt = taxAmt.add(tax.calculateTax(baseAmt, isTaxIncluded(), getPrecision())); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, get_TrxName(), e); taxBaseAmt = null; } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // diff --git a/org.adempiere.base/src/org/compiere/model/MRecordAccess.java b/org.adempiere.base/src/org/compiere/model/MRecordAccess.java index 7104d96dbd..6c062a0861 100644 --- a/org.adempiere.base/src/org/compiere/model/MRecordAccess.java +++ b/org.adempiere.base/src/org/compiere/model/MRecordAccess.java @@ -97,11 +97,12 @@ public class MRecordAccess extends X_AD_Record_Access + "FROM AD_Column " + "WHERE AD_Table_ID=? AND IsKey='Y' AND IsActive='Y'"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, getAD_Table_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { String s = rs.getString(1); @@ -110,22 +111,15 @@ public class MRecordAccess extends X_AD_Record_Access else log.log(Level.SEVERE, "More than one key = " + s); } - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } if (m_keyColumnName == null) @@ -251,31 +245,25 @@ public class MRecordAccess extends X_AD_Record_Access { String sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, getAD_Table_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { m_tableName = rs.getString(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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // Get Clear Text diff --git a/org.adempiere.base/src/org/compiere/model/MRefList.java b/org.adempiere.base/src/org/compiere/model/MRefList.java index 5ad9de57b8..b5227056dd 100644 --- a/org.adempiere.base/src/org/compiere/model/MRefList.java +++ b/org.adempiere.base/src/org/compiere/model/MRefList.java @@ -155,9 +155,6 @@ public class MRefList extends X_AD_Ref_List rs = pstmt.executeQuery (); if (rs.next ()) retValue = rs.getString(1); - rs.close (); - pstmt.close (); - pstmt = null; } catch (SQLException ex) { @@ -213,9 +210,6 @@ public class MRefList extends X_AD_Ref_List rs = pstmt.executeQuery(); while (rs.next()) list.add(new ValueNamePair(rs.getString(1), rs.getString(2))); - rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException e) { diff --git a/org.adempiere.base/src/org/compiere/model/MRegion.java b/org.adempiere.base/src/org/compiere/model/MRegion.java index 661dc7dd43..23b739f8ea 100644 --- a/org.adempiere.base/src/org/compiere/model/MRegion.java +++ b/org.adempiere.base/src/org/compiere/model/MRegion.java @@ -57,10 +57,12 @@ public final class MRegion extends X_C_Region { s_regions = new CCache(Table_Name, 100); String sql = "SELECT * FROM C_Region WHERE IsActive='Y'"; + Statement stmt = null; + ResultSet rs = null; try { - Statement stmt = DB.createStatement(); - ResultSet rs = stmt.executeQuery(sql); + stmt = DB.createStatement(); + rs = stmt.executeQuery(sql); while(rs.next()) { MRegion r = new MRegion (ctx, rs, null); @@ -68,13 +70,17 @@ public final class MRegion extends X_C_Region if (r.isDefault()) s_default = r; } - rs.close(); - stmt.close(); } catch (SQLException e) { s_log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, stmt); + rs = null; + stmt = null; + } s_log.fine(s_regions.size() + " - default=" + s_default); } // loadAllRegions diff --git a/org.adempiere.base/src/org/compiere/model/MRegistration.java b/org.adempiere.base/src/org/compiere/model/MRegistration.java index e48bc1babc..2b8f7b116e 100644 --- a/org.adempiere.base/src/org/compiere/model/MRegistration.java +++ b/org.adempiere.base/src/org/compiere/model/MRegistration.java @@ -125,29 +125,23 @@ public class MRegistration extends X_A_Registration ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getA_Registration_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MRegistrationValue(getCtx(), rs, get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // Convert and Sort @@ -171,32 +165,26 @@ public class MRegistration extends X_A_Registration + " AND NOT EXISTS (SELECT A_RegistrationAttribute_ID FROM A_RegistrationValue v " + "WHERE ra.A_RegistrationAttribute_ID=v.A_RegistrationAttribute_ID AND r.A_Registration_ID=v.A_Registration_ID)"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getA_Registration_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { MRegistrationValue v = new MRegistrationValue (this, rs.getInt(1), "?"); v.saveEx(); } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, null, e); } - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } } // createMissingValues diff --git a/org.adempiere.base/src/org/compiere/model/MRegistrationAttribute.java b/org.adempiere.base/src/org/compiere/model/MRegistrationAttribute.java index 9c49eeeaf9..eb90a0d5b6 100644 --- a/org.adempiere.base/src/org/compiere/model/MRegistrationAttribute.java +++ b/org.adempiere.base/src/org/compiere/model/MRegistrationAttribute.java @@ -55,11 +55,12 @@ public class MRegistrationAttribute extends X_A_RegistrationAttribute + "ORDER BY SeqNo"; int AD_Client_ID = Env.getAD_Client_ID(ctx); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { MRegistrationAttribute value = new MRegistrationAttribute(ctx, rs, null); @@ -67,22 +68,15 @@ public class MRegistrationAttribute extends X_A_RegistrationAttribute s_cache.put(key, value); list.add(value); } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // diff --git a/org.adempiere.base/src/org/compiere/model/MRequestProcessor.java b/org.adempiere.base/src/org/compiere/model/MRequestProcessor.java index 30364ebd50..9b3afa0bbc 100644 --- a/org.adempiere.base/src/org/compiere/model/MRequestProcessor.java +++ b/org.adempiere.base/src/org/compiere/model/MRequestProcessor.java @@ -51,28 +51,22 @@ public class MRequestProcessor extends X_R_RequestProcessor ArrayList list = new ArrayList(); String sql = "SELECT * FROM R_RequestProcessor WHERE IsActive='Y'"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MRequestProcessor (ctx, rs, null)); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } MRequestProcessor[] retValue = new MRequestProcessor[list.size ()]; @@ -146,29 +140,23 @@ public class MRequestProcessor extends X_R_RequestProcessor String sql = "SELECT * FROM R_RequestProcessor_Route WHERE R_RequestProcessor_ID=? ORDER BY SeqNo"; ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getR_RequestProcessor_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MRequestProcessorRoute (getCtx(), rs, get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // @@ -189,29 +177,23 @@ public class MRequestProcessor extends X_R_RequestProcessor + "WHERE R_RequestProcessor_ID=? " + "ORDER BY Created DESC"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getR_RequestProcessor_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MRequestProcessorLog (getCtx(), rs, get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } MRequestProcessorLog[] retValue = new MRequestProcessorLog[list.size ()]; diff --git a/org.adempiere.base/src/org/compiere/model/MRequestType.java b/org.adempiere.base/src/org/compiere/model/MRequestType.java index 1e8363092e..fcabf19f4a 100644 --- a/org.adempiere.base/src/org/compiere/model/MRequestType.java +++ b/org.adempiere.base/src/org/compiere/model/MRequestType.java @@ -158,11 +158,12 @@ public class MRequestType extends X_R_RequestType // + "FROM R_RequestType x WHERE R_RequestType_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, getR_RequestType_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) { m_openNo = rs.getInt(1); @@ -170,22 +171,15 @@ public class MRequestType extends X_R_RequestType m_new30No = rs.getInt(3); m_closed30No = rs.getInt(4); } - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } @@ -251,29 +245,23 @@ public class MRequestType extends X_R_RequestType // ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, getR_RequestType_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MRequest (getCtx(), rs, null)); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.base/src/org/compiere/model/MRfQLine.java b/org.adempiere.base/src/org/compiere/model/MRfQLine.java index f031986010..5a064a4e09 100644 --- a/org.adempiere.base/src/org/compiere/model/MRfQLine.java +++ b/org.adempiere.base/src/org/compiere/model/MRfQLine.java @@ -126,29 +126,23 @@ public class MRfQLine extends X_C_RfQLine + "WHERE C_RfQLine_ID=? AND IsActive='Y' " + "ORDER BY Qty"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getC_RfQLine_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MRfQLineQty (getCtx(), rs, get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // Create Default (1) diff --git a/org.adempiere.base/src/org/compiere/model/MRfQLineQty.java b/org.adempiere.base/src/org/compiere/model/MRfQLineQty.java index 6a6a295a11..3cd9688fa3 100644 --- a/org.adempiere.base/src/org/compiere/model/MRfQLineQty.java +++ b/org.adempiere.base/src/org/compiere/model/MRfQLineQty.java @@ -127,12 +127,13 @@ public class MRfQLineQty extends X_C_RfQLineQty { ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; String sql = "SELECT * FROM C_RfQResponseLineQty WHERE C_RfQLineQty_ID=? AND IsActive='Y'"; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getC_RfQLineQty_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MRfQResponseLineQty qty = new MRfQResponseLineQty(getCtx(), rs, get_TrxName()); @@ -141,22 +142,15 @@ public class MRfQLineQty extends X_C_RfQLineQty else list.add (qty); } - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } MRfQResponseLineQty[] retValue = new MRfQResponseLineQty[list.size ()]; diff --git a/org.adempiere.base/src/org/compiere/model/MRfQResponse.java b/org.adempiere.base/src/org/compiere/model/MRfQResponse.java index bb04a13815..153d185493 100644 --- a/org.adempiere.base/src/org/compiere/model/MRfQResponse.java +++ b/org.adempiere.base/src/org/compiere/model/MRfQResponse.java @@ -171,29 +171,23 @@ public class MRfQResponse extends X_C_RfQResponse String sql = "SELECT * FROM C_RfQResponseLine " + "WHERE C_RfQResponse_ID=? AND IsActive='Y'"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getC_RfQResponse_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add(new MRfQResponseLine(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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.base/src/org/compiere/model/MRfQResponseLine.java b/org.adempiere.base/src/org/compiere/model/MRfQResponseLine.java index 10ed82c8a0..56c23f4c53 100644 --- a/org.adempiere.base/src/org/compiere/model/MRfQResponseLine.java +++ b/org.adempiere.base/src/org/compiere/model/MRfQResponseLine.java @@ -125,29 +125,23 @@ public class MRfQResponseLine extends X_C_RfQResponseLine String sql = "SELECT * FROM C_RfQResponseLineQty " + "WHERE C_RfQResponseLine_ID=? AND IsActive='Y'"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getC_RfQResponseLine_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MRfQResponseLineQty(getCtx(), rs, get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.base/src/org/compiere/model/MRfQTopic.java b/org.adempiere.base/src/org/compiere/model/MRfQTopic.java index 69d8819878..9a07f61cd8 100644 --- a/org.adempiere.base/src/org/compiere/model/MRfQTopic.java +++ b/org.adempiere.base/src/org/compiere/model/MRfQTopic.java @@ -70,29 +70,23 @@ public class MRfQTopic extends X_C_RfQ_Topic String sql = "SELECT * FROM C_RfQ_TopicSubscriber " + "WHERE C_RfQ_Topic_ID=? AND IsActive='Y'"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getC_RfQ_Topic_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MRfQTopicSubscriber (getCtx(), rs, get_TrxName())); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, "getSubscribers", e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.base/src/org/compiere/model/MRfQTopicSubscriber.java b/org.adempiere.base/src/org/compiere/model/MRfQTopicSubscriber.java index 4d22501b5e..5d5b6f4b3d 100644 --- a/org.adempiere.base/src/org/compiere/model/MRfQTopicSubscriber.java +++ b/org.adempiere.base/src/org/compiere/model/MRfQTopicSubscriber.java @@ -76,29 +76,23 @@ public class MRfQTopicSubscriber extends X_C_RfQ_TopicSubscriber ArrayList list = new ArrayList(); String sql = "SELECT * FROM C_RfQ_TopicSubscriberOnly WHERE C_RfQ_TopicSubscriber_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getC_RfQ_TopicSubscriber_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add(new MRfQTopicSubscriberOnly(getCtx(), rs, get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.base/src/org/compiere/model/MRoleOrgAccess.java b/org.adempiere.base/src/org/compiere/model/MRoleOrgAccess.java index 21ff7b7889..9686cb1e81 100644 --- a/org.adempiere.base/src/org/compiere/model/MRoleOrgAccess.java +++ b/org.adempiere.base/src/org/compiere/model/MRoleOrgAccess.java @@ -84,29 +84,23 @@ public class MRoleOrgAccess extends X_AD_Role_OrgAccess { ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, id); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MRoleOrgAccess(ctx, rs, null)); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, "get", e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } MRoleOrgAccess[] retValue = new MRoleOrgAccess[list.size ()]; @@ -233,32 +227,26 @@ public class MRoleOrgAccess extends X_AD_Role_OrgAccess + "FROM AD_Client c INNER JOIN AD_Org o ON (c.AD_Client_ID=o.AD_Client_ID) " + "WHERE o.AD_Org_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, getAD_Org_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { m_clientName = rs.getString(1); m_orgName = rs.getString(2); } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, "getClientName", e); } - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } } diff --git a/org.adempiere.base/src/org/compiere/model/MSLACriteria.java b/org.adempiere.base/src/org/compiere/model/MSLACriteria.java index dee31844f7..00f858f0b8 100644 --- a/org.adempiere.base/src/org/compiere/model/MSLACriteria.java +++ b/org.adempiere.base/src/org/compiere/model/MSLACriteria.java @@ -96,29 +96,23 @@ public class MSLACriteria extends X_PA_SLA_Criteria + "WHERE PA_SLA_Criteria_ID=?"; ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getPA_SLA_Criteria_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add(new MSLAGoal(getCtx(), rs, get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } MSLAGoal[] retValue = new MSLAGoal[list.size ()]; diff --git a/org.adempiere.base/src/org/compiere/model/MSLAGoal.java b/org.adempiere.base/src/org/compiere/model/MSLAGoal.java index ff1a4ca2f4..1d26dc20b3 100644 --- a/org.adempiere.base/src/org/compiere/model/MSLAGoal.java +++ b/org.adempiere.base/src/org/compiere/model/MSLAGoal.java @@ -102,29 +102,23 @@ public class MSLAGoal extends X_PA_SLA_Goal { ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getPA_SLA_Goal_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add(new MSLAMeasure(getCtx(), rs, get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } MSLAMeasure[] retValue = new MSLAMeasure[list.size ()]; diff --git a/org.adempiere.base/src/org/compiere/model/MStatus.java b/org.adempiere.base/src/org/compiere/model/MStatus.java index 23a871dc48..968c5a984c 100644 --- a/org.adempiere.base/src/org/compiere/model/MStatus.java +++ b/org.adempiere.base/src/org/compiere/model/MStatus.java @@ -81,30 +81,25 @@ public class MStatus extends X_R_Status + " AND IsDefault='Y' " + "ORDER BY SeqNo"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt(1, R_RequestType_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = new MStatus (ctx, rs, null); - rs.close (); - pstmt.close (); - pstmt = null; } catch (SQLException ex) { s_log.log(Level.SEVERE, sql, ex); } - try + finally { - if (pstmt != null) - pstmt.close (); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - pstmt = null; if (retValue != null) s_cacheDefault.put(key, retValue); return retValue; @@ -123,30 +118,25 @@ public class MStatus extends X_R_Status + "ORDER BY Value"; ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt(1, AD_Client_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add(new MStatus (ctx, rs, null)); - rs.close (); - pstmt.close (); - pstmt = null; } catch (SQLException ex) { s_log.log(Level.SEVERE, sql, ex); } - try + finally { - if (pstmt != null) - pstmt.close (); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - pstmt = null; MStatus[] retValue = new MStatus[list.size()]; list.toArray(retValue); return retValue; diff --git a/org.adempiere.base/src/org/compiere/model/MStatusCategory.java b/org.adempiere.base/src/org/compiere/model/MStatusCategory.java index b0fb0e2814..a196e7fc38 100644 --- a/org.adempiere.base/src/org/compiere/model/MStatusCategory.java +++ b/org.adempiere.base/src/org/compiere/model/MStatusCategory.java @@ -55,29 +55,23 @@ public class MStatusCategory extends X_R_StatusCategory + "ORDER BY AD_Client_ID DESC"; MStatusCategory retValue = null; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, AD_Client_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = new MStatusCategory (ctx, rs, null); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } return retValue; @@ -173,29 +167,23 @@ public class MStatusCategory extends X_R_StatusCategory + "ORDER BY SeqNo"; ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, getR_StatusCategory_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MStatus (getCtx(), rs, null)); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // diff --git a/org.adempiere.base/src/org/compiere/model/MStore.java b/org.adempiere.base/src/org/compiere/model/MStore.java index 500ebb7813..af83283297 100644 --- a/org.adempiere.base/src/org/compiere/model/MStore.java +++ b/org.adempiere.base/src/org/compiere/model/MStore.java @@ -81,30 +81,24 @@ public class MStore extends X_W_Store // Search by context PreparedStatement pstmt = null; + ResultSet rs = null; String sql = "SELECT * FROM W_Store WHERE WebContext=?"; try { pstmt = DB.prepareStatement (sql, null); pstmt.setString(1, contextPath); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) wstore = new MStore (ctx, rs, null); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // Try client @@ -115,29 +109,22 @@ public class MStore extends X_W_Store { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, Env.getAD_Client_ID(ctx)); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) { wstore = new MStore (ctx, rs, null); s_log.warning("Context " + contextPath + " Not found - Found via AD_Client_ID=" + Env.getAD_Client_ID(ctx)); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } } @@ -161,29 +148,23 @@ public class MStore extends X_W_Store ArrayList list = new ArrayList(); String sql = "SELECT * FROM W_Store WHERE AD_Client_ID=? AND IsActive='Y'"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, client.get_TrxName()); pstmt.setInt (1, client.getAD_Client_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MStore (client.getCtx(), rs, client.get_TrxName())); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // @@ -469,29 +450,23 @@ public class MStore extends X_W_Store // String sql = "SELECT * FROM W_MailMsg WHERE W_Store_ID=? ORDER BY MailMsgType"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getW_Store_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new MMailMsg (getCtx(), rs, get_TrxName())); - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } // diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ColumnElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ColumnElementHandler.java index f0d5a530b3..6e7227cd4a 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ColumnElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ColumnElementHandler.java @@ -248,12 +248,8 @@ public class ColumnElementHandler extends AbstractElementHandler { // No existing column sql = column.getSQLAdd(table); } - rsc.close(); - rsc = null; } - rst.close(); - rst = null; //execute modify or add if needed if (sql != null && sql.trim().length() > 0) { log.info(sql); @@ -277,23 +273,16 @@ public class ColumnElementHandler extends AbstractElementHandler { trx.commit(true); } catch (SQLException e) { log.log(Level.SEVERE, e.getLocalizedMessage(), e); - if (rsc != null) { - try { - rsc.close(); - } catch (SQLException e1) { - } - rsc = null; - } - if (rst != null) { - try { - rst.close(); - } catch (SQLException e1) { - } - rst = null; - } trx.rollback(); return 0; } + finally + { + DB.close(rsc); + rsc = null; + DB.close(rst); + rst = null; + } return 1; } diff --git a/org.adempiere.ui.swing/src/org/compiere/apps/form/VAttributeGrid.java b/org.adempiere.ui.swing/src/org/compiere/apps/form/VAttributeGrid.java index 40439b2c1a..2ab2d9ab3c 100644 --- a/org.adempiere.ui.swing/src/org/compiere/apps/form/VAttributeGrid.java +++ b/org.adempiere.ui.swing/src/org/compiere/apps/form/VAttributeGrid.java @@ -196,18 +196,20 @@ public class VAttributeGrid extends CPanel // Add Access & Order sql = MRole.getDefault().addAccessSQL (sql, "M_PriceList_Version", true, false) // fully qualidfied - RO + " ORDER BY M_PriceList_Version.Name"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { pickPriceList.addItem(new KeyNamePair (0, "")); - PreparedStatement pstmt = DB.prepareStatement(sql, null); - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(sql, null); + rs = pstmt.executeQuery(); while (rs.next()) { KeyNamePair kn = new KeyNamePair (rs.getInt(1), rs.getString(2)); pickPriceList.addItem(kn); } - rs.close(); - pstmt.close(); + DB.close(rs, pstmt); + rs = null;pstmt = null; // Warehouse sql = "SELECT M_Warehouse_ID, Value || ' - ' || Name AS ValueName " @@ -225,13 +227,17 @@ public class VAttributeGrid extends CPanel (rs.getInt("M_Warehouse_ID"), rs.getString("ValueName")); pickWarehouse.addItem(kn); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } // fillPicks @@ -430,33 +436,27 @@ public class VAttributeGrid extends CPanel sql = MRole.getDefault().addAccessSQL(sql, "M_Product", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO); PreparedStatement pstmt = null; + ResultSet rs = null; int noProducts = 0; try { pstmt = DB.prepareStatement (sql, null); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MProduct product = new MProduct(Env.getCtx(), rs, null); addProduct (element, product); noProducts++; } - 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) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocatorDialog.java b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocatorDialog.java index 866fec07df..0b03cc564f 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocatorDialog.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocatorDialog.java @@ -227,19 +227,25 @@ public class VLocatorDialog extends CDialog String SQL = MRole.getDefault().addAccessSQL( sql, "M_Warehouse", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO) + " ORDER BY 2"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(SQL, null); - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(SQL, null); + rs = pstmt.executeQuery(); while (rs.next()) fWarehouse.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2))); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, SQL, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } log.fine("Warehouses=" + fWarehouse.getItemCount()); // Load existing Locators diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromInvoice.java b/org.adempiere.ui/src/org/compiere/grid/CreateFromInvoice.java index fd0ba621d1..28b6439590 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromInvoice.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFromInvoice.java @@ -102,23 +102,29 @@ public abstract class CreateFromInvoice extends CreateFrom + "HAVING (sl.MovementQty<>SUM(mi.Qty) AND mi.M_InOutLine_ID IS NOT NULL)" + " OR mi.M_InOutLine_ID IS NULL) " + "ORDER BY s.MovementDate"); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), null); pstmt.setInt(1, C_BPartner_ID); pstmt.setInt(2, C_BPartner_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { list.add(new KeyNamePair(rs.getInt(1), rs.getString(2))); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return list; } @@ -201,12 +207,13 @@ public abstract class CreateFromInvoice extends CreateFrom + "l.C_UOM_ID, COALESCE(uom.UOMSymbol, uom.Name), " + "l.M_Product_ID, p.Name, po.VendorProductNo, l.M_InOutLine_ID, l.Line, l.C_OrderLine_ID ") .append("ORDER BY l.Line"); - + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), null); pstmt.setInt(1, M_InOut_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { Vector line = new Vector(7); @@ -230,13 +237,17 @@ public abstract class CreateFromInvoice extends CreateFrom line.add(null); // 7-RMA data.add(line); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return data; } // loadShipment @@ -310,7 +321,6 @@ public abstract class CreateFromInvoice extends CreateFrom line.add(pp); //7-RMA data.add(line); } - rs.close(); } catch (Exception ex) { diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromShipment.java b/org.adempiere.ui/src/org/compiere/grid/CreateFromShipment.java index e99187031c..0ed849bd55 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromShipment.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFromShipment.java @@ -159,13 +159,17 @@ public abstract class CreateFromShipment extends CreateFrom { list.add(new KeyNamePair(rs.getInt(1), rs.getString(2))); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); + }finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; } + return list; } diff --git a/org.adempiere.ui/src/org/compiere/install/Translation.java b/org.adempiere.ui/src/org/compiere/install/Translation.java index bcd551c771..816da01b43 100644 --- a/org.adempiere.ui/src/org/compiere/install/Translation.java +++ b/org.adempiere.ui/src/org/compiere/install/Translation.java @@ -168,6 +168,8 @@ public class Translation String[] trlColumns = getTrlColumns (Base_Table); // StringBuffer sql = null; + PreparedStatement pstmt = null; + ResultSet rs = null; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); @@ -214,10 +216,10 @@ public class Translation sql.append(haveWhere ? " AND " : " WHERE ").append("o.AD_Client_ID=").append(AD_Client_ID); sql.append(" ORDER BY t.").append(keyColumn); // - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), null); if (!isBaseLanguage) pstmt.setString(1, AD_Language); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); int rows = 0; while (rs.next()) { @@ -245,8 +247,6 @@ public class Translation root.appendChild(row); rows++; } - rs.close(); - pstmt.close(); log.info("Records=" + rows + ", DTD=" + document.getDoctype() + " - " + Trl_Table); @@ -275,6 +275,12 @@ public class Translation log.log(Level.SEVERE, "", e); return e.toString(); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return ""; } // exportTrl @@ -291,20 +297,26 @@ public class Translation String sql = "SELECT TableName FROM AD_Table t" + " INNER JOIN AD_Column c ON (c.AD_Table_ID=t.AD_Table_ID AND c.ColumnName='IsCentrallyMaintained') " + "WHERE t.TableName=? AND c.IsActive='Y'"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setString(1, Base_Table); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) m_IsCentrallyMaintained = true; - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } sql = "SELECT ColumnName " + "FROM AD_Column c" @@ -316,23 +328,27 @@ public class Translation ArrayList list = new ArrayList(); try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setString(1, Base_Table + "_Trl"); pstmt.setString(2, PO.getUUIDColumnName(Base_Table + "_Trl")); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { String s = rs.getString(1); // System.out.println(s); list.add(s); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Convert to Array String[] retValue = new String[list.size()]; @@ -354,21 +370,27 @@ public class Translation + "FROM AD_Language " + "WHERE AD_Language=?"; MLanguage language = null; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setString(1, AD_Language); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) language = new MLanguage (m_ctx, rs, null); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); return e.toString(); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // No AD_Language Record if (language == null) @@ -408,19 +430,25 @@ public class Translation + "WHERE TableName LIKE '%_Trl' " + "ORDER BY Name"; ArrayList trlTables = new ArrayList(); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(sql, null); + rs = pstmt.executeQuery(); while (rs.next()) trlTables.add(rs.getString(2)); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } for (int i = 0; i < trlTables.size(); i++) { diff --git a/org.adempiere.ui/src/org/compiere/install/TranslationController.java b/org.adempiere.ui/src/org/compiere/install/TranslationController.java index ec7671d1c3..f036ae1a73 100644 --- a/org.adempiere.ui/src/org/compiere/install/TranslationController.java +++ b/org.adempiere.ui/src/org/compiere/install/TranslationController.java @@ -46,22 +46,28 @@ public class TranslationController + "FROM AD_Client " + "WHERE IsActive='Y' " + "ORDER BY AD_Client_ID"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(sql, null); + rs = pstmt.executeQuery(); while (rs.next()) { KeyNamePair kp = new KeyNamePair (rs.getInt(2), rs.getString(1)); list.add(kp); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return list; } @@ -75,22 +81,28 @@ public class TranslationController + "FROM AD_Language " + "WHERE IsActive='Y' AND (IsSystemLanguage='Y' OR IsBaseLanguage='Y')" + "ORDER BY Name"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(sql, null); + rs = pstmt.executeQuery(); while (rs.next()) { ValueNamePair vp = new ValueNamePair (rs.getString(2), rs.getString(1)); list.add(vp); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return list; } @@ -105,22 +117,28 @@ public class TranslationController + "FROM AD_Table " + "WHERE TableName LIKE '%_Trl' AND TableName<>'AD_Column_Trl' " + "ORDER BY Name"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(sql, null); + rs = pstmt.executeQuery(); while (rs.next()) { ValueNamePair vp = new ValueNamePair (rs.getString(2), rs.getString(1)); list.add(vp); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return list; }