diff --git a/org.adempiere.base.process/src/org/compiere/process/CommissionCalc.java b/org.adempiere.base.process/src/org/compiere/process/CommissionCalc.java index a877e0f96e..22e7014af8 100644 --- a/org.adempiere.base.process/src/org/compiere/process/CommissionCalc.java +++ b/org.adempiere.base.process/src/org/compiere/process/CommissionCalc.java @@ -349,15 +349,12 @@ public class CommissionCalc extends SvrProcess */ private void createDetail (String sql, MCommissionAmt comAmt) throws Exception { - PreparedStatement pstmt = null; - ResultSet rs = null; - try + try (PreparedStatement pstmt = DB.prepareStatement(sql, get_TrxName());) { - pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt.setInt(1, m_com.getAD_Client_ID()); pstmt.setTimestamp(2, p_StartDate); pstmt.setTimestamp(3, m_EndDate); - rs = pstmt.executeQuery(); + ResultSet rs = pstmt.executeQuery(); while (rs.next()) { // CommissionAmount, C_Currency_ID, Amt, Qty, @@ -388,11 +385,6 @@ public class CommissionCalc extends SvrProcess { throw new AdempiereSystemError("System Error: " + e.getLocalizedMessage(), e); } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } } // createDetail } // CommissionCalc diff --git a/org.adempiere.base.process/src/org/compiere/process/ExpenseAPInvoice.java b/org.adempiere.base.process/src/org/compiere/process/ExpenseAPInvoice.java index 55b6ebb36b..ae49654c89 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ExpenseAPInvoice.java +++ b/org.adempiere.base.process/src/org/compiere/process/ExpenseAPInvoice.java @@ -95,12 +95,9 @@ public class ExpenseAPInvoice extends SvrProcess // int old_BPartner_ID = -1; MInvoice invoice = null; - // - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement (sql.toString (), get_TrxName()); + // + try (PreparedStatement pstmt = DB.prepareStatement (sql.toString (), get_TrxName());) + { int par = 1; pstmt.setInt(par++, getAD_Client_ID()); if (m_C_BPartner_ID != 0) @@ -109,7 +106,7 @@ public class ExpenseAPInvoice extends SvrProcess pstmt.setTimestamp (par++, m_DateFrom); if (m_DateTo != null) pstmt.setTimestamp (par++, m_DateTo); - rs = pstmt.executeQuery (); + ResultSet rs = pstmt.executeQuery (); while (rs.next()) // ********* Expense Line Loop { MTimeExpense te = new MTimeExpense (getCtx(), rs, get_TrxName()); @@ -201,11 +198,6 @@ public class ExpenseAPInvoice extends SvrProcess { log.log(Level.SEVERE, sql.toString(), e); } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } completeInvoice (invoice); StringBuilder msgreturn = new StringBuilder("@Created@=").append(m_noInvoices); return msgreturn.toString(); 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 b5e66cdaed..ea5421815b 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportInventory.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportInventory.java @@ -351,12 +351,9 @@ public class ImportInventory extends SvrProcess implements ImportProcess sql = new StringBuilder ("SELECT * FROM I_Inventory ") .append("WHERE I_IsImported='N'").append (clientCheck) .append(" ORDER BY M_Warehouse_ID, TRUNC(MovementDate), I_Inventory_ID"); - PreparedStatement pstmt = null; - ResultSet rs = null; - try + try (PreparedStatement pstmt = DB.prepareStatement (sql.toString (), get_TrxName());) { - pstmt = DB.prepareStatement (sql.toString (), get_TrxName()); - rs = pstmt.executeQuery (); + ResultSet rs = pstmt.executeQuery (); // int x_M_Warehouse_ID = -1; int x_C_DocType_ID = -1; @@ -487,11 +484,6 @@ public class ImportInventory extends SvrProcess implements ImportProcess { throw new AdempiereException(e); } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } // Set Error to indicator to not imported sql = new StringBuilder ("UPDATE I_Inventory ") 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 28fe2482d3..cf0a12cd74 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ImportPayment.java +++ b/org.adempiere.base.process/src/org/compiere/process/ImportPayment.java @@ -412,13 +412,11 @@ public class ImportPayment extends SvrProcess .append(" ORDER BY C_BankAccount_ID, CheckNo, DateTrx, R_AuthCode"); MBankAccount account = null; - PreparedStatement pstmt = null; - ResultSet rs = null; + int noInsert = 0; - try + try (PreparedStatement pstmt = DB.prepareStatement(sql.toString(), get_TrxName());) { - pstmt = DB.prepareStatement(sql.toString(), get_TrxName()); - rs = pstmt.executeQuery(); + ResultSet rs = pstmt.executeQuery(); while (rs.next()) { @@ -520,12 +518,6 @@ public class ImportPayment extends SvrProcess { 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/PaySelectionCreateFrom.java b/org.adempiere.base.process/src/org/compiere/process/PaySelectionCreateFrom.java index c1ec863eec..d96cb9c6d3 100644 --- a/org.adempiere.base.process/src/org/compiere/process/PaySelectionCreateFrom.java +++ b/org.adempiere.base.process/src/org/compiere/process/PaySelectionCreateFrom.java @@ -223,12 +223,9 @@ public class PaySelectionCreateFrom extends SvrProcess sql.append(sqlWhere.toString()); // int lines = 0; - int C_CurrencyTo_ID = psel.getC_Currency_ID(); - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement (sql.toString(), get_TrxName()); + int C_CurrencyTo_ID = psel.getC_Currency_ID(); + try (PreparedStatement pstmt = DB.prepareStatement (sql.toString(), get_TrxName());) + { int index = 1; pstmt.setInt (index++, C_CurrencyTo_ID); pstmt.setTimestamp(index++, psel.getPayDate()); @@ -267,7 +264,7 @@ public class PaySelectionCreateFrom extends SvrProcess pstmt.setInt (index++, p_C_BP_Group_ID); } // - rs = pstmt.executeQuery (); + ResultSet rs = pstmt.executeQuery (); while (rs.next ()) { int C_Invoice_ID = rs.getInt(1); @@ -301,12 +298,6 @@ public class PaySelectionCreateFrom extends SvrProcess { throw new AdempiereException(e); } - finally - { - DB.close(rs, pstmt); - rs = null; - pstmt = null; - } StringBuilder msgreturn = new StringBuilder("@C_PaySelectionLine_ID@ - #").append(lines); return msgreturn.toString(); } // doIt diff --git a/org.adempiere.base.process/src/org/compiere/process/SequenceCheck.java b/org.adempiere.base.process/src/org/compiere/process/SequenceCheck.java index dd031e74ae..5da3119ab9 100644 --- a/org.adempiere.base.process/src/org/compiere/process/SequenceCheck.java +++ b/org.adempiere.base.process/src/org/compiere/process/SequenceCheck.java @@ -100,13 +100,10 @@ public class SequenceCheck extends SvrProcess + "FROM AD_Table t " + "WHERE IsActive='Y' AND IsView='N'" + " AND NOT EXISTS (SELECT * FROM AD_Sequence s " - + "WHERE UPPER(s.Name)=UPPER(t.TableName) AND s.IsTableID='Y')"; - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement(sql, trxName); - rs = pstmt.executeQuery(); + + "WHERE UPPER(s.Name)=UPPER(t.TableName) AND s.IsTableID='Y')"; + try (PreparedStatement pstmt = DB.prepareStatement(sql, trxName);) + { + ResultSet rs = pstmt.executeQuery(); while (rs.next()) { String tableName = rs.getString(1); @@ -128,11 +125,6 @@ public class SequenceCheck extends SvrProcess s_log.log(Level.SEVERE, sql, e); throw new AdempiereException(e); } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } // Sync Table Name case sql = "UPDATE AD_Sequence s " @@ -161,10 +153,9 @@ public class SequenceCheck extends SvrProcess + "WHERE t.IsActive='Y' AND t.IsView='N'" + " AND UPPER(s.Name)=UPPER(t.TableName) AND s.Name<>t.TableName"; // - try - { - pstmt = DB.prepareStatement (sql, null); - rs = pstmt.executeQuery (); + try (PreparedStatement pstmt = DB.prepareStatement (sql, null);) + { + ResultSet rs = pstmt.executeQuery (); while (rs.next ()) { String TableName = rs.getString(1); @@ -178,11 +169,6 @@ public class SequenceCheck extends SvrProcess s_log.log (Level.SEVERE, sql, e); throw new AdempiereException(e); } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } } // checkTableSequences diff --git a/org.adempiere.base/src/org/compiere/impexp/OFXFileBankStatementLoader.java b/org.adempiere.base/src/org/compiere/impexp/OFXFileBankStatementLoader.java index 96e3221e9e..bb9980911e 100644 --- a/org.adempiere.base/src/org/compiere/impexp/OFXFileBankStatementLoader.java +++ b/org.adempiere.base/src/org/compiere/impexp/OFXFileBankStatementLoader.java @@ -39,7 +39,6 @@ public final class OFXFileBankStatementLoader extends OFXBankStatementHandler im */ //m_stream is not closed because the BufferedReader in the parent class is closed and according to the Java docs: //Calling close() on the BufferedReader closes the underlying stream by default implementation - @SuppressWarnings("resource") public boolean init(MBankStatementLoader controller) { boolean result = false; diff --git a/org.adempiere.base/src/org/compiere/model/GridTable.java b/org.adempiere.base/src/org/compiere/model/GridTable.java index f6766ddd73..6028912fc5 100644 --- a/org.adempiere.base/src/org/compiere/model/GridTable.java +++ b/org.adempiere.base/src/org/compiere/model/GridTable.java @@ -1618,14 +1618,11 @@ public class GridTable extends AbstractTableModel if (m_inserting) select.append(" WHERE 1=2"); else // FOR UPDATE causes - ORA-01002 fetch out of sequence - select.append(" WHERE ").append(getWhereClause(rowData)); - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement (select.toString(), - ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, null); - rs = pstmt.executeQuery(); + select.append(" WHERE ").append(getWhereClause(rowData)); + try (PreparedStatement pstmt = DB.prepareStatement (select.toString(), + ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, null);) + { + ResultSet rs = pstmt.executeQuery(); // only one row if (!(m_inserting || rs.next())) { @@ -2071,10 +2068,6 @@ public class GridTable extends AbstractTableModel rs.updateRow(); } - log.fine("Committing ..."); - DB.commit(true, null); // no Trx - DB.close(rs, pstmt); - rs = null; pstmt = null; // lobSave(whereClause); @@ -2082,29 +2075,31 @@ public class GridTable extends AbstractTableModel if (log.isLoggable(Level.FINE)) log.fine("Reading ... " + whereClause); StringBuilder refreshSQL = new StringBuilder(m_SQL_Select) .append(" WHERE ").append(whereClause); - pstmt = DB.prepareStatement(refreshSQL.toString(), null); - rs = pstmt.executeQuery(); - if (rs.next()) + try (PreparedStatement pstmt1 = DB.prepareStatement(refreshSQL.toString(), null);) { - rowDataDB = readData(rs); - // update buffer - setDataAtRow(m_rowChanged, rowDataDB); - if (m_virtual) + rs = pstmt1.executeQuery(); + if (rs.next()) { - MSort sort = m_sort.get(m_rowChanged); - int oldId = sort.index; - int newId = getKeyID(m_rowChanged); - if (newId != oldId) + rowDataDB = readData(rs); + // update buffer + setDataAtRow(m_rowChanged, rowDataDB); + if (m_virtual) { - sort.index = newId; - Object[] data = m_virtualBuffer.remove(oldId); - m_virtualBuffer.put(newId, data); + MSort sort = m_sort.get(m_rowChanged); + int oldId = sort.index; + int newId = getKeyID(m_rowChanged); + if (newId != oldId) + { + sort.index = newId; + Object[] data = m_virtualBuffer.remove(oldId); + m_virtualBuffer.put(newId, data); + } } + fireTableRowsUpdated(m_rowChanged, m_rowChanged); } - fireTableRowsUpdated(m_rowChanged, m_rowChanged); + else + log.log(Level.SEVERE, "Inserted row not found"); } - else - log.log(Level.SEVERE, "Inserted row not found"); // } catch (Exception e) @@ -2122,12 +2117,6 @@ public class GridTable extends AbstractTableModel fireDataStatusEEvent(msg, e.getLocalizedMessage(), true); return SAVE_ERROR; } - finally - { - DB.close(rs, pstmt); - rs = null; - pstmt = null; - } CacheMgt.get().reset(m_tableName); diff --git a/org.adempiere.base/src/org/compiere/model/MPayment.java b/org.adempiere.base/src/org/compiere/model/MPayment.java index a6e4bf1214..003e100b7b 100644 --- a/org.adempiere.base/src/org/compiere/model/MPayment.java +++ b/org.adempiere.base/src/org/compiere/model/MPayment.java @@ -1832,7 +1832,6 @@ public class MPayment extends X_C_Payment protected String m_processMsg = null; /** Just Prepared Flag */ protected boolean m_justPrepared = false; - @SuppressWarnings("unused") protected IProcessUI m_processUI; /** diff --git a/org.adempiere.base/src/org/compiere/model/MProduction.java b/org.adempiere.base/src/org/compiere/model/MProduction.java index 1d2831f0e5..19835d2b36 100644 --- a/org.adempiere.base/src/org/compiere/model/MProduction.java +++ b/org.adempiere.base/src/org/compiere/model/MProduction.java @@ -32,7 +32,6 @@ public class MProduction extends X_M_Production implements DocAction { * */ /** Log */ - @SuppressWarnings("unused") protected static CLogger m_log = CLogger.getCLogger (MProduction.class); protected int lineno; protected int count; @@ -260,14 +259,10 @@ public class MProduction extends X_M_Production implements DocAction { // products used in production String sql = "SELECT M_ProductBom_ID, BOMQty" + " FROM M_Product_BOM" + " WHERE M_Product_ID=" + finishedProduct.getM_Product_ID() + " ORDER BY Line"; + + try (PreparedStatement pstmt = DB.prepareStatement(sql, get_TrxName());) { - PreparedStatement pstmt = null; - ResultSet rs = null; - - try { - pstmt = DB.prepareStatement(sql, get_TrxName()); - - rs = pstmt.executeQuery(); + ResultSet rs = pstmt.executeQuery(); while (rs.next()) { lineno = lineno + 10; @@ -432,9 +427,6 @@ public class MProduction extends X_M_Production implements DocAction { } catch (Exception e) { throw new AdempiereException("Failed to create production lines", e); } - finally { - DB.close(rs, pstmt); - } return count; } diff --git a/org.adempiere.base/src/org/compiere/model/MProductionPlan.java b/org.adempiere.base/src/org/compiere/model/MProductionPlan.java index 00f3a48bf9..228a568791 100644 --- a/org.adempiere.base/src/org/compiere/model/MProductionPlan.java +++ b/org.adempiere.base/src/org/compiere/model/MProductionPlan.java @@ -126,14 +126,10 @@ public class MProductionPlan extends X_M_ProductionPlan { // products used in production String sql = "SELECT M_ProductBom_ID, BOMQty" + " FROM M_Product_BOM" + " WHERE M_Product_ID=" + finishedProduct.getM_Product_ID() + " ORDER BY Line"; + + try (PreparedStatement pstmt = DB.prepareStatement(sql, get_TrxName());) { - PreparedStatement pstmt = null; - ResultSet rs = null; - - try { - pstmt = DB.prepareStatement(sql, get_TrxName()); - - rs = pstmt.executeQuery(); + ResultSet rs = pstmt.executeQuery(); while (rs.next()) { lineno = lineno + 10; @@ -298,9 +294,6 @@ public class MProductionPlan extends X_M_ProductionPlan { } catch (Exception e) { throw new AdempiereException("Failed to create production lines", e); } - finally { - DB.close(rs, pstmt); - } return count; } diff --git a/org.adempiere.base/src/org/globalqss/process/CashFlow.java b/org.adempiere.base/src/org/globalqss/process/CashFlow.java index 3fc4e72490..b749ac2d85 100644 --- a/org.adempiere.base/src/org/globalqss/process/CashFlow.java +++ b/org.adempiere.base/src/org/globalqss/process/CashFlow.java @@ -136,16 +136,13 @@ public class CashFlow extends SvrProcess { "cp.C_CashPlan_ID " + "FROM C_CashPlanLine cpl " + "JOIN C_CashPlan cp ON (cp.C_CashPlan_ID=cpl.C_CashPlan_ID) " + - "WHERE cp.AD_Client_ID=? AND cp.IsActive='Y' AND cpl.IsActive='Y' AND cpl.DateTrx BETWEEN ? AND ?"; - PreparedStatement pstmtPlan = null; - ResultSet rsPlan = null; - try - { - pstmtPlan = DB.prepareStatement(sqlPlan, get_TrxName()); + "WHERE cp.AD_Client_ID=? AND cp.IsActive='Y' AND cpl.IsActive='Y' AND cpl.DateTrx BETWEEN ? AND ?"; + try (PreparedStatement pstmtPlan = DB.prepareStatement(sqlPlan, get_TrxName());) + { pstmtPlan.setInt(1, getAD_Client_ID()); pstmtPlan.setTimestamp(2, p_dateFrom); pstmtPlan.setTimestamp(3, p_dateTo); - rsPlan = pstmtPlan.executeQuery(); + ResultSet rsPlan = pstmtPlan.executeQuery(); int noPlan = 0; while (rsPlan.next()) { @@ -185,25 +182,17 @@ public class CashFlow extends SvrProcess { { log.log(Level.SEVERE, sqlPlan, e); } - finally - { - DB.close(rsPlan, pstmtPlan); - rsPlan = null; pstmtPlan = null; - } /* commitment records */ String sqlOpenOrders = "SELECT o.C_Order_ID, o.IsPayScheduleValid, " + "SUM((ol.QtyOrdered-ol.QtyInvoiced)*ol.PriceActual)/o.TotalLines as Pending " + "FROM C_Order o JOIN C_OrderLine ol ON (o.C_Order_ID=ol.C_Order_ID) " + "WHERE o.AD_Client_ID=? AND o.TotalLines != 0 AND o.DocStatus IN ('CO') AND ol.QtyInvoiced