details:   https://code.openbravo.com/erp/devel/pi/rev/1f5df7e3b8b6
changeset: 29604:1f5df7e3b8b6
user:      Stefan Hühner <stefan.huehner <at> openbravo.com>
date:      Fri Jun 10 12:24:45 2016 +0200
summary:   fixed bug 33187: OrganizationStructureProvider loads many ADTreeNode 
objects

  OrganizationStructureProvider loads in memory DAL object for each ADTreeNode 
of
  the organization tree. This causes initialization to be slower as well as 
subsequent
  flushes.

  Now only ids are loaded instead of loading full DAL node objects, this reduces
  initialization time and does not affect flushes.

details:   https://code.openbravo.com/erp/devel/pi/rev/21598578f881
changeset: 29605:21598578f881
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Fri Jun 10 13:43:44 2016 +0200
summary:   related to bug 33187: rename some mehtods/variables to make code 
more readable

diffstat:

 src/org/openbravo/dal/security/OrganizationStructureProvider.java |  57 
+++++----
 1 files changed, 32 insertions(+), 25 deletions(-)

diffs (145 lines):

diff -r 7b9f6cdbce15 -r 21598578f881 
src/org/openbravo/dal/security/OrganizationStructureProvider.java
--- a/src/org/openbravo/dal/security/OrganizationStructureProvider.java Fri Jun 
10 19:02:58 2016 +0200
+++ b/src/org/openbravo/dal/security/OrganizationStructureProvider.java Fri Jun 
10 13:43:44 2016 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2016 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -77,25 +77,27 @@
     }
 
     // read all trees of all clients, bypass DAL to prevent security checks
-    final String qryStr = "select t from " + Tree.class.getName() + " t where 
table.id='"
+    final String qryStr = "select t.id from " + Tree.class.getName() + " t 
where table.id='"
         + AD_ORG_TABLE_ID + "' and client.id='" + getClientId() + "'";
     final Query qry = SessionHandler.getInstance().createQuery(qryStr);
     @SuppressWarnings("unchecked")
-    final List<Tree> ts = qry.list();
-    final List<TreeNode> treeNodes = new ArrayList<TreeNode>();
-    for (final Tree t : ts) {
-      final String nodeQryStr = "select tn from " + TreeNode.class.getName()
-          + " tn where tn.tree.id='" + t.getId() + "'";
+    final List<String> ts = qry.list();
+    final List<Object[]> treeNodes = new ArrayList<Object[]>();
+    for (final String treeId : ts) {
+      final String nodeQryStr = "select tn.node, tn.reportSet from " + 
TreeNode.class.getName()
+          + " tn where tn.tree.id='" + treeId + "'";
       final Query nodeQry = 
SessionHandler.getInstance().createQuery(nodeQryStr);
       @SuppressWarnings("unchecked")
-      final List<TreeNode> tns = nodeQry.list();
+      final List<Object[]> tns = nodeQry.list();
       treeNodes.addAll(tns);
     }
 
     final List<OrgNode> orgNodes = new ArrayList<OrgNode>(treeNodes.size());
-    for (final TreeNode tn : treeNodes) {
+    for (final Object[] tn : treeNodes) {
       final OrgNode on = new OrgNode();
-      on.setTreeNode(tn);
+      String nodeId = (String) tn[0];
+      String parentId = (String) tn[1];
+      on.setTreeNodeData(nodeId, parentId);
       orgNodes.add(on);
     }
 
@@ -105,18 +107,17 @@
 
     for (final OrgNode on : orgNodes) {
       if (on.getParent() != null) {
-        parentByOrganizationID.put(on.getTreeNode().getNode(), 
on.getParent().getTreeNode()
-            .getNode());
+        parentByOrganizationID.put(on.getNodeId(), on.getParent().getNodeId());
       }
     }
 
     for (final OrgNode on : orgNodes) {
-      naturalTreesByOrgID.put(on.getTreeNode().getNode(), on.getNaturalTree());
+      naturalTreesByOrgID.put(on.getNodeId(), on.getNaturalTree());
       if (on.getChildren() != null) {
         Set<String> os = new HashSet<String>();
         for (OrgNode o : on.getChildren())
-          os.add(o.getTreeNode().getNode());
-        childByOrganizationID.put(on.getTreeNode().getNode(), os);
+          os.add(o.getNodeId());
+        childByOrganizationID.put(on.getNodeId(), os);
       }
     }
     isInitialized = true;
@@ -293,7 +294,8 @@
 
   class OrgNode {
 
-    private TreeNode treeNode;
+    private String nodeId;
+    private String parentNodeId;
     private OrgNode parent;
     private List<OrgNode> children = new ArrayList<OrgNode>();
 
@@ -306,11 +308,11 @@
     }
 
     public void resolve(List<OrgNode> nodes) {
-      if (treeNode.getReportSet() == null) {
+      if (parentNodeId == null) {
         return;
       }
       for (final OrgNode on : nodes) {
-        if (on.getTreeNode().getNode().equals(treeNode.getReportSet())) {
+        if (on.getNodeId().equals(parentNodeId)) {
           on.addChild(this);
           setParent(on);
           break;
@@ -321,7 +323,7 @@
     public Set<String> getNaturalTree() {
       if (naturalTree == null) {
         naturalTree = new HashSet<String>();
-        naturalTree.add(getTreeNode().getNode());
+        naturalTree.add(getNodeId());
         if (getParent() != null) {
           getParent().getParentPath(naturalTree);
         }
@@ -335,7 +337,7 @@
     public void getParentPath(Set<String> theNaturalTree) {
       if (naturalTreeParent == null) {
         naturalTreeParent = new HashSet<String>();
-        naturalTreeParent.add(getTreeNode().getNode());
+        naturalTreeParent.add(getNodeId());
         if (getParent() != null) {
           getParent().getParentPath(naturalTreeParent);
         }
@@ -346,7 +348,7 @@
     public void getChildPath(Set<String> theNaturalTree) {
       if (naturalTreeChildren == null) {
         naturalTreeChildren = new HashSet<String>();
-        naturalTreeChildren.add(getTreeNode().getNode());
+        naturalTreeChildren.add(getNodeId());
         for (final OrgNode child : getChildren()) {
           child.getChildPath(naturalTreeChildren);
         }
@@ -354,12 +356,17 @@
       theNaturalTree.addAll(naturalTreeChildren);
     }
 
-    public TreeNode getTreeNode() {
-      return treeNode;
+    public String getNodeId() {
+      return nodeId;
     }
 
-    public void setTreeNode(TreeNode treeNode) {
-      this.treeNode = treeNode;
+    public String getParentNodeId() {
+      return parentNodeId;
+    }
+
+    public void setTreeNodeData(String nodeId, String parentNodeId) {
+      this.nodeId = nodeId;
+      this.parentNodeId = parentNodeId;
     }
 
     public OrgNode getParent() {

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to