diff --git a/base/src/org/compiere/model/MTree.java b/base/src/org/compiere/model/MTree.java index baa89b2a10..108f1cf69d 100644 --- a/base/src/org/compiere/model/MTree.java +++ b/base/src/org/compiere/model/MTree.java @@ -80,6 +80,8 @@ public class MTree extends MTree_Base private RowSet m_nodeRowSet; /** The tree is displayed on the Java Client (i.e. not web) */ private boolean m_clientTree = true; + + private HashMap m_nodeIdMap; /** Logger */ private static CLogger s_log = CLogger.getCLogger(MTree.class); @@ -209,11 +211,13 @@ public class MTree extends MTree_Base //closing the rowset will also close connection for oracle rowset implementation //m_nodeRowSet.close(); m_nodeRowSet = null; + m_nodeIdMap = null; } catch (SQLException e) { log.log(Level.SEVERE, sql.toString(), e); m_nodeRowSet = null; + m_nodeIdMap = null; } // Done with loading - add remainder from buffer @@ -401,6 +405,28 @@ public class MTree extends MTree_Base sourceTable, MRole.SQL_FULLYQUALIFIED, m_editable); log.fine(sql); m_nodeRowSet = DB.getRowSet (sql); + m_nodeIdMap = new HashMap(50); + try + { + m_nodeRowSet.beforeFirst(); + int i = 0; + while (m_nodeRowSet.next()) + { + i++; + int node = m_nodeRowSet.getInt(1); + Integer nodeId = Integer.valueOf(node); + ArrayList list = m_nodeIdMap.get(nodeId); + if (list == null) + { + list = new ArrayList(5); + m_nodeIdMap.put(nodeId, list); + } + list.add(Integer.valueOf(i)); + } + } catch (SQLException e) + { + log.log(Level.SEVERE, "", e); + } } // getNodeDetails /** @@ -417,9 +443,16 @@ public class MTree extends MTree_Base MTreeNode retValue = null; try { - m_nodeRowSet.beforeFirst(); - while (m_nodeRowSet.next()) + //m_nodeRowSet.beforeFirst(); + ArrayList nodeList = m_nodeIdMap.get(Integer.valueOf(node_ID)); + int size = nodeList != null ? nodeList.size() : 0; + int i = 0; + //while (m_nodeRowSet.next()) + while (i < size) { + Integer nodeId = (Integer)nodeList.get(i); + i++; + m_nodeRowSet.absolute(nodeId.intValue()); int node = m_nodeRowSet.getInt(1); if (node_ID != node) // search for correct one continue;