You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by nm...@apache.org on 2019/09/27 07:21:31 UTC

svn commit: r1867620 - in /ofbiz/ofbiz-framework/trunk/framework/widget: config/widget.properties src/main/java/org/apache/ofbiz/widget/model/ModelScreen.java

Author: nmalin
Date: Fri Sep 27 07:21:30 2019
New Revision: 1867620

URL: http://svn.apache.org/viewvc?rev=1867620&view=rev
Log:
Implemented: Add transaction timeout default properties for screen widget
(OFBIZ-11190)

Currently when you rendering a screen, the transaction timeout would be resolve from the context or use default value (60s)
I reviewed this code part to reorganize timeout resolution on dedicate function (transaction timeout on widget screen is pre-apache)
and introduce possibility to set a default value by properties on 'widget.property' with name 'widget.screen.transaction.defaultTimeout'.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/widget/config/widget.properties
    ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreen.java

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/config/widget.properties
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/config/widget.properties?rev=1867620&r1=1867619&r2=1867620&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/config/widget.properties (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/config/widget.properties Fri Sep 27 07:21:30 2019
@@ -49,3 +49,6 @@ widget.defaultNoConditionFind=N
 # When you don't displaying freemarker stacktrace, you can replace it by an other message
 # by default it use ∎ but you can set what you want, like 'ERROR', '##' or ' '
 #widget.freemarker.template.exception.message=
+
+#Default transaction timeout to rendering screen
+#widget.screen.transaction.defaultTimeout=60

Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreen.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreen.java?rev=1867620&r1=1867619&r2=1867620&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreen.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreen.java Fri Sep 27 07:21:30 2019
@@ -22,6 +22,7 @@ import java.util.Map;
 
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.UtilGenerics;
+import org.apache.ofbiz.base.util.UtilProperties;
 import org.apache.ofbiz.base.util.UtilValidate;
 import org.apache.ofbiz.base.util.UtilXml;
 import org.apache.ofbiz.base.util.string.FlexibleStringExpander;
@@ -120,44 +121,12 @@ public class ModelScreen extends ModelWi
         context.put("nullField", GenericEntity.NULL_FIELD);
 
         // wrap the whole screen rendering in a transaction, should improve performance in querying and such
-        Map<String, String> parameters = UtilGenerics.cast(context.get("parameters"));
         boolean beganTransaction = false;
-        int transactionTimeout = -1;
-        if (parameters != null) {
-            String transactionTimeoutPar = parameters.get("TRANSACTION_TIMEOUT");
-            if (transactionTimeoutPar != null) {
-                try {
-                    transactionTimeout = Integer.parseInt(transactionTimeoutPar);
-                } catch (NumberFormatException nfe) {
-                    String msg = "TRANSACTION_TIMEOUT parameter for screen [" + this.sourceLocation + "#" + getName() + "] is invalid and it will be ignored: " + nfe.toString();
-                    Debug.logWarning(msg, module);
-                }
-            }
-        }
-
-        if (transactionTimeout < 0 && !transactionTimeoutExdr.isEmpty()) {
-            // no TRANSACTION_TIMEOUT parameter, check screen attribute
-            String transactionTimeoutStr = transactionTimeoutExdr.expandString(context);
-            if (UtilValidate.isNotEmpty(transactionTimeoutStr)) {
-                try {
-                    transactionTimeout = Integer.parseInt(transactionTimeoutStr);
-                } catch (NumberFormatException e) {
-                    Debug.logWarning(e, "Could not parse transaction-timeout value, original=[" + transactionTimeoutExdr + "], expanded=[" + transactionTimeoutStr + "]", module);
-                }
-            }
-        }
 
         try {
-            // If transaction timeout is not present (i.e. is equal to -1), the default transaction timeout is used
-            // If transaction timeout is present, use it to start the transaction
-            // If transaction timeout is set to zero, no transaction is started
+            // Start a transaction if needed
             if (useTransaction) {
-                if (transactionTimeout < 0) {
-                    beganTransaction = TransactionUtil.begin();
-                }
-                if (transactionTimeout > 0) {
-                    beganTransaction = TransactionUtil.begin(transactionTimeout);
-                }
+                beganTransaction = TransactionUtil.begin(resolveTransactionTimeout(context));
             }
 
             // render the screen, starting with the top-level section
@@ -191,6 +160,45 @@ public class ModelScreen extends ModelWi
         Delegator delegator = (Delegator) context.get("delegator");
         return delegator;
     }
+
+    /**
+     * Resolve the transaction timeout used from a screen with the following step :
+     *  * scan parameters.TRANSACTION_TIMEOUT on the context
+     *  * expand transaction-timeout attribute on screen definition with the context
+     *  * use default value
+     *  if the transaction timeout found is <=0 use the default value
+     * @param context
+     * @return
+     */
+    private int resolveTransactionTimeout(Map<String, Object> context) {
+        Map<String, String> parameters = UtilGenerics.cast(context.get("parameters"));
+        int transactionTimeout = -1;
+        if (parameters != null) {
+            String transactionTimeoutPar = parameters.get("TRANSACTION_TIMEOUT");
+            if (transactionTimeoutPar != null) {
+                try {
+                    transactionTimeout = Integer.parseInt(transactionTimeoutPar);
+                } catch (NumberFormatException nfe) {
+                    String msg = "TRANSACTION_TIMEOUT parameter for screen [" + this.sourceLocation + "#" + getName() + "] is invalid and it will be ignored: " + nfe.toString();
+                    Debug.logWarning(msg, module);
+                }
+            }
+        }
+
+        // no TRANSACTION_TIMEOUT parameter, check screen attribute
+        if (transactionTimeout < 0 && !transactionTimeoutExdr.isEmpty()) {
+            String transactionTimeoutStr = transactionTimeoutExdr.expandString(context);
+            if (UtilValidate.isNotEmpty(transactionTimeoutStr)) {
+                try {
+                    transactionTimeout = Integer.parseInt(transactionTimeoutStr);
+                } catch (NumberFormatException e) {
+                    Debug.logWarning(e, "Could not parse transaction-timeout value, original=[" + transactionTimeoutExdr + "], expanded=[" + transactionTimeoutStr + "]", module);
+                }
+            }
+        }
+        return transactionTimeout > 0 ? transactionTimeout:
+                UtilProperties.getPropertyAsInteger("widget", "widget.screen.transaction.defaultTimeout", 60);
+    }
 }