From 41249300e789813dc8982800839e109984244af4 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Mon, 3 Dec 2012 14:36:30 +0800 Subject: [PATCH] IDEMPIERE-496 Exception when changing Organization Info. Performance improvement. --- .../src/org/compiere/model/GridTable.java | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/GridTable.java b/org.adempiere.base/src/org/compiere/model/GridTable.java index cc36f5ef0b..0b488c09c5 100644 --- a/org.adempiere.base/src/org/compiere/model/GridTable.java +++ b/org.adempiere.base/src/org/compiere/model/GridTable.java @@ -36,6 +36,7 @@ import java.util.List; import java.util.Map; import java.util.Properties; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import javax.swing.event.TableModelListener; @@ -1011,9 +1012,9 @@ public class GridTable extends AbstractTableModel log.fine("Waiting for loader row=" + row + ", size=" + m_sort.size()); try { - Thread.sleep(500); // 1/2 second + m_loaderFuture.get(500, TimeUnit.MILLISECONDS); } - catch (InterruptedException ie) + catch (Exception ie) {} loops++; } @@ -3318,6 +3319,8 @@ public class GridTable extends AbstractTableModel private ResultSet m_rs = null; private Trx trx = null; private Properties m_context = null; + private int maxRows; + private int rows; public void setContext(Properties context) { @@ -3331,9 +3334,10 @@ public class GridTable extends AbstractTableModel */ protected int open (int maxRows) { - // log.config( "MTable Loader.open"); + this.maxRows = maxRows; + // Get Number of Rows - int rows = 0; + rows = 0; PreparedStatement pstmt = null; ResultSet rs = null; try @@ -3361,7 +3365,20 @@ public class GridTable extends AbstractTableModel info.append(rows); if (rows == 0) info.append(" - ").append(m_SQL_Count); - + + if (maxRows > 0 && rows > maxRows) + { + info.append(" - MaxRows=").append(maxRows); + rows = maxRows; + } + + if (log.isLoggable(Level.FINE)) + log.fine(info.toString()); + + return rows; + } // open + + private void openResultSet() { //postgresql need trx to use cursor based resultset String trxName = m_virtual ? Trx.createTrxName("Loader") : null; trx = trxName != null ? Trx.get(trxName, true) : null; @@ -3369,11 +3386,9 @@ public class GridTable extends AbstractTableModel try { m_pstmt = DB.prepareStatement(m_SQL, trxName); - if (maxRows > 0 && rows > maxRows) + if (this.maxRows > 0 && rows > this.maxRows) { - m_pstmt.setMaxRows(maxRows); - info.append(" - MaxRows=").append(maxRows); - rows = maxRows; + m_pstmt.setMaxRows(this.maxRows); } //ensure not all row is fectch into memory for virtual table if (m_virtual) @@ -3384,11 +3399,8 @@ public class GridTable extends AbstractTableModel catch (SQLException e) { log.log(Level.SEVERE, m_SQL, e); - return 0; } - log.fine(info.toString()); - return rows; - } // open + } /** * Close RS and Statement @@ -3419,7 +3431,7 @@ public class GridTable extends AbstractTableModel } // run private void doRun() { - log.info(""); + openResultSet(); if (m_rs == null) return;