diff --git a/org.adempiere.base.callout/src/org/compiere/model/CalloutGLJournal.java b/org.adempiere.base.callout/src/org/compiere/model/CalloutGLJournal.java index f7924c8afa..39f277d93a 100644 --- a/org.adempiere.base.callout/src/org/compiere/model/CalloutGLJournal.java +++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutGLJournal.java @@ -90,9 +90,6 @@ public class CalloutGLJournal extends CalloutEngine rs = pstmt.executeQuery(); if (rs.next()) C_Period_ID = rs.getInt(1); - rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException e) { @@ -102,6 +99,8 @@ public class CalloutGLJournal extends CalloutEngine finally { DB.close(rs, pstmt); + rs = null; + pstmt = null; } if (C_Period_ID != 0) mTab.setValue("C_Period_ID", new Integer(C_Period_ID)); diff --git a/org.adempiere.base.callout/src/org/compiere/model/CalloutInventory.java b/org.adempiere.base.callout/src/org/compiere/model/CalloutInventory.java index 324518cf06..88130d3b31 100644 --- a/org.adempiere.base.callout/src/org/compiere/model/CalloutInventory.java +++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutInventory.java @@ -155,15 +155,16 @@ public class CalloutInventory extends CalloutEngine sql = "SELECT SUM(QtyOnHand) FROM M_StorageOnHand " + "WHERE M_Product_ID=?" // 1 + " AND M_Locator_ID=?"; // 2 - + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, M_Product_ID); pstmt.setInt(2, M_Locator_ID); if (M_AttributeSetInstance_ID != 0) pstmt.setInt(3, M_AttributeSetInstance_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { bd = rs.getBigDecimal(1); @@ -174,14 +175,19 @@ public class CalloutInventory extends CalloutEngine // for example when the locator has never stored a particular product. return new BigDecimal(0); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); throw new Exception(e.getLocalizedMessage()); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } + return new BigDecimal(0); } diff --git a/org.adempiere.base.callout/src/org/compiere/model/CalloutRequest.java b/org.adempiere.base.callout/src/org/compiere/model/CalloutRequest.java index c105bf8224..d344cd08af 100644 --- a/org.adempiere.base.callout/src/org/compiere/model/CalloutRequest.java +++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutRequest.java @@ -88,24 +88,30 @@ public class CalloutRequest extends CalloutEngine Integer R_StandardResponse_ID = (Integer)value; String sql = "SELECT Name, ResponseText FROM R_StandardResponse " + "WHERE R_StandardResponse_ID=?"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, R_StandardResponse_ID.intValue()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { String txt = rs.getString(2); txt = Env.parseContext(ctx, WindowNo, txt, false, true); mTab.setValue("Result", txt); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return ""; } // copyResponse diff --git a/org.adempiere.base.process/src/org/adempiere/process/ApplyMigrationScripts.java b/org.adempiere.base.process/src/org/adempiere/process/ApplyMigrationScripts.java index c2d1c7db58..77692c7f1b 100644 --- a/org.adempiere.base.process/src/org/adempiere/process/ApplyMigrationScripts.java +++ b/org.adempiere.base.process/src/org/adempiere/process/ApplyMigrationScripts.java @@ -44,67 +44,73 @@ import org.compiere.util.DB; public class ApplyMigrationScripts extends SvrProcess { /** Logger */ - private static CLogger log = CLogger - .getCLogger(ApplyMigrationScripts.class); + private static CLogger log = CLogger.getCLogger(ApplyMigrationScripts.class); @Override protected String doIt() throws Exception { - // TODO Auto-generated method stub log.info("Applying migrations scripts"); StringBuilder sql = new StringBuilder() .append("select ad_migrationscript_id, script, name from ad_migrationscript where isApply = 'Y' and status = 'IP' order by name, created"); - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), this.get_TrxName()); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) { - byte[] scriptArray = rs.getBytes(2); - int seqID = rs.getInt(1); - boolean execOk = true; - try { - StringBuilder tmpSql = new StringBuilder(new String(scriptArray)); - - if (tmpSql.length() > 0) { - log.info("Executing script " + rs.getString(3)); - execOk = executeScript(tmpSql.toString(), rs.getString(3)); - System.out.println(); - } - } catch (SQLException e) { - execOk = false; - e.printStackTrace(); - StringBuilder msglog = new StringBuilder("Script: ").append(rs.getString(3)).append(" - ").append(e.getMessage()); - log.saveError("Error", msglog.toString()); - log.severe(e.getMessage()); - } finally { - sql = new StringBuilder("UPDATE ad_migrationscript SET status = ? , isApply = 'N' WHERE ad_migrationscript_id = ? "); - pstmt = DB.prepareStatement(sql.toString(), this.get_TrxName()); - if (execOk) { - pstmt.setString(1, "CO"); - pstmt.setInt(2, seqID); - } else { - pstmt.setString(1, "ER"); - pstmt.setInt(2, seqID); - } + PreparedStatement pstmt = null; + ResultSet rs = null; + try { + pstmt = DB.prepareStatement(sql.toString(), this.get_TrxName()); + rs = pstmt.executeQuery(); + while (rs.next()) { + byte[] scriptArray = rs.getBytes(2); + int seqID = rs.getInt(1); + boolean execOk = true; try { - pstmt.executeUpdate(); - if (!execOk) { - pstmt.close(); - return null; + StringBuilder tmpSql = new StringBuilder(new String(scriptArray)); + + if (tmpSql.length() > 0) { + log.info("Executing script " + rs.getString(3)); + execOk = executeScript(tmpSql.toString(), rs.getString(3)); + System.out.println(); } } catch (SQLException e) { + execOk = false; e.printStackTrace(); StringBuilder msglog = new StringBuilder("Script: ").append(rs.getString(3)).append(" - ").append(e.getMessage()); log.saveError("Error", msglog.toString()); log.severe(e.getMessage()); + } finally { + sql = new StringBuilder("UPDATE ad_migrationscript SET status = ? , isApply = 'N' WHERE ad_migrationscript_id = ? "); + PreparedStatement pstmtu = DB.prepareStatement(sql.toString(), this.get_TrxName()); + if (execOk) { + pstmtu.setString(1, "CO"); + pstmtu.setInt(2, seqID); + } else { + pstmtu.setString(1, "ER"); + pstmtu.setInt(2, seqID); + } + try { + pstmtu.executeUpdate(); + if (!execOk) { + return null; + } + } catch (SQLException e) { + e.printStackTrace(); + StringBuilder msglog = new StringBuilder("Script: ").append(rs.getString(3)).append(" - ").append(e.getMessage()); + log.saveError("Error", msglog.toString()); + log.severe(e.getMessage()); + } finally { + DB.close(pstmtu); + pstmtu = null; + } } } + } catch (SQLException e) { + throw e; + } finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } - rs.close(); - pstmt.close(); return null; } @Override protected void prepare() { - // TODO Auto-generated method stub } @@ -156,7 +162,8 @@ public class ApplyMigrationScripts extends SvrProcess { log.saveError("Error", msglog.toString()); log.severe(e.getMessage()); } finally { - if (stmt != null)stmt.close(); + DB.close(stmt); + stmt = null; if(execOk) conn.commit(); else diff --git a/org.adempiere.base.process/src/org/compiere/process/ColumnSync.java b/org.adempiere.base.process/src/org/compiere/process/ColumnSync.java index 4d02367b69..27f5ca8ecb 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ColumnSync.java +++ b/org.adempiere.base.process/src/org/compiere/process/ColumnSync.java @@ -81,6 +81,7 @@ public class ColumnSync extends SvrProcess // Find Column in Database Connection conn = null; + ResultSet rs = null; try { conn = DB.getConnectionRO(); DatabaseMetaData md = conn.getMetaData(); @@ -98,7 +99,7 @@ public class ColumnSync extends SvrProcess int noColumns = 0; String sql = null; // - ResultSet rs = md.getColumns(catalog, schema, tableName, null); + rs = md.getColumns(catalog, schema, tableName, null); while (rs.next()) { noColumns++; @@ -111,7 +112,7 @@ public class ColumnSync extends SvrProcess sql = column.getSQLModify(table, column.isMandatory() != notNull); break; } - rs.close(); + DB.close(rs); rs = null; // No Table @@ -149,6 +150,8 @@ public class ColumnSync extends SvrProcess } return sql; } finally { + DB.close(rs); + rs = null; if (conn != null) { try { conn.close(); diff --git a/org.adempiere.base.process/src/org/compiere/process/CostUpdate.java b/org.adempiere.base.process/src/org/compiere/process/CostUpdate.java index 0ef7963bc7..9cce4a99ee 100644 --- a/org.adempiere.base.process/src/org/compiere/process/CostUpdate.java +++ b/org.adempiere.base.process/src/org/compiere/process/CostUpdate.java @@ -193,6 +193,7 @@ public class CostUpdate extends SvrProcess sql += " AND M_Product_Category_ID=?"; int counter = 0; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); @@ -202,28 +203,21 @@ public class CostUpdate extends SvrProcess pstmt.setInt (4, as.getAD_Client_ID()); if (p_M_Product_Category_ID != 0) pstmt.setInt (5, p_M_Product_Category_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { if (createNew (new MProduct (getCtx(), rs, null), as)) counter++; } - 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("#" + counter); @@ -256,13 +250,14 @@ public class CostUpdate extends SvrProcess sql += " AND EXISTS (SELECT * FROM M_Product p " + "WHERE c.M_Product_ID=p.M_Product_ID AND p.M_Product_Category_ID=?)"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, m_ce.getM_CostElement_ID()); if (p_M_Product_Category_ID != 0) pstmt.setInt (2, p_M_Product_Category_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MCost cost = new MCost (getCtx(), rs, get_TrxName()); @@ -277,22 +272,15 @@ public class CostUpdate extends SvrProcess } } } - 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("#" + counter); @@ -502,32 +490,26 @@ public class CostUpdate extends SvrProcess + "FROM M_ProductPrice " + "WHERE M_Product_ID=? AND M_PriceList_Version_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, cost.getM_Product_ID()); pstmt.setInt (2, p_M_PriceList_Version_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) { retValue = 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; } return retValue; diff --git a/org.adempiere.base.process/src/org/compiere/process/DocumentTypeVerify.java b/org.adempiere.base.process/src/org/compiere/process/DocumentTypeVerify.java index f7b5cb8df9..9ba8455f4e 100644 --- a/org.adempiere.base.process/src/org/compiere/process/DocumentTypeVerify.java +++ b/org.adempiere.base.process/src/org/compiere/process/DocumentTypeVerify.java @@ -78,11 +78,12 @@ public class DocumentTypeVerify extends SvrProcess + " AND rl.IsActive='Y' AND NOT EXISTS " + " (SELECT * FROM C_DocType dt WHERE dt.AD_Client_ID=? AND rl.Value=dt.DocBaseType)"; 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(); while (rs.next()) { String name = rs.getString(2); @@ -104,22 +105,15 @@ public class DocumentTypeVerify extends SvrProcess s_log.warning("Not created: " + name); } } - 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; } } // createDocumentTypes @@ -160,12 +154,13 @@ public class DocumentTypeVerify extends SvrProcess + " (SELECT * FROM C_PeriodControl pc " + "WHERE pc.C_Period_ID=p.C_Period_ID AND pc.DocBaseType=dt.DocBaseType)"; PreparedStatement pstmt = null; + ResultSet rs = null; int counter = 0; try { pstmt = DB.prepareStatement(sql, trxName); pstmt.setInt(1, AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { int Client_ID = rs.getInt(1); @@ -184,22 +179,15 @@ public class DocumentTypeVerify extends SvrProcess else s_log.warning("Not saved: " + pc); } - 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 (sp != null) diff --git a/org.adempiere.base.process/src/org/compiere/process/DunningRunCreate.java b/org.adempiere.base.process/src/org/compiere/process/DunningRunCreate.java index 2276400c76..da4c05ddfb 100644 --- a/org.adempiere.base.process/src/org/compiere/process/DunningRunCreate.java +++ b/org.adempiere.base.process/src/org/compiere/process/DunningRunCreate.java @@ -203,6 +203,7 @@ public class DunningRunCreate extends SvrProcess PreparedStatement pstmt = null; PreparedStatement pstmt2 = null; ResultSet rs = null; + ResultSet rs2 = null; try { pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); @@ -255,13 +256,14 @@ public class DunningRunCreate extends SvrProcess // SubQuery pstmt2.setInt (1, m_run.get_ID ()); pstmt2.setInt (2, C_Invoice_ID); - ResultSet rs2 = pstmt2.executeQuery (); + rs2 = pstmt2.executeQuery (); if (rs2.next()) { TimesDunned = rs2.getInt(1); DaysAfterLast = rs2.getInt(2); } - rs2.close(); + DB.close(rs2); + rs2 = null; // SubQuery // Ensure that Daysbetween Dunning is enforced @@ -298,7 +300,8 @@ public class DunningRunCreate extends SvrProcess finally { DB.close(rs, pstmt); - rs = null; pstmt = null; pstmt2 = null; + DB.close(rs2, pstmt2); + rs = null; pstmt = null; rs2 = null; pstmt2 = null; } return count; } // addInvoices diff --git a/org.adempiere.base.process/src/org/compiere/process/FactAcctReset.java b/org.adempiere.base.process/src/org/compiere/process/FactAcctReset.java index 9d6c7a4686..24002b18f0 100644 --- a/org.adempiere.base.process/src/org/compiere/process/FactAcctReset.java +++ b/org.adempiere.base.process/src/org/compiere/process/FactAcctReset.java @@ -112,10 +112,11 @@ public class FactAcctReset extends SvrProcess sql += " AND EXISTS (SELECT * FROM AD_Column c " + "WHERE t.AD_Table_ID=c.AD_Table_ID AND c.ColumnName='Posted' AND c.IsActive='Y')"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { int AD_Table_ID = rs.getInt(1); @@ -125,22 +126,15 @@ public class FactAcctReset extends SvrProcess else reset (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; } // diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportAccount.java b/org.adempiere.base.process/src/org/compiere/process/ImportAccount.java index 68f54f42a6..7f64897822 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportAccount.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportAccount.java @@ -264,10 +264,12 @@ public class ImportAccount extends SvrProcess .append("FROM I_ElementValue ") .append("WHERE I_IsImported='N'").append(clientCheck) .append(" ORDER BY I_ElementValue_ID"); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); + rs = pstmt.executeQuery(); while (rs.next()) { X_I_ElementValue impEV = new X_I_ElementValue(getCtx(), rs, get_TrxName()); @@ -316,13 +318,17 @@ public class ImportAccount extends SvrProcess } } } // for all I_Product - rs.close(); - pstmt.close(); } catch (SQLException e) { throw new Exception ("create", e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Set Error to indicator to not imported sql = new StringBuilder ("UPDATE I_ElementValue ") @@ -362,8 +368,8 @@ public class ImportAccount extends SvrProcess int noParentUpdate = 0; try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); + rs = pstmt.executeQuery(); // String updateSQL = "UPDATE AD_TreeNode SET Parent_ID=?, SeqNo=? " + "WHERE AD_Tree_ID=? AND Node_ID=?"; @@ -391,13 +397,17 @@ public class ImportAccount extends SvrProcess if (no == 0) log.info("Parent not found for " + rs.getString(5)); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, "(ParentUpdateLoop) " + sql.toString(), e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } addLog (0, null, new BigDecimal (noParentUpdate), "@ParentElementValue_ID@: @Updated@"); commitEx(); @@ -444,20 +454,26 @@ public class ImportAccount extends SvrProcess // **** Update Defaults StringBuilder sql = new StringBuilder ("SELECT C_AcctSchema_ID FROM C_AcctSchema_Element ") .append("WHERE C_Element_ID=?").append(clientCheck); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); + pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); pstmt.setInt(1, m_C_Element_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) updateDefaultAccounts (rs.getInt(1)); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Default Account DEFAULT_ACCT sql = new StringBuilder ("UPDATE C_AcctSchema_Element e ") @@ -498,11 +514,13 @@ public class ImportAccount extends SvrProcess .append(" INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID) ") .append("WHERE i.I_IsImported='Y' AND Processing='Y'") .append(" AND i.C_ElementValue_ID IS NOT NULL AND C_Element_ID=?"); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); + pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); pstmt.setInt(1, m_C_Element_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { int C_ElementValue_ID = rs.getInt(1); @@ -521,13 +539,17 @@ public class ImportAccount extends SvrProcess log.log(Level.SEVERE, "Updated=" + no); } } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, "", e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } addLog (0, null, new BigDecimal (counts[UPDATE_ERROR]), as.toString() + ": @Errors@"); addLog (0, null, new BigDecimal (counts[UPDATE_YES]), as.toString() + ": @Updated@"); addLog (0, null, new BigDecimal (counts[UPDATE_SAME]), as.toString() + ": OK"); @@ -562,10 +584,12 @@ public class ImportAccount extends SvrProcess .append(TableName).append(" x INNER JOIN C_ValidCombination vc ON (x.") .append(ColumnName).append("=vc.C_ValidCombination_ID) ") .append("WHERE x.C_AcctSchema_ID=").append(C_AcctSchema_ID); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); + rs = pstmt.executeQuery(); if (rs.next()) { int C_ValidCombination_ID = rs.getInt(1); @@ -635,13 +659,17 @@ public class ImportAccount extends SvrProcess } // for all default accounts else log.log(Level.SEVERE, "Account not found " + sql); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return retValue; } // updateDefaultAccount diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportBankStatement.java b/org.adempiere.base.process/src/org/compiere/process/ImportBankStatement.java index d3ba73baf2..5448c8e440 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportBankStatement.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportBankStatement.java @@ -329,11 +329,12 @@ public class ImportBankStatement extends SvrProcess PreparedStatement pupdt = DB.prepareStatement(updateSql.toString(), get_TrxName()); PreparedStatement pstmtDuplicates = null; + ResultSet rs = null; no = 0; try { pstmtDuplicates = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet rs = pstmtDuplicates.executeQuery(); + rs = pstmtDuplicates.executeQuery(); while (rs.next()) { StringBuilder info = new StringBuilder("Line_ID=").append(rs.getInt(2)) // l.C_BankStatementLine_ID @@ -343,18 +344,18 @@ public class ImportBankStatement extends SvrProcess pupdt.executeUpdate(); no++; } - rs.close(); - pstmtDuplicates.close(); - pupdt.close(); - - rs = null; - pstmtDuplicates = null; - pupdt = null; } catch(Exception e) { log.log(Level.SEVERE, "DetectDuplicates " + e.getMessage()); } + finally + { + DB.close(rs, pstmtDuplicates); + rs = null;pstmtDuplicates = null; + DB.close(pupdt); + pupdt = null; + } if (no != 0) log.info("Duplicates=" + no); @@ -374,7 +375,7 @@ public class ImportBankStatement extends SvrProcess try { pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { @@ -508,18 +509,17 @@ public class ImportBankStatement extends SvrProcess line = null; } - - // Close database connection - rs.close(); - pstmt.close(); - rs = null; - pstmt = null; - } catch(Exception e) { log.log(Level.SEVERE, sql.toString(), e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Set Error to indicator to not imported sql = new StringBuilder ("UPDATE I_BankStatement ") diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportConversionRate.java b/org.adempiere.base.process/src/org/compiere/process/ImportConversionRate.java index 21cccbb37d..b2a067c77a 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportConversionRate.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportConversionRate.java @@ -236,10 +236,11 @@ public class ImportConversionRate extends SvrProcess .append("WHERE I_IsImported='N'").append (clientCheck) .append(" ORDER BY C_Currency_ID, C_Currency_ID_To, ValidFrom"); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { X_I_Conversion_Rate imp = new X_I_Conversion_Rate (getCtx(), rs, get_TrxName()); @@ -270,22 +271,15 @@ public class ImportConversionRate extends SvrProcess } } } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { 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; } diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportGLJournal.java b/org.adempiere.base.process/src/org/compiere/process/ImportGLJournal.java index db6846b241..15ef431761 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportGLJournal.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportGLJournal.java @@ -588,10 +588,11 @@ public class ImportGLJournal extends SvrProcess .append("FROM I_GLJournal ") .append("WHERE I_IsImported='N'").append (clientCheck); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) { BigDecimal source = rs.getBigDecimal(1); @@ -608,23 +609,17 @@ public class ImportGLJournal extends SvrProcess if (acct != null) addLog (0, null, acct, "@AmtAcctDr@ - @AmtAcctCr@"); } - 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; // globalqss (moved the commit here to save the error messages) commitEx(); @@ -669,7 +664,7 @@ public class ImportGLJournal extends SvrProcess try { pstmt = DB.prepareStatement (sql.toString (), get_TrxName()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); // while (rs.next()) { @@ -831,23 +826,18 @@ public class ImportGLJournal extends SvrProcess noInsertLine++; } } // while records - rs.close(); - pstmt.close(); } catch (Exception e) { log.log(Level.SEVERE, "", e); } // clean up - try + finally { - if (pstmt != null) - pstmt.close (); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - pstmt = null; // Set Error to indicator to not imported sql = new StringBuilder ("UPDATE I_GLJournal ") diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportInOutConfirm.java b/org.adempiere.base.process/src/org/compiere/process/ImportInOutConfirm.java index a3b4ef52d3..dbce76bcf3 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportInOutConfirm.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportInOutConfirm.java @@ -139,6 +139,7 @@ public class ImportInOutConfirm extends SvrProcess /*********************************************************************/ PreparedStatement pstmt = null; + ResultSet rs = null; sql = new StringBuilder ("SELECT * FROM I_InOutLineConfirm ") .append("WHERE I_IsImported='N'").append (clientCheck) .append(" ORDER BY I_InOutLineConfirm_ID"); @@ -146,7 +147,7 @@ public class ImportInOutConfirm extends SvrProcess try { pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { X_I_InOutLineConfirm importLine = new X_I_InOutLineConfirm (getCtx(), rs, get_TrxName()); @@ -176,22 +177,15 @@ public class ImportInOutConfirm extends SvrProcess } } } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { 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; } StringBuilder msgreturn = new StringBuilder("@Updated@ #").append(no); diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportInventory.java b/org.adempiere.base.process/src/org/compiere/process/ImportInventory.java index 1b499163d0..31ac613127 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportInventory.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportInventory.java @@ -227,7 +227,6 @@ public class ImportInventory extends SvrProcess if (no != 0) log.warning ("No Location=" + no); - // Set M_Warehouse_ID sql = new StringBuilder ("UPDATE I_Inventory i ") .append("SET M_Warehouse_ID=(SELECT M_Warehouse_ID FROM M_Locator l WHERE i.M_Locator_ID=l.M_Locator_ID) ") @@ -243,6 +242,14 @@ public class ImportInventory extends SvrProcess if (no != 0) log.warning ("No Warehouse=" + no); + // IDEMPIERE-590 do not allow locator/wh from different org + sql = new StringBuilder ("UPDATE I_Inventory ") + .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Locator not from Org, ' ") + .append("WHERE AD_Org_ID <> (SELECT AD_Org_ID FROM M_Warehouse WHERE M_Warehouse_ID = I_Inventory.M_Warehouse_ID") + .append(" AND I_IsImported<>'Y'").append (clientCheck).append(" )"); + no = DB.executeUpdate (sql.toString (), get_TrxName()); + if (no != 0) + log.warning ("Locator not from Org=" + no); // Product sql = new StringBuilder ("UPDATE I_Inventory i ") diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportInvoice.java b/org.adempiere.base.process/src/org/compiere/process/ImportInvoice.java index c3cd8010c7..f9547e721a 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportInvoice.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportInvoice.java @@ -483,10 +483,12 @@ public class ImportInvoice extends SvrProcess // Go through Invoice Records w/o C_BPartner_ID sql = new StringBuilder ("SELECT * FROM I_Invoice ") .append("WHERE I_IsImported='N' AND C_BPartner_ID IS NULL").append (clientCheck); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery (); + pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); + rs = pstmt.executeQuery (); while (rs.next ()) { X_I_Invoice imp = new X_I_Invoice (getCtx(), rs, get_TrxName()); @@ -593,14 +595,18 @@ public class ImportInvoice extends SvrProcess } imp.save (); } // for all new BPartners - rs.close (); - pstmt.close (); // } catch (SQLException e) { log.log(Level.SEVERE, "CreateBP", e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } sql = new StringBuilder ("UPDATE I_Invoice ") .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No BPartner, ' ") .append("WHERE C_BPartner_ID IS NULL") @@ -622,8 +628,8 @@ public class ImportInvoice extends SvrProcess .append(" ORDER BY C_BPartner_ID, C_BPartner_Location_ID, I_Invoice_ID"); try { - PreparedStatement pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery (); + pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); + rs = pstmt.executeQuery (); // Group Change int oldC_BPartner_ID = 0; int oldC_BPartner_Location_ID = 0; @@ -751,13 +757,17 @@ public class ImportInvoice extends SvrProcess } invoice.saveEx(); } - rs.close(); - pstmt.close(); } catch (Exception e) { log.log(Level.SEVERE, "CreateInvoice", e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Set Error to indicator to not imported sql = new StringBuilder ("UPDATE I_Invoice ") diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportOrder.java b/org.adempiere.base.process/src/org/compiere/process/ImportOrder.java index 08ecf97f96..25ae8d22bb 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportOrder.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportOrder.java @@ -499,10 +499,12 @@ public class ImportOrder extends SvrProcess // Go through Order Records w/o C_BPartner_ID sql = new StringBuilder ("SELECT * FROM I_Order ") .append("WHERE I_IsImported='N' AND C_BPartner_ID IS NULL").append (clientCheck); + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery (); + pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); + rs = pstmt.executeQuery (); while (rs.next ()) { X_I_Order imp = new X_I_Order (getCtx (), rs, get_TrxName()); @@ -610,14 +612,18 @@ public class ImportOrder extends SvrProcess } imp.save (); } // for all new BPartners - rs.close (); - pstmt.close (); // } catch (SQLException e) { log.log(Level.SEVERE, "BP - " + sql.toString(), e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } sql = new StringBuilder ("UPDATE I_Order ") .append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No BPartner, ' ") .append("WHERE C_BPartner_ID IS NULL") @@ -639,8 +645,8 @@ public class ImportOrder extends SvrProcess .append(" ORDER BY C_BPartner_ID, BillTo_ID, C_BPartner_Location_ID, I_Order_ID"); try { - PreparedStatement pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery (); + pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); + rs = pstmt.executeQuery (); // int oldC_BPartner_ID = 0; int oldBillTo_ID = 0; @@ -779,13 +785,17 @@ public class ImportOrder extends SvrProcess } order.saveEx(); } - rs.close(); - pstmt.close(); } catch (Exception e) { log.log(Level.SEVERE, "Order - " + sql.toString(), e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Set Error to indicator to not imported sql = new StringBuilder ("UPDATE I_Order ") diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportPayment.java b/org.adempiere.base.process/src/org/compiere/process/ImportPayment.java index 2064eac3d9..eccf0f60fd 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportPayment.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportPayment.java @@ -413,11 +413,12 @@ public class ImportPayment extends SvrProcess MBankAccount account = null; PreparedStatement pstmt = null; + ResultSet rs = null; int noInsert = 0; try { pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { @@ -512,18 +513,17 @@ public class ImportPayment extends SvrProcess } } - - // Close database connection - rs.close(); - pstmt.close(); - rs = null; - pstmt = null; - } catch(Exception e) { log.log(Level.SEVERE, sql.toString(), e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Set Error to indicator to not imported sql = new StringBuilder ("UPDATE I_Payment ") diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportProduct.java b/org.adempiere.base.process/src/org/compiere/process/ImportProduct.java index 884b94f9c5..be195a83a9 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportProduct.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportProduct.java @@ -385,20 +385,26 @@ public class ImportProduct extends SvrProcess implements ImportProcess // Get Default Tax Category int C_TaxCategory_ID = 0; + PreparedStatement pstmt = null; + ResultSet rs = null; try { StringBuilder dbpst = new StringBuilder("SELECT C_TaxCategory_ID FROM C_TaxCategory WHERE IsDefault='Y'").append(clientCheck); - PreparedStatement pstmt = DB.prepareStatement(dbpst.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(dbpst.toString(), get_TrxName()); + rs = pstmt.executeQuery(); if (rs.next()) C_TaxCategory_ID = rs.getInt(1); - rs.close(); - pstmt.close(); } catch (SQLException e) { throw new Exception ("TaxCategory", e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } log.fine("C_TaxCategory_ID=" + C_TaxCategory_ID); ModelValidationEngine.get().fireImportValidate(this, null, null, ImportValidator.TIMING_AFTER_VALIDATE); @@ -415,6 +421,8 @@ public class ImportProduct extends SvrProcess implements ImportProcess log.fine("start inserting/updating ..."); sql = new StringBuilder ("SELECT * FROM I_Product WHERE I_IsImported='N'") .append(clientCheck); + PreparedStatement pstmt_setImported = null; + PreparedStatement pstmt_insertProductPO = null; try { /* Insert Product from Import @@ -468,7 +476,7 @@ public class ImportProduct extends SvrProcess implements ImportProcess (sqlt, get_TrxName()); */ // Insert Product from Import - PreparedStatement pstmt_insertProductPO = DB.prepareStatement + pstmt_insertProductPO = DB.prepareStatement ("INSERT INTO M_Product_PO (M_Product_ID,C_BPartner_ID, " + "AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy," + "IsCurrentVendor,C_UOM_ID,C_Currency_ID,UPC," @@ -487,13 +495,13 @@ public class ImportProduct extends SvrProcess implements ImportProcess + "WHERE I_Product_ID=?", get_TrxName()); // Set Imported = Y - PreparedStatement pstmt_setImported = DB.prepareStatement + pstmt_setImported = DB.prepareStatement ("UPDATE I_Product SET I_IsImported='Y', M_Product_ID=?, " + "Updated=SysDate, Processed='Y' WHERE I_Product_ID=?", get_TrxName()); // - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); + rs = pstmt.executeQuery(); while (rs.next()) { X_I_Product imp = new X_I_Product(getCtx(), rs, get_TrxName()); @@ -558,7 +566,11 @@ public class ImportProduct extends SvrProcess implements ImportProcess DB.executeUpdate(sql0.toString(), get_TrxName()); continue; } - pstmt_updateProduct.close(); + finally + { + DB.close(pstmt_updateProduct); + pstmt_updateProduct = null; + } } // Do we have PO Info @@ -604,7 +616,11 @@ public class ImportProduct extends SvrProcess implements ImportProcess DB.executeUpdate(sql0.toString(), get_TrxName()); continue; } - pstmt_updateProductPO.close(); + finally + { + DB.close(pstmt_updateProductPO); + pstmt_updateProductPO = null; + } } if (no == 0) // Insert PO { @@ -657,20 +673,19 @@ public class ImportProduct extends SvrProcess implements ImportProcess // commitEx(); } // for all I_Product - rs.close(); - pstmt.close(); - - // - // pstmt_insertProduct.close(); - // pstmt_updateProduct.close(); - pstmt_insertProductPO.close(); - // pstmt_updateProductPO.close(); - pstmt_setImported.close(); - // } catch (SQLException e) { } + finally + { + DB.close(rs, pstmt); + rs = null;pstmt = null; + DB.close(pstmt_insertProductPO); + pstmt_insertProductPO = null; + DB.close(pstmt_setImported); + pstmt_setImported = null; + } // Set Error to indicator to not imported sql = new StringBuilder ("UPDATE I_Product ") diff --git a/org.adempiere.base.process/src/org/compiere/process/ImportReportLine.java b/org.adempiere.base.process/src/org/compiere/process/ImportReportLine.java index f93ef38233..8f6ec98939 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportReportLine.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportReportLine.java @@ -265,6 +265,9 @@ public class ImportReportLine extends SvrProcess .append("FROM I_ReportLine ") .append("WHERE I_IsImported='N' AND PA_ReportLine_ID IS NULL") .append(" AND I_IsImported='N'").append(clientCheck); + PreparedStatement pstmt_insertLine = null; + PreparedStatement pstmt = null; + ResultSet rs = null; try { // Insert ReportLine @@ -283,10 +286,10 @@ public class ImportReportLine extends SvrProcess .append("WHERE PA_ReportLineSet_ID=? AND Name=? ") // #2..3 //jz + clientCheck, get_TrxName()); .append(clientCheck).append(")"); - PreparedStatement pstmt_insertLine = DB.prepareStatement(dbpst.toString(), get_TrxName()); + pstmt_insertLine = DB.prepareStatement(dbpst.toString(), get_TrxName()); - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); + rs = pstmt.executeQuery(); while (rs.next()) { int PA_ReportLineSet_ID = rs.getInt(1); @@ -311,15 +314,18 @@ public class ImportReportLine extends SvrProcess continue; } } - rs.close(); - pstmt.close(); - // - pstmt_insertLine.close(); } catch (SQLException e) { log.log(Level.SEVERE, "Create ReportLine", e); } + finally + { + DB.close(rs, pstmt); + rs = null;pstmt = null; + DB.close(pstmt_insertLine); + pstmt_insertLine = null; + } // Set PA_ReportLine_ID (for newly created) sql = new StringBuilder ("UPDATE I_ReportLine i ") @@ -356,6 +362,9 @@ public class ImportReportLine extends SvrProcess .append("WHERE PA_ReportLine_ID IS NOT NULL") .append(" AND I_IsImported='N'").append(clientCheck); + PreparedStatement pstmt_insertSource = null; + PreparedStatement pstmt_deleteSource = null; + PreparedStatement pstmt_setImported = null; try { // Insert ReportSource @@ -370,7 +379,7 @@ public class ImportReportLine extends SvrProcess .append("WHERE I_ReportLine_ID=?") .append(" AND I_IsImported='N'") .append(clientCheck); - PreparedStatement pstmt_insertSource = DB.prepareStatement(dbpst.toString(), get_TrxName()); + pstmt_insertSource = DB.prepareStatement(dbpst.toString(), get_TrxName()); // Update ReportSource //jz @@ -391,17 +400,17 @@ public class ImportReportLine extends SvrProcess .append("WHERE C_ElementValue_ID IS NULL") .append(" AND PA_ReportSource_ID=?") .append(clientCheck); - PreparedStatement pstmt_deleteSource = DB.prepareStatement(dbpst.toString(), get_TrxName()); + pstmt_deleteSource = DB.prepareStatement(dbpst.toString(), get_TrxName()); //End afalcone 22/02/2007 - F.R. [ 1642250 ] Import ReportLine / Very Slow Reports // Set Imported = Y - PreparedStatement pstmt_setImported = DB.prepareStatement + pstmt_setImported = DB.prepareStatement ("UPDATE I_ReportLine SET I_IsImported='Y'," + " PA_ReportSource_ID=?, " + " Updated=SysDate, Processed='Y' WHERE I_ReportLine_ID=?", get_TrxName()); - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); + rs = pstmt.executeQuery(); while (rs.next()) { int I_ReportLine_ID = rs.getInt(1); @@ -461,7 +470,11 @@ public class ImportReportLine extends SvrProcess DB.executeUpdate(sql.toString(), get_TrxName()); continue; } - pstmt_updateSource.close(); + finally + { + DB.close(pstmt_updateSource); + pstmt_updateSource = null; + } } // update source // Set Imported to Y @@ -481,17 +494,19 @@ public class ImportReportLine extends SvrProcess commitEx(); } - rs.close(); - pstmt.close(); - // - pstmt_insertSource.close(); - //jz pstmt_updateSource.close(); - pstmt_setImported.close(); - // } catch (SQLException e) { } + finally + { + DB.close(rs, pstmt); + rs = null;pstmt = null; + DB.close(pstmt_insertSource); + pstmt_insertSource = null; + DB.close(pstmt_setImported); + pstmt_setImported = null; + } // Set Error to indicator to not imported sql = new StringBuilder ("UPDATE I_ReportLine ") diff --git a/org.adempiere.base.process/src/org/compiere/process/InOutGenerate.java b/org.adempiere.base.process/src/org/compiere/process/InOutGenerate.java index 629b8e4b7c..6d9aefc6fc 100644 --- a/org.adempiere.base.process/src/org/compiere/process/InOutGenerate.java +++ b/org.adempiere.base.process/src/org/compiere/process/InOutGenerate.java @@ -209,9 +209,10 @@ public class InOutGenerate extends SvrProcess private String generate (PreparedStatement pstmt) { + ResultSet rs = null; try { - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) // Order { MOrder order = new MOrder (getCtx(), rs, get_TrxName()); @@ -391,22 +392,15 @@ public class InOutGenerate extends SvrProcess } m_line += 1000; } // while order - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, m_sql.toString(), e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } completeShipment(); diff --git a/org.adempiere.base.process/src/org/compiere/process/InventoryCountCreate.java b/org.adempiere.base.process/src/org/compiere/process/InventoryCountCreate.java index 7dcedb7afc..9cf5ae112f 100644 --- a/org.adempiere.base.process/src/org/compiere/process/InventoryCountCreate.java +++ b/org.adempiere.base.process/src/org/compiere/process/InventoryCountCreate.java @@ -200,6 +200,7 @@ public class InventoryCountCreate extends SvrProcess // int count = 0; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); @@ -213,7 +214,7 @@ public class InventoryCountCreate extends SvrProcess pstmt.setString(index++, p_ProductValue.toUpperCase()); if (!p_DeleteOld) pstmt.setInt(index++, p_M_Inventory_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { int M_Product_ID = rs.getInt(1); @@ -235,22 +236,15 @@ public class InventoryCountCreate extends SvrProcess M_AttributeSetInstance_ID, QtyOnHand, M_AttributeSet_ID); } } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { 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; } @@ -354,17 +348,28 @@ public class InventoryCountCreate extends SvrProcess StringBuilder retString = new StringBuilder(); String sql = " SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category"; final Vector categories = new Vector(100); - Statement stmt = DB.createStatement(); - ResultSet rs = stmt.executeQuery(sql); - while (rs.next()) { - if(rs.getInt(1)==productCategoryId) { - subTreeRootParentId = rs.getInt(2); + Statement stmt = null; + ResultSet rs = null; + try + { + stmt = DB.createStatement(); + rs = stmt.executeQuery(sql); + while (rs.next()) { + if(rs.getInt(1)==productCategoryId) { + subTreeRootParentId = rs.getInt(2); + } + categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2))); } - categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2))); + retString.append(getSubCategoriesString(productCategoryId, categories, subTreeRootParentId)); + } catch (SQLException e) + { + throw e; + } + finally + { + DB.close(rs, stmt); + rs = null;stmt = null; } - retString.append(getSubCategoriesString(productCategoryId, categories, subTreeRootParentId)); - rs.close(); - stmt.close(); return retString.toString(); } diff --git a/org.adempiere.base.process/src/org/compiere/process/InventoryCountUpdate.java b/org.adempiere.base.process/src/org/compiere/process/InventoryCountUpdate.java index e75cc51f0d..4cfcb5428b 100644 --- a/org.adempiere.base.process/src/org/compiere/process/InventoryCountUpdate.java +++ b/org.adempiere.base.process/src/org/compiere/process/InventoryCountUpdate.java @@ -136,11 +136,12 @@ public class InventoryCountUpdate extends SvrProcess // String sql = "SELECT * FROM M_InventoryLine WHERE M_Inventory_ID=? AND M_AttributeSetInstance_ID=0"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, p_M_Inventory_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MInventoryLine il = new MInventoryLine (getCtx(), rs, get_TrxName()); @@ -168,22 +169,15 @@ public class InventoryCountUpdate extends SvrProcess if (il.save()) no++; } - 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.process/src/org/compiere/process/InvoiceGenerate.java b/org.adempiere.base.process/src/org/compiere/process/InvoiceGenerate.java index 2910b72b27..b92bff7e1c 100644 --- a/org.adempiere.base.process/src/org/compiere/process/InvoiceGenerate.java +++ b/org.adempiere.base.process/src/org/compiere/process/InvoiceGenerate.java @@ -191,9 +191,10 @@ public class InvoiceGenerate extends SvrProcess */ private String generate (PreparedStatement pstmt) { + ResultSet rs = null; try { - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MOrder order = new MOrder (getCtx(), rs, get_TrxName()); @@ -320,22 +321,15 @@ public class InvoiceGenerate extends SvrProcess } } // complete Order } // for all orders - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, "", e); } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } completeInvoice(); diff --git a/org.adempiere.base.process/src/org/compiere/process/InvoiceWriteOff.java b/org.adempiere.base.process/src/org/compiere/process/InvoiceWriteOff.java index 68e175257e..a0f1b9d3c9 100644 --- a/org.adempiere.base.process/src/org/compiere/process/InvoiceWriteOff.java +++ b/org.adempiere.base.process/src/org/compiere/process/InvoiceWriteOff.java @@ -170,32 +170,26 @@ public class InvoiceWriteOff extends SvrProcess // int counter = 0; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { if (writeOff(rs.getInt(1), rs.getString(2), rs.getTimestamp(3), rs.getInt(4), rs.getBigDecimal(6))) counter++; } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { 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; } // final diff --git a/org.adempiere.base.process/src/org/compiere/process/M_PriceList_Create.java b/org.adempiere.base.process/src/org/compiere/process/M_PriceList_Create.java index 4f2dfc2491..324e9181e0 100644 --- a/org.adempiere.base.process/src/org/compiere/process/M_PriceList_Create.java +++ b/org.adempiere.base.process/src/org/compiere/process/M_PriceList_Create.java @@ -42,7 +42,7 @@ import org.compiere.util.ValueNamePair; * @version $Id: M_PriceList_Create,v 1.0 2005/10/09 22:19:00 * globalqss Exp $ * @author Carlos Ruiz (globalqss) - * Make T_Selection tables permanent + * Make T_Selection tables permanent */ public class M_PriceList_Create extends SvrProcess { @@ -92,9 +92,9 @@ public class M_PriceList_Create extends SvrProcess { int toti = 0; @SuppressWarnings("unused") int totd = 0; - int V_temp; + int v_temp; int v_NextNo = 0; - StringBuilder Message = new StringBuilder(); + StringBuilder message = new StringBuilder(); // //Checking Prerequisites //PO Prices must exists @@ -171,49 +171,52 @@ public class M_PriceList_Create extends SvrProcess { sql.append(" AND IsCurrentVendor='Y' AND IsActive='Y' "); sql.append(" GROUP BY M_Product_ID ").append(" HAVING COUNT(*) > 1 ) "); - PreparedStatement Cur_Duplicates = null; - Cur_Duplicates = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet dupl = Cur_Duplicates.executeQuery(); - while (dupl.next()) { - sql = new StringBuilder("SELECT M_Product_ID ,C_BPartner_ID "); - sql.append(" FROM M_Product_PO WHERE IsCurrentVendor = 'Y' "); - sql.append(" AND IsActive = 'Y' "); - sql.append(" AND M_Product_ID = ").append(dupl.getInt("M_Product_ID")); - sql.append(" ORDER BY PriceList DESC"); + PreparedStatement stmtDupl = null; + ResultSet rsDupl = null; + PreparedStatement stmtVendors = null; + ResultSet rsVend = null; + try { + stmtDupl = DB.prepareStatement(sql.toString(), get_TrxName()); + rsDupl = stmtDupl.executeQuery(); + while (rsDupl.next()) { + sql = new StringBuilder("SELECT M_Product_ID ,C_BPartner_ID "); + sql.append(" FROM M_Product_PO WHERE IsCurrentVendor = 'Y' "); + sql.append(" AND IsActive = 'Y' "); + sql.append(" AND M_Product_ID = ").append(rsDupl.getInt("M_Product_ID")); + sql.append(" ORDER BY PriceList DESC"); - PreparedStatement Cur_Vendors = null; - Cur_Vendors = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet Vend = Cur_Vendors.executeQuery(); + stmtVendors = DB.prepareStatement(sql.toString(), get_TrxName()); + rsVend = stmtVendors.executeQuery(); - // - // Leave First - // - Vend.next(); - - while (Vend.next()) { - sqlupd = new StringBuilder("UPDATE M_Product_PO "); - sqlupd.append(" SET IsCurrentVendor = 'N' "); - sqlupd.append(" WHERE M_Product_ID= ").append(Vend.getInt("M_Product_ID")); - sqlupd.append(" AND C_BPartner_ID= "); - sqlupd.append(Vend.getInt("C_BPartner_ID")); + // + // Leave First + // + rsVend.next(); - cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName()); - if (cntu == -1) - raiseError( - "Update IsCurrentVendor to N of M_Product_PO for a M_Product_ID and C_BPartner_ID ingresed", - sqlupd.toString()); - totu += cntu; - log.fine("Updated " + cntu); - + while (rsVend.next()) { + sqlupd = new StringBuilder("UPDATE M_Product_PO "); + sqlupd.append(" SET IsCurrentVendor = 'N' "); + sqlupd.append(" WHERE M_Product_ID= ").append(rsVend.getInt("M_Product_ID")); + sqlupd.append(" AND C_BPartner_ID= "); + sqlupd.append(rsVend.getInt("C_BPartner_ID")); + + cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName()); + if (cntu == -1) + raiseError( + "Update IsCurrentVendor to N of M_Product_PO for a M_Product_ID and C_BPartner_ID ingresed", + sqlupd.toString()); + totu += cntu; + log.fine("Updated " + cntu); + } } - Vend.close(); - Cur_Vendors.close(); - Cur_Vendors = null; - + } catch (SQLException e) { + throw e; + } finally { + DB.close(rsDupl, stmtDupl); + rsDupl = null; stmtDupl = null; + DB.close(rsVend, stmtVendors); + rsVend = null; stmtVendors = null; } - dupl.close(); - Cur_Duplicates.close(); - Cur_Duplicates = null; // DB.commit(true, get_TrxName()); @@ -228,7 +231,7 @@ public class M_PriceList_Create extends SvrProcess { if (cntd == -1) raiseError(" DELETE M_ProductPrice ", sqldel.toString()); totd += cntd; - Message = new StringBuilder("@Deleted@=").append(cntd).append(" - "); + message = new StringBuilder("@Deleted@=").append(cntd).append(" - "); log.fine("Deleted " + cntd); } // @@ -243,476 +246,486 @@ public class M_PriceList_Create extends SvrProcess { sql.append(" AND p.C_Currency_ID = c.C_Currency_ID"); sql.append(" AND v.M_PriceList_Version_ID = ").append(p_PriceList_Version_ID); - PreparedStatement curgen = null; - curgen = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet v = curgen.executeQuery(); - while (v.next()) { - // - // For All Discount Lines in Sequence - // - sql = new StringBuilder("SELECT m_discountschemaline_id"); - sql.append(",ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby"); - sql.append(",m_discountschema_id,seqno,m_product_category_id,c_bpartner_id,m_product_id"); - sql.append(",conversiondate,list_base,list_addamt,list_discount,list_rounding,list_minamt"); - sql.append(",list_maxamt,list_fixed,std_base,std_addamt,std_discount,std_rounding"); - sql.append(",std_minamt,std_maxamt,std_fixed,limit_base,limit_addamt,limit_discount"); - sql.append(",limit_rounding,limit_minamt,limit_maxamt,limit_fixed,group1,group2,c_conversiontype_id"); - sql.append(" FROM M_DiscountSchemaLine"); - sql.append(" WHERE M_DiscountSchema_ID="); - sql.append(v.getInt("M_DiscountSchema_ID")); - sql.append(" AND IsActive='Y' ORDER BY SeqNo"); - - PreparedStatement Cur_DiscountLine = null; - Cur_DiscountLine = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet dl = Cur_DiscountLine.executeQuery(); - while (dl.next()) { + PreparedStatement stmtCurgen = null; + ResultSet rsCurgen = null; + PreparedStatement stmtDiscountLine = null; + ResultSet rsDiscountLine = null; + CPreparedStatement stmt = null; + PreparedStatement pstmt = null; + try { + stmtCurgen = DB.prepareStatement(sql.toString(), get_TrxName()); + rsCurgen = stmtCurgen.executeQuery(); + while (rsCurgen.next()) { // - //Clear Temporary Table + // For All Discount Lines in Sequence // - sqldel = new StringBuilder("DELETE FROM T_Selection WHERE AD_PInstance_ID="); - sqldel.append(m_AD_PInstance_ID); - + sql = new StringBuilder("SELECT m_discountschemaline_id"); + sql.append(",ad_client_id,ad_org_id,isactive,created,createdby,updated,updatedby"); + sql.append(",m_discountschema_id,seqno,m_product_category_id,c_bpartner_id,m_product_id"); + sql.append(",conversiondate,list_base,list_addamt,list_discount,list_rounding,list_minamt"); + sql.append(",list_maxamt,list_fixed,std_base,std_addamt,std_discount,std_rounding"); + sql.append(",std_minamt,std_maxamt,std_fixed,limit_base,limit_addamt,limit_discount"); + sql.append(",limit_rounding,limit_minamt,limit_maxamt,limit_fixed,group1,group2,c_conversiontype_id"); + sql.append(" FROM M_DiscountSchemaLine"); + sql.append(" WHERE M_DiscountSchema_ID="); + sql.append(rsCurgen.getInt("M_DiscountSchema_ID")); + sql.append(" AND IsActive='Y' ORDER BY SeqNo"); + + stmtDiscountLine = DB.prepareStatement(sql.toString(), get_TrxName()); + rsDiscountLine = stmtDiscountLine.executeQuery(); + while (rsDiscountLine.next()) { + // + //Clear Temporary Table + // + sqldel = new StringBuilder("DELETE FROM T_Selection WHERE AD_PInstance_ID="); + sqldel.append(m_AD_PInstance_ID); + + cntd = DB.executeUpdate(sqldel.toString(), get_TrxName()); + if (cntd == -1) + raiseError(" DELETE T_Selection ", sqldel.toString()); + totd += cntd; + log.fine("Deleted " + cntd); + // + //Create Selection in temporary table + // + v_temp = rsCurgen.getInt("M_PriceList_Version_Base_ID"); + String dl_Group1 = rsDiscountLine.getString("Group1"); + String dl_Group2 = rsDiscountLine.getString("Group2"); + if (rsCurgen.wasNull()) { + // + //Create Selection from M_Product_PO + // + sqlins.append("INSERT INTO T_Selection (AD_PInstance_ID, T_Selection_ID) "); + sqlins.append( " SELECT DISTINCT ").append(m_AD_PInstance_ID).append(", po.M_Product_ID "); + sqlins.append(" FROM M_Product p, M_Product_PO po"); + sqlins.append(" WHERE p.M_Product_ID=po.M_Product_ID "); + sqlins.append(" AND (p.AD_Client_ID=").append(rsCurgen.getInt("AD_Client_ID")).append(" OR p.AD_Client_ID=0)"); + sqlins.append(" AND p.IsActive='Y' AND po.IsActive='Y' AND po.IsCurrentVendor='Y' "); + // + //Optional Restrictions + // + // globalqss - detected bug, JDBC returns zero for null values + // so we're going to use NULLIF(value, 0) + sqlins.append(" AND (NULLIF(").append(rsDiscountLine.getInt("M_Product_Category_ID")).append(",0) IS NULL"); + sqlins.append(" OR p.M_Product_Category_ID IN (").append(getSubCategoryWhereClause(rsDiscountLine.getInt("M_Product_Category_ID"))) + .append("))"); + if(dl_Group1 != null) + sqlins.append(" AND (p.Group1=?)"); + if (dl_Group2 != null) + sqlins.append(" AND (p.Group2=?)"); + sqlins.append(" AND (NULLIF(").append(rsDiscountLine.getInt("C_BPartner_ID")).append(",0) IS NULL "); + sqlins.append(" OR po.C_BPartner_ID=").append(rsDiscountLine.getInt("C_BPartner_ID")).append(")"); + sqlins.append(" AND (NULLIF(").append(rsDiscountLine.getInt("M_Product_ID")).append(",0) IS NULL "); + sqlins.append(" OR p.M_Product_ID=").append(rsDiscountLine.getInt("M_Product_ID")).append(")"); + + stmt = DB.prepareStatement(sqlins.toString(), get_TrxName()); + + int i = 1; + + if (dl_Group1!=null) + stmt.setString(i++, dl_Group1); + if (dl_Group2!=null) + stmt.setString(i++, dl_Group2); + + cnti = stmt.executeUpdate(); + + if (cnti == -1) + raiseError(" INSERT INTO T_Selection ", sqlins.toString()); + toti += cnti; + log.fine("Inserted " + cnti); + + } else { + // + // Create Selection from existing PriceList + // + sqlins = new StringBuilder("INSERT INTO T_Selection (AD_PInstance_ID, T_Selection_ID)"); + sqlins.append(" SELECT DISTINCT ").append(m_AD_PInstance_ID).append(", p.M_Product_ID"); + sqlins.append(" FROM M_Product p, M_ProductPrice pp"); + sqlins.append(" WHERE p.M_Product_ID=pp.M_Product_ID"); + sqlins.append(" AND pp.M_PriceList_Version_ID = ").append(rsCurgen.getInt("M_PriceList_Version_Base_ID")); + sqlins.append(" AND p.IsActive='Y' AND pp.IsActive='Y'"); + // + //Optional Restrictions + // + sqlins.append(" AND (NULLIF(").append(rsDiscountLine.getInt("M_Product_Category_ID")).append(",0) IS NULL"); + sqlins.append(" OR p.M_Product_Category_ID IN (").append(getSubCategoryWhereClause(rsDiscountLine.getInt("M_Product_Category_ID"))) + .append("))"); + if(dl_Group1 != null) + sqlins.append(" AND (p.Group1=?)"); + if (dl_Group2 != null) + sqlins.append(" AND (p.Group2=?)"); + sqlins.append(" AND (NULLIF(").append(rsDiscountLine.getInt("C_BPartner_ID")).append(",0) IS NULL OR EXISTS "); + sqlins.append("(SELECT m_product_id,c_bpartner_id,ad_client_id,ad_org_id,isactive"); + sqlins.append(",created,createdby,updated,updatedby,iscurrentvendor,c_uom_id"); + sqlins.append(",c_currency_id,pricelist,pricepo,priceeffective,pricelastpo"); + sqlins.append(",pricelastinv,vendorproductno,upc,vendorcategory,discontinued"); + sqlins.append(",discontinuedby,order_min,order_pack,costperorder"); + sqlins.append(",deliverytime_promised,deliverytime_actual,qualityrating"); + sqlins.append(",royaltyamt,group1,group2"); + sqlins.append(",manufacturer FROM M_Product_PO po WHERE po.M_Product_ID=p.M_Product_ID"); + sqlins.append(" AND po.C_BPartner_ID=").append(rsDiscountLine.getInt("C_BPartner_ID")).append("))"); + sqlins.append(" AND (NULLIF(").append(rsDiscountLine.getInt("M_Product_ID")).append(",0) IS NULL "); + sqlins.append(" OR p.M_Product_ID=").append(rsDiscountLine.getInt("M_Product_ID")).append(")"); + + + stmt = DB.prepareStatement(sqlins.toString(), get_TrxName()); + int i = 1; + + if (dl_Group1!=null) + stmt.setString(i++, dl_Group1); + if (dl_Group2!=null) + stmt.setString(i++, dl_Group2); + + cnti = stmt.executeUpdate(); + if (cnti == -1) + raiseError( + " INSERT INTO T_Selection from existing PriceList", + sqlins.toString()); + toti += cnti; + log.fine("Inserted " + cnti); + + } + + message.append("@Selected@=").append(cnti); + + // + //Delete Prices in Selection, so that we can insert + // + v_temp = rsCurgen.getInt("M_PriceList_Version_Base_ID"); + if (rsCurgen.wasNull() || v_temp != p_PriceList_Version_ID) { + + sqldel = new StringBuilder("DELETE M_ProductPrice pp"); + sqldel.append(" WHERE pp.M_PriceList_Version_ID = "); + sqldel.append(p_PriceList_Version_ID); + sqldel.append(" AND EXISTS (SELECT t_selection_id FROM T_Selection s WHERE pp.M_Product_ID=s.T_Selection_ID"); + sqldel.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")"); + + cntd = DB.executeUpdate(sqldel.toString(), get_TrxName()); + if (cntd == -1) + raiseError(" DELETE M_ProductPrice ", sqldel.toString()); + totd += cntd; + message.append(", @Deleted@=").append(cntd); + log.fine("Deleted " + cntd); + } + + // + // Copy (Insert) Prices + // + v_temp = rsCurgen.getInt("M_PriceList_Version_Base_ID"); + if (v_temp == p_PriceList_Version_ID) + // + // We have Prices already + // + ; + else if (rsCurgen.wasNull()) + // + //Copy and Convert from Product_PO + // + { + sqlins = new StringBuilder("INSERT INTO M_ProductPrice "); + sqlins.append("(M_PriceList_Version_ID"); + sqlins.append(" ,M_Product_ID "); + sqlins.append(" ,AD_Client_ID"); + sqlins.append(" , AD_Org_ID"); + sqlins.append(" , IsActive"); + sqlins.append(" , Created"); + sqlins.append(" , CreatedBy"); + sqlins.append(" , Updated"); + sqlins.append(" , UpdatedBy"); + sqlins.append(" , PriceList"); + sqlins.append(" , PriceStd"); + sqlins.append(" , PriceLimit) "); + sqlins.append("SELECT "); + sqlins.append(p_PriceList_Version_ID); + sqlins.append(" ,po.M_Product_ID "); + sqlins.append(" ,"); + sqlins.append(rsCurgen.getInt("AD_Client_ID")); + sqlins.append(" ,"); + sqlins.append(rsCurgen.getInt("AD_Org_ID")); + sqlins.append(" ,'Y'"); + sqlins.append(" ,SysDate,"); + sqlins.append(rsCurgen.getInt("UpdatedBy")); + sqlins.append(" ,SysDate,"); + sqlins.append(rsCurgen.getInt("UpdatedBy")); + // + //Price List + // + sqlins.append(" ,COALESCE(currencyConvert(po.PriceList, po.C_Currency_ID, "); + sqlins.append(rsCurgen.getInt("C_Currency_ID")); + sqlins.append(", ? , "); + sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID")); + sqlins.append(", "); + sqlins.append(rsCurgen.getInt("AD_Client_ID")); + sqlins.append(", "); + sqlins.append(rsCurgen.getInt("AD_Org_ID")); + sqlins.append("),0)"); + + // Price Std + sqlins.append(" ,COALESCE(currencyConvert(po.PriceList, po.C_Currency_ID, "); + sqlins.append(rsCurgen.getInt("C_Currency_ID")); + sqlins.append(", ? , "); + sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID")); + sqlins.append(", "); + sqlins.append(rsCurgen.getInt("AD_Client_ID")); + sqlins.append(", "); + sqlins.append(rsCurgen.getInt("AD_Org_ID")); + sqlins.append("),0)"); + + // Price Limit + sqlins.append(" ,COALESCE(currencyConvert(po.PricePO ,po.C_Currency_ID, "); + sqlins.append(rsCurgen.getInt("C_Currency_ID")); + sqlins.append(",? , "); + sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID")); + sqlins.append(", "); + sqlins.append(rsCurgen.getInt("AD_Client_ID")); + sqlins.append(", "); + sqlins.append(rsCurgen.getInt("AD_Org_ID")); + sqlins.append("),0)"); + sqlins.append(" FROM M_Product_PO po "); + sqlins.append(" WHERE EXISTS (SELECT * FROM T_Selection s WHERE po.M_Product_ID=s.T_Selection_ID"); + sqlins.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(") "); + sqlins.append(" AND po.IsCurrentVendor='Y' AND po.IsActive='Y'"); + + pstmt = DB.prepareStatement(sqlins.toString(), + ResultSet.TYPE_SCROLL_INSENSITIVE, + ResultSet.CONCUR_UPDATABLE, get_TrxName()); + pstmt.setTimestamp(1, rsDiscountLine.getTimestamp("ConversionDate")); + pstmt.setTimestamp(2, rsDiscountLine.getTimestamp("ConversionDate")); + pstmt.setTimestamp(3, rsDiscountLine.getTimestamp("ConversionDate")); + + cnti = pstmt.executeUpdate(); + if (cnti == -1) + raiseError( + " INSERT INTO T_Selection from existing PriceList", + sqlins.toString()); + toti += cnti; + log.fine("Inserted " + cnti); + } else { + // + //Copy and Convert from other PriceList_Version + // + sqlins = new StringBuilder("INSERT INTO M_ProductPrice "); + sqlins.append(" (M_PriceList_Version_ID, M_Product_ID,"); + sqlins.append(" AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,"); + sqlins.append(" PriceList, PriceStd, PriceLimit)"); + sqlins.append(" SELECT "); + sqlins.append(p_PriceList_Version_ID); + sqlins.append(", pp.M_Product_ID,"); + sqlins.append(rsCurgen.getInt("AD_Client_ID")); + sqlins.append(", "); + sqlins.append(rsCurgen.getInt("AD_Org_ID")); + sqlins.append(", 'Y', SysDate, "); + sqlins.append(rsCurgen.getInt("UpdatedBy")); + sqlins.append(", SysDate, "); + sqlins.append(rsCurgen.getInt("UpdatedBy")); + sqlins.append(" ,"); + // Price List + sqlins.append("COALESCE(currencyConvert(pp.PriceList, pl.C_Currency_ID, "); + sqlins.append(rsCurgen.getInt("C_Currency_ID")); + sqlins.append(", ?, "); + sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID")); + sqlins.append(", "); + sqlins.append(rsCurgen.getInt("AD_Client_ID")); + sqlins.append(", "); + sqlins.append(rsCurgen.getInt("AD_Org_ID")); + sqlins.append("),0),"); + // Price Std + sqlins.append("COALESCE(currencyConvert(pp.PriceStd,pl.C_Currency_ID, "); + sqlins.append(rsCurgen.getInt("C_Currency_ID")); + sqlins.append(" , ? , "); + sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID")); + sqlins.append(", "); + sqlins.append(rsCurgen.getInt("AD_Client_ID")); + sqlins.append(", "); + sqlins.append(rsCurgen.getInt("AD_Org_ID")); + sqlins.append("),0),"); + //Price Limit + sqlins.append(" COALESCE(currencyConvert(pp.PriceLimit,pl.C_Currency_ID, "); + sqlins.append(rsCurgen.getInt("C_Currency_ID")); + sqlins.append(" , ? , "); + sqlins.append(rsDiscountLine.getInt("C_ConversionType_ID")); + sqlins.append(", "); + sqlins.append(rsCurgen.getInt("AD_Client_ID")); + sqlins.append(", "); + sqlins.append(rsCurgen.getInt("AD_Org_ID")); + sqlins.append("),0)"); + sqlins.append(" FROM M_ProductPrice pp"); + sqlins.append(" INNER JOIN M_PriceList_Version plv ON (pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID)"); + sqlins.append(" INNER JOIN M_PriceList pl ON (plv.M_PriceList_ID=pl.M_PriceList_ID)"); + sqlins.append(" WHERE pp.M_PriceList_Version_ID="); + sqlins.append(rsCurgen.getInt("M_PriceList_Version_Base_ID")); + sqlins.append(" AND EXISTS (SELECT * FROM T_Selection s WHERE pp.M_Product_ID=s.T_Selection_ID"); + sqlins.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")"); + sqlins.append("AND pp.IsActive='Y'"); + + pstmt = DB.prepareStatement(sqlins.toString(), + ResultSet.TYPE_SCROLL_INSENSITIVE, + ResultSet.CONCUR_UPDATABLE, get_TrxName()); + pstmt.setTimestamp(1, rsDiscountLine.getTimestamp("ConversionDate")); + pstmt.setTimestamp(2, rsDiscountLine.getTimestamp("ConversionDate")); + pstmt.setTimestamp(3, rsDiscountLine.getTimestamp("ConversionDate")); + + cnti = pstmt.executeUpdate(); + + if (cnti == -1) + raiseError( + " INSERT INTO T_Selection from existing PriceList", + sqlins.toString()); + toti += cnti; + log.fine("Inserted " + cnti); + + } + message.append(", @Inserted@=").append(cnti); + // + // Calculation + // + sqlupd = new StringBuilder("UPDATE M_ProductPrice p "); + sqlupd.append(" SET PriceList = (DECODE( '"); + sqlupd.append(rsDiscountLine.getString("List_Base")); + sqlupd.append("', 'S', PriceStd, 'X', PriceLimit, PriceList)"); + sqlupd.append(" + ?) * (1 - ?/100), PriceStd = (DECODE('"); + sqlupd.append(rsDiscountLine.getString("Std_Base")); + sqlupd.append("', 'L', PriceList, 'X', PriceLimit, PriceStd) "); + sqlupd.append(" + ?) * (1 - ?/100), ").append(" PriceLimit = (DECODE('"); + sqlupd.append(rsDiscountLine.getString("Limit_Base")); + sqlupd.append("', 'L', PriceList, 'S', PriceStd, PriceLimit) "); + sqlupd.append(" + ?) * (1 - ? /100) "); + sqlupd.append(" WHERE M_PriceList_Version_ID = "); + sqlupd.append(p_PriceList_Version_ID); + sqlupd.append(" AND EXISTS (SELECT * FROM T_Selection s "); + sqlupd.append(" WHERE s.T_Selection_ID = p.M_Product_ID"); + sqlupd.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")"); + + PreparedStatement pstmu = DB.prepareStatement(sqlupd.toString(), + ResultSet.TYPE_SCROLL_INSENSITIVE, + ResultSet.CONCUR_UPDATABLE, get_TrxName()); + + pstmu.setDouble(1, rsDiscountLine.getDouble("List_AddAmt")); + pstmu.setDouble(2, rsDiscountLine.getDouble("List_Discount")); + pstmu.setDouble(3, rsDiscountLine.getDouble("Std_AddAmt")); + pstmu.setDouble(4, rsDiscountLine.getDouble("Std_Discount")); + pstmu.setDouble(5, rsDiscountLine.getDouble("Limit_AddAmt")); + pstmu.setDouble(6, rsDiscountLine.getDouble("Limit_Discount")); + + cntu = pstmu.executeUpdate(); + + if (cntu == -1) + raiseError("Update M_ProductPrice ", sqlupd.toString()); + totu += cntu; + log.fine("Updated " + cntu); + + // + //Rounding (AD_Reference_ID=155) + // + sqlupd = new StringBuilder("UPDATE M_ProductPrice p "); + sqlupd.append(" SET PriceList = DECODE('"); + sqlupd.append(rsDiscountLine.getString("List_Rounding")).append("',"); + sqlupd.append(" 'N', PriceList, "); + sqlupd.append(" '0', ROUND(PriceList, 0),"); //Even .00 + sqlupd.append(" 'D', ROUND(PriceList, 1),"); //Dime .10 + sqlupd.append(" 'T', ROUND(PriceList, -1), "); //Ten 10.00 + sqlupd.append(" '5', ROUND(PriceList*20,0)/20,"); //Nickle .05 + sqlupd.append(" 'Q', ROUND(PriceList*4,0)/4,"); //Quarter .25 + sqlupd.append(" '9', CASE"); //Whole 9 or 5 + sqlupd.append(" WHEN MOD(ROUND(PriceList),10)<=5 THEN ROUND(PriceList)+(5-MOD(ROUND(PriceList),10))"); + sqlupd.append(" WHEN MOD(ROUND(PriceList),10)>5 THEN ROUND(PriceList)+(9-MOD(ROUND(PriceList),10)) END,"); + sqlupd.append(" ROUND(PriceList, ").append(rsCurgen.getInt("StdPrecision")); + sqlupd.append(")),");//Currency + sqlupd.append(" PriceStd = DECODE('").append(rsDiscountLine.getString("Std_Rounding")); + sqlupd.append("',").append(" 'N', PriceStd, "); + sqlupd.append(" '0', ROUND(PriceStd, 0), "); //Even .00 + sqlupd.append(" 'D', ROUND(PriceStd, 1), "); //Dime .10 + sqlupd.append("'T', ROUND(PriceStd, -1),"); //Ten 10.00) + sqlupd.append("'5', ROUND(PriceStd*20,0)/20,"); //Nickle .05 + sqlupd.append("'Q', ROUND(PriceStd*4,0)/4,"); //Quarter .25 + sqlupd.append(" '9', CASE"); //Whole 9 or 5 + sqlupd.append(" WHEN MOD(ROUND(PriceStd),10)<=5 THEN ROUND(PriceStd)+(5-MOD(ROUND(PriceStd),10))"); + sqlupd.append(" WHEN MOD(ROUND(PriceStd),10)>5 THEN ROUND(PriceStd)+(9-MOD(ROUND(PriceStd),10)) END,"); + sqlupd.append("ROUND(PriceStd, ").append(rsCurgen.getInt("StdPrecision")).append(")),"); //Currency + sqlupd.append("PriceLimit = DECODE('"); + sqlupd.append(rsDiscountLine.getString("Limit_Rounding")).append("', "); + sqlupd.append(" 'N', PriceLimit, "); + sqlupd.append(" '0', ROUND(PriceLimit, 0), "); // Even .00 + sqlupd.append(" 'D', ROUND(PriceLimit, 1), "); // Dime .10 + sqlupd.append(" 'T', ROUND(PriceLimit, -1), "); // Ten 10.00 + sqlupd.append(" '5', ROUND(PriceLimit*20,0)/20, "); // Nickle .05 + sqlupd.append(" 'Q', ROUND(PriceLimit*4,0)/4, "); //Quarter .25 + sqlupd.append(" '9', CASE"); //Whole 9 or 5 + sqlupd.append(" WHEN MOD(ROUND(PriceLimit),10)<=5 THEN ROUND(PriceLimit)+(5-MOD(ROUND(PriceLimit),10))"); + sqlupd.append(" WHEN MOD(ROUND(PriceLimit),10)>5 THEN ROUND(PriceLimit)+(9-MOD(ROUND(PriceLimit),10)) END,"); + sqlupd.append(" ROUND(PriceLimit, ").append(rsCurgen.getInt("StdPrecision")); + sqlupd.append(")) "); // Currency + sqlupd.append(" WHERE M_PriceList_Version_ID="); + sqlupd.append(p_PriceList_Version_ID); + sqlupd.append(" AND EXISTS (SELECT * FROM T_Selection s "); + sqlupd.append(" WHERE s.T_Selection_ID=p.M_Product_ID"); + sqlupd.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")"); + + cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName()); + if (cntu == -1) + raiseError("Update M_ProductPrice ", sqlupd.toString()); + totu += cntu; + log.fine("Updated " + cntu); + + message.append(", @Updated@=").append(cntu); + // + //Fixed Price overwrite + // + sqlupd = new StringBuilder("UPDATE M_ProductPrice p "); + sqlupd.append(" SET PriceList = DECODE('"); + sqlupd.append(rsDiscountLine.getString("List_Base")).append("', 'F', "); + sqlupd.append(rsDiscountLine.getDouble("List_Fixed")).append(", PriceList), "); + sqlupd.append(" PriceStd = DECODE('"); + sqlupd.append(rsDiscountLine.getString("Std_Base")).append("', 'F', "); + sqlupd.append(rsDiscountLine.getDouble("Std_Fixed")).append(", PriceStd),"); + sqlupd.append(" PriceLimit = DECODE('"); + sqlupd.append(rsDiscountLine.getString("Limit_Base")).append("', 'F', "); + sqlupd.append(rsDiscountLine.getDouble("Limit_Fixed")).append(", PriceLimit)"); + sqlupd.append(" WHERE M_PriceList_Version_ID="); + sqlupd.append(p_PriceList_Version_ID); + sqlupd.append(" AND EXISTS (SELECT * FROM T_Selection s"); + sqlupd.append(" WHERE s.T_Selection_ID=p.M_Product_ID"); + sqlupd.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")"); + + cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName()); + if (cntu == -1) + raiseError("Update M_ProductPrice ", sqlupd.toString()); + totu += cntu; + log.fine("Updated " + cntu); + + v_NextNo = v_NextNo + 1; + addLog(0, null, null, message.toString()); + message = new StringBuilder(); + } + // + // Delete Temporary Selection + // + sqldel = new StringBuilder("DELETE FROM T_Selection "); cntd = DB.executeUpdate(sqldel.toString(), get_TrxName()); if (cntd == -1) raiseError(" DELETE T_Selection ", sqldel.toString()); totd += cntd; log.fine("Deleted " + cntd); - // - //Create Selection in temporary table - // - V_temp = v.getInt("M_PriceList_Version_Base_ID"); - String dl_Group1 = dl.getString("Group1"); - String dl_Group2 = dl.getString("Group2"); - if (v.wasNull()) { - // - //Create Selection from M_Product_PO - // - sqlins.append("INSERT INTO T_Selection (AD_PInstance_ID, T_Selection_ID) "); - sqlins.append( " SELECT DISTINCT ").append(m_AD_PInstance_ID).append(", po.M_Product_ID "); - sqlins.append(" FROM M_Product p, M_Product_PO po"); - sqlins.append(" WHERE p.M_Product_ID=po.M_Product_ID "); - sqlins.append(" AND (p.AD_Client_ID=").append(v.getInt("AD_Client_ID")).append(" OR p.AD_Client_ID=0)"); - sqlins.append(" AND p.IsActive='Y' AND po.IsActive='Y' AND po.IsCurrentVendor='Y' "); - // - //Optional Restrictions - // - // globalqss - detected bug, JDBC returns zero for null values - // so we're going to use NULLIF(value, 0) - sqlins.append(" AND (NULLIF(").append(dl.getInt("M_Product_Category_ID")).append(",0) IS NULL"); - sqlins.append(" OR p.M_Product_Category_ID IN (").append(getSubCategoryWhereClause(dl.getInt("M_Product_Category_ID"))) - .append("))"); - if(dl_Group1 != null) - sqlins.append(" AND (p.Group1=?)"); - if (dl_Group2 != null) - sqlins.append(" AND (p.Group2=?)"); - sqlins.append(" AND (NULLIF(").append(dl.getInt("C_BPartner_ID")).append(",0) IS NULL "); - sqlins.append(" OR po.C_BPartner_ID=").append(dl.getInt("C_BPartner_ID")).append(")"); - sqlins.append(" AND (NULLIF(").append(dl.getInt("M_Product_ID")).append(",0) IS NULL "); - sqlins.append(" OR p.M_Product_ID=").append(dl.getInt("M_Product_ID")).append(")"); - - CPreparedStatement stmt = DB.prepareStatement(sqlins.toString(), get_TrxName()); - - int i = 1; - - if (dl_Group1!=null) - stmt.setString(i++, dl_Group1); - if (dl_Group2!=null) - stmt.setString(i++, dl_Group2); - - cnti = stmt.executeUpdate(); - - if (cnti == -1) - raiseError(" INSERT INTO T_Selection ", sqlins.toString()); - toti += cnti; - log.fine("Inserted " + cnti); - - } else { - // - // Create Selection from existing PriceList - // - sqlins = new StringBuilder("INSERT INTO T_Selection (AD_PInstance_ID, T_Selection_ID)"); - sqlins.append(" SELECT DISTINCT ").append(m_AD_PInstance_ID).append(", p.M_Product_ID"); - sqlins.append(" FROM M_Product p, M_ProductPrice pp"); - sqlins.append(" WHERE p.M_Product_ID=pp.M_Product_ID"); - sqlins.append(" AND pp.M_PriceList_Version_ID = ").append(v.getInt("M_PriceList_Version_Base_ID")); - sqlins.append(" AND p.IsActive='Y' AND pp.IsActive='Y'"); - // - //Optional Restrictions - // - sqlins.append(" AND (NULLIF(").append(dl.getInt("M_Product_Category_ID")).append(",0) IS NULL"); - sqlins.append(" OR p.M_Product_Category_ID IN (").append(getSubCategoryWhereClause(dl.getInt("M_Product_Category_ID"))) - .append("))"); - if(dl_Group1 != null) - sqlins.append(" AND (p.Group1=?)"); - if (dl_Group2 != null) - sqlins.append(" AND (p.Group2=?)"); - sqlins.append(" AND (NULLIF(").append(dl.getInt("C_BPartner_ID")).append(",0) IS NULL OR EXISTS "); - sqlins.append("(SELECT m_product_id,c_bpartner_id,ad_client_id,ad_org_id,isactive"); - sqlins.append(",created,createdby,updated,updatedby,iscurrentvendor,c_uom_id"); - sqlins.append(",c_currency_id,pricelist,pricepo,priceeffective,pricelastpo"); - sqlins.append(",pricelastinv,vendorproductno,upc,vendorcategory,discontinued"); - sqlins.append(",discontinuedby,order_min,order_pack,costperorder"); - sqlins.append(",deliverytime_promised,deliverytime_actual,qualityrating"); - sqlins.append(",royaltyamt,group1,group2"); - sqlins.append(",manufacturer FROM M_Product_PO po WHERE po.M_Product_ID=p.M_Product_ID"); - sqlins.append(" AND po.C_BPartner_ID=").append(dl.getInt("C_BPartner_ID")).append("))"); - sqlins.append(" AND (NULLIF(").append(dl.getInt("M_Product_ID")).append(",0) IS NULL "); - sqlins.append(" OR p.M_Product_ID=").append(dl.getInt("M_Product_ID")).append(")"); - - - CPreparedStatement stmt = DB.prepareStatement(sqlins.toString(), get_TrxName()); - int i = 1; - - if (dl_Group1!=null) - stmt.setString(i++, dl_Group1); - if (dl_Group2!=null) - stmt.setString(i++, dl_Group2); - - cnti = stmt.executeUpdate(); - if (cnti == -1) - raiseError( - " INSERT INTO T_Selection from existing PriceList", - sqlins.toString()); - toti += cnti; - log.fine("Inserted " + cnti); - - } - - Message.append("@Selected@=").append(cnti); - - // - //Delete Prices in Selection, so that we can insert - // - V_temp = v.getInt("M_PriceList_Version_Base_ID"); - if (v.wasNull() || V_temp != p_PriceList_Version_ID) { - - sqldel = new StringBuilder("DELETE M_ProductPrice pp"); - sqldel.append(" WHERE pp.M_PriceList_Version_ID = "); - sqldel.append(p_PriceList_Version_ID); - sqldel.append(" AND EXISTS (SELECT t_selection_id FROM T_Selection s WHERE pp.M_Product_ID=s.T_Selection_ID"); - sqldel.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")"); - - cntd = DB.executeUpdate(sqldel.toString(), get_TrxName()); - if (cntd == -1) - raiseError(" DELETE M_ProductPrice ", sqldel.toString()); - totd += cntd; - Message.append(", @Deleted@=").append(cntd); - log.fine("Deleted " + cntd); - } - - // - // Copy (Insert) Prices - // - V_temp = v.getInt("M_PriceList_Version_Base_ID"); - if (V_temp == p_PriceList_Version_ID) - // - // We have Prices already - // - ; - else if (v.wasNull()) - // - //Copy and Convert from Product_PO - // - { - sqlins = new StringBuilder("INSERT INTO M_ProductPrice "); - sqlins.append("(M_PriceList_Version_ID"); - sqlins.append(" ,M_Product_ID "); - sqlins.append(" ,AD_Client_ID"); - sqlins.append(" , AD_Org_ID"); - sqlins.append(" , IsActive"); - sqlins.append(" , Created"); - sqlins.append(" , CreatedBy"); - sqlins.append(" , Updated"); - sqlins.append(" , UpdatedBy"); - sqlins.append(" , PriceList"); - sqlins.append(" , PriceStd"); - sqlins.append(" , PriceLimit) "); - sqlins.append("SELECT "); - sqlins.append(p_PriceList_Version_ID); - sqlins.append(" ,po.M_Product_ID "); - sqlins.append(" ,"); - sqlins.append(v.getInt("AD_Client_ID")); - sqlins.append(" ,"); - sqlins.append(v.getInt("AD_Org_ID")); - sqlins.append(" ,'Y'"); - sqlins.append(" ,SysDate,"); - sqlins.append(v.getInt("UpdatedBy")); - sqlins.append(" ,SysDate,"); - sqlins.append(v.getInt("UpdatedBy")); - // - //Price List - // - sqlins.append(" ,COALESCE(currencyConvert(po.PriceList, po.C_Currency_ID, "); - sqlins.append(v.getInt("C_Currency_ID")); - sqlins.append(", ? , "); - sqlins.append(dl.getInt("C_ConversionType_ID")); - sqlins.append(", "); - sqlins.append(v.getInt("AD_Client_ID")); - sqlins.append(", "); - sqlins.append(v.getInt("AD_Org_ID")); - sqlins.append("),0)"); - - // Price Std - sqlins.append(" ,COALESCE(currencyConvert(po.PriceList, po.C_Currency_ID, "); - sqlins.append(v.getInt("C_Currency_ID")); - sqlins.append(", ? , "); - sqlins.append(dl.getInt("C_ConversionType_ID")); - sqlins.append(", "); - sqlins.append(v.getInt("AD_Client_ID")); - sqlins.append(", "); - sqlins.append(v.getInt("AD_Org_ID")); - sqlins.append("),0)"); - - // Price Limit - sqlins.append(" ,COALESCE(currencyConvert(po.PricePO ,po.C_Currency_ID, "); - sqlins.append(v.getInt("C_Currency_ID")); - sqlins.append(",? , "); - sqlins.append(dl.getInt("C_ConversionType_ID")); - sqlins.append(", "); - sqlins.append(v.getInt("AD_Client_ID")); - sqlins.append(", "); - sqlins.append(v.getInt("AD_Org_ID")); - sqlins.append("),0)"); - sqlins.append(" FROM M_Product_PO po "); - sqlins.append(" WHERE EXISTS (SELECT * FROM T_Selection s WHERE po.M_Product_ID=s.T_Selection_ID"); - sqlins.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(") "); - sqlins.append(" AND po.IsCurrentVendor='Y' AND po.IsActive='Y'"); - - PreparedStatement pstmt = DB.prepareStatement(sqlins.toString(), - ResultSet.TYPE_SCROLL_INSENSITIVE, - ResultSet.CONCUR_UPDATABLE, get_TrxName()); - pstmt.setTimestamp(1, dl.getTimestamp("ConversionDate")); - pstmt.setTimestamp(2, dl.getTimestamp("ConversionDate")); - pstmt.setTimestamp(3, dl.getTimestamp("ConversionDate")); - - cnti = pstmt.executeUpdate(); - if (cnti == -1) - raiseError( - " INSERT INTO T_Selection from existing PriceList", - sqlins.toString()); - toti += cnti; - log.fine("Inserted " + cnti); - } else { - // - //Copy and Convert from other PriceList_Version - // - sqlins = new StringBuilder("INSERT INTO M_ProductPrice "); - sqlins.append(" (M_PriceList_Version_ID, M_Product_ID,"); - sqlins.append(" AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,"); - sqlins.append(" PriceList, PriceStd, PriceLimit)"); - sqlins.append(" SELECT "); - sqlins.append(p_PriceList_Version_ID); - sqlins.append(", pp.M_Product_ID,"); - sqlins.append(v.getInt("AD_Client_ID")); - sqlins.append(", "); - sqlins.append(v.getInt("AD_Org_ID")); - sqlins.append(", 'Y', SysDate, "); - sqlins.append(v.getInt("UpdatedBy")); - sqlins.append(", SysDate, "); - sqlins.append(v.getInt("UpdatedBy")); - sqlins.append(" ,"); - // Price List - sqlins.append("COALESCE(currencyConvert(pp.PriceList, pl.C_Currency_ID, "); - sqlins.append(v.getInt("C_Currency_ID")); - sqlins.append(", ?, "); - sqlins.append(dl.getInt("C_ConversionType_ID")); - sqlins.append(", "); - sqlins.append(v.getInt("AD_Client_ID")); - sqlins.append(", "); - sqlins.append(v.getInt("AD_Org_ID")); - sqlins.append("),0),"); - // Price Std - sqlins.append("COALESCE(currencyConvert(pp.PriceStd,pl.C_Currency_ID, "); - sqlins.append(v.getInt("C_Currency_ID")); - sqlins.append(" , ? , "); - sqlins.append(dl.getInt("C_ConversionType_ID")); - sqlins.append(", "); - sqlins.append(v.getInt("AD_Client_ID")); - sqlins.append(", "); - sqlins.append(v.getInt("AD_Org_ID")); - sqlins.append("),0),"); - //Price Limit - sqlins.append(" COALESCE(currencyConvert(pp.PriceLimit,pl.C_Currency_ID, "); - sqlins.append(v.getInt("C_Currency_ID")); - sqlins.append(" , ? , "); - sqlins.append(dl.getInt("C_ConversionType_ID")); - sqlins.append(", "); - sqlins.append(v.getInt("AD_Client_ID")); - sqlins.append(", "); - sqlins.append(v.getInt("AD_Org_ID")); - sqlins.append("),0)"); - sqlins.append(" FROM M_ProductPrice pp"); - sqlins.append(" INNER JOIN M_PriceList_Version plv ON (pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID)"); - sqlins.append(" INNER JOIN M_PriceList pl ON (plv.M_PriceList_ID=pl.M_PriceList_ID)"); - sqlins.append(" WHERE pp.M_PriceList_Version_ID="); - sqlins.append(v.getInt("M_PriceList_Version_Base_ID")); - sqlins.append(" AND EXISTS (SELECT * FROM T_Selection s WHERE pp.M_Product_ID=s.T_Selection_ID"); - sqlins.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")"); - sqlins.append("AND pp.IsActive='Y'"); - - PreparedStatement pstmt = DB.prepareStatement(sqlins.toString(), - ResultSet.TYPE_SCROLL_INSENSITIVE, - ResultSet.CONCUR_UPDATABLE, get_TrxName()); - pstmt.setTimestamp(1, dl.getTimestamp("ConversionDate")); - pstmt.setTimestamp(2, dl.getTimestamp("ConversionDate")); - pstmt.setTimestamp(3, dl.getTimestamp("ConversionDate")); - - cnti = pstmt.executeUpdate(); - - if (cnti == -1) - raiseError( - " INSERT INTO T_Selection from existing PriceList", - sqlins.toString()); - toti += cnti; - log.fine("Inserted " + cnti); - - } - Message.append(", @Inserted@=").append(cnti); - // - // Calculation - // - sqlupd = new StringBuilder("UPDATE M_ProductPrice p "); - sqlupd.append(" SET PriceList = (DECODE( '"); - sqlupd.append(dl.getString("List_Base")); - sqlupd.append("', 'S', PriceStd, 'X', PriceLimit, PriceList)"); - sqlupd.append(" + ?) * (1 - ?/100), PriceStd = (DECODE('"); - sqlupd.append(dl.getString("Std_Base")); - sqlupd.append("', 'L', PriceList, 'X', PriceLimit, PriceStd) "); - sqlupd.append(" + ?) * (1 - ?/100), ").append(" PriceLimit = (DECODE('"); - sqlupd.append(dl.getString("Limit_Base")); - sqlupd.append("', 'L', PriceList, 'S', PriceStd, PriceLimit) "); - sqlupd.append(" + ?) * (1 - ? /100) "); - sqlupd.append(" WHERE M_PriceList_Version_ID = "); - sqlupd.append(p_PriceList_Version_ID); - sqlupd.append(" AND EXISTS (SELECT * FROM T_Selection s "); - sqlupd.append(" WHERE s.T_Selection_ID = p.M_Product_ID"); - sqlupd.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")"); - PreparedStatement pstmu = DB.prepareStatement(sqlupd.toString(), - ResultSet.TYPE_SCROLL_INSENSITIVE, - ResultSet.CONCUR_UPDATABLE, get_TrxName()); - - pstmu.setDouble(1, dl.getDouble("List_AddAmt")); - pstmu.setDouble(2, dl.getDouble("List_Discount")); - pstmu.setDouble(3, dl.getDouble("Std_AddAmt")); - pstmu.setDouble(4, dl.getDouble("Std_Discount")); - pstmu.setDouble(5, dl.getDouble("Limit_AddAmt")); - pstmu.setDouble(6, dl.getDouble("Limit_Discount")); - - cntu = pstmu.executeUpdate(); - - if (cntu == -1) - raiseError("Update M_ProductPrice ", sqlupd.toString()); - totu += cntu; - log.fine("Updated " + cntu); - // - //Rounding (AD_Reference_ID=155) + //commit; // - sqlupd = new StringBuilder("UPDATE M_ProductPrice p "); - sqlupd.append(" SET PriceList = DECODE('"); - sqlupd.append(dl.getString("List_Rounding")).append("',"); - sqlupd.append(" 'N', PriceList, "); - sqlupd.append(" '0', ROUND(PriceList, 0),"); //Even .00 - sqlupd.append(" 'D', ROUND(PriceList, 1),"); //Dime .10 - sqlupd.append(" 'T', ROUND(PriceList, -1), "); //Ten 10.00 - sqlupd.append(" '5', ROUND(PriceList*20,0)/20,"); //Nickle .05 - sqlupd.append(" 'Q', ROUND(PriceList*4,0)/4,"); //Quarter .25 - sqlupd.append(" '9', CASE"); //Whole 9 or 5 - sqlupd.append(" WHEN MOD(ROUND(PriceList),10)<=5 THEN ROUND(PriceList)+(5-MOD(ROUND(PriceList),10))"); - sqlupd.append(" WHEN MOD(ROUND(PriceList),10)>5 THEN ROUND(PriceList)+(9-MOD(ROUND(PriceList),10)) END,"); - sqlupd.append(" ROUND(PriceList, ").append(v.getInt("StdPrecision")); - sqlupd.append(")),");//Currency - sqlupd.append(" PriceStd = DECODE('").append(dl.getString("Std_Rounding")); - sqlupd.append("',").append(" 'N', PriceStd, "); - sqlupd.append(" '0', ROUND(PriceStd, 0), "); //Even .00 - sqlupd.append(" 'D', ROUND(PriceStd, 1), "); //Dime .10 - sqlupd.append("'T', ROUND(PriceStd, -1),"); //Ten 10.00) - sqlupd.append("'5', ROUND(PriceStd*20,0)/20,"); //Nickle .05 - sqlupd.append("'Q', ROUND(PriceStd*4,0)/4,"); //Quarter .25 - sqlupd.append(" '9', CASE"); //Whole 9 or 5 - sqlupd.append(" WHEN MOD(ROUND(PriceStd),10)<=5 THEN ROUND(PriceStd)+(5-MOD(ROUND(PriceStd),10))"); - sqlupd.append(" WHEN MOD(ROUND(PriceStd),10)>5 THEN ROUND(PriceStd)+(9-MOD(ROUND(PriceStd),10)) END,"); - sqlupd.append("ROUND(PriceStd, ").append(v.getInt("StdPrecision")).append(")),"); //Currency - sqlupd.append("PriceLimit = DECODE('"); - sqlupd.append(dl.getString("Limit_Rounding")).append("', "); - sqlupd.append(" 'N', PriceLimit, "); - sqlupd.append(" '0', ROUND(PriceLimit, 0), "); // Even .00 - sqlupd.append(" 'D', ROUND(PriceLimit, 1), "); // Dime .10 - sqlupd.append(" 'T', ROUND(PriceLimit, -1), "); // Ten 10.00 - sqlupd.append(" '5', ROUND(PriceLimit*20,0)/20, "); // Nickle .05 - sqlupd.append(" 'Q', ROUND(PriceLimit*4,0)/4, "); //Quarter .25 - sqlupd.append(" '9', CASE"); //Whole 9 or 5 - sqlupd.append(" WHEN MOD(ROUND(PriceLimit),10)<=5 THEN ROUND(PriceLimit)+(5-MOD(ROUND(PriceLimit),10))"); - sqlupd.append(" WHEN MOD(ROUND(PriceLimit),10)>5 THEN ROUND(PriceLimit)+(9-MOD(ROUND(PriceLimit),10)) END,"); - sqlupd.append(" ROUND(PriceLimit, ").append(v.getInt("StdPrecision")); - sqlupd.append(")) "); // Currency - sqlupd.append(" WHERE M_PriceList_Version_ID="); - sqlupd.append(p_PriceList_Version_ID); - sqlupd.append(" AND EXISTS (SELECT * FROM T_Selection s "); - sqlupd.append(" WHERE s.T_Selection_ID=p.M_Product_ID"); - sqlupd.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")"); - - cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName()); - if (cntu == -1) - raiseError("Update M_ProductPrice ", sqlupd.toString()); - totu += cntu; - log.fine("Updated " + cntu); + // log.fine("Committing ..."); + // DB.commit(true, get_TrxName()); - Message.append(", @Updated@=").append(cntu); - // - //Fixed Price overwrite - // - sqlupd = new StringBuilder("UPDATE M_ProductPrice p "); - sqlupd.append(" SET PriceList = DECODE('"); - sqlupd.append(dl.getString("List_Base")).append("', 'F', "); - sqlupd.append(dl.getDouble("List_Fixed")).append(", PriceList), "); - sqlupd.append(" PriceStd = DECODE('"); - sqlupd.append(dl.getString("Std_Base")).append("', 'F', "); - sqlupd.append(dl.getDouble("Std_Fixed")).append(", PriceStd),"); - sqlupd.append(" PriceLimit = DECODE('"); - sqlupd.append(dl.getString("Limit_Base")).append("', 'F', "); - sqlupd.append(dl.getDouble("Limit_Fixed")).append(", PriceLimit)"); - sqlupd.append(" WHERE M_PriceList_Version_ID="); - sqlupd.append(p_PriceList_Version_ID); - sqlupd.append(" AND EXISTS (SELECT * FROM T_Selection s"); - sqlupd.append(" WHERE s.T_Selection_ID=p.M_Product_ID"); - sqlupd.append(" AND s.AD_PInstance_ID=").append(m_AD_PInstance_ID).append(")"); - - cntu = DB.executeUpdate(sqlupd.toString(), get_TrxName()); - if (cntu == -1) - raiseError("Update M_ProductPrice ", sqlupd.toString()); - totu += cntu; - log.fine("Updated " + cntu); - - v_NextNo = v_NextNo + 1; - addLog(0, null, null, Message.toString()); - Message = new StringBuilder(); } - dl.close(); - Cur_DiscountLine.close(); - Cur_DiscountLine = null; - - // - // Delete Temporary Selection - // - sqldel = new StringBuilder("DELETE FROM T_Selection "); - cntd = DB.executeUpdate(sqldel.toString(), get_TrxName()); - if (cntd == -1) - raiseError(" DELETE T_Selection ", sqldel.toString()); - totd += cntd; - log.fine("Deleted " + cntd); - - // - //commit; - // - // log.fine("Committing ..."); - // DB.commit(true, get_TrxName()); - + } catch (SQLException e) { + throw e; + } finally { + DB.close(rsCurgen, stmtCurgen); + rsCurgen = null; stmtCurgen = null; + DB.close(rsDiscountLine, stmtDiscountLine); + rsDiscountLine = null; stmtDiscountLine = null; + DB.close(stmt); + stmt = null; + DB.close(pstmt); + pstmt = null; } - v.close(); - curgen.close(); - curgen = null; return "OK"; @@ -734,24 +747,32 @@ public class M_PriceList_Create extends SvrProcess { * It is used as restriction in MQuery. * @param productCategoryId * @return + * @throws */ - private String getSubCategoryWhereClause(int productCategoryId) throws SQLException, AdempiereSystemError{ + private String getSubCategoryWhereClause(int productCategoryId) throws SQLException, AdempiereSystemError { //if a node with this id is found later in the search we have a loop in the tree int subTreeRootParentId = 0; StringBuilder retString = new StringBuilder(); String sql = " SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category"; final Vector categories = new Vector(100); - Statement stmt = DB.createStatement(); - ResultSet rs = stmt.executeQuery(sql); - while (rs.next()) { - if(rs.getInt(1)==productCategoryId) { - subTreeRootParentId = rs.getInt(2); + Statement stmt = null; + ResultSet rs = null; + try { + stmt = DB.createStatement(); + rs = stmt.executeQuery(sql); + while (rs.next()) { + if(rs.getInt(1)==productCategoryId) { + subTreeRootParentId = rs.getInt(2); + } + categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2))); } - categories.add(new SimpleTreeNode(rs.getInt(1), rs.getInt(2))); + retString.append(getSubCategoriesString(productCategoryId, categories, subTreeRootParentId)); + } catch (SQLException e) { + throw e; + } finally { + DB.close(rs, stmt); + rs = null; stmt = null; } - retString.append(getSubCategoriesString(productCategoryId, categories, subTreeRootParentId)); - rs.close(); - stmt.close(); return retString.toString(); } @@ -760,7 +781,7 @@ public class M_PriceList_Create extends SvrProcess { * @param productCategoryId * @param categories * @param loopIndicatorId - * @return comma seperated list of category ids + * @return comma separated list of category ids * @throws AdempiereSystemError if a loop is detected */ private String getSubCategoriesString(int productCategoryId, Vector categories, int loopIndicatorId) throws AdempiereSystemError { diff --git a/org.adempiere.base.process/src/org/compiere/process/M_Product_BOM_Check.java b/org.adempiere.base.process/src/org/compiere/process/M_Product_BOM_Check.java index 7cb9424b79..f1c0f0c5e6 100644 --- a/org.adempiere.base.process/src/org/compiere/process/M_Product_BOM_Check.java +++ b/org.adempiere.base.process/src/org/compiere/process/M_Product_BOM_Check.java @@ -110,20 +110,26 @@ public class M_Product_BOM_Check extends SvrProcess // Get count remaining on t_selection int countno = 0; + PreparedStatement pstmt = null; + ResultSet rs = null; try { StringBuilder dbpst = new StringBuilder("SELECT COUNT(*) FROM T_Selection WHERE AD_PInstance_ID=").append(m_AD_PInstance_ID); - PreparedStatement pstmt = DB.prepareStatement(dbpst.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(dbpst.toString(), get_TrxName()); + rs = pstmt.executeQuery(); if (rs.next()) countno = rs.getInt(1); - rs.close(); - pstmt.close(); } catch (SQLException e) { throw new Exception ("count t_selection", e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } log.fine("Count T_Selection =" + countno); if (countno == 0) diff --git a/org.adempiere.base.process/src/org/compiere/process/OrderBatchProcess.java b/org.adempiere.base.process/src/org/compiere/process/OrderBatchProcess.java index 66dab9845f..cd11a5cd78 100644 --- a/org.adempiere.base.process/src/org/compiere/process/OrderBatchProcess.java +++ b/org.adempiere.base.process/src/org/compiere/process/OrderBatchProcess.java @@ -128,12 +128,13 @@ public class OrderBatchProcess extends SvrProcess int counter = 0; int errCounter = 0; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); pstmt.setInt(1, p_C_DocTypeTarget_ID); pstmt.setString(2, p_DocStatus); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { if (process(new MOrder(getCtx(),rs, get_TrxName()))) @@ -141,22 +142,15 @@ public class OrderBatchProcess extends SvrProcess else errCounter++; } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { 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; } StringBuilder msgreturn = new StringBuilder("@Updated@=").append(counter).append(", @Errors@=").append(errCounter); diff --git a/org.adempiere.base.process/src/org/compiere/process/PaySelectionCreateFrom.java b/org.adempiere.base.process/src/org/compiere/process/PaySelectionCreateFrom.java index 6cde6e3dd9..6053851e81 100644 --- a/org.adempiere.base.process/src/org/compiere/process/PaySelectionCreateFrom.java +++ b/org.adempiere.base.process/src/org/compiere/process/PaySelectionCreateFrom.java @@ -183,7 +183,8 @@ public class PaySelectionCreateFrom extends SvrProcess // int lines = 0; int C_CurrencyTo_ID = psel.getC_Currency_ID(); - PreparedStatement pstmt = null; + PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); @@ -207,7 +208,7 @@ public class PaySelectionCreateFrom extends SvrProcess else if (p_C_BP_Group_ID != 0) pstmt.setInt (index++, p_C_BP_Group_ID); // - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { int C_Invoice_ID = rs.getInt(1); @@ -228,23 +229,16 @@ public class PaySelectionCreateFrom extends SvrProcess throw new IllegalStateException ("Cannot save MPaySelectionLine"); } } - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, sql.toString(), e); } - try + finally { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; + DB.close(rs, pstmt); + rs = null; + pstmt = null; } StringBuilder msgreturn = new StringBuilder("@C_PaySelectionLine_ID@ - #").append(lines); return msgreturn.toString(); diff --git a/org.adempiere.base.process/src/org/compiere/process/ReplenishReport.java b/org.adempiere.base.process/src/org/compiere/process/ReplenishReport.java index b3f1e7510b..52e42303c4 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ReplenishReport.java +++ b/org.adempiere.base.process/src/org/compiere/process/ReplenishReport.java @@ -737,29 +737,23 @@ public class ReplenishReport extends SvrProcess sql.append(" ORDER BY M_Warehouse_ID, M_WarehouseSource_ID, C_BPartner_ID"); ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); pstmt.setInt (1, getAD_PInstance_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new X_T_Replenish (getCtx(), rs, get_TrxName())); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { 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; } X_T_Replenish[] retValue = new X_T_Replenish[list.size ()]; @@ -780,29 +774,23 @@ public class ReplenishReport extends SvrProcess sql.append(" ORDER BY M_Warehouse_ID, M_WarehouseSource_ID, C_BPartner_ID"); ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); pstmt.setInt (1, getAD_PInstance_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new X_T_Replenish (getCtx(), rs, get_TrxName())); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { 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; } X_T_Replenish[] retValue = new X_T_Replenish[list.size ()]; diff --git a/org.adempiere.base.process/src/org/compiere/process/ReplenishReportProduction.java b/org.adempiere.base.process/src/org/compiere/process/ReplenishReportProduction.java index 50795a7efb..ff3e801250 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ReplenishReportProduction.java +++ b/org.adempiere.base.process/src/org/compiere/process/ReplenishReportProduction.java @@ -838,29 +838,23 @@ public class ReplenishReportProduction extends SvrProcess sql.append(" ORDER BY M_Warehouse_ID, M_WarehouseSource_ID, C_BPartner_ID"); ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); pstmt.setInt (1, getAD_PInstance_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) list.add (new X_T_Replenish (getCtx(), rs, get_TrxName())); - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { 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; } X_T_Replenish[] retValue = new X_T_Replenish[list.size ()]; diff --git a/org.adempiere.base.process/src/org/compiere/process/ReplicationLocal.java b/org.adempiere.base.process/src/org/compiere/process/ReplicationLocal.java index 5fffb0e8d4..35d0966489 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ReplicationLocal.java +++ b/org.adempiere.base.process/src/org/compiere/process/ReplicationLocal.java @@ -227,14 +227,17 @@ public class ReplicationLocal extends SvrProcess { while (rowset.next()) mergeDataTable (rowset.getInt(1), rowset.getString(3), rowset.getInt(4)); - rowset.close(); - rowset = null; } catch (SQLException ex) { log.log(Level.SEVERE, "mergeData", ex); m_replicated = false; } + finally + { + DB.close(rowset); + rowset = null; + } } // mergeData /** @@ -318,9 +321,9 @@ public class ReplicationLocal extends SvrProcess rLog.setIsReplicated(replicated); if (result != null) rLog.setP_Msg("< " + result.toString()); - sourceRS.close(); + DB.close(sourceRS); sourceRS = null; - targetRS.close(); + DB.close(targetRS); targetRS = null; } rLog.saveEx(); @@ -336,6 +339,7 @@ public class ReplicationLocal extends SvrProcess { ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { // Get Keys @@ -344,14 +348,14 @@ public class ReplicationLocal extends SvrProcess + " AND IsKey='Y'"; pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, AD_Table_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(rs.getString(1)); - rs.close(); - // no keys - search for parents if (list.size() == 0) { + DB.close(rs); + rs = null; sql = "SELECT ColumnName FROM AD_Column " + "WHERE AD_Table_ID=?" + " AND IsParent='Y'"; @@ -360,22 +364,17 @@ public class ReplicationLocal extends SvrProcess rs = pstmt.executeQuery(); while (rs.next()) list.add(rs.getString(1)); - rs.close(); } - pstmt.close(); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, "getKeyColumns", e); } - try - { - if (pstmt != null) - pstmt.close(); - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; + pstmt = null; } // Convert to Array @@ -406,13 +405,17 @@ public class ReplicationLocal extends SvrProcess { while (rowset.next()) sendUpdatesTable (rowset.getInt(1), rowset.getString(3), rowset.getInt(4)); - rowset.close(); } catch (SQLException ex) { log.log(Level.SEVERE, "sendUpdates", ex); m_replicated = false; } + finally + { + DB.close(rowset); + rowset = null; + } } // sendUpdates /** @@ -534,6 +537,7 @@ public class ReplicationLocal extends SvrProcess Connection conn = DB.getConnectionRO(); PreparedStatement pstmt = null; RowSet rowSet = null; + ResultSet rs = null; // try { @@ -557,7 +561,7 @@ public class ReplicationLocal extends SvrProcess } } // - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); rowSet = CCachedRowSet.getRowSet(rs); } catch (Exception ex) @@ -568,8 +572,8 @@ public class ReplicationLocal extends SvrProcess // Close Cursor finally { - DB.close(pstmt); - pstmt = null; + DB.close(rs,pstmt); + rs = null;pstmt = null; } return rowSet; diff --git a/org.adempiere.base.process/src/org/compiere/process/RequestEMailProcessor.java b/org.adempiere.base.process/src/org/compiere/process/RequestEMailProcessor.java index 76ffdef0e2..f791882fcc 100644 --- a/org.adempiere.base.process/src/org/compiere/process/RequestEMailProcessor.java +++ b/org.adempiere.base.process/src/org/compiere/process/RequestEMailProcessor.java @@ -352,16 +352,25 @@ public class RequestEMailProcessor extends SvrProcess + "and documentno = ? " + "and startdate = ?"; PreparedStatement pstmtdup = null; + ResultSet rsdup = null; + try + { pstmtdup = DB.prepareStatement (sqldup, null); pstmtdup.setInt(1, getAD_Client_ID()); pstmtdup.setString(2, hdrs[0].substring(0,30)); pstmtdup.setTimestamp(3, new Timestamp(msg.getSentDate().getTime())); - ResultSet rsdup = pstmtdup.executeQuery (); + rsdup = pstmtdup.executeQuery (); if (rsdup.next ()) retValuedup = rsdup.getInt(1); - rsdup.close (); - pstmtdup.close (); - pstmtdup = null; + } catch (SQLException e) + { + throw e; + } + finally + { + DB.close (rsdup,pstmtdup); + rsdup = null;pstmtdup = null; + } if (retValuedup > 0) { log.info("request already existed for msg -> " + hdrs[0]); return true; @@ -390,6 +399,9 @@ public class RequestEMailProcessor extends SvrProcess + " ) " + " ) "; PreparedStatement pstmtupd = null; + ResultSet rsupd = null; + try + { pstmtupd = DB.prepareStatement (sqlupd, null); pstmtupd.setInt(1, getAD_Client_ID()); pstmtupd.setString(2, fromAddress); @@ -398,12 +410,19 @@ public class RequestEMailProcessor extends SvrProcess pstmtupd.setString(5, msg.getSubject()); pstmtupd.setString(6, fromAddress); pstmtupd.setString(7, msg.getSubject()); - ResultSet rsupd = pstmtupd.executeQuery (); + rsupd = pstmtupd.executeQuery (); if (rsupd.next ()) request_upd = rsupd.getInt(1); - rsupd.close (); - pstmtupd.close (); - pstmtupd = null; + } + catch (SQLException e) + { + throw e; + } + finally + { + DB.close(rsupd,pstmtupd); + rsupd = null;pstmtupd = null; + } if (request_upd > 0) { log.info("msg -> " + hdrs[0] + " is an answer for req " + request_upd); return updateRequest(request_upd, msg); @@ -443,15 +462,25 @@ public class RequestEMailProcessor extends SvrProcess + " WHERE UPPER (email) = UPPER (?) " + " AND ad_client_id = ?"; PreparedStatement pstmtu = null; + ResultSet rsu = null; + try + { pstmtu = DB.prepareStatement (sqlu, null); pstmtu.setString(1, fromAddress); pstmtu.setInt(2, getAD_Client_ID()); - ResultSet rsu = pstmtu.executeQuery (); + rsu = pstmtu.executeQuery (); if (rsu.next ()) retValueu = rsu.getInt(1); - rsu.close (); - pstmtu.close (); - pstmtu = null; + } + catch(SQLException e) + { + throw e; + } + finally + { + DB.close (rsu,pstmtu); + rsu = null;pstmtu = null; + } if (retValueu > 0) { req.setAD_User_ID(retValueu); } else { diff --git a/org.adempiere.base.process/src/org/compiere/process/RequestInvoice.java b/org.adempiere.base.process/src/org/compiere/process/RequestInvoice.java index f5c2a18812..11a15339d8 100644 --- a/org.adempiere.base.process/src/org/compiere/process/RequestInvoice.java +++ b/org.adempiere.base.process/src/org/compiere/process/RequestInvoice.java @@ -116,6 +116,7 @@ public class RequestInvoice extends SvrProcess .append("ORDER BY C_BPartner_ID"); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); @@ -127,7 +128,7 @@ public class RequestInvoice extends SvrProcess pstmt.setInt (index++, p_R_Category_ID); if (p_C_BPartner_ID != 0) pstmt.setInt (index++, p_C_BPartner_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); int oldC_BPartner_ID = 0; while (rs.next ()) { @@ -145,22 +146,15 @@ public class RequestInvoice extends SvrProcess } invoiceDone(); // - rs.close (); - pstmt.close (); - pstmt = null; } catch (Exception e) { 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; } // R_Category_ID diff --git a/org.adempiere.base.process/src/org/compiere/process/SendMailText.java b/org.adempiere.base.process/src/org/compiere/process/SendMailText.java index e3529a65ae..e108d88759 100644 --- a/org.adempiere.base.process/src/org/compiere/process/SendMailText.java +++ b/org.adempiere.base.process/src/org/compiere/process/SendMailText.java @@ -167,11 +167,12 @@ public class SendMailText extends SvrProcess + " AND u.EMail IS NOT NULL" + " AND ci.R_InterestArea_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, m_R_InterestArea_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { Boolean ok = sendIndividualMail (rs.getString(1), rs.getInt(3), unsubscribe); @@ -182,24 +183,18 @@ public class SendMailText extends SvrProcess else m_errors++; } - rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException ex) { log.log(Level.SEVERE, sql, ex); } // Clean Up - try + finally { - if (pstmt != null) - pstmt.close(); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - pstmt = null; m_ia = null; } // sendInterestArea @@ -217,11 +212,12 @@ public class SendMailText extends SvrProcess + " AND u.EMail IS NOT NULL" + " AND bp.C_BP_Group_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, m_C_BP_Group_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { Boolean ok = sendIndividualMail (rs.getString(1), rs.getInt(3), null); @@ -232,24 +228,18 @@ public class SendMailText extends SvrProcess else m_errors++; } - rs.close(); - pstmt.close(); - pstmt = null; } catch (SQLException ex) { log.log(Level.SEVERE, sql, ex); } // Clean Up - try + finally { - if (pstmt != null) - pstmt.close(); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - pstmt = null; } // sendBPGroup /** diff --git a/org.adempiere.base.process/src/org/compiere/process/SynchronizeTerminology.java b/org.adempiere.base.process/src/org/compiere/process/SynchronizeTerminology.java index 663c714f6b..3ec9b26bf5 100644 --- a/org.adempiere.base.process/src/org/compiere/process/SynchronizeTerminology.java +++ b/org.adempiere.base.process/src/org/compiere/process/SynchronizeTerminology.java @@ -51,6 +51,8 @@ public class SynchronizeTerminology extends SvrProcess { //TODO Error handling String sql = null; + PreparedStatement pstmt = null; + ResultSet rs = null; try { int no; Trx trx = Trx.get(get_TrxName(), false); @@ -60,8 +62,8 @@ public class SynchronizeTerminology extends SvrProcess +"(SELECT 1 FROM AD_ELEMENT e " +" WHERE UPPER(c.ColumnName)=UPPER(e.ColumnName))" +" AND c.isActive = 'Y'"; - PreparedStatement pstmt = DB.prepareStatement(sql, get_TrxName()); - ResultSet rs = pstmt.executeQuery (); + pstmt = DB.prepareStatement(sql, get_TrxName()); + rs = pstmt.executeQuery (); while (rs.next()){ String columnName = rs.getString(1); String name = rs.getString(2); @@ -74,8 +76,8 @@ public class SynchronizeTerminology extends SvrProcess elem.setPrintName(name); elem.saveEx(); } - pstmt.close(); - rs.close(); + DB.close(rs, pstmt); + rs = null; pstmt = null; trx.commit(true); // Create Elements for Process Parameters which are centrally maintained /* IDEMPIERE 109 - this create unwanted Element @@ -844,6 +846,12 @@ public class SynchronizeTerminology extends SvrProcess log.log (Level.SEVERE, "@Failed@: "+e.getLocalizedMessage(), e); throw e; } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return "@OK@"; } diff --git a/org.adempiere.base.process/src/org/compiere/process/TreeMaintenance.java b/org.adempiere.base.process/src/org/compiere/process/TreeMaintenance.java index 2fe0112ba9..51ba67360d 100644 --- a/org.adempiere.base.process/src/org/compiere/process/TreeMaintenance.java +++ b/org.adempiere.base.process/src/org/compiere/process/TreeMaintenance.java @@ -130,10 +130,11 @@ public class TreeMaintenance extends SvrProcess // boolean ok = true; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { int Node_ID = rs.getInt(1); @@ -157,23 +158,16 @@ public class TreeMaintenance extends SvrProcess log.log(Level.SEVERE, "Could not add to " + tree + " Node_ID=" + Node_ID); } } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { log.log(Level.SEVERE, "verifyTree", e); ok = false; } - try - { - if (pstmt != null) - pstmt.close(); - pstmt = null; - } - catch (Exception e) + finally { + DB.close(rs, pstmt); + rs = null; pstmt = null; } StringBuilder msglog = new StringBuilder().append(tree.getName()).append(" Inserted"); 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/MOrder.java b/org.adempiere.base/src/org/compiere/model/MOrder.java index 0a59f8c9af..47a19533a2 100644 --- a/org.adempiere.base/src/org/compiere/model/MOrder.java +++ b/org.adempiere.base/src/org/compiere/model/MOrder.java @@ -2698,15 +2698,22 @@ public class MOrder extends X_C_Order implements DocAction List result = new Vector(); Properties ctx = Env.getCtx(); MOrderLine line; - PreparedStatement ps = conn.prepareStatement(OrderLinesToAllocate); - ps.setInt(1, productId); - ResultSet rs = ps.executeQuery(); - while(rs.next()) { - line = new MOrderLine(ctx, rs, trxName); - result.add(line); + PreparedStatement ps = null; + ResultSet rs = null; + try { + ps = conn.prepareStatement(OrderLinesToAllocate); + ps.setInt(1, productId); + rs = ps.executeQuery(); + while(rs.next()) { + line = new MOrderLine(ctx, rs, trxName); + result.add(line); + } + } catch (SQLException e) { + throw e; + } finally { + DB.close(rs, ps); + rs = null; ps = null; } - rs.close(); - ps.close(); return(result); } @@ -2735,23 +2742,28 @@ public class MOrder extends X_C_Order implements DocAction "(QtyOrdered-QtyDelivered)>0 AND (QtyOrdered-QtyDelivered)>C_OrderLine.QtyAllocated)" + "group by M_Product_ID " + "order by M_Product_ID"; - - PreparedStatement ps = conn.prepareStatement(query1); - ps.setInt(1, WarehouseID); - ps.setInt(2, WarehouseID); - ResultSet rs = ps.executeQuery(); - - while(rs.next()) { - si = new StockInfo(); - si.productId = rs.getInt(1); - si.qtyOnHand = rs.getBigDecimal(2); - si.qtyReserved = rs.getBigDecimal(3); - si.qtyAvailable = si.qtyOnHand.subtract(si.qtyReserved); - si.qtyAllocated = rs.getBigDecimal(4); - result.add(si); + PreparedStatement ps = null; + ResultSet rs = null; + try { + ps = conn.prepareStatement(query1); + ps.setInt(1, WarehouseID); + ps.setInt(2, WarehouseID); + rs = ps.executeQuery(); + while(rs.next()) { + si = new StockInfo(); + si.productId = rs.getInt(1); + si.qtyOnHand = rs.getBigDecimal(2); + si.qtyReserved = rs.getBigDecimal(3); + si.qtyAvailable = si.qtyOnHand.subtract(si.qtyReserved); + si.qtyAllocated = rs.getBigDecimal(4); + result.add(si); + } + } catch (SQLException e) { + throw e; + } finally { + DB.close(rs, ps); + rs = null; ps = null; } - rs.close(); - ps.close(); return(result); } 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.base/src/org/compiere/model/MTableAccess.java b/org.adempiere.base/src/org/compiere/model/MTableAccess.java index ffa708dd84..6de607483b 100644 --- a/org.adempiere.base/src/org/compiere/model/MTableAccess.java +++ b/org.adempiere.base/src/org/compiere/model/MTableAccess.java @@ -118,29 +118,23 @@ public class MTableAccess extends X_AD_Table_Access { String sql = "SELECT TableName FROM AD_Table WHERE AD_Table_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); 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, "getTableName", 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/MTemplate.java b/org.adempiere.base/src/org/compiere/model/MTemplate.java index e6bcc03eaf..119f820b26 100644 --- a/org.adempiere.base/src/org/compiere/model/MTemplate.java +++ b/org.adempiere.base/src/org/compiere/model/MTemplate.java @@ -278,17 +278,19 @@ public class MTemplate extends X_CM_Template int[] AdCats = null; String sql = "SELECT count(*) FROM CM_Template_AD_Cat WHERE CM_Template_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { int numberAdCats = 0; pstmt = DB.prepareStatement (sql, get_TrxName ()); pstmt.setInt (1, get_ID ()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) { numberAdCats = rs.getInt (1); } - rs.close (); + DB.close(rs, pstmt); + rs = null; pstmt = null; AdCats = new int[numberAdCats]; int i = 0; sql = "SELECT CM_Ad_Cat_ID FROM CM_Template_AD_Cat WHERE CM_Template_ID=?"; @@ -300,23 +302,16 @@ public class MTemplate extends X_CM_Template AdCats[i] = rs.getInt (1); i++; } - 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; if (AdCats != null && AdCats.length > 0) { MAd[] returnAds = new MAd[AdCats.length]; diff --git a/org.adempiere.base/src/org/compiere/model/MTimeExpense.java b/org.adempiere.base/src/org/compiere/model/MTimeExpense.java index 121dad548e..4b46441cd1 100644 --- a/org.adempiere.base/src/org/compiere/model/MTimeExpense.java +++ b/org.adempiere.base/src/org/compiere/model/MTimeExpense.java @@ -117,34 +117,29 @@ public class MTimeExpense extends X_S_TimeExpense implements DocAction // String sql = "SELECT * FROM S_TimeExpenseLine WHERE S_TimeExpense_ID=? ORDER BY Line"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, get_TrxName()); pstmt.setInt (1, getS_TimeExpense_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MTimeExpenseLine te = new MTimeExpenseLine(getCtx(), rs, get_TrxName()); te.setC_Currency_Report_ID(C_Currency_ID); list.add(te); } - rs.close (); - pstmt.close (); - pstmt = null; } catch (SQLException ex) { log.log(Level.SEVERE, "getLines", ex); } - try + finally { - if (pstmt != null) - pstmt.close (); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - pstmt = null; // m_lines = new MTimeExpenseLine[list.size()]; list.toArray(m_lines); @@ -176,30 +171,25 @@ public class MTimeExpense extends X_S_TimeExpense implements DocAction String sql = "SELECT M_Locator_ID FROM M_Locator " + "WHERE M_Warehouse_ID=? AND IsActive='Y' ORDER BY IsDefault DESC, Created"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, getM_Warehouse_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) m_M_Locator_ID = rs.getInt(1); - rs.close (); - pstmt.close (); - pstmt = null; } catch (SQLException ex) { log.log(Level.SEVERE, "getM_Locator_ID", ex); } - try + finally { - if (pstmt != null) - pstmt.close (); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - catch (SQLException ex1) - { - } - pstmt = null; // return m_M_Locator_ID; } // getM_Locator_ID diff --git a/org.adempiere.base/src/org/compiere/model/MTree.java b/org.adempiere.base/src/org/compiere/model/MTree.java index f2ef328310..4fd484f433 100644 --- a/org.adempiere.base/src/org/compiere/model/MTree.java +++ b/org.adempiere.base/src/org/compiere/model/MTree.java @@ -167,21 +167,27 @@ public class MTree extends MTree_Base String sql = "SELECT AD_Tree_ID, Name FROM AD_Tree " + "WHERE AD_Client_ID=? AND TreeType=? AND IsActive='Y' AND IsAllNodes='Y' " + "ORDER BY IsDefault DESC, AD_Tree_ID"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_Client_ID); pstmt.setString(2, TreeType); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) AD_Tree_ID = rs.getInt(1); - rs.close(); - pstmt.close(); } catch (SQLException e) { s_log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return AD_Tree_ID; } // getDefaultAD_Tree_ID @@ -225,18 +231,20 @@ public class MTree extends MTree_Base } log.finest(sql.toString()); // The Node Loop + PreparedStatement pstmt = null; + ResultSet rs = null; try { // load Node details - addToTree -> getNodeDetail getNodeDetails(); // - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); + pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); int idx = 1; if (AD_User_ID != -1 && getTreeType().equals(TREETYPE_Menu)) // IDEMPIERE 329 - nmicoud pstmt.setInt(idx++, AD_User_ID); pstmt.setInt(idx++, getAD_Tree_ID()); // Get Tree & Bar - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); m_root = new MTreeNode (0, 0, getName(), getDescription(), 0, true, null, false, null); while (rs.next()) { @@ -250,8 +258,6 @@ public class MTree extends MTree_Base else addToTree (node_ID, parent_ID, seqNo, onBar); // calls getNodeDetail } - rs.close(); - pstmt.close(); // //closing the rowset will also close connection for oracle rowset implementation //m_nodeRowSet.close(); @@ -264,6 +270,12 @@ public class MTree extends MTree_Base m_nodeRowSet = null; m_nodeIdMap = null; } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // Done with loading - add remainder from buffer if (m_buffer.size() != 0) diff --git a/org.adempiere.base/src/org/compiere/model/MTree_Node.java b/org.adempiere.base/src/org/compiere/model/MTree_Node.java index ac63bbe45b..abd8070904 100644 --- a/org.adempiere.base/src/org/compiere/model/MTree_Node.java +++ b/org.adempiere.base/src/org/compiere/model/MTree_Node.java @@ -48,30 +48,24 @@ public class MTree_Node extends X_AD_TreeNode MTree_Node retValue = null; String sql = "SELECT * FROM AD_TreeNode WHERE AD_Tree_ID=? AND Node_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, tree.get_TrxName()); pstmt.setInt (1, tree.getAD_Tree_ID()); pstmt.setInt (2, Node_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = new MTree_Node (tree.getCtx(), rs, tree.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; } return retValue; diff --git a/org.adempiere.base/src/org/compiere/model/MTree_NodeBP.java b/org.adempiere.base/src/org/compiere/model/MTree_NodeBP.java index 3ab62a48a7..dcc50dce1f 100644 --- a/org.adempiere.base/src/org/compiere/model/MTree_NodeBP.java +++ b/org.adempiere.base/src/org/compiere/model/MTree_NodeBP.java @@ -48,30 +48,24 @@ public class MTree_NodeBP extends X_AD_TreeNodeBP MTree_NodeBP retValue = null; String sql = "SELECT * FROM AD_TreeNodeBP WHERE AD_Tree_ID=? AND Node_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, tree.get_TrxName()); pstmt.setInt (1, tree.getAD_Tree_ID()); pstmt.setInt (2, Node_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = new MTree_NodeBP (tree.getCtx(), rs, tree.get_TrxName()); - 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; } return retValue; diff --git a/org.adempiere.base/src/org/compiere/model/MTree_NodeCMC.java b/org.adempiere.base/src/org/compiere/model/MTree_NodeCMC.java index f43961392b..cb564c71cf 100644 --- a/org.adempiere.base/src/org/compiere/model/MTree_NodeCMC.java +++ b/org.adempiere.base/src/org/compiere/model/MTree_NodeCMC.java @@ -51,31 +51,25 @@ public class MTree_NodeCMC extends X_AD_TreeNodeCMC ArrayList list = new ArrayList(); String sql = "SELECT * FROM AD_TreeNodeCMC WHERE AD_Tree_ID=? ORDER BY Node_ID"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, trxName); pstmt.setInt (1, AD_Tree_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { list.add (new MTree_NodeCMC (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; } MTree_NodeCMC[] retValue = new MTree_NodeCMC[list.size ()]; @@ -95,30 +89,24 @@ public class MTree_NodeCMC extends X_AD_TreeNodeCMC MTree_NodeCMC retValue = null; String sql = "SELECT * FROM AD_TreeNodeCMC WHERE AD_Tree_ID=? AND Node_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, tree.get_TrxName()); pstmt.setInt (1, tree.getAD_Tree_ID()); pstmt.setInt (2, Node_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = new MTree_NodeCMC (tree.getCtx(), rs, tree.get_TrxName()); - 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; } return retValue; diff --git a/org.adempiere.base/src/org/compiere/model/MTree_NodeCMS.java b/org.adempiere.base/src/org/compiere/model/MTree_NodeCMS.java index 29add588e2..3755569434 100644 --- a/org.adempiere.base/src/org/compiere/model/MTree_NodeCMS.java +++ b/org.adempiere.base/src/org/compiere/model/MTree_NodeCMS.java @@ -51,31 +51,25 @@ public class MTree_NodeCMS extends X_AD_TreeNodeCMS ArrayList list = new ArrayList(); String sql = "SELECT * FROM AD_TreeNodeCMS WHERE AD_Tree_ID=? ORDER BY Node_ID"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, trxName); pstmt.setInt (1, AD_Tree_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { list.add (new MTree_NodeCMS (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; } MTree_NodeCMS[] retValue = new MTree_NodeCMS[list.size ()]; @@ -94,30 +88,24 @@ public class MTree_NodeCMS extends X_AD_TreeNodeCMS MTree_NodeCMS retValue = null; String sql = "SELECT * FROM AD_TreeNodeCMS WHERE AD_Tree_ID=? AND Node_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, tree.get_TrxName()); pstmt.setInt (1, tree.getAD_Tree_ID()); pstmt.setInt (2, Node_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = new MTree_NodeCMS (tree.getCtx(), rs, tree.get_TrxName()); - 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; } return retValue; diff --git a/org.adempiere.base/src/org/compiere/model/MTree_NodeMM.java b/org.adempiere.base/src/org/compiere/model/MTree_NodeMM.java index d51963a124..202c73a9fd 100644 --- a/org.adempiere.base/src/org/compiere/model/MTree_NodeMM.java +++ b/org.adempiere.base/src/org/compiere/model/MTree_NodeMM.java @@ -48,30 +48,24 @@ public class MTree_NodeMM extends X_AD_TreeNodeMM MTree_NodeMM retValue = null; String sql = "SELECT * FROM AD_TreeNodeMM WHERE AD_Tree_ID=? AND Node_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, tree.get_TrxName()); pstmt.setInt (1, tree.getAD_Tree_ID()); pstmt.setInt (2, Node_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = new MTree_NodeMM (tree.getCtx(), rs, tree.get_TrxName()); - 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; } return retValue; diff --git a/org.adempiere.base/src/org/compiere/model/MTree_NodePR.java b/org.adempiere.base/src/org/compiere/model/MTree_NodePR.java index 6b9c3588a3..e7ea9d93ca 100644 --- a/org.adempiere.base/src/org/compiere/model/MTree_NodePR.java +++ b/org.adempiere.base/src/org/compiere/model/MTree_NodePR.java @@ -48,30 +48,24 @@ public class MTree_NodePR extends X_AD_TreeNodePR MTree_NodePR retValue = null; String sql = "SELECT * FROM AD_TreeNodePR WHERE AD_Tree_ID=? AND Node_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, tree.get_TrxName()); pstmt.setInt (1, tree.getAD_Tree_ID()); pstmt.setInt (2, Node_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = new MTree_NodePR (tree.getCtx(), rs, tree.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; } return retValue; diff --git a/org.adempiere.base/src/org/compiere/model/MUserOrgAccess.java b/org.adempiere.base/src/org/compiere/model/MUserOrgAccess.java index 0fc58d85c9..45e9d79d00 100644 --- a/org.adempiere.base/src/org/compiere/model/MUserOrgAccess.java +++ b/org.adempiere.base/src/org/compiere/model/MUserOrgAccess.java @@ -63,29 +63,23 @@ public class MUserOrgAccess extends X_AD_User_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 MUserOrgAccess(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; } MUserOrgAccess[] retValue = new MUserOrgAccess[list.size ()]; @@ -190,32 +184,26 @@ public class MUserOrgAccess extends X_AD_User_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, 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/MWarehousePrice.java b/org.adempiere.base/src/org/compiere/model/MWarehousePrice.java index 17dbe5cab3..30b784a732 100644 --- a/org.adempiere.base/src/org/compiere/model/MWarehousePrice.java +++ b/org.adempiere.base/src/org/compiere/model/MWarehousePrice.java @@ -95,6 +95,7 @@ public class MWarehousePrice extends X_RV_WarehousePrice + " - " + finalSQL); ArrayList list = new ArrayList(); PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(finalSQL, trxName); @@ -109,27 +110,20 @@ public class MWarehousePrice extends X_RV_WarehousePrice pstmt.setString(index++, UPC); if (SKU != null && SKU.length() > 0) pstmt.setString(index++, SKU); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MWarehousePrice(ctx, rs, trxName)); - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { s_log.log(Level.SEVERE, finalSQL, e); } - try + finally { - if (pstmt != null) - pstmt.close(); + DB.close(rs, pstmt); + rs = null; pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } + } // s_log.fine("find - #" + list.size()); MWarehousePrice[] retValue = new MWarehousePrice[list.size()]; @@ -191,31 +185,25 @@ public class MWarehousePrice extends X_RV_WarehousePrice String sql = "SELECT * FROM RV_WarehousePrice " + "WHERE M_Product_ID=? AND M_PriceList_Version_ID=? AND M_Warehouse_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, trxName); pstmt.setInt (1, product.getM_Product_ID()); pstmt.setInt(2, M_PriceList_Version_ID); pstmt.setInt(3, M_Warehouse_ID); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); if (rs.next ()) retValue = new MWarehousePrice(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; } return retValue; diff --git a/org.adempiere.base/src/org/compiere/model/MWebProjectDomain.java b/org.adempiere.base/src/org/compiere/model/MWebProjectDomain.java index ba71d88347..1589a282f5 100644 --- a/org.adempiere.base/src/org/compiere/model/MWebProjectDomain.java +++ b/org.adempiere.base/src/org/compiere/model/MWebProjectDomain.java @@ -71,29 +71,23 @@ public class MWebProjectDomain extends X_CM_WebProject_Domain MWebProjectDomain thisWebProjectDomain = null; String sql = "SELECT * FROM CM_WebProject_Domain WHERE lower(FQDN) LIKE ? ORDER by CM_WebProject_Domain_ID DESC"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, trxName); pstmt.setString(1, ServerName); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) thisWebProjectDomain = (new MWebProjectDomain(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; } return thisWebProjectDomain; diff --git a/org.adempiere.base/src/org/compiere/model/ScheduleUtil.java b/org.adempiere.base/src/org/compiere/model/ScheduleUtil.java index 74a4975a03..df4a176743 100644 --- a/org.adempiere.base/src/org/compiere/model/ScheduleUtil.java +++ b/org.adempiere.base/src/org/compiere/model/ScheduleUtil.java @@ -133,14 +133,16 @@ public class ScheduleUtil + " AND DateTo >= ?" // #2 start + " AND DateFrom <= ?" // #3 end + " AND IsActive='Y'"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { // log.fine( sql, "ID=" + S_Resource_ID + ", Start=" + m_startDate + ", End=" + m_endDate); - PreparedStatement pstmt = DB.prepareStatement(sql, trxName); + pstmt = DB.prepareStatement(sql, trxName); pstmt.setInt(1, m_S_Resource_ID); pstmt.setTimestamp(2, m_startDate); pstmt.setTimestamp(3, m_endDate); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { ma = new MAssignmentSlot (TimeUtil.getDay(rs.getTimestamp(2)), @@ -153,8 +155,6 @@ public class ScheduleUtil else list.add(ma); } - rs.close(); - pstmt.close(); } catch (SQLException e) { @@ -163,6 +163,13 @@ public class ScheduleUtil Msg.getMsg (m_ctx, "ResourceUnAvailable"), e.toString(), MAssignmentSlot.STATUS_UnAvailable); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } + if (ma != null && !getAll) return new MAssignmentSlot[] {ma}; @@ -180,10 +187,10 @@ public class ScheduleUtil Timestamp startDay = TimeUtil.getDay(m_startDate); Timestamp endDay = TimeUtil.getDay(m_endDate); // log.fine( sql, "Start=" + startDay + ", End=" + endDay); - PreparedStatement pstmt = DB.prepareStatement(sql, trxName); + pstmt = DB.prepareStatement(sql, trxName); pstmt.setTimestamp(1, startDay); pstmt.setTimestamp(2, endDay); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { Timestamp date = rs.getTimestamp(2); @@ -194,8 +201,6 @@ public class ScheduleUtil log.finer("- NonBusinessDay " + ma); list.add(ma); } - rs.close(); - pstmt.close(); } catch (SQLException e) { @@ -204,6 +209,12 @@ public class ScheduleUtil Msg.getMsg(m_ctx, "NonBusinessDay"), e.toString(), MAssignmentSlot.STATUS_NonBusinessDay); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } if (ma != null && !getAll) return new MAssignmentSlot[] {ma}; @@ -217,9 +228,9 @@ public class ScheduleUtil + "WHERE S_ResourceType_ID=?"; try { - PreparedStatement pstmt = DB.prepareStatement(sql, trxName); + pstmt = DB.prepareStatement(sql, trxName); pstmt.setInt(1, m_S_ResourceType_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { m_typeName = rs.getString(1); @@ -259,8 +270,6 @@ public class ScheduleUtil } // DaySlot } - rs.close(); - pstmt.close(); } catch (SQLException e) { @@ -269,6 +278,12 @@ public class ScheduleUtil Msg.getMsg(m_ctx, "ResourceNotInSlotDay"), e.toString(), MAssignmentSlot.STATUS_NonBusinessDay); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } if (ma != null && !getAll) return new MAssignmentSlot[] {ma}; @@ -281,11 +296,11 @@ public class ScheduleUtil + " AND IsActive='Y'"; try { - PreparedStatement pstmt = DB.prepareStatement(sql, trxName); + pstmt = DB.prepareStatement(sql, trxName); pstmt.setInt(1, m_S_Resource_ID); pstmt.setTimestamp(2, m_startDate); pstmt.setTimestamp(3, m_endDate); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { MResourceAssignment mAssignment = @@ -295,8 +310,6 @@ public class ScheduleUtil break; list.add(ma); } - rs.close(); - pstmt.close(); } catch (SQLException e) { @@ -305,6 +318,12 @@ public class ScheduleUtil Msg.translate(m_ctx, "S_R"), e.toString(), MAssignmentSlot.STATUS_NotConfirmed); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } if (ma != null && !getAll) return new MAssignmentSlot[] {ma}; @@ -578,11 +597,13 @@ public class ScheduleUtil + " AND r.S_ResourceType_ID=rt.S_ResourceType_ID", "r", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO); // + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, S_Resource_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { if (!"Y".equals(rs.getString(1))) // Active @@ -597,14 +618,18 @@ public class ScheduleUtil } else m_isAvailable = false; - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); m_isAvailable = false; } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } m_S_Resource_ID = S_Resource_ID; } // getBaseInfo diff --git a/org.adempiere.base/src/org/compiere/process/DocumentEngine.java b/org.adempiere.base/src/org/compiere/process/DocumentEngine.java index c7f2497342..5efdd8230a 100644 --- a/org.adempiere.base/src/org/compiere/process/DocumentEngine.java +++ b/org.adempiere.base/src/org/compiere/process/DocumentEngine.java @@ -1184,12 +1184,13 @@ public class DocumentEngine implements DocAction + "WHERE l.AD_Ref_List_ID=t.AD_Ref_List_ID" + " AND t.AD_Language='" + Env.getAD_Language(Env.getCtx()) + "'" + " AND l.AD_Reference_ID=? ORDER BY t.Name"; - + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, DocAction.AD_REFERENCE_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { String value = rs.getString(1); @@ -1202,13 +1203,17 @@ public class DocumentEngine implements DocAction v_name.add(name); v_description.add(description); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } /** diff --git a/org.adempiere.base/src/org/compiere/process/ProcessInfoUtil.java b/org.adempiere.base/src/org/compiere/process/ProcessInfoUtil.java index 6b871803bf..7c05abc2f2 100644 --- a/org.adempiere.base/src/org/compiere/process/ProcessInfoUtil.java +++ b/org.adempiere.base/src/org/compiere/process/ProcessInfoUtil.java @@ -54,15 +54,16 @@ public class ProcessInfoUtil String sql = "SELECT Result, ErrorMsg FROM AD_PInstance " + "WHERE AD_PInstance_ID=?" + " AND Result IS NOT NULL"; - + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement (sql, + pstmt = DB.prepareStatement (sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, null); for (int noTry = 0; noTry < noRetry; noTry++) { pstmt.setInt(1, pi.getAD_PInstance_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { // we have a result @@ -76,16 +77,14 @@ public class ProcessInfoUtil pi.setSummary(Msg.getMsg(Env.getCtx(), "Failure"), true); } String Message = rs.getString(2); - rs.close(); - pstmt.close(); // if (Message != null) pi.addSummary (" (" + Msg.parseTranslation(Env.getCtx(), Message) + ")"); // s_log.fine("setSummaryFromDB - " + Message); return; } - - rs.close(); + DB.close(rs); + rs = null; // sleep try { @@ -97,7 +96,6 @@ public class ProcessInfoUtil s_log.log(Level.SEVERE, "Sleep Thread", ie); } } - pstmt.close(); } catch (SQLException e) { @@ -105,6 +103,11 @@ public class ProcessInfoUtil pi.setSummary (e.getLocalizedMessage(), true); return; } + finally + { + DB.close(rs,pstmt); + rs = null;pstmt = null; + } pi.setSummary (Msg.getMsg(Env.getCtx(), "Timeout"), true); } // setSummaryFromDB @@ -119,23 +122,28 @@ public class ProcessInfoUtil + "FROM AD_PInstance_Log " + "WHERE AD_PInstance_ID=? " + "ORDER BY Log_ID"; - + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, pi.getAD_PInstance_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()){ // int Log_ID, int P_ID, Timestamp P_Date, BigDecimal P_Number, String P_Msg, AD_Table_ID, Record_ID pi.addLog (rs.getInt(1), rs.getInt(2), rs.getTimestamp(3), rs.getBigDecimal(4), rs.getString(5), rs.getInt(6), rs.getInt(7)); } - rs.close(); - pstmt.close(); } catch (SQLException e) { s_log.log(Level.SEVERE, "setLogFromDB", e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } } // getLogFromDB /** @@ -207,11 +215,13 @@ public class ProcessInfoUtil + " INNER JOIN AD_PInstance i ON (p.AD_PInstance_ID=i.AD_PInstance_ID) " + "WHERE p.AD_PInstance_ID=? " + "ORDER BY p.SeqNo"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, pi.getAD_PInstance_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { String ParameterName = rs.getString(1); @@ -241,13 +251,17 @@ public class ProcessInfoUtil if (pi.getAD_User_ID() == null) pi.setAD_User_ID(rs.getInt(12)); } - rs.close(); - pstmt.close(); } catch (SQLException e) { s_log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // ProcessInfoParameter[] pars = new ProcessInfoParameter[list.size()]; list.toArray(pars); diff --git a/org.adempiere.base/src/org/compiere/report/MReportColumnSet.java b/org.adempiere.base/src/org/compiere/report/MReportColumnSet.java index 2e9e9db0cb..11526e4c45 100644 --- a/org.adempiere.base/src/org/compiere/report/MReportColumnSet.java +++ b/org.adempiere.base/src/org/compiere/report/MReportColumnSet.java @@ -66,16 +66,14 @@ public class MReportColumnSet extends X_PA_ReportColumnSet ArrayList list = new ArrayList(); String sql = "SELECT * FROM PA_ReportColumn WHERE PA_ReportColumnSet_ID=? AND IsActive='Y' ORDER BY SeqNo"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getPA_ReportColumnSet_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MReportColumn (getCtx(), rs, null)); - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { @@ -83,13 +81,8 @@ public class MReportColumnSet extends X_PA_ReportColumnSet } 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/report/MReportLine.java b/org.adempiere.base/src/org/compiere/report/MReportLine.java index 3a10426e87..a764ab1f55 100644 --- a/org.adempiere.base/src/org/compiere/report/MReportLine.java +++ b/org.adempiere.base/src/org/compiere/report/MReportLine.java @@ -84,16 +84,14 @@ public class MReportLine extends X_PA_ReportLine ArrayList list = new ArrayList(); String sql = "SELECT * FROM PA_ReportSource WHERE PA_ReportLine_ID=? AND IsActive='Y'"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getPA_ReportLine_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MReportSource (getCtx(), rs, null)); - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { @@ -101,13 +99,8 @@ public class MReportLine extends X_PA_ReportLine } 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/report/MReportLineSet.java b/org.adempiere.base/src/org/compiere/report/MReportLineSet.java index 013440fe4e..e9228a2afd 100644 --- a/org.adempiere.base/src/org/compiere/report/MReportLineSet.java +++ b/org.adempiere.base/src/org/compiere/report/MReportLineSet.java @@ -68,16 +68,14 @@ public class MReportLineSet extends X_PA_ReportLineSet + "WHERE PA_ReportLineSet_ID=? AND IsActive='Y' " + "ORDER BY SeqNo"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getPA_ReportLineSet_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MReportLine (getCtx(), rs, get_TrxName())); - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { @@ -85,13 +83,8 @@ public class MReportLineSet extends X_PA_ReportLineSet } 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/report/MReportTree.java b/org.adempiere.base/src/org/compiere/report/MReportTree.java index 41bc4f1e54..e2993c3aae 100644 --- a/org.adempiere.base/src/org/compiere/report/MReportTree.java +++ b/org.adempiere.base/src/org/compiere/report/MReportTree.java @@ -170,21 +170,27 @@ public class MReportTree String sql = "SELECT AD_Tree_ID, Name FROM AD_Tree " + "WHERE AD_Client_ID=? AND TreeType=? AND IsActive='Y' AND IsAllNodes='Y' " + "ORDER BY IsDefault DESC, AD_Tree_ID"; // assumes first is primary tree + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_Client_ID); pstmt.setString(2, m_TreeType); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) AD_Tree_ID = rs.getInt(1); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return AD_Tree_ID; } // getDefaultAD_Tree_ID diff --git a/org.adempiere.base/src/org/compiere/report/TrialBalance.java b/org.adempiere.base/src/org/compiere/report/TrialBalance.java index 348b315826..e1f5646a21 100644 --- a/org.adempiere.base/src/org/compiere/report/TrialBalance.java +++ b/org.adempiere.base/src/org/compiere/report/TrialBalance.java @@ -245,19 +245,17 @@ public class TrialBalance extends SvrProcess String sql = "SELECT StartDate, EndDate FROM C_Period WHERE C_Period_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, p_C_Period_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); if (rs.next()) { p_DateAcct_From = rs.getTimestamp(1); p_DateAcct_To = rs.getTimestamp(2); } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { @@ -265,13 +263,8 @@ public class TrialBalance extends SvrProcess } finally { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} + DB.close(rs, pstmt); + rs = null; pstmt = null; } } // setDateAcct diff --git a/org.adempiere.base/src/org/compiere/report/core/RModelData.java b/org.adempiere.base/src/org/compiere/report/core/RModelData.java index 77e48ec9f5..a7f79c0ba8 100644 --- a/org.adempiere.base/src/org/compiere/report/core/RModelData.java +++ b/org.adempiere.base/src/org/compiere/report/core/RModelData.java @@ -123,10 +123,12 @@ public class RModelData // FillData int index = 0; // rowset index m_rows.clear(); + Statement stmt = null; + ResultSet rs = null; try { - Statement stmt = DB.createStatement(); - ResultSet rs = stmt.executeQuery(finalSQL); + stmt = DB.createStatement(); + rs = stmt.executeQuery(finalSQL); while (rs.next()) { ArrayList row = new ArrayList(size); @@ -163,8 +165,6 @@ public class RModelData } m_rows.add(row); } - rs.close(); - stmt.close(); } catch (SQLException e) { @@ -174,6 +174,12 @@ public class RModelData log.log(Level.SEVERE, "Index=" + index + "," + rc, e); e.printStackTrace(); } + finally + { + DB.close(rs, stmt); + rs = null; + stmt = null; + } process(); } // query diff --git a/org.adempiere.base/src/org/compiere/util/CCachedRowSet.java b/org.adempiere.base/src/org/compiere/util/CCachedRowSet.java index 16a889b3a5..7291952c30 100644 --- a/org.adempiere.base/src/org/compiere/util/CCachedRowSet.java +++ b/org.adempiere.base/src/org/compiere/util/CCachedRowSet.java @@ -101,14 +101,26 @@ public class CCachedRowSet extends CachedRowSetImpl implements CachedRowSet { if (db.getName().equals(Database.DB_ORACLE)) { - Statement stmt = conn.createStatement - (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); - ResultSet rs = stmt.executeQuery(sql); - CachedRowSetImpl crs = new CachedRowSetImpl(); - crs.populate(rs); - rs.close(); - stmt.close(); - return crs; + Statement stmt = null; + ResultSet rs = null; + try + { + stmt = conn.createStatement + (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); + rs = stmt.executeQuery(sql); + CachedRowSetImpl crs = new CachedRowSetImpl(); + crs.populate(rs); + return crs; + } catch (SQLException e) + { + throw e; + } + finally + { + DB.close(rs, stmt); + rs = null; + stmt = null; + } } CachedRowSet crs = get(); crs.setConcurrency(ResultSet.CONCUR_READ_ONLY); diff --git a/org.adempiere.base/src/org/compiere/util/GenericPaymentExport.java b/org.adempiere.base/src/org/compiere/util/GenericPaymentExport.java index ccfc608413..ca0cdef7b6 100644 --- a/org.adempiere.base/src/org/compiere/util/GenericPaymentExport.java +++ b/org.adempiere.base/src/org/compiere/util/GenericPaymentExport.java @@ -194,11 +194,13 @@ public class GenericPaymentExport implements PaymentExport + " AND a.C_Region_ID=r.C_Region_ID(+)" + " AND a.C_Country_ID=cc.C_Country_ID " + "ORDER BY l.IsBillTo DESC"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, C_BPartner_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); // if (rs.next()) { @@ -233,13 +235,17 @@ public class GenericPaymentExport implements PaymentExport if (bp[BP_REFNO] == null) bp[BP_REFNO] = ""; } - rs.close(); - pstmt.close(); } catch (SQLException e) { s_log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return bp; } // getBPartnerInfo diff --git a/org.adempiere.base/src/org/compiere/util/WebInfo.java b/org.adempiere.base/src/org/compiere/util/WebInfo.java index d32b3ba5b0..721f164c75 100644 --- a/org.adempiere.base/src/org/compiere/util/WebInfo.java +++ b/org.adempiere.base/src/org/compiere/util/WebInfo.java @@ -476,9 +476,6 @@ public class WebInfo rs = pstmt.executeQuery(); while (rs.next()) list.add (new MRequestType (m_ctx, rs, null)); - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { diff --git a/org.adempiere.base/src/org/eevolution/model/MDDOrder.java b/org.adempiere.base/src/org/eevolution/model/MDDOrder.java index 64051b3fdb..e763b7a502 100644 --- a/org.adempiere.base/src/org/eevolution/model/MDDOrder.java +++ b/org.adempiere.base/src/org/eevolution/model/MDDOrder.java @@ -511,16 +511,14 @@ public class MDDOrder extends X_DD_Order implements DocAction "ORDER BY m.Created DESC"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, getDD_Order_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) list.add(new MMovement(getCtx(), rs, get_TrxName())); - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { @@ -528,13 +526,8 @@ public class MDDOrder extends X_DD_Order implements DocAction } 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/idempiere/fa/model/CalloutAsset.java b/org.adempiere.base/src/org/idempiere/fa/model/CalloutAsset.java index 4632f2eb72..872a85d0a4 100644 --- a/org.adempiere.base/src/org/idempiere/fa/model/CalloutAsset.java +++ b/org.adempiere.base/src/org/idempiere/fa/model/CalloutAsset.java @@ -81,17 +81,19 @@ public class CalloutAsset extends CalloutEngine { { Integer A_Depreciation_Table_Header_ID = (Integer)value; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - if (A_Depreciation_Table_Header_ID != null){ + if (A_Depreciation_Table_Header_ID != null){ String SQL = "SELECT A_Term " + "FROM A_Depreciation_Table_Header " + "WHERE A_Depreciation_Table_Header_ID='" +A_Depreciation_Table_Header_ID +"'"; - PreparedStatement pstmt = DB.prepareStatement(SQL, null); // arhipac: compatibility - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(SQL, null); // arhipac: compatibility + rs = pstmt.executeQuery(); if (rs.next()) { // Charges - Set Context @@ -99,15 +101,19 @@ public class CalloutAsset extends CalloutEngine { mTab.setValue ("A_DEPRECIATION_MANUAL_PERIOD", rs.getString("A_Term")); } - rs.close(); - pstmt.close(); - } + } } catch (SQLException e) { log.info("PeriodType "+ e); return e.getLocalizedMessage(); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return ""; } // Period Type @@ -131,6 +137,8 @@ public class CalloutAsset extends CalloutEngine { { Object A_Depreciation_ID = value; + PreparedStatement pstmt = null; + ResultSet rs = null; try { String SQL = "SELECT DepreciationType " @@ -138,8 +146,8 @@ public class CalloutAsset extends CalloutEngine { + "WHERE A_Depreciation_ID=" + A_Depreciation_ID; - PreparedStatement pstmt = DB.prepareStatement(SQL, null); // arhipac: compatibility - ResultSet rs = pstmt.executeQuery(); + pstmt = DB.prepareStatement(SQL, null); // arhipac: compatibility + rs = pstmt.executeQuery(); if (rs.next()) { // Charges - Set Context @@ -160,14 +168,18 @@ public class CalloutAsset extends CalloutEngine { mTab.setValue ("A_Depreciation_Table_Header_ID", null); } } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.info("PeriodType "+ e); return e.getLocalizedMessage(); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } return ""; } // Period Type 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.server-feature/server.product b/org.adempiere.server-feature/server.product index 43e285d515..3c43351ac7 100644 --- a/org.adempiere.server-feature/server.product +++ b/org.adempiere.server-feature/server.product @@ -3,6 +3,7 @@ + @@ -14,6 +15,7 @@ + @@ -21,9 +23,11 @@ + + @@ -31,6 +35,7 @@ + @@ -39,11 +44,14 @@ + + + @@ -54,7 +62,6 @@ - diff --git a/org.adempiere.server-feature/server.product.launch b/org.adempiere.server-feature/server.product.launch index 5466fcdaf2..2dbed27e21 100644 --- a/org.adempiere.server-feature/server.product.launch +++ b/org.adempiere.server-feature/server.product.launch @@ -21,8 +21,8 @@ - - + + diff --git a/org.adempiere.server/src/main/server/org/compiere/server/AcctProcessor.java b/org.adempiere.server/src/main/server/org/compiere/server/AcctProcessor.java index 28c4b226ef..8029cc64fb 100644 --- a/org.adempiere.server/src/main/server/org/compiere/server/AcctProcessor.java +++ b/org.adempiere.server/src/main/server/org/compiere/server/AcctProcessor.java @@ -202,7 +202,6 @@ public class AcctProcessor extends AdempiereServer if (!ok) countError[i]++; } - rs.close(); } catch (Exception e) { @@ -211,6 +210,8 @@ public class AcctProcessor extends AdempiereServer finally { DB.close(rs, pstmt); + rs = null; + pstmt = null; } } // for tableID diff --git a/org.adempiere.server/src/main/server/org/compiere/server/RequestProcessor.java b/org.adempiere.server/src/main/server/org/compiere/server/RequestProcessor.java index 7afee9eec7..18dff4c00c 100644 --- a/org.adempiere.server/src/main/server/org/compiere/server/RequestProcessor.java +++ b/org.adempiere.server/src/main/server/org/compiere/server/RequestProcessor.java @@ -102,6 +102,7 @@ public class RequestProcessor extends AdempiereServer if (m_model.getR_RequestType_ID() != 0) sql += " AND R_RequestType_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; int count = 0; int countEMails = 0; try @@ -110,7 +111,7 @@ public class RequestProcessor extends AdempiereServer pstmt.setInt (1, m_model.getAD_Client_ID()); if (m_model.getR_RequestType_ID() != 0) pstmt.setInt(2, m_model.getR_RequestType_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MRequest request = new MRequest (getCtx(), rs, null); @@ -129,7 +130,6 @@ public class RequestProcessor extends AdempiereServer count++; } } - rs.close (); } catch (Exception e) { @@ -137,7 +137,9 @@ public class RequestProcessor extends AdempiereServer } finally { - DB.close(pstmt); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } m_summary.append("New Due #").append(count); if (countEMails > 0) @@ -164,7 +166,7 @@ public class RequestProcessor extends AdempiereServer pstmt.setInt (1, m_model.getAD_Client_ID()); if (m_model.getR_RequestType_ID() != 0) pstmt.setInt(2, m_model.getR_RequestType_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MRequest request = new MRequest (getCtx(), rs, null); @@ -184,7 +186,6 @@ public class RequestProcessor extends AdempiereServer count++; } } - rs.close (); } catch (Exception e) { @@ -192,7 +193,9 @@ public class RequestProcessor extends AdempiereServer } finally { - DB.close(pstmt); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } m_summary.append("New Overdue #").append(count); if (countEMails > 0) @@ -223,7 +226,7 @@ public class RequestProcessor extends AdempiereServer pstmt.setInt(1, m_model.getAD_Client_ID()); if (m_model.getR_RequestType_ID() != 0) pstmt.setInt(2, m_model.getR_RequestType_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { MRequest request = new MRequest (getCtx(), rs, null); @@ -241,7 +244,6 @@ public class RequestProcessor extends AdempiereServer request.saveEx(); count++; } - rs.close(); } catch (SQLException e) { @@ -249,7 +251,9 @@ public class RequestProcessor extends AdempiereServer } finally { - DB.close(pstmt); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } m_summary.append("Alerts #").append(count); if (countEMails > 0) @@ -278,14 +282,13 @@ public class RequestProcessor extends AdempiereServer pstmt.setInt(1, m_model.getAD_Client_ID()); if (m_model.getR_RequestType_ID() != 0) pstmt.setInt(2, m_model.getR_RequestType_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { MRequest request = new MRequest (getCtx(), rs, null); if (escalate(request)) count++; } - rs.close(); } catch (SQLException e) { @@ -293,7 +296,9 @@ public class RequestProcessor extends AdempiereServer } finally { - DB.close(pstmt); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } m_summary.append("Escalated #").append(count).append(" - "); } // Esacalate @@ -322,7 +327,7 @@ public class RequestProcessor extends AdempiereServer pstmt.setInt(1, m_model.getAD_Client_ID()); if (m_model.getR_RequestType_ID() != 0) pstmt.setInt(2, m_model.getR_RequestType_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { MRequest request = new MRequest (getCtx(), rs, null); @@ -339,7 +344,6 @@ public class RequestProcessor extends AdempiereServer count++; } } - rs.close(); } catch (SQLException e) { @@ -347,7 +351,9 @@ public class RequestProcessor extends AdempiereServer } finally { - DB.close(pstmt); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } m_summary.append("Inactivity #").append(count); if (countEMails > 0) @@ -430,12 +436,13 @@ public class RequestProcessor extends AdempiereServer + ") " + "ORDER BY R_Status_ID"; PreparedStatement pstmt = null; + ResultSet rs = null; MStatus status = null; MStatus next = null; try { pstmt = DB.prepareStatement (sql, null); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MRequest r = new MRequest(getCtx(), rs, null); @@ -456,7 +463,6 @@ public class RequestProcessor extends AdempiereServer if (r.save()) count++; } - rs.close (); } catch (Exception e) { @@ -464,7 +470,9 @@ public class RequestProcessor extends AdempiereServer } finally { - DB.close(pstmt); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } m_summary.append("Status Timeout #").append(count) @@ -492,10 +500,11 @@ public class RequestProcessor extends AdempiereServer int failure = 0; // PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement (sql, null); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MRequest r = new MRequest (getCtx(), rs, null); @@ -512,7 +521,6 @@ public class RequestProcessor extends AdempiereServer else failure++; } - rs.close (); } catch (Exception e) { @@ -520,7 +528,9 @@ public class RequestProcessor extends AdempiereServer } finally { - DB.close(pstmt); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } m_summary.append("Auto Change Request #").append(count); @@ -555,13 +565,14 @@ public class RequestProcessor extends AdempiereServer if (m_model.getR_RequestType_ID() != 0) sql += " AND R_RequestType_ID=?"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_model.getAD_Client_ID()); if (m_model.getR_RequestType_ID() != 0) pstmt.setInt(2, m_model.getR_RequestType_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { MRequest request = new MRequest (ctx, rs, null); @@ -577,7 +588,6 @@ public class RequestProcessor extends AdempiereServer else notFound++; } - rs.close(); } catch (SQLException ex) { @@ -585,9 +595,10 @@ public class RequestProcessor extends AdempiereServer } finally { - DB.close(pstmt); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } - pstmt = null; // if (changed == 0 && notFound == 0) m_summary.append("No unallocated Requests"); diff --git a/org.adempiere.server/src/main/server/org/compiere/server/WorkflowProcessor.java b/org.adempiere.server/src/main/server/org/compiere/server/WorkflowProcessor.java index b3f36f2705..9939007cb1 100644 --- a/org.adempiere.server/src/main/server/org/compiere/server/WorkflowProcessor.java +++ b/org.adempiere.server/src/main/server/org/compiere/server/WorkflowProcessor.java @@ -103,13 +103,14 @@ public class WorkflowProcessor extends AdempiereServer + " AND wfn.Action='Z'" // sleeping + " AND (wf.AD_WorkflowProcessor_ID IS NULL OR wf.AD_WorkflowProcessor_ID=?))"; PreparedStatement pstmt = null; + ResultSet rs = null; int count = 0; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt (1, m_model.getAD_Client_ID()); pstmt.setInt (2, m_model.getAD_WorkflowProcessor_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MWFActivity activity = new MWFActivity (getCtx(), rs, null); @@ -117,7 +118,6 @@ public class WorkflowProcessor extends AdempiereServer // saves and calls MWFProcess.checkActivities(); count++; } - rs.close (); } catch (Exception e) { @@ -125,7 +125,9 @@ public class WorkflowProcessor extends AdempiereServer } finally { - DB.close(pstmt); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } m_summary.append("Wakeup #").append(count).append (" - "); } // wakeup @@ -144,12 +146,13 @@ public class WorkflowProcessor extends AdempiereServer + "WHERE a.AD_WF_Node_ID=wfn.AD_WF_Node_ID AND wf.AD_WorkflowProcessor_ID=?" + " AND wfn.DynPriorityUnit IS NOT NULL AND wfn.DynPriorityChange IS NOT NULL)"; PreparedStatement pstmt = null; + ResultSet rs = null; int count = 0; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt(1, m_model.getAD_WorkflowProcessor_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MWFActivity activity = new MWFActivity (getCtx(), rs, null); @@ -162,7 +165,6 @@ public class WorkflowProcessor extends AdempiereServer activity.saveEx(); count++; } - rs.close (); } catch (Exception e) { @@ -170,7 +172,9 @@ public class WorkflowProcessor extends AdempiereServer } finally { - DB.close(pstmt); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } m_summary.append("DynPriority #").append(count).append (" - "); @@ -200,12 +204,13 @@ public class WorkflowProcessor extends AdempiereServer int count = 0; int countEMails = 0; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sql, null); pstmt.setInt (1, m_model.getAlertOverPriority()); pstmt.setInt (2, m_model.getAD_WorkflowProcessor_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { MWFActivity activity = new MWFActivity (getCtx(), rs, null); @@ -216,8 +221,6 @@ public class WorkflowProcessor extends AdempiereServer activity.saveEx(); count++; } - rs.close(); - pstmt.close(); } catch (SQLException e) { @@ -225,7 +228,9 @@ public class WorkflowProcessor extends AdempiereServer } finally { - DB.close(pstmt); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } m_summary.append("OverPriority #").append(count); if (countEMails > 0) @@ -250,13 +255,14 @@ public class WorkflowProcessor extends AdempiereServer + " AND wfn.Action<>'Z'" // not sleeping + " AND (wf.AD_WorkflowProcessor_ID IS NULL OR wf.AD_WorkflowProcessor_ID=?))"; PreparedStatement pstmt = null; + ResultSet rs = null; int count = 0; int countEMails = 0; try { pstmt = DB.prepareStatement (sql, null); pstmt.setInt(1, m_model.getAD_WorkflowProcessor_ID()); - ResultSet rs = pstmt.executeQuery (); + rs = pstmt.executeQuery (); while (rs.next ()) { MWFActivity activity = new MWFActivity (getCtx(), rs, null); @@ -267,7 +273,6 @@ public class WorkflowProcessor extends AdempiereServer activity.saveEx(); count++; } - rs.close (); } catch (Exception e) { @@ -275,7 +280,9 @@ public class WorkflowProcessor extends AdempiereServer } finally { - DB.close(pstmt); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } m_summary.append("EndWaitTime #").append(count); @@ -306,7 +313,7 @@ public class WorkflowProcessor extends AdempiereServer { pstmt = DB.prepareStatement(sql, null); pstmt.setInt (1, m_model.getAD_WorkflowProcessor_ID()); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { MWFActivity activity = new MWFActivity (getCtx(), rs, null); @@ -317,8 +324,6 @@ public class WorkflowProcessor extends AdempiereServer activity.saveEx(); count++; } - rs.close(); - pstmt.close(); } catch (SQLException e) { @@ -326,7 +331,9 @@ public class WorkflowProcessor extends AdempiereServer } finally { - DB.close(pstmt); + DB.close(rs, pstmt); + rs = null; + pstmt = null; } m_summary.append("Inactivity #").append(count); if (countEMails > 0) diff --git a/org.adempiere.ui.swing-feature/swingclient.product b/org.adempiere.ui.swing-feature/swingclient.product index 0d40ead680..418b99fa71 100644 --- a/org.adempiere.ui.swing-feature/swingclient.product +++ b/org.adempiere.ui.swing-feature/swingclient.product @@ -29,10 +29,13 @@ + + + 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.swing/src/org/compiere/print/Viewer.java b/org.adempiere.ui.swing/src/org/compiere/print/Viewer.java index fc26d865f9..2f147d2184 100644 --- a/org.adempiere.ui.swing/src/org/compiere/print/Viewer.java +++ b/org.adempiere.ui.swing/src/org/compiere/print/Viewer.java @@ -380,13 +380,15 @@ public class Viewer extends CFrame + "WHERE c.AD_Table_ID=? AND c.IsKey='Y'" + " AND et.AD_Language=? " + "ORDER BY 3"; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, m_reportEngine.getPrintFormat().getAD_Table_ID()); if (trl) pstmt.setString(2, Env.getAD_Language(Env.getCtx())); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); while (rs.next()) { String tableName = rs.getString(2); @@ -396,13 +398,17 @@ public class Viewer extends CFrame name += "/" + poName; comboDrill.addItem(new ValueNamePair (tableName, name)); } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } if (comboDrill.getItemCount() == 1) { labelDrill.setVisible(false); @@ -434,11 +440,13 @@ public class Viewer extends CFrame + "ORDER BY Name", "AD_PrintFormat", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO); int AD_Table_ID = m_reportEngine.getPrintFormat().getAD_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(); while (rs.next()) { KeyNamePair pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); @@ -446,13 +454,17 @@ public class Viewer extends CFrame if (rs.getInt(1) == AD_PrintFormat_ID) selectValue = pp; } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // IDEMPIERE-297 - Check for Table Access and Window Access for New Report if ( MRole.getDefault().isTableAccess(MPrintFormat.Table_ID, false) && MRole.getDefault().getWindowAccess(WINDOW_PRINTFORMAT)) @@ -1151,11 +1163,13 @@ public class Viewer extends CFrame if (!Env.isBaseLanguage(Env.getCtx(), "AD_Tab")) sql = "SELECT Name, TableName FROM AD_Tab_vt WHERE AD_Tab_ID=?" + " AND AD_Language='" + Env.getAD_Language(Env.getCtx()) + "' " + ASPFilter; + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt = DB.prepareStatement(sql, null); pstmt.setInt(1, AD_Tab_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); // if (rs.next()) { @@ -1163,13 +1177,17 @@ public class Viewer extends CFrame tableName = 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; + } GridField[] findFields = null; if (tableName != null) @@ -1250,19 +1268,25 @@ public class Viewer extends CFrame ArrayList list = new ArrayList(); ValueNamePair pp = null; String sql = "SELECT Name, AD_Language FROM AD_Language WHERE IsSystemLanguage='Y' ORDER BY 1"; + 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()) list.add(new ValueNamePair (rs.getString(2), rs.getString(1))); - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql, e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } if (list.size() == 0) { ADialog.warn(m_WindowNo, this, "NoTranslation"); diff --git a/org.adempiere.ui.swing/src/org/eevolution/form/VInOutInvoiceGen.java b/org.adempiere.ui.swing/src/org/eevolution/form/VInOutInvoiceGen.java index ba9435029b..d48cad27f5 100755 --- a/org.adempiere.ui.swing/src/org/eevolution/form/VInOutInvoiceGen.java +++ b/org.adempiere.ui.swing/src/org/eevolution/form/VInOutInvoiceGen.java @@ -366,11 +366,13 @@ public class VInOutInvoiceGen extends CPanel int row = 0; miniTable.setRowCount(row); // Execute + PreparedStatement pstmt = null; + ResultSet rs = null; try { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); + pstmt = DB.prepareStatement(sql.toString(), null); pstmt.setInt(1, AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); + rs = pstmt.executeQuery(); // while (rs.next()) { @@ -387,13 +389,17 @@ public class VInOutInvoiceGen extends CPanel // prepare next row++; } - rs.close(); - pstmt.close(); } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); } + finally + { + DB.close(rs, pstmt); + rs = null; + pstmt = null; + } // miniTable.autoSize(); // statusBar.setStatusDB(String.valueOf(miniTable.getRowCount())); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ProcessInfoDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ProcessInfoDialog.java index dd4000b014..9c6165565b 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ProcessInfoDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ProcessInfoDialog.java @@ -14,9 +14,12 @@ package org.adempiere.webui.component; +import java.text.SimpleDateFormat; + import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.apps.AEnv; import org.compiere.process.ProcessInfoLog; +import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.Msg; import org.zkoss.zhtml.Text; @@ -72,20 +75,35 @@ public class ProcessInfoDialog extends Window implements EventListener { pnlMessage.appendChild(sep); for (int loopCtr = 0; loopCtr < m_logs.length; loopCtr++) { - if (m_logs[loopCtr].getP_Msg() != null) { + ProcessInfoLog log = m_logs[loopCtr]; + if (log.getP_Msg() != null || log.getP_Date() != null || log.getP_Number() != null) { + SimpleDateFormat dateFormat = DisplayType.getDateFormat(DisplayType.DateTime); + StringBuffer sb = new StringBuffer (); + // + if (log.getP_Date() != null) + sb.append(dateFormat.format(log.getP_Date())) + .append(" \t"); + // + if (log.getP_Number() != null) + sb.append(log.getP_Number()) + .append(" \t"); + // + if (log.getP_Msg() != null) + sb.append(Msg.parseTranslation(Env.getCtx(), log.getP_Msg())); + // - if (m_logs[loopCtr].getAD_Table_ID() > 0 - && m_logs[loopCtr].getRecord_ID() > 0) { + if (log.getAD_Table_ID() > 0 + && log.getRecord_ID() > 0) { A recordLink = new A(); - recordLink.setLabel(m_logs[loopCtr].getP_Msg()); + recordLink.setLabel(sb.toString()); recordLink.setAttribute("Record_ID", - String.valueOf(m_logs[loopCtr].getRecord_ID())); + String.valueOf(log.getRecord_ID())); recordLink.setAttribute("AD_Table_ID", - String.valueOf(m_logs[loopCtr].getAD_Table_ID())); + String.valueOf(log.getAD_Table_ID())); recordLink.addEventListener(Events.ON_CLICK, this); pnlMessage.appendChild(recordLink); } else { - Text recordText = new Text(Msg.parseTranslation(Env.getCtx(), m_logs[loopCtr].getP_Msg())); + Text recordText = new Text(sb.toString()); pnlMessage.appendChild(recordText); } pnlMessage.appendChild(new Separator("horizontal")); diff --git a/org.adempiere.ui/src/org/compiere/grid/CreateFromInvoice.java b/org.adempiere.ui/src/org/compiere/grid/CreateFromInvoice.java index fd0ba621d1..b80a3391b5 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; } @@ -137,24 +143,20 @@ public abstract class CreateFromInvoice extends CreateFrom + "WHERE inv.M_RMA_ID=r.M_RMA_ID AND inv.DocStatus IN ('CO', 'CL'))"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sqlStmt, null); pstmt.setInt(1, 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(); } catch (SQLException e) { log.log(Level.SEVERE, sqlStmt.toString(), e); - } finally { - if (pstmt != null) { - try { - pstmt.close(); - } catch (Exception ex) { - log.severe("Could not close prepared statement"); - } - } + } finally{ + DB.close(rs, pstmt); + rs = null; + pstmt = null; } return list; @@ -201,12 +203,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 +233,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 +317,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..d90106e647 100644 --- a/org.adempiere.ui/src/org/compiere/grid/CreateFromShipment.java +++ b/org.adempiere.ui/src/org/compiere/grid/CreateFromShipment.java @@ -98,24 +98,20 @@ public abstract class CreateFromShipment extends CreateFrom + "AND rl.M_InOutLine_ID IS NOT NULL)"; PreparedStatement pstmt = null; + ResultSet rs = null; try { pstmt = DB.prepareStatement(sqlStmt, null); pstmt.setInt(1, 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(); } catch (SQLException e) { log.log(Level.SEVERE, sqlStmt.toString(), e); - } finally { - if (pstmt != null) { - try { - pstmt.close(); - } catch (Exception ex) { - log.severe("Could not close prepared statement"); - } - } + } finally{ + DB.close(rs, pstmt); + rs = null; + pstmt = null; } return list; @@ -159,13 +155,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; } diff --git a/org.adempiere.webstore.servlet/src/org/compiere/wstore/RequestOrderRefTag.java b/org.adempiere.webstore.servlet/src/org/compiere/wstore/RequestOrderRefTag.java index f04d39cbe6..fa04736242 100644 --- a/org.adempiere.webstore.servlet/src/org/compiere/wstore/RequestOrderRefTag.java +++ b/org.adempiere.webstore.servlet/src/org/compiere/wstore/RequestOrderRefTag.java @@ -123,11 +123,12 @@ public class RequestOrderRefTag extends TagSupport + "WHERE C_BPartner_ID=? " + "ORDER BY CreatedBy DESC"; 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(); while (rs.next()) { o = new option (rs.getString(1)); @@ -137,9 +138,6 @@ public class RequestOrderRefTag extends TagSupport o.addElement(Util.maskHTML(display)); list.add(o); } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { @@ -147,16 +145,10 @@ public class RequestOrderRefTag extends TagSupport } finally { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} + DB.close(rs, pstmt); + rs = null; pstmt = null; } - // Return to Array and return option options[] = new option [list.size()]; list.toArray(options); diff --git a/org.adempiere.webstore.servlet/src/org/compiere/wstore/RequestTypeTag.java b/org.adempiere.webstore.servlet/src/org/compiere/wstore/RequestTypeTag.java index 12672f0889..537121e0aa 100644 --- a/org.adempiere.webstore.servlet/src/org/compiere/wstore/RequestTypeTag.java +++ b/org.adempiere.webstore.servlet/src/org/compiere/wstore/RequestTypeTag.java @@ -93,20 +93,18 @@ public class RequestTypeTag extends TagSupport + "WHERE AD_Client_ID=? AND IsActive='Y' AND IsSelfService='Y' " + "ORDER BY IsDefault DESC, Name"; 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()) { option o = new option (rs.getString(1)); o.addElement(Util.maskHTML(rs.getString(2))); list.add(o); } - rs.close(); - pstmt.close(); - pstmt = null; } catch (Exception e) { @@ -114,13 +112,8 @@ public class RequestTypeTag extends TagSupport } finally { - try - { - if (pstmt != null) - pstmt.close (); - } - catch (Exception e) - {} + DB.close(rs, pstmt); + rs = null; pstmt = null; } diff --git a/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/CompiereService.java b/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/CompiereService.java index 46065e497a..59a0fbaed9 100644 --- a/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/CompiereService.java +++ b/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/CompiereService.java @@ -223,14 +223,14 @@ public class CompiereService { rs = pstmt.executeQuery(); if (rs.next()) loginInfo = rs.getString(1); - rs.close(); - pstmt.close(); } catch (SQLException e) { e.printStackTrace(); } finally { DB.close(rs, pstmt); + rs = null; + pstmt = null; } // not verified