commit/iDempiere: richard1988: IDEMPIERE-568 Review proper closing of JDBC statements and resultsets

0 views
Skip to first unread message

Bitbucket

unread,
Feb 15, 2013, 7:26:47 PM2/15/13
to idempi...@googlegroups.com
1 new commit in iDempiere:

https://bitbucket.org/idempiere/idempiere/commits/04277f8ad9d3/
changeset: 04277f8ad9d3
branch: development
user: richard1988
date: 2013-02-16 01:26:22
summary: IDEMPIERE-568 Review proper closing of JDBC statements and resultsets
affected #: 57 files

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.base.process/src/org/adempiere/process/Export.java
--- a/org.adempiere.base.process/src/org/adempiere/process/Export.java
+++ b/org.adempiere.base.process/src/org/adempiere/process/Export.java
@@ -182,10 +182,7 @@
}

} finally {
- try {
- if (rs != null) rs.close();
- if (pstmt != null) pstmt.close();
- } catch (SQLException ex) {/*ignored*/}
+ DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
@@ -378,10 +375,7 @@
}

} finally {
- try {
- if (rsEmbedded != null) rsEmbedded.close();
- if (pstmt != null) pstmt.close();
- } catch (SQLException ex) { }
+ DB.close(rsEmbedded, pstmt);
rsEmbedded = null;
pstmt = null;
}

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.base/src/org/compiere/acct/Doc.java
--- a/org.adempiere.base/src/org/compiere/acct/Doc.java
+++ b/org.adempiere.base/src/org/compiere/acct/Doc.java
@@ -845,21 +845,27 @@
{
String sql = "SELECT GL_Category_ID FROM C_DocType "
+ "WHERE AD_Client_ID=? AND DocBaseType=?";
+ PreparedStatement pstmt = null;
+ ResultSet rsDT = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
+ pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, getAD_Client_ID());
pstmt.setString(2, m_DocumentType);
- ResultSet rsDT = pstmt.executeQuery();
+ rsDT = pstmt.executeQuery();
if (rsDT.next())
m_GL_Category_ID = rsDT.getInt(1);
- rsDT.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
+ finally
+ {
+ DB.close(rsDT, pstmt);
+ rsDT = null;
+ pstmt = null;
+ }
}

// Still no GL_Category - get Default GL Category
@@ -868,20 +874,26 @@
String sql = "SELECT GL_Category_ID FROM GL_Category "
+ "WHERE AD_Client_ID=? "
+ "ORDER BY IsDefault DESC";
+ PreparedStatement pstmt = null;
+ ResultSet rsDT = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(sql, null);
+ pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, getAD_Client_ID());
- ResultSet rsDT = pstmt.executeQuery();
+ rsDT = pstmt.executeQuery();
if (rsDT.next())
m_GL_Category_ID = rsDT.getInt(1);
- rsDT.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
+ finally
+ {
+ DB.close(rsDT, pstmt);
+ rsDT = null;
+ pstmt = null;
+ }
}
//
if (m_GL_Category_ID == 0)

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.base/src/org/compiere/acct/Doc_Production.java
--- a/org.adempiere.base/src/org/compiere/acct/Doc_Production.java
+++ b/org.adempiere.base/src/org/compiere/acct/Doc_Production.java
@@ -83,36 +83,40 @@
String sqlPL = "SELECT * FROM M_ProductionLine pl "
+ "WHERE pl.M_Production_ID=? "
+ "ORDER BY pl.Line";
-
+ PreparedStatement pstmtPL = null;
+ ResultSet rsPL = null;
try
+ {
+ pstmtPL = DB.prepareStatement(sqlPL, getTrxName());
+ pstmtPL.setInt(1,get_ID());
+ rsPL = pstmtPL.executeQuery();
+ while (rsPL.next())
+ {
+ X_M_ProductionLine line = new X_M_ProductionLine(getCtx(), rsPL, getTrxName());
+ if (line.getMovementQty().signum() == 0)
+ {
+ log.info("LineQty=0 - " + line);
+ continue;
+ }
+ DocLine docLine = new DocLine (line, this);
+ docLine.setQty (line.getMovementQty(), false);
+ // Identify finished BOM Product
+ docLine.setProductionBOM(line.getM_Product_ID() == prod.getM_Product_ID());
+ //
+ log.fine(docLine.toString());
+ list.add (docLine);
+ }
+ }
+ catch (Exception ee)
{
-
- PreparedStatement pstmtPL = DB.prepareStatement(sqlPL, getTrxName());
- pstmtPL.setInt(1,get_ID());
- ResultSet rsPL = pstmtPL.executeQuery();
- while (rsPL.next())
- {
- X_M_ProductionLine line = new X_M_ProductionLine(getCtx(), rsPL, getTrxName());
- if (line.getMovementQty().signum() == 0)
- {
- log.info("LineQty=0 - " + line);
- continue;
- }
- DocLine docLine = new DocLine (line, this);
- docLine.setQty (line.getMovementQty(), false);
- // Identify finished BOM Product
- docLine.setProductionBOM(line.getM_Product_ID() == prod.getM_Product_ID());
- //
- log.fine(docLine.toString());
- list.add (docLine);
- }
- rsPL.close();
- pstmtPL.close();
- }
- catch (Exception ee)
- {
- log.log(Level.SEVERE, sqlPL, ee);
- }
+ log.log(Level.SEVERE, sqlPL, ee);
+ }
+ finally
+ {
+ DB.close(rsPL, pstmtPL);
+ rsPL = null;
+ pstmtPL = null;
+ }

DocLine[] dl = new DocLine[list.size()];
list.toArray(dl);

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.base/src/org/compiere/db/CreateAdempiere.java
--- a/org.adempiere.base/src/org/compiere/db/CreateAdempiere.java
+++ b/org.adempiere.base/src/org/compiere/db/CreateAdempiere.java
@@ -353,11 +353,13 @@

StringBuilder sb = new StringBuilder("CREATE TABLE ");
sb.append(tableName).append(" (");
+ ResultSet sourceColumns = null;
+ ResultSet sourcePK = null;
try
{
// Columns
boolean first = true;
- ResultSet sourceColumns = md.getColumns(catalog, schema, table, null);
+ sourceColumns = md.getColumns(catalog, schema, table, null);
while (sourceColumns.next())
{
sb.append(first ? "" : ", ");
@@ -431,10 +433,9 @@


} // for all columns
- sourceColumns.close();

// Primary Key
- ResultSet sourcePK = md.getPrimaryKeys(catalog, schema, table);
+ sourcePK = md.getPrimaryKeys(catalog, schema, table);
// TABLE_CAT=null, TABLE_SCHEM=REFERENCE, TABLE_NAME=A_ASSET, COLUMN_NAME=A_ASSET_ID, KEY_SEQ=1, PK_NAME=A_ASSET_KEY
first = true;
boolean hasPK = false;
@@ -451,7 +452,6 @@
}
if (hasPK) // close constraint
sb.append(")"); // USING INDEX TABLESPACE INDX
- sourcePK.close();
//
sb.append(")"); // close create table
}
@@ -460,6 +460,13 @@
log.log(Level.SEVERE, "createTable", ex);
return false;
}
+ finally
+ {
+ DB.close(sourceColumns);
+ DB.close(sourcePK);
+ sourceColumns = null;
+ sourcePK = null;
+ }

// Execute Create Table
if (!executeCommands(new String[]{sb.toString()}, m_conn, false, true))

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.extend/src/compiere/model/CalloutUser.java
--- a/org.adempiere.extend/src/compiere/model/CalloutUser.java
+++ b/org.adempiere.extend/src/compiere/model/CalloutUser.java
@@ -89,11 +89,13 @@
+ " LEFT OUTER JOIN AD_User c ON (p.C_BPartner_ID=c.C_BPartner_ID) "
+ "WHERE p.C_BPartner_ID=? AND p.IsActive='Y'"; // #1

+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(sql, null);
+ pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, C_BPartner_ID.intValue());
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
//
if (rs.next())
{
@@ -125,14 +127,18 @@
else
mTab.setValue("AD_User_ID", new Integer(contID));
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
return e.getLocalizedMessage();
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }

return "";
} // bPartner
@@ -160,20 +166,26 @@
//
String retValue = value;
String SQL = "SELECT FRIE_Name(?) FROM DUAL";
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(SQL, null);
+ pstmt = DB.prepareStatement(SQL, null);
pstmt.setString(1, value);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
if (rs.next())
- retValue = rs.getString(1);
- rs.close();
- pstmt.close();
+ retValue = rs.getString(1);
}
catch (SQLException e)
{
log.log(Level.SEVERE, SQL, e);
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }
return retValue;
} // Frie_Name

@@ -191,20 +203,26 @@
//
String retValue = value;
String SQL = "SELECT FRIE_Value(FRIE_Name(?)) FROM DUAL";
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(SQL, null);
+ pstmt = DB.prepareStatement(SQL, null);
pstmt.setString(1, value);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
if (rs.next())
retValue = 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;
+ }
return retValue;
} // Frie_Value


diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/acct/AcctViewerData.java
--- a/org.adempiere.ui.swing/src/org/compiere/acct/AcctViewerData.java
+++ b/org.adempiere.ui.swing/src/org/compiere/acct/AcctViewerData.java
@@ -195,10 +195,12 @@
+ "WHERE EXISTS (SELECT * FROM AD_Column c"
+ " WHERE t.AD_Table_ID=c.AD_Table_ID AND c.ColumnName='Posted')"
+ " AND IsView='N'";
+ 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())
{
int id = rs.getInt(1);
@@ -211,13 +213,17 @@
if (id == AD_Table_ID)
select = pp;
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }
if (select != null)
cb.setSelectedItem(select);
} // fillTable
@@ -232,20 +238,26 @@
KeyNamePair pp = new KeyNamePair(0, "");
cb.addItem(pp);
String sql = "SELECT AD_Org_ID, Name FROM AD_Org WHERE AD_Client_ID=? ORDER BY Value";
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(sql, null);
+ pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Client_ID);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
while (rs.next())
cb.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;
+ }
} // fillOrg

