details: https://code.openbravo.com/erp/devel/pi/rev/01860dfaa385 changeset: 35357:01860dfaa385 user: Carlos Aristu <carlos.aristu <at> openbravo.com> date: Thu Jan 24 10:05:04 2019 +0100 summary: fixes issue 40009: Concurrency problems in MyOpenbravoActionHandler
As part of the changes done to decrease the time spent to load the widgets after login, the WidgetProviders are cached[1]. This kind of classes had a private field named widgetClass (a DAL object) which could cause errors when accessing to some of its properties in a concurrent way. To fix this issue we are now keeping in cache the properties of the WidgetClass instead of keeping the reference to the DAL object. [1] https://code.openbravo.com/erp/devel/pi/rev/2a1a09ee6e6852cb977efa1a987e27d2811e9127#l1.178 diffstat: modules/org.openbravo.client.myob/src/org/openbravo/client/myob/WidgetProvider.java | 63 +++++---- 1 files changed, 34 insertions(+), 29 deletions(-) diffs (138 lines): diff -r 31cca65027c8 -r 01860dfaa385 modules/org.openbravo.client.myob/src/org/openbravo/client/myob/WidgetProvider.java --- a/modules/org.openbravo.client.myob/src/org/openbravo/client/myob/WidgetProvider.java Wed Jan 23 13:48:18 2019 +0100 +++ b/modules/org.openbravo.client.myob/src/org/openbravo/client/myob/WidgetProvider.java Thu Jan 24 10:05:04 2019 +0100 @@ -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) 2010-2018 Openbravo SLU + * All portions are Copyright (C) 2010-2019 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -27,8 +27,6 @@ import java.util.Map; import java.util.Set; -import javax.inject.Inject; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.codehaus.jettison.json.JSONException; @@ -110,30 +108,30 @@ private Map<String, Object> parameters = new HashMap<String, Object>(); - // note is only set if the widgetprovider is created - // through the MyOBUtils class. - private WidgetClass widgetClass; - - @Inject - private MyOBUtils myOBUtils; + // note this is only set if the widgetprovider is created through the MyOBUtils class + private JSONObject widgetClassDefinition; // prevent anyone else from creating a widgetprovider directly protected WidgetProvider() { } public JSONObject getWidgetClassDefinition() { + return widgetClassDefinition; + } + + private void setWidgetClassDefinition(WidgetClass widgetClass) { try { - final JSONObject jsonObject = new JSONObject(); - jsonObject.put(MyOpenbravoWidgetComponent.CLASSNAMEPARAMETER, - this.getClientSideWidgetClassName()); - jsonObject.put(WIDGETCLASSID, widgetClass.getId()); - jsonObject.put(TITLE, MyOBUtils.getWidgetTitle(widgetClass)); - jsonObject.put(HEIGHT, widgetClass.getHeight() + WIDGET_HEADER_HEIGHT); - jsonObject.put(MENU_ITEMS, MyOBUtils.getWidgetMenuItems(widgetClass)); + widgetClassDefinition = new JSONObject(); + widgetClassDefinition.put(WIDGETCLASSID, widgetClass.getId()); + widgetClassDefinition.put(MyOpenbravoWidgetComponent.CLASSNAMEPARAMETER, + getClientSideWidgetClassName()); + widgetClassDefinition.put(TITLE, MyOBUtils.getWidgetTitle(widgetClass)); + widgetClassDefinition.put(HEIGHT, widgetClass.getHeight() + WIDGET_HEADER_HEIGHT); + widgetClassDefinition.put(MENU_ITEMS, MyOBUtils.getWidgetMenuItems(widgetClass)); if (widgetClass.getWidgetSuperclass() != null) { - jsonObject.put(CAN_MAXIMIZE, widgetClass.getWidgetSuperclass().isCanMaximize()); + widgetClassDefinition.put(CAN_MAXIMIZE, widgetClass.getWidgetSuperclass().isCanMaximize()); } else { - jsonObject.put(CAN_MAXIMIZE, widgetClass.isCanMaximize()); + widgetClassDefinition.put(CAN_MAXIMIZE, widgetClass.isCanMaximize()); } final JSONObject aboutFieldDefinitions = new JSONObject(); @@ -231,10 +229,9 @@ fieldDefinition.put(PARAMETERTITLE, getParameterLabel(parameter)); fieldDefinitions.add(fieldDefinition); } - jsonObject.put(PARAMETERS, defaultParameters); - jsonObject.put(FIELDDEFINITIONS, fieldDefinitions); - jsonObject.put(ABOUTFIELDDEFINITIONS, aboutFieldDefinitions); - return jsonObject; + widgetClassDefinition.put(PARAMETERS, defaultParameters); + widgetClassDefinition.put(FIELDDEFINITIONS, fieldDefinitions); + widgetClassDefinition.put(ABOUTFIELDDEFINITIONS, aboutFieldDefinitions); } catch (Exception e) { throw new OBException(e); } @@ -243,13 +240,12 @@ protected void addDefaultWidgetProperties(JSONObject jsonObject, WidgetInstance widgetInstance) throws JSONException { jsonObject.put(WIDGETCLASSID, widgetInstance.getWidgetClass().getId()); - jsonObject.put(MyOpenbravoWidgetComponent.CLASSNAMEPARAMETER, - myOBUtils.getWidgetProvider(widgetClass).getClientSideWidgetClassName()); + jsonObject.put(MyOpenbravoWidgetComponent.CLASSNAMEPARAMETER, getClientSideWidgetClassName()); jsonObject.put(DBINSTANCEID, widgetInstance.getId()); jsonObject.put(TITLE, MyOBUtils.getWidgetTitle(widgetInstance)); jsonObject.put(COLNUM, widgetInstance.getColumnPosition()); jsonObject.put(ROWNUM, widgetInstance.getSequenceInColumn()); - jsonObject.put(HEIGHT, widgetClass.getHeight() + WIDGET_HEADER_HEIGHT); + jsonObject.put(HEIGHT, widgetClassDefinition.get(HEIGHT)); jsonObject.put(PRIORITY, widgetInstance.getRelativePriority()); final JSONObject widgetParameters = new JSONObject(); @@ -272,7 +268,7 @@ } public String getClientSideWidgetClassName() { - return KernelConstants.ID_PREFIX + getWidgetClass().getId(); + return KernelConstants.ID_PREFIX + getWidgetClassId(); } /** @@ -280,7 +276,7 @@ * */ public String generate() { - return "isc.defineClass('" + KernelConstants.ID_PREFIX + getWidgetClass().getId() + return "isc.defineClass('" + KernelConstants.ID_PREFIX + getWidgetClassId() + "', isc.OBShowParameterWidget);"; } @@ -445,11 +441,20 @@ } public WidgetClass getWidgetClass() { - return widgetClass; + return OBDal.getInstance().get(WidgetClass.class, getWidgetClassId()); + } + + private String getWidgetClassId() { + String widgetClassId = null; + try { + widgetClassId = widgetClassDefinition.getString(WIDGETCLASSID); + } catch (JSONException ignore) { + } + return widgetClassId; } public void setWidgetClass(WidgetClass widgetClass) { - this.widgetClass = widgetClass; + setWidgetClassDefinition(widgetClass); } private boolean getBooleanValueFromString(String value) { _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits