diff --git a/base/src/org/compiere/model/M_Element.java b/base/src/org/compiere/model/M_Element.java index af9239feed..aaf9eb484c 100644 --- a/base/src/org/compiere/model/M_Element.java +++ b/base/src/org/compiere/model/M_Element.java @@ -16,10 +16,14 @@ *****************************************************************************/ package org.compiere.model; -import java.sql.*; -import java.util.*; -import java.util.logging.*; -import org.compiere.util.*; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.Properties; +import java.util.logging.Level; + +import org.compiere.util.CLogger; +import org.compiere.util.DB; +import org.compiere.util.Msg; /** @@ -52,12 +56,13 @@ public class M_Element extends X_AD_Element return columnName; String retValue = columnName; String sql = "SELECT ColumnName FROM AD_Element WHERE UPPER(ColumnName)=?"; - PreparedStatement pstmt = null; + PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, trxName); pstmt.setString (1, columnName.toUpperCase()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) { retValue = rs.getString(1); @@ -67,24 +72,17 @@ public class M_Element extends X_AD_Element } else s_log.warning("No found: " + columnName); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, columnName, e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } + finally + { + DB.close(rs, pstmt); + rs = null; pstmt = null; + } + return retValue; } // getColumnName @@ -112,12 +110,13 @@ public class M_Element extends X_AD_Element return null; M_Element retValue = null; String sql = "SELECT * FROM AD_Element WHERE UPPER(ColumnName)=?"; - PreparedStatement pstmt = null; + PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, trxName); pstmt.setString (1, columnName.toUpperCase()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) { retValue = new M_Element (ctx, rs, trxName); @@ -125,24 +124,16 @@ public class M_Element extends X_AD_Element s_log.warning("Not unique: " + columnName + " -> " + retValue + " - " + rs.getString("ColumnName")); } - 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) - { - pstmt = null; - } + finally + { + DB.close(rs, pstmt); + rs = null; pstmt = null; + } return retValue; } // get @@ -163,31 +154,25 @@ public class M_Element extends X_AD_Element + "WHERE EXISTS (SELECT * FROM AD_Column c " + "WHERE c.AD_Element_ID=e.AD_Element_ID AND c.AD_Column_ID=?)"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, trxName); pstmt.setInt (1, AD_Column_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = new M_Element (ctx, rs, trxName); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { s_log.log (Level.SEVERE, sql, e); } - try + finally { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; + DB.close(rs, pstmt); + rs = null; pstmt = null; } + return retValue; } // get