/**
@@ -264,19 +276,25 @@
sql.append(MLookupFactory.getLookup_TableDirEmbed(language, columnName, "avd"))
.append(") FROM ").append(tableName).append(" avd WHERE avd.").append(selectSQL);
String retValue = "<" + selectSQL + ">";
+ Statement stmt = null;
+ ResultSet rs = null;
try
{
- Statement stmt = DB.createStatement();
- ResultSet rs = stmt.executeQuery(sql.toString());
+ stmt = DB.createStatement();
+ rs = stmt.executeQuery(sql.toString());
if (rs.next())
retValue = rs.getString(1);
- rs.close();
- stmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql.toString(), e);
}
+ finally
+ {
+ DB.close(rs, stmt);
+ rs = null;
+ stmt = null;
+ }
return retValue;
} // getButtonText


diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/apps/AEnv.java
--- a/org.adempiere.ui.swing/src/org/compiere/apps/AEnv.java
+++ b/org.adempiere.ui.swing/src/org/compiere/apps/AEnv.java
@@ -635,24 +635,30 @@
int AD_Window_ID = 0;
int PO_Window_ID = 0;
String sql = "SELECT TableName, AD_Window_ID, PO_Window_ID FROM AD_Table WHERE 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())
{
TableName = rs.getString(1);
AD_Window_ID = rs.getInt(2);
PO_Window_ID = rs.getInt(3);
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }
// Nothing to Zoom to
if (TableName == null || AD_Window_ID == 0)
return;
@@ -695,23 +701,29 @@
int AD_Window_ID = 0;
int PO_Window_ID = 0;
String sql = "SELECT AD_Window_ID, PO_Window_ID FROM AD_Table WHERE TableName=?";
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(sql, null);
+ pstmt = DB.prepareStatement(sql, null);
pstmt.setString(1, TableName);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
if (rs.next())
{
AD_Window_ID = rs.getInt(1);
PO_Window_ID = rs.getInt(2);
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }
// Nothing to Zoom to
if (AD_Window_ID == 0)
return;

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/apps/APanel.java
--- a/org.adempiere.ui.swing/src/org/compiere/apps/APanel.java
+++ b/org.adempiere.ui.swing/src/org/compiere/apps/APanel.java
@@ -2209,21 +2209,25 @@
+ Env.getAD_Language(Env.getCtx())
+ "'"
+ " AND l.AD_Reference_ID=?";
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try {
- PreparedStatement pstmt = DB
- .prepareStatement(SQL, null);
+ pstmt = DB.prepareStatement(SQL, null);
pstmt.setInt(1, AD_Reference_ID);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
while (rs.next()) {
String value = rs.getString(1);
String name = rs.getString(2);
values.put(value, name);
}
- rs.close();
- pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, SQL, e);
}
+ finally{
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }

// Nothing to show or Record_ID
if (field.getValue() == null

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/apps/ProcessParameter.java
--- a/org.adempiere.ui.swing/src/org/compiere/apps/ProcessParameter.java
+++ b/org.adempiere.ui.swing/src/org/compiere/apps/ProcessParameter.java
@@ -233,23 +233,29 @@

// Create Fields
boolean hasFields = false;
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(sql, null);
+ pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_processInfo.getAD_Process_ID());
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
while (rs.next())
{
hasFields = true;
createField (rs);
}
- rs.close();
- pstmt.close();
}
catch(SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }

// both vectors the same?
if (m_mFields.size() != m_mFields2.size()

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/apps/RecordInfo.java
--- a/org.adempiere.ui.swing/src/org/compiere/apps/RecordInfo.java
+++ b/org.adempiere.ui.swing/src/org/compiere/apps/RecordInfo.java
@@ -209,33 +209,27 @@
+ "WHERE AD_Table_ID=? AND Record_ID=? "
+ "ORDER BY Updated DESC";
PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, dse.AD_Table_ID);
pstmt.setInt (2, Record_ID);
- ResultSet rs = pstmt.executeQuery ();
+ rs = pstmt.executeQuery ();
while (rs.next ())
{
addLine (rs.getInt(1), rs.getTimestamp(2), rs.getInt(3),
rs.getString(4), rs.getString(5));
}
- rs.close ();
- pstmt.close ();
- pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
- try
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}


diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/apps/form/VFileImport.java
--- a/org.adempiere.ui.swing/src/org/compiere/apps/form/VFileImport.java
+++ b/org.adempiere.ui.swing/src/org/compiere/apps/form/VFileImport.java
@@ -208,19 +208,25 @@
pickFormat.addItem(s_none);
String sql = MRole.getDefault().addAccessSQL("SELECT Name FROM AD_ImpFormat", "AD_ImpFormat",
MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
+ 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())
pickFormat.addItem(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;
+ }
pickFormat.setSelectedIndex(0);
pickFormat.addActionListener(this);
//

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/apps/search/InfoGeneral.java
--- a/org.adempiere.ui.swing/src/org/compiere/apps/search/InfoGeneral.java
+++ b/org.adempiere.ui.swing/src/org/compiere/apps/search/InfoGeneral.java
@@ -265,8 +265,6 @@
tableName = rs.getString(3);
}
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/grid/RecordAccessDialog.java
--- a/org.adempiere.ui.swing/src/org/compiere/grid/RecordAccessDialog.java
+++ b/org.adempiere.ui.swing/src/org/compiere/grid/RecordAccessDialog.java
@@ -123,31 +123,25 @@
sql = "SELECT * FROM AD_Record_Access "
+ "WHERE AD_Table_ID=? AND Record_ID=? AND AD_Client_ID=?";
PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_AD_Table_ID);
pstmt.setInt(2, m_Record_ID);
pstmt.setInt(3, Env.getAD_Client_ID(Env.getCtx()));
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
while (rs.next())
m_recordAccesss.add(new MRecordAccess(Env.getCtx(), rs, null));
- rs.close();
- pstmt.close();
- pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
- try
+ finally
{
- if (pstmt != null)
- pstmt.close();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
log.fine("#" + m_recordAccesss.size());

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/grid/ed/Calculator.java
--- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/Calculator.java
+++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/Calculator.java
@@ -576,10 +576,12 @@
String sql = "SELECT C_Currency_ID, ISO_Code FROM C_Currency "
+ "WHERE IsActive='Y' ORDER BY 2";
KeyNamePair defaultValue = null;
+ 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())
{
int id = rs.getInt("C_Currency_ID");
@@ -591,13 +593,17 @@
if (id == C_Currency_ID)
defaultValue = p;
}
- rs.close();
- stmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, "Calculator.loadCurrency", e);
}
+ finally
+ {
+ DB.close(rs, stmt);
+ rs = null;
+ stmt = null;
+ }

// Set Defaults
if (defaultValue != null)

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccount.java
--- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccount.java
+++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccount.java
@@ -373,35 +373,29 @@
//
int C_ValidCombination_ID = 0;
PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, C_AcctSchema_ID);
pstmt.setString(2, text.toUpperCase());
pstmt.setString(3, text.toUpperCase());
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
if (rs.next())
{
C_ValidCombination_ID = rs.getInt(1);
if (rs.next()) // only one
C_ValidCombination_ID = 0;
}
- rs.close();
- pstmt.close();
- pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
- try
+ finally
{
- if (pstmt != null)
- pstmt.close();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
// We have a Value

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccountDialog.java
--- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccountDialog.java
+++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccountDialog.java
@@ -519,12 +519,14 @@
{
log.fine("C_ValidCombination_ID=" + C_ValidCombination_ID);
String sql = "SELECT * FROM C_ValidCombination WHERE C_ValidCombination_ID=? AND C_AcctSchema_ID=?";
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(sql, null);
+ pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, C_ValidCombination_ID);
pstmt.setInt(2, C_AcctSchema_ID);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
if (rs.next())
{
if (f_Alias != null)
@@ -549,13 +551,17 @@
//
f_Description.setText (rs.getString("Description"));
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }
} // loadInfo

/**
@@ -920,25 +926,32 @@
log.fine("Check = " + sql.toString());
int IDvalue = 0;
String Alias = null;
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
+ pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, m_AD_Client_ID);
pstmt.setInt(2, s_AcctSchema.getC_AcctSchema_ID());
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
if (rs.next())
{
IDvalue = rs.getInt(1);
Alias = rs.getString(2);
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql.toString(), e);
IDvalue = 0;
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }
+
log.fine("ID=" + IDvalue + ", Alias=" + Alias);

if (Alias == null)

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignment.java
--- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignment.java
+++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignment.java
@@ -309,10 +309,11 @@
+ " AND r.S_ResourceType_ID=rt.S_ResourceType_ID"
+ " and rt.C_UOM_ID=uom.C_UOM_ID", null);
//
+ ResultSet rs = null;
try
{
m_pstmt.setInt(1, S_ResourceAssignment_ID);
- ResultSet rs = m_pstmt.executeQuery();
+ rs = m_pstmt.executeQuery();
if (rs.next())
{
StringBuilder sb = new StringBuilder(rs.getString(1));
@@ -323,12 +324,16 @@
}
else
m_text.setText("<" + S_ResourceAssignment_ID + ">");
- rs.close();
}
catch (Exception e)
{
log.log(Level.SEVERE, "", e);
}
+ finally
+ {
+ DB.close(rs);
+ rs = null;
+ }
} // setValue

/**

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignmentDialog.java
--- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignmentDialog.java
+++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignmentDialog.java
@@ -348,10 +348,12 @@
+ "FROM S_Resource r, S_ResourceType rt, C_UOM uom "
+ "WHERE r.S_ResourceType_ID=rt.S_ResourceType_ID AND rt.C_UOM_ID=uom.C_UOM_ID",
"r", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
+ 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())
{
StringBuilder sb = new StringBuilder (rs.getString(2));
@@ -363,13 +365,17 @@
KeyNamePair value = new KeyNamePair (rs.getInt(4), rs.getString(5).trim());
m_lookup.put(key, value);
}
- 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
KeyNamePair[] retValue = new KeyNamePair[m_lookup.size()];

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/grid/ed/VButton.java
--- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VButton.java
+++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VButton.java
@@ -312,25 +312,30 @@
+ "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=?";
-
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(SQL, null);
+ pstmt = DB.prepareStatement(SQL, null);
pstmt.setInt(1, AD_Reference_ID);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
while (rs.next())
{
String value = rs.getString(1);
String name = rs.getString(2);
m_values.put(value, name);
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, SQL, e);
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }
} // readReference

/**

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/grid/ed/VColor.java
--- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VColor.java
+++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VColor.java
@@ -272,22 +272,28 @@
//
String retValue = null;
String sql = "SELECT ImageURL FROM AD_Image WHERE AD_Image_ID=?";
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(sql, null);
+ pstmt = DB.prepareStatement(sql, null);
pstmt.setInt (1, AD_Image_ID.intValue());
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
if (rs.next())
{
retValue = 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;
+ }
return retValue;
} // getURL


diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocator.java
--- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocator.java
+++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocator.java
@@ -463,6 +463,7 @@
//
int M_Locator_ID = 0;
PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(finalSql, null);
@@ -474,30 +475,25 @@
pstmt.setInt(index++, only_Product_ID);
pstmt.setInt(index++, only_Product_ID);
}
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
if (rs.next())
{
M_Locator_ID = rs.getInt(1);
if (rs.next())
M_Locator_ID = 0; // more than one
}
- rs.close();
- pstmt.close();
- pstmt = null;
}
catch (SQLException ex)
{
log.log(Level.SEVERE, finalSql, ex);
}
- try
+ finally
{
- if (pstmt != null)
- pstmt.close();
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
}
- catch (SQLException ex1)
- {
- }
- pstmt = null;
+
if (M_Locator_ID == 0)
return false;


diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocatorDialog.java
--- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocatorDialog.java
+++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VLocatorDialog.java
@@ -385,11 +385,13 @@
//
String SQL = "SELECT M_Warehouse_ID, Value, Name, Separator, AD_Client_ID, AD_Org_ID "
+ "FROM M_Warehouse WHERE M_Warehouse_ID=?";
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(SQL, null);
+ pstmt = DB.prepareStatement(SQL, null);
pstmt.setInt(1, M_Warehouse_ID);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
if (rs.next())
{
m_M_Warehouse_ID = rs.getInt(1);
@@ -399,13 +401,17 @@
m_AD_Client_ID = rs.getInt(5);
m_AD_Org_ID = rs.getInt(6);
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, SQL, e);
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }
} // getWarehouseInfo

/**

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewerData.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewerData.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewerData.java
@@ -226,11 +226,12 @@
+ "WHERE EXISTS (SELECT * FROM AD_Column c"
+ " WHERE t.AD_Table_ID=c.AD_Table_ID AND c.ColumnName='Posted')"
+ " AND IsView='N'";
-
+ 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())
{
@@ -245,13 +246,17 @@
if (id == AD_Table_ID)
select = pp;
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }

if (select != null)
;//cb.setSelectedItem(select);
@@ -268,26 +273,30 @@
KeyNamePair pp = new KeyNamePair(0, "");
cb.appendItem(pp.getName(), pp);
String sql = "SELECT AD_Org_ID, Name FROM AD_Org WHERE AD_Client_ID=? ORDER BY Value";
-
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(sql, null);
+ pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Client_ID);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();

while (rs.next())
{
KeyNamePair key = new KeyNamePair(rs.getInt(1), rs.getString(2));
cb.appendItem(key.getName(), key);
}
-
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }
} // fillOrg

/**
@@ -309,21 +318,27 @@
sql.append(MLookupFactory.getLookup_TableDirEmbed(language, columnName, "avd"))
.append(") FROM ").append(tableName).append(" avd WHERE avd.").append(selectSQL);
String retValue = "<" + selectSQL + ">";
-
+
+ Statement stmt = null;
+ ResultSet rs = null;
try
{
- Statement stmt = DB.createStatement();
- ResultSet rs = stmt.executeQuery(sql.toString());
-
+ stmt = DB.createStatement();
+ rs = stmt.executeQuery(sql.toString());
+
if (rs.next())
retValue = rs.getString(1);
- rs.close();
- stmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql.toString(), e);
}
+ finally
+ {
+ DB.close(rs, stmt);
+ rs = null;
+ stmt = null;
+ }
return retValue;
} // getButtonText


diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java
@@ -156,24 +156,31 @@
int AD_Window_ID = 0;
int PO_Window_ID = 0;
String sql = "SELECT TableName, AD_Window_ID, PO_Window_ID FROM AD_Table WHERE 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())
{
TableName = rs.getString(1);
AD_Window_ID = rs.getInt(2);
PO_Window_ID = rs.getInt(3);
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
+ finally
+ {
+
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }
// Nothing to Zoom to
if (TableName == null || AD_Window_ID == 0)
return;
@@ -496,23 +503,29 @@
int AD_Window_ID = 0;
int PO_Window_ID = 0;
String sql = "SELECT AD_Window_ID, PO_Window_ID FROM AD_Table WHERE TableName=?";
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(sql, null);
+ pstmt = DB.prepareStatement(sql, null);
pstmt.setString(1, TableName);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
if (rs.next())
{
AD_Window_ID = rs.getInt(1);
PO_Window_ID = rs.getInt(2);
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }
// Nothing to Zoom to
if (AD_Window_ID == 0)
return;

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessParameterPanel.java
@@ -222,19 +222,24 @@
// Create Fields
boolean hasFields = false;
Rows rows = new Rows();
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try {
- PreparedStatement pstmt = DB.prepareStatement(sql, null);
+ pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_processInfo.getAD_Process_ID());
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
while (rs.next()) {
hasFields = true;
createField(rs, rows);
}
- rs.close();
- pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
}
+ finally{
+ DB.close(rs,pstmt);
+ rs = null;
+ pstmt = null;
+ }

// both vectors the same?
if (m_mFields.size() != m_mFields2.size()

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WAttributeGrid.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WAttributeGrid.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WAttributeGrid.java
@@ -266,18 +266,20 @@
// 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.appendItem("", 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.appendItem(kn.getName(), kn.getKey());
}
- rs.close();
- pstmt.close();
+ DB.close(rs, pstmt);
+ rs = null; pstmt = null;

// Warehouse
sql = "SELECT M_Warehouse_ID, Value || ' - ' || Name AS ValueName "
@@ -295,13 +297,16 @@
(rs.getInt("M_Warehouse_ID"), rs.getString("ValueName"));
pickWarehouse.appendItem(kn.getName(), kn.getKey());
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null; pstmt = null;
+ }
} // fillPicks

public void onEvent(Event e) throws Exception
@@ -522,36 +527,30 @@
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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
- catch (Exception e)
- {
- pstmt = null;
- }
-
+
int mode = modeCombo.getSelectedIndex();
// No Products
if (noProducts == 0 && mode == MODE_VIEW)

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WFileImport.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WFileImport.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WFileImport.java
@@ -235,21 +235,26 @@

String sql = MRole.getDefault().addAccessSQL("SELECT Name FROM AD_ImpFormat", "AD_ImpFormat",
MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
+ 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())
pickFormat.appendItem(rs.getString(1), 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;
+ }

pickFormat.setSelectedIndex(0);
pickFormat.addEventListener(Events.ON_SELECT, this);

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WAccountEditor.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WAccountEditor.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WAccountEditor.java
@@ -155,9 +155,6 @@
if (rs.next()) // only one
C_ValidCombination_ID = 0;
}
- rs.close();
- pstmt.close();
- pstmt = null;
}
catch (Exception e)
{

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WAssignmentEditor.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WAssignmentEditor.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WAssignmentEditor.java
@@ -113,10 +113,11 @@
+ " AND r.S_ResourceType_ID=rt.S_ResourceType_ID"
+ " and rt.C_UOM_ID=uom.C_UOM_ID", null);
//
+ ResultSet rs = null;
try
{
m_pstmt.setInt(1, S_ResourceAssignment_ID);
- ResultSet rs = m_pstmt.executeQuery();
+ rs = m_pstmt.executeQuery();
if (rs.next())
{
StringBuilder sb = new StringBuilder(rs.getString(1));
@@ -127,12 +128,15 @@
}
else
getComponent().setText("<" + S_ResourceAssignment_ID + ">");
- rs.close();
}
catch (Exception e)
{
log.log(Level.SEVERE, "", e);
}
+ finally
+ {
+ DB.close(rs);
+ }

}


diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WLocatorEditor.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WLocatorEditor.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WLocatorEditor.java
@@ -357,7 +357,7 @@

int M_Locator_ID = 0;
PreparedStatement pstmt = null;
-
+ ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(finalSql, null);
@@ -372,7 +372,7 @@
pstmt.setInt(index++, only_Product_ID);
}

- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();

if (rs.next())
{
@@ -381,25 +381,17 @@
if (rs.next())
M_Locator_ID = 0; // more than one
}
- rs.close();
- pstmt.close();
- pstmt = null;
}
catch (SQLException ex)
{
log.log(Level.SEVERE, finalSql, ex);
}
-
- try
+ finally
{
- if (pstmt != null)
- pstmt.close();
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
}
- catch (SQLException ex1)
- {
- }
-
- pstmt = null;

if (M_Locator_ID == 0)
return false;

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WSearchEditor.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WSearchEditor.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WSearchEditor.java
@@ -709,12 +709,12 @@
m_keyColumnName = m_columnName;
sql = new StringBuffer();
PreparedStatement pstmt = null;
-
+ ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(query, null);
pstmt.setString(1, m_keyColumnName);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();

while (rs.next())
{
@@ -724,25 +724,17 @@
m_tableName = rs.getString(1);
sql.append("UPPER(").append(rs.getString(2)).append(") LIKE ").append(DB.TO_STRING(text));
}
-
- rs.close();
- pstmt.close();
- pstmt = null;
}
catch (SQLException ex)
{
log.log(Level.SEVERE, query, ex);
}
-
- try
+ finally
{
- if (pstmt != null)
- pstmt.close();
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
}
- catch (SQLException ex1)
- {
- }
- pstmt = null;
//
if (sql.length() == 0)
{

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoGeneralPanel.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoGeneralPanel.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoGeneralPanel.java
@@ -269,11 +269,13 @@
int AD_Table_ID = 0;
String tableName = null;

+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(sql, null);
+ pstmt = DB.prepareStatement(sql, null);
pstmt.setString(1, p_tableName);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();

while (rs.next())
{
@@ -291,14 +293,18 @@
tableName = rs.getString(3);
}
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
return false;
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }

// Miminum check
if (m_queryColumns.size() == 0)
@@ -340,9 +346,9 @@

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())
{
String columnName = rs.getString(1);
@@ -399,14 +405,18 @@
else
log.finest("Not Added Column=" + columnName);
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
return false;
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }

if (list.size() == 0)
{

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java
@@ -773,23 +773,28 @@
log.finer(countSql);
m_count = -1;

+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(countSql, null);
+ pstmt = DB.prepareStatement(countSql, null);
setParameters (pstmt, true);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();

if (rs.next())
m_count = rs.getInt(1);
-
- rs.close();
- pstmt.close();
}
catch (Exception e)
{
log.log(Level.SEVERE, countSql, e);
m_count = -2;
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }

if (log.isLoggable(Level.FINE))
log.fine("#" + m_count + " - " + (System.currentTimeMillis()-start) + "ms");
@@ -1079,32 +1084,26 @@
//
String sql = "SELECT AD_Window_ID, PO_Window_ID FROM AD_Table WHERE TableName=?";
PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setString(1, tableName);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
if (rs.next())
{
m_SO_Window_ID = rs.getInt(1);
m_PO_Window_ID = rs.getInt(2);
}
- rs.close();
- pstmt.close();
- pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
- try
+ finally
{
- if (pstmt != null)
- pstmt.close();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
//

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java
@@ -1861,19 +1861,25 @@

// Execute Qusery
m_total = 999999;
+ Statement stmt = null;
+ ResultSet rs = null;
try
{
- Statement stmt = DB.createStatement();
- ResultSet rs = stmt.executeQuery(finalSQL);
+ stmt = DB.createStatement();
+ rs = stmt.executeQuery(finalSQL);
if (rs.next())
m_total = rs.getInt(1);
- rs.close();
- stmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, finalSQL, e);
}
+ finally
+ {
+ DB.close(rs, stmt);
+ rs = null;
+ stmt = null;
+ }
MRole role = MRole.getDefault();
// No Records
/* if (m_total == 0 && alertZeroRecords)
@@ -1920,9 +1926,11 @@
StringBuilder retString = new StringBuilder(" M_Product_Category_ID IN (");
String sql = " SELECT M_Product_Category_ID, M_Product_Category_Parent_ID FROM M_Product_Category";
final Vector<SimpleTreeNode> categories = new Vector<SimpleTreeNode>(100);
+ 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()) {
if(rs.getInt(1)==productCategoryId) {
subTreeRootParentId = rs.getInt(2);
@@ -1931,8 +1939,6 @@
}
retString.append(getSubCategoriesString(productCategoryId, categories, subTreeRootParentId))
.append(") ");
- rs.close();
- stmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
retString = new StringBuilder();
@@ -1940,6 +1946,11 @@
log.log(Level.SEVERE, sql, e);
retString = new StringBuilder();
}
+ finally{
+ DB.close(rs,stmt);
+ rs = null;
+ stmt = null;
+ }
return retString.toString();

} // getSubCategoryWhereClause

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/InfoSchedule.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/InfoSchedule.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/InfoSchedule.java
@@ -268,20 +268,26 @@
if (m_mAssignment.getS_Resource_ID() != 0)
{
String sql = "SELECT S_ResourceType_ID FROM S_Resource WHERE S_Resource_ID=?";
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(sql, null);
+ pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_mAssignment.getS_Resource_ID());
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
if (rs.next())
S_ResourceType_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;
+ }
}

// Get Resource Types
@@ -289,10 +295,12 @@
"SELECT S_ResourceType_ID, Name FROM S_ResourceType WHERE IsActive='Y' ORDER BY 2",
"S_ResourceType", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
KeyNamePair defaultValue = null;
+ 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 pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
@@ -300,13 +308,17 @@
defaultValue = pp;
fieldResourceType.appendItem(pp.getName(), pp.getKey());
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }
if (defaultValue != null) {
int cnt = fieldResourceType.getItemCount();
for(int i = 0; i < cnt; i++) {
@@ -340,11 +352,13 @@
m_loading = true;
fieldResource.getChildren().clear();
String sql = "SELECT S_Resource_ID, Name FROM S_Resource WHERE S_ResourceType_ID=? ORDER BY 2";
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(sql, null);
+ pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, S_ResourceType_ID);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
while (rs.next())
{
pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
@@ -352,13 +366,17 @@
defaultValue = pp;
fieldResource.appendItem(pp.getName(), pp.getKey());
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
+ finally
+ {
+ DB.close(rs,pstmt);
+ rs = null;
+ pstmt = null;
+ }
if (defaultValue != null) {
int cnt = fieldResource.getItemCount();
for(int i = 0; i < cnt; i++) {

diff -r cf769656a7bb1663324d4984a2dfda474fe0f5a1 -r 04277f8ad9d3b2dffd0bc3cb14cb64940d484fb1 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAccountDialog.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAccountDialog.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAccountDialog.java
@@ -510,12 +510,14 @@
{
log.fine("C_ValidCombination_ID=" + C_ValidCombination_ID);
String sql = "SELECT * FROM C_ValidCombination WHERE C_ValidCombination_ID=? AND C_AcctSchema_ID=?";
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(sql, null);
+ pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, C_ValidCombination_ID);
pstmt.setInt(2, C_AcctSchema_ID);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
if (rs.next())
{
if (f_Alias != null)
@@ -540,13 +542,17 @@
//
f_Description.setValue (rs.getString("Description"));
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }
} // loadInfo

/**
@@ -909,25 +915,31 @@
log.fine("Check = " + sql.toString());
int IDvalue = 0;
String Alias = null;
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
- PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
+ pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, m_AD_Client_ID);
pstmt.setInt(2, s_AcctSchema.getC_AcctSchema_ID());
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
if (rs.next())
{
IDvalue = rs.getInt(1);
Alias = rs.getString(2);
}
- rs.close();
- pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql.toString(), e);
IDvalue = 0;
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }
log.fine("ID=" + IDvalue + ", Alias=" + Alias);

if (Alias == null)

This diff is so big that we needed to truncate the remainder.

Repository URL: https://bitbucket.org/idempiere/idempiere/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.

Bitbucket

unread,
Feb 19, 2013, 4:08:33 PM2/19/13
to idempi...@googlegroups.com
1 new commit in iDempiere:

https://bitbucket.org/idempiere/idempiere/commits/4538f345ddfc/
changeset: 4538f345ddfc
branch: development
user: richard1988
date: 2013-02-19 22:08:13
summary: IDEMPIERE-568 Review proper closing of JDBC statements and resultsets
affected #: 101 files

diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/impexp/ImpFormat.java
--- a/org.adempiere.base/src/org/compiere/impexp/ImpFormat.java
+++ b/org.adempiere.base/src/org/compiere/impexp/ImpFormat.java
@@ -118,23 +118,29 @@
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 @@
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 @@
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 @@
+ "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 @@
//
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 @@
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 -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/impexp/MImpFormat.java
--- a/org.adempiere.base/src/org/compiere/impexp/MImpFormat.java
+++ b/org.adempiere.base/src/org/compiere/impexp/MImpFormat.java
@@ -73,29 +73,23 @@
+ "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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
MImpFormatRow[] retValue = new MImpFormatRow[list.size ()];

diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/GridField.java
--- a/org.adempiere.base/src/org/compiere/model/GridField.java
+++ b/org.adempiere.base/src/org/compiere/model/GridField.java
@@ -581,21 +581,27 @@
}
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 @@

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
+ finally
{
- if (pstmt != null)
- pstmt.close();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}


diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/GridTab.java
--- a/org.adempiere.base/src/org/compiere/model/GridTab.java
+++ b/org.adempiere.base/src/org/compiere/model/GridTab.java
@@ -794,21 +794,27 @@
+ " 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 @@
+ " 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 @@
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 @@
+ "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 @@
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 @@
+ "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<Integer>();
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 -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/GridTabVO.java
--- a/org.adempiere.base/src/org/compiere/model/GridTabVO.java
+++ b/org.adempiere.base/src/org/compiere/model/GridTabVO.java
@@ -285,11 +285,13 @@
mTabVO.Fields = new ArrayList<GridFieldVO>();

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 @@
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 -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/GridWorkbench.java
--- a/org.adempiere.base/src/org/compiere/model/GridWorkbench.java
+++ b/org.adempiere.base/src/org/compiere/model/GridWorkbench.java
@@ -112,11 +112,13 @@
+ " 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 @@
}
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 @@
+ "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 @@
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 -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MArchive.java
--- 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 static MArchive[] get(Properties ctx, String whereClause) {
ArrayList<MArchive> list = new ArrayList<MArchive>();
- 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 @@
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 -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MBPGroup.java
--- a/org.adempiere.base/src/org/compiere/model/MBPGroup.java
+++ b/org.adempiere.base/src/org/compiere/model/MBPGroup.java
@@ -71,37 +71,31 @@
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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
if (retValue == null)
@@ -119,6 +113,7 @@
{
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 @@
{
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 @@
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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}


diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MBPartner.java
--- a/org.adempiere.base/src/org/compiere/model/MBPartner.java
+++ b/org.adempiere.base/src/org/compiere/model/MBPartner.java
@@ -150,29 +150,23 @@
+ " 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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
return retValue;
@@ -314,11 +308,12 @@
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 @@
success = false;
log.severe ("None found");
}
- rs.close();
- pstmt.close();
- pstmt = null;
}
catch (Exception e)
{
@@ -337,13 +329,8 @@
}
finally
{
- try
- {
- if (pstmt != null)
- pstmt.close ();
- }
- catch (Exception e)
- {}
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
setStandardDefaults();
@@ -492,16 +479,14 @@
ArrayList<MBPBankAccount> list = new ArrayList<MBPBankAccount>();
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 @@
}
finally
{
- try
- {
- if (pstmt != null)
- pstmt.close ();
- }
- catch (Exception e)
- {}
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}

@@ -689,32 +669,26 @@
+ "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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
//
@@ -739,29 +713,23 @@
+ "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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
if (ActualLifeTimeValue != null)

diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MBPartnerInfo.java
--- a/org.adempiere.base/src/org/compiere/model/MBPartnerInfo.java
+++ b/org.adempiere.base/src/org/compiere/model/MBPartnerInfo.java
@@ -100,6 +100,7 @@
"RV_BPartner", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
ArrayList<MBPartnerInfo> list = new ArrayList<MBPartnerInfo>();
PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(finalSQL, null);
@@ -116,25 +117,18 @@
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
+ finally
{
- if (pstmt != null)
- pstmt.close();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
// Return

diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MBankAccountProcessor.java
--- a/org.adempiere.base/src/org/compiere/model/MBankAccountProcessor.java
+++ b/org.adempiere.base/src/org/compiere/model/MBankAccountProcessor.java
@@ -94,23 +94,29 @@
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 -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MBankStatementMatcher.java
--- a/org.adempiere.base/src/org/compiere/model/MBankStatementMatcher.java
+++ b/org.adempiere.base/src/org/compiere/model/MBankStatementMatcher.java
@@ -55,28 +55,22 @@
@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
+ finally
{
- if (pstmt != null)
- pstmt.close();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
// Convert

diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MCStage.java
--- 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 static MCStage[] getStages (MWebProject project)
{
ArrayList<MCStage> list = new ArrayList<MCStage>();
+ String sql = "SELECT * FROM CM_CStage WHERE CM_WebProject_ID=? ORDER BY CM_CStage_ID";
PreparedStatement pstmt = null;
- String sql = "SELECT * FROM CM_CStage WHERE CM_WebProject_ID=? ORDER BY CM_CStage_ID";
+ 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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
MCStage[] retValue = new MCStage[list.size ()];

diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MCashPlan.java
--- a/org.adempiere.base/src/org/compiere/model/MCashPlan.java
+++ b/org.adempiere.base/src/org/compiere/model/MCashPlan.java
@@ -118,9 +118,6 @@
MCashPlanLine il = new MCashPlanLine(getCtx(), rs, get_TrxName());
list.add(il);
}
- rs.close();
- pstmt.close();
- pstmt = null;
}
catch (Exception e)
{

diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MClick.java
--- a/org.adempiere.base/src/org/compiere/model/MClick.java
+++ b/org.adempiere.base/src/org/compiere/model/MClick.java
@@ -52,31 +52,25 @@
ArrayList<MClick> list = new ArrayList<MClick> ();
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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
//
@@ -199,12 +193,13 @@
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 @@
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 -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MClickCount.java
--- a/org.adempiere.base/src/org/compiere/model/MClickCount.java
+++ b/org.adempiere.base/src/org/compiere/model/MClickCount.java
@@ -114,11 +114,12 @@
.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 @@
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 -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MClient.java
--- a/org.adempiere.base/src/org/compiere/model/MClient.java
+++ b/org.adempiere.base/src/org/compiere/model/MClient.java
@@ -303,10 +303,12 @@
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 @@
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 -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MClientInfo.java
--- a/org.adempiere.base/src/org/compiere/model/MClientInfo.java
+++ b/org.adempiere.base/src/org/compiere/model/MClientInfo.java
@@ -68,34 +68,29 @@
//
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 -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MClientShare.java
--- a/org.adempiere.base/src/org/compiere/model/MClientShare.java
+++ b/org.adempiere.base/src/org/compiere/model/MClientShare.java
@@ -80,10 +80,11 @@
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 @@
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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
if (s_shares.isEmpty()) // put in something
@@ -249,11 +243,12 @@
+ " 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 @@
info.append(", ");
info.append(TableName);
}
- rs.close ();
- pstmt.close ();
- pstmt = null;
}
catch (Exception e)
{
log.log (Level.SEVERE, sql, e);
}
- try
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
log.info(info.toString());

diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MColumn.java
--- a/org.adempiere.base/src/org/compiere/model/MColumn.java
+++ b/org.adempiere.base/src/org/compiere/model/MColumn.java
@@ -558,22 +558,28 @@

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 -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MColumnAccess.java
--- a/org.adempiere.base/src/org/compiere/model/MColumnAccess.java
+++ b/org.adempiere.base/src/org/compiere/model/MColumnAccess.java
@@ -126,11 +126,12 @@
+ "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 @@
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
+ finally
{
- if (pstmt != null)
- pstmt.close();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
// Get Clear Text

diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MConversionRate.java
--- a/org.adempiere.base/src/org/compiere/model/MConversionRate.java
+++ b/org.adempiere.base/src/org/compiere/model/MConversionRate.java
@@ -226,6 +226,7 @@
+ "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 @@
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 -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MCostQueue.java
--- a/org.adempiere.base/src/org/compiere/model/MCostQueue.java
+++ b/org.adempiere.base/src/org/compiere/model/MCostQueue.java
@@ -63,6 +63,7 @@
+ " 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 @@
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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
// New
@@ -127,6 +121,7 @@
if (!ce.isFifo())
sql.append("DESC");
PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
pstmt = DB.prepareStatement (sql.toString(), trxName);
@@ -138,25 +133,18 @@
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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
MCostQueue[] costQ = new MCostQueue[list.size()];

diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MCountry.java
--- a/org.adempiere.base/src/org/compiere/model/MCountry.java
+++ b/org.adempiere.base/src/org/compiere/model/MCountry.java
@@ -113,10 +113,12 @@
//
s_countries = new CCache<String,MCountry>(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 @@
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 -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MDesktop.java
--- a/org.adempiere.base/src/org/compiere/model/MDesktop.java
+++ b/org.adempiere.base/src/org/compiere/model/MDesktop.java
@@ -85,11 +85,13 @@
.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 @@
}
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 @@
+ "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 -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MDiscountSchema.java
--- a/org.adempiere.base/src/org/compiere/model/MDiscountSchema.java
+++ b/org.adempiere.base/src/org/compiere/model/MDiscountSchema.java
@@ -115,29 +115,23 @@
String sql = "SELECT * FROM M_DiscountSchemaBreak WHERE M_DiscountSchema_ID=? ORDER BY SeqNo";
ArrayList<MDiscountSchemaBreak> list = new ArrayList<MDiscountSchemaBreak>();
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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
m_breaks = new MDiscountSchemaBreak[list.size ()];
@@ -160,29 +154,23 @@
String sql = "SELECT * FROM M_DiscountSchemaLine WHERE M_DiscountSchema_ID=? ORDER BY SeqNo";
ArrayList<MDiscountSchemaLine> list = new ArrayList<MDiscountSchemaLine>();
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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
m_lines = new MDiscountSchemaLine[list.size ()];

diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MDistributionList.java
--- a/org.adempiere.base/src/org/compiere/model/MDistributionList.java
+++ b/org.adempiere.base/src/org/compiere/model/MDistributionList.java
@@ -73,11 +73,12 @@
//
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 @@
if (ratio != null)
ratioTotal = ratioTotal.add(ratio);
}
- rs.close ();
- pstmt.close ();
- pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, "getLines", e);
}
- try
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
// Update Ratio

diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MDistributionRun.java
--- a/org.adempiere.base/src/org/compiere/model/MDistributionRun.java
+++ b/org.adempiere.base/src/org/compiere/model/MDistributionRun.java
@@ -79,29 +79,23 @@
+ "WHERE M_DistributionRun_ID=? AND IsActive='Y' AND TotalQty IS NOT NULL AND TotalQty<> 0 ORDER BY Line";
ArrayList<MDistributionRunLine> list = new ArrayList<MDistributionRunLine>();
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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
m_lines = new MDistributionRunLine[list.size()];

diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MDistributionRunDetail.java
--- a/org.adempiere.base/src/org/compiere/model/MDistributionRunDetail.java
+++ b/org.adempiere.base/src/org/compiere/model/MDistributionRunDetail.java
@@ -58,29 +58,23 @@
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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
MDistributionRunDetail[] retValue = new MDistributionRunDetail[list.size()];

diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MDocTypeCounter.java
--- a/org.adempiere.base/src/org/compiere/model/MDocTypeCounter.java
+++ b/org.adempiere.base/src/org/compiere/model/MDocTypeCounter.java
@@ -99,11 +99,12 @@
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 @@
retValue = null;
}
}
- rs.close ();
- pstmt.close ();
- pstmt = null;
}
catch (Exception e)
{
s_log.log(Level.SEVERE, "getCounterDocType", e);
}
- try
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
if (retValue != null) // valid

diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MDunningLevel.java
--- a/org.adempiere.base/src/org/compiere/model/MDunningLevel.java
+++ b/org.adempiere.base/src/org/compiere/model/MDunningLevel.java
@@ -88,31 +88,25 @@
ArrayList<MDunningLevel> list = new ArrayList<MDunningLevel>();
String sql = "SELECT * FROM C_DunningLevel WHERE C_Dunning_ID=? AND DaysAfterDue+DaysBetweenDunning<?";
PreparedStatement pstmt = null;
+ ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getParent().get_ID ());
int totalDays = getDaysAfterDue ().intValue ()+getDaysBetweenDunning ();
pstmt.setInt(2, totalDays);
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
while (rs.next())
list.add(new MDunningLevel(getCtx(), rs, get_TrxName()));
- rs.close();
- pstmt.close();
- pstmt = null;
}
catch (Exception e)
{
s_log.log(Level.SEVERE, sql, e);
}
- try
+ finally
{
- if (pstmt != null)
- pstmt.close();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}


diff -r 0b48c5ae988e49090a1b4ff2ff51ade1b500f4ce -r 4538f345ddfcee6b65149a62ae68a63006731b9a org.adempiere.base/src/org/compiere/model/MDunningRun.java
--- a/org.adempiere.base/src/org/compiere/model/MDunningRun.java
+++ b/org.adempiere.base/src/org/compiere/model/MDunningRun.java
@@ -133,33 +133,27 @@
String sql = "SELECT * FROM C_DunningRunEntry WHERE C_DunningRun_ID=? ORDER BY C_DunningLevel_ID, C_DunningRunEntry_ID";
ArrayList<MDunningRunEntry> list = new ArrayList<MDunningRunEntry>();
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
+ finally
{
- if (pstmt != null)
- pstmt.close ();
- pstmt = null;
- }
- catch (Exception e)
- {
+ DB.close(rs, pstmt);
+ rs = null;
pstmt = null;
}
m_entries = new MDunningRunEntry[list.size ()];

Bitbucket

unread,
Feb 20, 2013, 8:31:33 PM2/20/13
to idempi...@googlegroups.com
1 new commit in iDempiere:

https://bitbucket.org/idempiere/idempiere/commits/abd4a57ee146/
changeset: abd4a57ee146
branch: development
user: richard1988
date: 2013-02-21 02:31:16
summary: IDEMPIERE-568 Review proper closing of JDBC statements and resultsets
affected #: 26 files

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.base.process/src/org/adempiere/process/InOutGenerateRMA.java
--- a/org.adempiere.base.process/src/org/adempiere/process/InOutGenerateRMA.java
+++ b/org.adempiere.base.process/src/org/adempiere/process/InOutGenerateRMA.java
@@ -97,13 +97,13 @@
+ "AND T_Selection.AD_PInstance_ID=? ";

PreparedStatement pstmt = null;
-
+ ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, Env.getAD_Client_ID(getCtx()));
pstmt.setInt(2, getAD_PInstance_ID());
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();

while (rs.next())
{
@@ -116,14 +116,8 @@
}
finally
{
- try
- {
- pstmt.close();
- }
- catch (Exception ex)
- {
- log.log(Level.SEVERE, "Could not close prepared statement");
- }
+ DB.close(rs,pstmt);
+ rs = null;pstmt = null;
}

StringBuilder msgreturn = new StringBuilder("@Created@ = ").append(m_created);

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.base.process/src/org/adempiere/process/InvoiceGenerateRMA.java
--- a/org.adempiere.base.process/src/org/adempiere/process/InvoiceGenerateRMA.java
+++ b/org.adempiere.base.process/src/org/adempiere/process/InvoiceGenerateRMA.java
@@ -92,13 +92,13 @@
+ "AND T_Selection.AD_PInstance_ID=? ";

PreparedStatement pstmt = null;
-
+ ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, Env.getAD_Client_ID(getCtx()));
pstmt.setInt(2, getAD_PInstance_ID());
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();

while (rs.next())
{
@@ -111,14 +111,8 @@
}
finally
{
- try
- {
- pstmt.close();
- }
- catch (Exception ex)
- {
- log.log(Level.SEVERE, "Could not close prepared statement");
- }
+ DB.close(rs,pstmt);
+ rs = null;pstmt = null;
}
StringBuilder msgreturn = new StringBuilder("@Created@ = ").append(m_created);
return msgreturn.toString();

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.base.process/src/org/adempiere/process/PrepareMigrationScripts.java
--- a/org.adempiere.base.process/src/org/adempiere/process/PrepareMigrationScripts.java
+++ b/org.adempiere.base.process/src/org/adempiere/process/PrepareMigrationScripts.java
@@ -85,21 +85,23 @@
.append(fileName.get(i))
.append("]. Finding out if the script has or hasn't been applied yet...");
log.fine(msglog.toString());
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
try {
// First of all, check if the script hasn't been applied yet...
String checkScript = "select ad_migrationscript_id from ad_migrationscript where name = ?";
- PreparedStatement pstmt = DB.prepareStatement(checkScript, this
+ pstmt = DB.prepareStatement(checkScript, this
.get_TrxName());
pstmt.setString(1, fileName.get(i));
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();
if (rs.next()) {
msglog = new StringBuilder("Script ").append(fileName.get(i))
.append(" already in the database");
log.warning(msglog.toString());
- pstmt.close();
continue;
}
- pstmt.close();
+ DB.close(pstmt);
+ pstmt = null;
// first use a Scanner to get each line
Scanner scanner = new Scanner(dirList[i]);
StringBuilder body = new StringBuilder();
@@ -213,7 +215,8 @@
pstmt.setTimestamp(15, ts);
pstmt.setTimestamp(16, ts);
int result = pstmt.executeUpdate();
- pstmt.close();
+ DB.close(pstmt);
+ pstmt = null;
if (result > 0)
log.info("Header inserted. Now inserting the script body");
else {
@@ -227,7 +230,8 @@
pstmt.setBytes(1, body.toString().getBytes());
pstmt.setInt(2, seqID);
result = pstmt.executeUpdate();
- pstmt.close();
+ DB.close(pstmt);
+ pstmt = null;
if (result > 0)
log.info("Script Body inserted.");
else {
@@ -245,6 +249,13 @@
} catch (Exception ex) {
log.severe(ex.getMessage());
}
+ finally
+ {
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
+ }
+
}
return "Sucess";
}

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.base.process/src/org/adempiere/process/UpdateRoleMenu.java
--- a/org.adempiere.base.process/src/org/adempiere/process/UpdateRoleMenu.java
+++ b/org.adempiere.base.process/src/org/adempiere/process/UpdateRoleMenu.java
@@ -80,11 +80,12 @@
String sqlStmt = "SELECT U_WebMenu_ID, IsActive FROM U_WebMenu";

PreparedStatement pstmt = null;
+ ResultSet rs = null;

try
{
pstmt = DB.prepareStatement(sqlStmt, get_TrxName());
- ResultSet rs = pstmt.executeQuery();
+ rs = pstmt.executeQuery();

while (rs.next())
{
@@ -101,17 +102,9 @@
}
finally
{
- if (pstmt != null)
- {
- try
- {
- pstmt.close();
- }
- catch (Exception ex)
- {
- log.log(Level.SEVERE, "Could not close prepared statement");
- }
- }
+ DB.close(rs, pstmt);
+ rs = null;
+ pstmt = null;
}

return "Role updated successfully";

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.base.process/src/org/compiere/process/PaySelectionCreateFrom.java
--- a/org.adempiere.base.process/src/org/compiere/process/PaySelectionCreateFrom.java
+++ b/org.adempiere.base.process/src/org/compiere/process/PaySelectionCreateFrom.java
@@ -225,7 +225,6 @@
PayAmt, PayAmt.subtract(DiscountAmt), DiscountAmt);
if (!pselLine.save())
{
- pstmt.close();
throw new IllegalStateException ("Cannot save MPaySelectionLine");
}
}

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.base/src/org/adempiere/util/ProcessUtil.java
--- a/org.adempiere.base/src/org/adempiere/util/ProcessUtil.java
+++ b/org.adempiere.base/src/org/adempiere/util/ProcessUtil.java
@@ -80,13 +80,13 @@
public static boolean startDatabaseProcedure (ProcessInfo processInfo, String ProcedureName, Trx trx, boolean managedTrx) {
String sql = "{call " + ProcedureName + "(?)}";
String trxName = trx != null ? trx.getTrxName() : null;
+ CallableStatement cstmt = null;
try
{
//hengsin, add trx support, updateable support.
- CallableStatement cstmt = DB.prepareCall(sql, ResultSet.CONCUR_UPDATABLE, trxName);
+ cstmt = DB.prepareCall(sql, ResultSet.CONCUR_UPDATABLE, trxName);
cstmt.setInt(1, processInfo.getAD_PInstance_ID());
cstmt.executeUpdate();
- cstmt.close();
if (trx != null && trx.isActive() && managedTrx)
{
trx.commit(true);
@@ -105,6 +105,8 @@
}
finally
{
+ DB.close(cstmt);
+ cstmt = null;
if (trx != null && managedTrx)
trx.close();
}

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.base/src/org/compiere/db/CreateAdempiere.java
--- a/org.adempiere.base/src/org/compiere/db/CreateAdempiere.java
+++ b/org.adempiere.base/src/org/compiere/db/CreateAdempiere.java
@@ -749,9 +749,6 @@
log.finest("# " + no);
}
//
- stmt.close();
- stmt = null;
- //
if (batch)
conn.commit();
//
@@ -774,17 +771,11 @@
msg += "\n=>" + cmd;
log.log(Level.SEVERE, msg);
}
- // Error clean up
- try
+ finally
{
- if (stmt != null)
- stmt.close();
+ DB.close(stmt);
+ stmt = null;
}
- catch (SQLException e1)
- {
- log.log(Level.SEVERE, "close statement", e1);
- }
- stmt = null;
return false;
} // execureCommands


diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.base/src/org/compiere/db/StatementProxy.java
--- a/org.adempiere.base/src/org/compiere/db/StatementProxy.java
+++ b/org.adempiere.base/src/org/compiere/db/StatementProxy.java
@@ -179,10 +179,7 @@
if (close) return;

try {
- if (p_stmt != null)
- {
- p_stmt.close();
- }
+ DB.close(p_stmt);
} finally {
if (m_conn != null)
{
@@ -194,6 +191,7 @@
{}
}
m_conn = null;
+ p_stmt = null;
close = true;
}
} // close
@@ -222,6 +220,9 @@
finally
{
DB.close(rs);
+ rs = null;
+ DB.close(rowSet);
+ rowSet = null;
}
return rowSet;
} // local_getRowSet

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.base/src/org/compiere/model/MDepreciationConvention.java
--- a/org.adempiere.base/src/org/compiere/model/MDepreciationConvention.java
+++ b/org.adempiere.base/src/org/compiere/model/MDepreciationConvention.java
@@ -97,16 +97,11 @@
cs.setInt(6, Period);
cs.execute();
retValue = cs.getBigDecimal(1);
- cs.close();
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
}
finally {
- try {
- if (cs != null) cs.close();
- } catch (SQLException e) {
- log.log(Level.FINEST, "Error", e);
- }
+ DB.close(cs);
cs = null;
}
}

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.base/src/org/compiere/model/MDepreciationMethod.java
--- a/org.adempiere.base/src/org/compiere/model/MDepreciationMethod.java
+++ b/org.adempiere.base/src/org/compiere/model/MDepreciationMethod.java
@@ -178,7 +178,6 @@
cs.setInt(6, A_Asset_Acct_ID);
cs.execute();
retValue = cs.getBigDecimal(1);
- cs.close();
}
catch (SQLException e)
{

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.base/src/org/compiere/model/MElementValue.java
--- a/org.adempiere.base/src/org/compiere/model/MElementValue.java
+++ b/org.adempiere.base/src/org/compiere/model/MElementValue.java
@@ -20,6 +20,7 @@
import java.util.Properties;

import org.adempiere.exceptions.AdempiereException;
+import org.compiere.util.DB;
import org.compiere.util.Env;

/**
@@ -223,16 +224,18 @@
//
// Check Valid Combinations - teo_sarca FR [ 1883533 ]
String whereClause = MAccount.COLUMNNAME_Account_ID+"=?";
- POResultSet<MAccount> rs = new Query(getCtx(), I_C_ValidCombination.Table_Name, whereClause, get_TrxName())
- .setParameters(get_ID())
- .scroll();
+ POResultSet<MAccount> rs = null;
try {
+ rs = new Query(getCtx(), I_C_ValidCombination.Table_Name, whereClause, get_TrxName())
+ .setParameters(get_ID())
+ .scroll();
while(rs.hasNext()) {
rs.next().deleteEx(true);
}
}
finally {
- rs.close();
+ DB.close(rs);
+ rs = null;
}
}
return true;

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.base/src/org/compiere/model/MSequence.java
--- a/org.adempiere.base/src/org/compiere/model/MSequence.java
+++ b/org.adempiere.base/src/org/compiere/model/MSequence.java
@@ -177,14 +177,15 @@
// get ID from http site
retValue = getNextOfficialID_HTTP(TableName);
if (retValue > 0) {
- PreparedStatement updateSQL;
- updateSQL = conn.prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = ? + 1 WHERE AD_Sequence_ID = ?");
+ PreparedStatement updateSQL = null;
try {
+ updateSQL = conn.prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = ? + 1 WHERE AD_Sequence_ID = ?");
updateSQL.setInt(1, retValue);
updateSQL.setInt(2, AD_Sequence_ID);
updateSQL.executeUpdate();
} finally {
- updateSQL.close();
+ DB.close(updateSQL);
+ updateSQL = null;
}
}
gotFromHTTP = true;
@@ -206,14 +207,15 @@
// get ID from http site
retValue = getNextProjectID_HTTP(TableName);
if (retValue > 0) {
- PreparedStatement updateSQL;
- updateSQL = conn.prepareStatement("UPDATE AD_Sequence SET CurrentNext = GREATEST(CurrentNext, ? + 1) WHERE AD_Sequence_ID = ?");
+ PreparedStatement updateSQL = null;
try {
+ updateSQL = conn.prepareStatement("UPDATE AD_Sequence SET CurrentNext = GREATEST(CurrentNext, ? + 1) WHERE AD_Sequence_ID = ?");
updateSQL.setInt(1, retValue);
updateSQL.setInt(2, AD_Sequence_ID);
updateSQL.executeUpdate();
} finally {
- updateSQL.close();
+ DB.close(updateSQL);
+ updateSQL = null;
}
}
gotFromHTTP = true;
@@ -222,23 +224,25 @@
}

if (! gotFromHTTP) {
- PreparedStatement updateSQL;
- int incrementNo = rs.getInt(3);
- if (adempiereSys) {
- updateSQL = conn
- .prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = CurrentNextSys + ? WHERE AD_Sequence_ID = ?");
- retValue = rs.getInt(2);
- } else {
- updateSQL = conn
- .prepareStatement("UPDATE AD_Sequence SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ?");
- retValue = rs.getInt(1);
- }
- try {
+ PreparedStatement updateSQL = null;
+ try
+ {
+ int incrementNo = rs.getInt(3);
+ if (adempiereSys) {
+ updateSQL = conn
+ .prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = CurrentNextSys + ? WHERE AD_Sequence_ID = ?");
+ retValue = rs.getInt(2);
+ } else {
+ updateSQL = conn
+ .prepareStatement("UPDATE AD_Sequence SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ?");
+ retValue = rs.getInt(1);
+ }
updateSQL.setInt(1, incrementNo);
updateSQL.setInt(2, AD_Sequence_ID);
updateSQL.executeUpdate();
} finally {
- updateSQL.close();
+ DB.close(updateSQL);
+ updateSQL = null;
}
}

@@ -263,14 +267,10 @@
finally
{
DB.close(rs, pstmt);
- pstmt = null;
- rs = null;
- if (timeoutStatement != null){
- try {
- timeoutStatement.close();
- }catch(Exception e){}
- timeoutStatement = null;
- }
+ pstmt = null;rs = null;
+ DB.close(timeoutStatement);
+ timeoutStatement = null;
+
if (conn != null)
{
try {
@@ -478,6 +478,7 @@
finally
{
DB.close(updateSQL);
+ updateSQL = null;
}
}
else
@@ -516,13 +517,12 @@
finally
{
DB.close(rs, pstmt);
+ pstmt = null;rs = null;
+ DB.close(timeoutStatement);
+ timeoutStatement = null;
// Finish
try
{
- if (timeoutStatement != null) {
- timeoutStatement.close();
- timeoutStatement = null;
- }
if (trx == null && conn != null) {
conn.close();
conn = null;

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.base/src/org/compiere/report/FinReportJasper.java
--- a/org.adempiere.base/src/org/compiere/report/FinReportJasper.java
+++ b/org.adempiere.base/src/org/compiere/report/FinReportJasper.java
@@ -85,18 +85,23 @@
if (proc.getProcedureName() != null && proc.getProcedureName().length() > 0) {
// execute on this thread/connection
String sql = "{call " + proc.getProcedureName() + "(?)}";
+ CallableStatement cstmt = null;
try
{
- CallableStatement cstmt = DB.prepareCall(sql); // ro??
+ cstmt = DB.prepareCall(sql); // ro??
cstmt.setInt(1, getAD_PInstance_ID());
cstmt.executeUpdate();
- cstmt.close();
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
poInfo.setSummary (Msg.getMsg(Env.getCtx(), "ProcessRunError") + " " + e.getLocalizedMessage());
}
+ finally
+ {
+ DB.close(cstmt);
+ cstmt = null;
+ }
}

// TODO - allow java class preprocess if the classname <> ProcessUtil.JASPER_STARTER_CLASS

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.base/src/org/compiere/util/DB.java
--- a/org.adempiere.base/src/org/compiere/util/DB.java
+++ b/org.adempiere.base/src/org/compiere/util/DB.java
@@ -1056,6 +1056,7 @@
}
// Always close cursor
close(cs);
+ cs = null;
}
return no;
} // executeUpdate
@@ -1121,9 +1122,8 @@
}
finally
{
- if (rs != null)
- rs.getStatement().close();
- DB.close(rs);
+ close(rs.getStatement());
+ close(rs);rs = null;
}
}
timeoutStatement = conn.createStatement();
@@ -1134,12 +1134,8 @@
}
} catch (SQLException e) {}
finally{
- if (timeoutStatement != null) {
- try {
- timeoutStatement.close();
- } catch (Exception e) {}
- timeoutStatement = null;
- }
+ DB.close(timeoutStatement);
+ timeoutStatement = null;
}
}
else
@@ -1193,15 +1189,12 @@
} catch (SQLException e) {
}
finally{
- if (timeoutStatement != null) {
- try {
- timeoutStatement.close();
- } catch (Exception e) {}
+ close(timeoutStatement);
timeoutStatement = null;
- }
}
}
- DB.close(cs);
+ close(cs);
+ cs = null;
}
return no;
}

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.base/src/org/idempiere/fa/process/A_Asset_Addition_ProcessAll.java
--- a/org.adempiere.base/src/org/idempiere/fa/process/A_Asset_Addition_ProcessAll.java
+++ b/org.adempiere.base/src/org/idempiere/fa/process/A_Asset_Addition_ProcessAll.java
@@ -4,6 +4,7 @@
import org.compiere.model.POResultSet;
import org.compiere.model.Query;
import org.compiere.process.SvrProcess;
+import org.compiere.util.DB;


/**
@@ -21,11 +22,11 @@
//
String whereClause = "AD_Client_ID=? AND IsActive=?"
+" AND "+MAssetAddition.COLUMNNAME_Processed+"=?";
- POResultSet<MAssetAddition>
- rs = new Query(getCtx(), MAssetAddition.Table_Name, whereClause, get_TrxName())
- .setParameters(new Object[]{getAD_Client_ID(), "N", "N"})
- .scroll();
+ POResultSet<MAssetAddition> rs = null;
try {
+ rs = new Query(getCtx(), MAssetAddition.Table_Name, whereClause, get_TrxName())
+ .setParameters(new Object[]{getAD_Client_ID(), "N", "N"})
+ .scroll();
while (rs.hasNext()) {
MAssetAddition a = rs.next();
boolean ret = a.processIt(MAssetAddition.DOCACTION_Complete);
@@ -36,7 +37,7 @@
}
}
finally {
- rs.close(); rs = null;
+ DB.close(rs); rs = null;
}
//
return "OK/Error: "+cnt_ok+"/"+cnt_err;

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/SQLStatementElementHandler.java
--- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/SQLStatementElementHandler.java
+++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/SQLStatementElementHandler.java
@@ -78,8 +78,8 @@
int n = stmt.executeUpdate (sql);
log.info("Executed SQL Statement for PostgreSQL: "+ getStringValue(element,"statement") + " ReturnValue="+n);
} finally {
- if (stmt != null)
- stmt.close();
+ DB.close(stmt);
+ stmt = null;
}
}

@@ -105,6 +105,7 @@
logImportDetail (ctx, impDetail, 0, "SQLStatement",1,"Execute");
} finally {
DB.close(pstmt);
+ pstmt = null;
}
}


diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.ui.swing/src/org/compiere/apps/form/VSQLProcess.java
--- a/org.adempiere.ui.swing/src/org/compiere/apps/form/VSQLProcess.java
+++ b/org.adempiere.ui.swing/src/org/compiere/apps/form/VSQLProcess.java
@@ -232,26 +232,21 @@
log.log(Level.SEVERE, "process statement: " + sql + " - " + e.toString());
result.append("===> ").append(e.toString());
}
+ finally
+ {
+ DB.close(stmt);
+ stmt = null;
+ try
+ {
+ conn.close();
+ }
+ catch (SQLException e2)
+ {
+ log.log(Level.SEVERE, "processStatement - close connection", e2);
+ }
+ conn = null;
+ }

- // Clean up
- try
- {
- stmt.close();
- }
- catch (SQLException e1)
- {
- log.log(Level.SEVERE, "processStatement - close statement", e1);
- }
- stmt = null;
- try
- {
- conn.close();
- }
- catch (SQLException e2)
- {
- log.log(Level.SEVERE, "processStatement - close connection", e2);
- }
- conn = null;
//
result.append(Env.NL);
return result.toString();

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.ui.swing/src/org/compiere/apps/search/Find.java
--- a/org.adempiere.ui.swing/src/org/compiere/apps/search/Find.java
+++ b/org.adempiere.ui.swing/src/org/compiere/apps/search/Find.java
@@ -779,14 +779,7 @@
public void dispose()
{
log.config("");
-
- // Find SQL
- if (m_pstmt != null)
- {
- try {
- m_pstmt.close();
- } catch (SQLException e) {}
- }
+ DB.close(m_pstmt);
m_pstmt = null;

// Remove action listener from custom fields - teo_sarca [ 1709292 ]

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccountDialog.java
--- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccountDialog.java
+++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAccountDialog.java
@@ -968,17 +968,22 @@
sql.append("'").append(f_Alias.getValue()).append("'");
sql.append(" WHERE C_ValidCombination_ID=").append(IDvalue);
int i = 0;
+ PreparedStatement stmt = null;
try
{
- java.sql.PreparedStatement stmt = DB.prepareStatement(sql.toString(),
+ stmt = DB.prepareStatement(sql.toString(),
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, null);
i = stmt.executeUpdate();
- stmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql.toString(), e);
}
+ finally
+ {
+ DB.close(stmt);
+ stmt = null;
+ }
if (i == 0)
ADialog.error(m_WindowNo, this, "AccountNotUpdated");
}

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignment.java
--- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignment.java
+++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/VAssignment.java
@@ -188,8 +188,8 @@
{
try
{
- if (m_pstmt != null)
- m_pstmt.close();
+ DB.close(m_pstmt);
+ m_pstmt = null;
}
catch (Exception e)
{

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WSQLProcess.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WSQLProcess.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WSQLProcess.java
@@ -238,26 +238,20 @@
log.log(Level.SEVERE, "process statement: " + sql + " - " + exception);
result.append("===> ").append(exception);
}
-
- // Clean up
- try
+ finally
{
- stmt.close();
- }
- catch (SQLException e1)
- {
- log.log(Level.SEVERE, "processStatement - close statement", e1);
- }
- stmt = null;
- try
- {
- conn.close();
- }
- catch (SQLException e2)
- {
- log.log(Level.SEVERE, "processStatement - close connection", e2);
- }
- conn = null;
+ DB.close(stmt);
+ stmt = null;
+ try
+ {
+ conn.close();
+ }
+ catch (SQLException e2)
+ {
+ log.log(Level.SEVERE, "processStatement - close connection", e2);
+ }
+ conn = null;
+ }
//
result.append(Env.NL);
return result.toString();

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/FindWindow.java
@@ -1789,15 +1789,9 @@
log.config("");

// Find SQL
- if (m_pstmt != null)
- {
- try {
- m_pstmt.close();
- } catch (SQLException e) {}
- }
+ DB.close(m_pstmt);
m_pstmt = null;
-
-
+
// TargetFields
if (m_targetFields != null)
m_targetFields.clear();

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAccountDialog.java
--- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAccountDialog.java
+++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAccountDialog.java
@@ -956,17 +956,22 @@
sql.append("'").append(f_Alias.getValue()).append("'");
sql.append(" WHERE C_ValidCombination_ID=").append(IDvalue);
int i = 0;
+ PreparedStatement stmt = null;
try
{
- java.sql.PreparedStatement stmt = DB.prepareStatement(sql.toString(),
+ stmt = DB.prepareStatement(sql.toString(),
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE, null);
i = stmt.executeUpdate();
- stmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql.toString(), e);
}
+ finally
+ {
+ DB.close(stmt);
+ stmt = null;
+ }
if (i == 0)
FDialog.error(m_WindowNo, this, "AccountNotUpdated");
}

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.adempiere.ui/src/org/compiere/apps/form/Match.java
--- a/org.adempiere.ui/src/org/compiere/apps/form/Match.java
+++ b/org.adempiere.ui/src/org/compiere/apps/form/Match.java
@@ -372,17 +372,23 @@
m_sql.toString(), "hdr", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO)
+ m_groupBy;
log.finest(sql);
+ Statement stmt = null;
+ ResultSet rs = null;
try
{
- Statement stmt = DB.createStatement();
- ResultSet rs = stmt.executeQuery(sql);
+ stmt = DB.createStatement();
+ rs = stmt.executeQuery(sql);
table.loadTable(rs);
- stmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
+ finally
+ {
+ DB.close(rs,stmt);
+ rs = null;stmt = null;
+ }
} // tableLoad

/**

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java
--- a/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java
+++ b/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java
@@ -831,10 +831,11 @@
public static void dumpLocks(Connection conn)
{
Statement stmt = null;
+ ResultSet rs = null;
try {
String sql = "select pg_class.relname,pg_locks.* from pg_class,pg_locks where pg_class.relfilenode=pg_locks.relation order by 1";
stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery(sql);
+ rs = stmt.executeQuery(sql);
int cnt = rs.getMetaData().getColumnCount();
System.out.println();
while (rs.next())
@@ -852,10 +853,8 @@
} catch (Exception e) {

} finally {
- try{
- if (stmt != null)
- stmt.close();
- } catch (Exception e) {}
+ DB.close(rs,stmt);
+ rs = null;stmt = null;
}
}

@@ -964,13 +963,24 @@
finally
{
if (rs != null)
- rs.getStatement().close();
+ DB.close(rs.getStatement());
DB.close(rs);
+ rs = null;
}

- Statement timeoutStatement = conn.createStatement();
- String sql = "SET " + (autoCommit ? "SESSION" : "LOCAL") + " statement_timeout TO " + ( timeOut > 0 ? Integer.toString(timeOut * 1000) : " DEFAULT ");
- timeoutStatement.execute(sql);
+ Statement timeoutStatement = null;
+ try
+ {
+ timeoutStatement = conn.createStatement();
+ String sql = "SET " + (autoCommit ? "SESSION" : "LOCAL") + " statement_timeout TO " + ( timeOut > 0 ? Integer.toString(timeOut * 1000) : " DEFAULT ");
+ timeoutStatement.execute(sql);
+ }
+ finally
+ {
+ DB.close(timeoutStatement);
+ timeoutStatement = null;
+ }
+
if (log.isLoggable(Level.FINEST))
{
log.finest("Set statement timeout to " + timeOut);
@@ -1035,6 +1045,7 @@
if(stmt!=null)setStatementTimeout(stmt.getConnection(), currentTimeout);
} catch (SQLException e) {}
DB.close(rs, stmt);
+ rs = null;stmt = null;
}
}
return false;

diff -r c71ca501af1d3df326d4a7eca00afed6fcc7c80b -r abd4a57ee1469a0dcd5ac48efa2b4ee067ddf101 org.idempiere.webservices/WEB-INF/src/net/sf/compilo/data/DBDataSource.java
--- a/org.idempiere.webservices/WEB-INF/src/net/sf/compilo/data/DBDataSource.java
+++ b/org.idempiere.webservices/WEB-INF/src/net/sf/compilo/data/DBDataSource.java
@@ -228,14 +228,9 @@
*/
public void close()
{
- try
- {
- if(m_resultSet != null)
- m_resultSet.close();
-
- if(m_pstmt != null)
- m_pstmt.close();
- }
- catch (Exception e){}
+ DB.close(m_resultSet);
+ m_resultSet = null;
+ DB.close(m_pstmt);
+ m_pstmt = null;
Reply all
Reply to author
Forward
0 new messages