details:   /erp/devel/pi/rev/f7dbd40fe737
changeset: 12355:f7dbd40fe737
user:      Antonio Moreno <antonio.moreno <at> openbravo.com>
date:      Mon May 23 16:22:55 2011 +0200
summary:   Add missing class to previous commit

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/ApplicationDictionaryCachedStructures.java
 |  198 ++++++++++
 1 files changed, 198 insertions(+), 0 deletions(-)

diffs (202 lines):

diff -r ebb0601149a4 -r f7dbd40fe737 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/ApplicationDictionaryCachedStructures.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/ApplicationDictionaryCachedStructures.java
   Mon May 23 16:22:55 2011 +0200
@@ -0,0 +1,198 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2011 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.client.application.window;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.context.SessionScoped;
+
+import org.hibernate.Hibernate;
+import org.hibernate.Query;
+import org.openbravo.base.exception.OBException;
+import org.openbravo.base.model.Property;
+import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.base.structure.BaseOBObject;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.erpCommon.utility.ComboTableData;
+import org.openbravo.model.ad.datamodel.Column;
+import org.openbravo.model.ad.datamodel.Table;
+import org.openbravo.model.ad.domain.ModelImplementation;
+import org.openbravo.model.ad.domain.Reference;
+import org.openbravo.model.ad.domain.ReferencedTable;
+import org.openbravo.model.ad.ui.AuxiliaryInput;
+import org.openbravo.model.ad.ui.Field;
+import org.openbravo.model.ad.ui.Tab;
+import org.openbravo.service.db.DalConnectionProvider;
+import org.openbravo.userinterface.selector.Selector;
+import org.openbravo.userinterface.selector.SelectorField;
+
+/**
+ * This class caches some AD structures used by the Form Initialization 
component. Basically, it
+ * caches: AD components (fields, columns, auxiliary inputs) and 
ComboTableData instances. This
+ * caching occurs to obtain better performance in FIC computations. For this 
cache to be used, the
+ * system needs to be on 'production' mode, that is, all the modules need to 
be not in development
+ */
+@SessionScoped
+public class ApplicationDictionaryCachedStructures implements Serializable {
+  private static final long serialVersionUID = 1L;
+
+  private Map<String, List<Field>> fieldMap = new HashMap<String, 
List<Field>>();
+  private Map<String, List<Column>> columnMap = new HashMap<String, 
List<Column>>();
+  private Map<String, List<AuxiliaryInput>> auxInputMap = new HashMap<String, 
List<AuxiliaryInput>>();
+  private Map<String, ComboTableData> comboTableDataMap = new HashMap<String, 
ComboTableData>();
+  private List<Object> initializedObjs = new ArrayList<Object>();
+
+  private boolean useCache;
+
+  public ApplicationDictionaryCachedStructures() {
+    // The cache will only be active when there are no modules in development 
in the system
+    final String query = "select m from ADModule m where m.inDevelopment=true";
+    final Query indevelMods = 
OBDal.getInstance().getSession().createQuery(query);
+    useCache = indevelMods.list().size() == 0;
+  }
+
+  public List<Field> getFieldsOfTab(String tabId) {
+    if (useCache() && fieldMap.containsKey(tabId)) {
+      return fieldMap.get(tabId);
+    }
+    Tab tab = OBDal.getInstance().get(Tab.class, tabId);
+    List<Field> fields = tab.getADFieldList();
+    for (Field f : fields) {
+      Hibernate.initialize(f.getColumn());
+      initializeColumn(f.getColumn());
+    }
+    fieldMap.put(tabId, fields);
+    return fields;
+  }
+
+  public List<Column> getColumnsOfTable(String tableId) {
+    if (useCache() && columnMap.get(tableId) != null) {
+      return columnMap.get(tableId);
+    }
+    Table table = OBDal.getInstance().get(Table.class, tableId);
+    List<Column> columns = table.getADColumnList();
+    for (Column c : columns) {
+      initializeColumn(c);
+    }
+    columnMap.put(tableId, columns);
+    return columns;
+  }
+
+  private void initializeColumn(Column c) {
+
+    Hibernate.initialize(c.getValidation());
+    if (c.getValidation() != null) {
+      Hibernate.initialize(c.getValidation().getValidationCode());
+    }
+    if (c.getCallout() != null) {
+      Hibernate.initialize(c.getCallout());
+      Hibernate.initialize(c.getCallout().getADModelImplementationList());
+      for (ModelImplementation imp : 
c.getCallout().getADModelImplementationList()) {
+        Hibernate.initialize(imp);
+      }
+    }
+
+    if (c.getReference() != null) {
+      Hibernate.initialize(c.getReference());
+      initializeReference(c.getReference());
+    }
+    if (c.getReferenceSearchKey() != null) {
+      initializeReference(c.getReferenceSearchKey());
+    }
+  }
+
+  private void initializeReference(Reference reference) {
+    for (ReferencedTable t : reference.getADReferencedTableList()) {
+      Hibernate.initialize(t);
+    }
+    for (Selector s : reference.getOBUISELSelectorList()) {
+      Hibernate.initialize(s);
+      SelectorField displayField = s.getDisplayfield();
+      Hibernate.initialize(displayField);
+    }
+
+  }
+
+  public List<AuxiliaryInput> getAuxiliarInputList(String tabId) {
+    if (useCache() && auxInputMap.get(tabId) != null) {
+      return auxInputMap.get(tabId);
+    }
+    Tab tab = OBDal.getInstance().get(Tab.class, tabId);
+    List<AuxiliaryInput> auxInputs = tab.getADAuxiliaryInputList();
+    auxInputMap.put(tabId, auxInputs);
+    return auxInputs;
+  }
+
+  private void fullyInitializeList(Collection<?> listOfObjs) {
+    if (initializedObjs.contains(listOfObjs)) {
+      return;
+    }
+    for (Object obj : listOfObjs) {
+      fullyInitializeEntity((BaseOBObject) obj);
+    }
+  }
+
+  private void fullyInitializeEntity(BaseOBObject obj) {
+    if (initializedObjs.contains(obj)) {
+      return;
+    }
+    initializedObjs.add(obj);
+    for (Property p : obj.getEntity().getProperties()) {
+      final Object value = obj.get(p.getName());
+      if (value instanceof BaseOBObject || value instanceof Collection<?>) {
+        Hibernate.initialize(value);
+        if (value instanceof BaseOBObject && 
!initializedObjs.contains((BaseOBObject) value)) {
+          fullyInitializeEntity((BaseOBObject) value);
+        } else if (value instanceof Collection<?>) {
+          fullyInitializeList((Collection<?>) value);
+          initializedObjs.add(value);
+        }
+      }
+    }
+  }
+
+  public ComboTableData getComboTableData(VariablesSecureApp vars, String ref, 
String colName,
+      String objectReference, String validation, String orgList, String 
clientList) {
+    String comboId = ref + colName + objectReference + validation + orgList + 
clientList;
+    if (useCache() && comboTableDataMap.get(comboId) != null) {
+      return comboTableDataMap.get(comboId);
+    }
+    ComboTableData comboTableData;
+    try {
+      comboTableData = new ComboTableData(vars, new 
DalConnectionProvider(false), ref, colName,
+          objectReference, validation, orgList, clientList, 0);
+    } catch (Exception e) {
+      throw new OBException("Error while computing combo table data for column 
" + colName, e);
+    }
+    if (comboTableData.canBeCached()) {
+      comboTableDataMap.put(comboId, comboTableData);
+    }
+    return comboTableData;
+
+  }
+
+  private boolean useCache() {
+    return useCache;
+  }
+}

------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its 
next-generation tools to help Windows* and Linux* C/C++ and Fortran 
developers boost performance applications - including clusters. 
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to