Author: adrianc
Date: Mon Feb 18 01:03:58 2013
New Revision: 1447112
URL: http://svn.apache.org/r1447112
Log:
Small enhancements to Entity ECA classes: improve thread safety, eliminate null
checks on fields that are never null, add some accessor methods, small code
cleanups.
Modified:
ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaAction.java
ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaCondition.java
ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaSetField.java
Modified:
ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaAction.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaAction.java?rev=1447112&r1=1447111&r2=1447112&view=diff
==============================================================================
---
ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaAction.java
(original)
+++
ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaAction.java
Mon Feb 18 01:03:58 2013
@@ -22,7 +22,6 @@ import java.util.Map;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilMisc;
-import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.GenericEntity;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
@@ -38,19 +37,17 @@ import org.w3c.dom.Element;
* EntityEcaAction
*/
@SuppressWarnings("serial")
-public class EntityEcaAction implements java.io.Serializable {
+public final class EntityEcaAction implements java.io.Serializable {
public static final String module = EntityEcaAction.class.getName();
- protected String serviceName = null;
- protected String serviceMode = null;
- protected String runAsUser = null;
- protected String valueAttr = null;
- protected boolean resultToValue = true;
- protected boolean abortOnError = false;
- protected boolean rollbackOnError = false;
- protected boolean persist = false;
-
- protected EntityEcaAction() {}
+ private final String serviceName;
+ private final String serviceMode;
+ private final String runAsUser;
+ private final String valueAttr;
+ private final boolean resultToValue;
+ private final boolean abortOnError;
+ private final boolean rollbackOnError;
+ private final boolean persist;
public EntityEcaAction(Element action) {
this.serviceName = action.getAttribute("service");
@@ -65,14 +62,16 @@ public class EntityEcaAction implements
this.valueAttr = action.getAttribute("value-attr");
}
- public void runAction(DispatchContext dctx, Map<String, ? extends Object>
context, GenericEntity newValue) throws GenericEntityException {
- Map<String, Object> actionResult = null;
+ public String getServiceName() {
+ return this.serviceName;
+ }
+ public void runAction(DispatchContext dctx, Map<String, ? extends Object>
context, GenericEntity newValue) throws GenericEntityException {
try {
// pull out context parameters needed for this service.
Map<String, Object> actionContext =
dctx.getModelService(serviceName).makeValid(context, ModelService.IN_PARAM);
// if value-attr is specified, insert the value object in that
attr name
- if (UtilValidate.isNotEmpty(valueAttr)) {
+ if (!valueAttr.isEmpty()) {
actionContext.put(valueAttr, newValue);
}
@@ -81,7 +80,7 @@ public class EntityEcaAction implements
// setup the run-as-user
GenericValue userLoginToRunAs = null;
- if (UtilValidate.isNotEmpty(this.runAsUser)) {
+ if (!this.runAsUser.isEmpty()) {
userLoginToRunAs = dctx.getDelegator().findOne("UserLogin",
UtilMisc.toMap("userLoginId", this.runAsUser), true);
if (userLoginToRunAs != null) {
actionContext.put("userLogin", userLoginToRunAs);
@@ -90,10 +89,14 @@ public class EntityEcaAction implements
LocalDispatcher dispatcher = dctx.getDispatcher();
if ("sync".equals(this.serviceMode)) {
- actionResult = dispatcher.runSync(this.serviceName,
actionContext);
+ Map<String, Object> actionResult =
dispatcher.runSync(this.serviceName, actionContext);
if (ServiceUtil.isError(actionResult)) {
throw new GenericServiceException("Error running Entity
ECA action service: " + ServiceUtil.getErrorMessage(actionResult));
}
+ // use the result to update the context fields.
+ if (resultToValue) {
+ newValue.setNonPKFields(actionResult);
+ }
} else if ("async".equals(this.serviceMode)) {
dispatcher.runAsync(serviceName, actionContext, persist);
}
@@ -111,10 +114,5 @@ public class EntityEcaAction implements
Debug.logError(e, "Error running Entity ECA action service",
module);
}
}
-
- // use the result to update the context fields.
- if (resultToValue) {
- newValue.setNonPKFields(actionResult);
- }
}
}
Modified:
ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaCondition.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaCondition.java?rev=1447112&r1=1447111&r2=1447112&view=diff
==============================================================================
---
ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaCondition.java
(original)
+++
ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaCondition.java
Mon Feb 18 01:03:58 2013
@@ -33,36 +33,27 @@ import org.w3c.dom.Element;
* EntityEcaCondition
*/
@SuppressWarnings("serial")
-public class EntityEcaCondition implements java.io.Serializable {
+public final class EntityEcaCondition implements java.io.Serializable {
public static final String module = EntityEcaCondition.class.getName();
- protected String lhsValueName, rhsValueName;
- protected String operator;
- protected String compareType;
- protected String format;
- protected boolean constant = false;
-
- protected EntityEcaCondition() {}
+ private final String lhsValueName, rhsValueName;
+ private final String operator;
+ private final String compareType;
+ private final String format;
+ private final boolean constant;
public EntityEcaCondition(Element condition, boolean constant) {
this.lhsValueName = condition.getAttribute("field-name");
-
this.constant = constant;
if (constant) {
this.rhsValueName = condition.getAttribute("value");
} else {
this.rhsValueName = condition.getAttribute("to-field-name");
}
-
this.operator = condition.getAttribute("operator");
this.compareType = condition.getAttribute("type");
this.format = condition.getAttribute("format");
-
- if (lhsValueName == null)
- lhsValueName = "";
- if (rhsValueName == null)
- rhsValueName = "";
}
public boolean eval(DispatchContext dctx, GenericEntity value) throws
GenericEntityException {
@@ -100,6 +91,21 @@ public class EntityEcaCondition implemen
}
}
+ public String getLValue() {
+ return this.lhsValueName;
+ }
+
+ public String getRValue() {
+ if (constant) {
+ return "\"".concat(this.rhsValueName).concat("\"");
+ }
+ return this.rhsValueName;
+ }
+
+ public String getOperator() {
+ return this.operator;
+ }
+
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
Modified:
ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaSetField.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaSetField.java?rev=1447112&r1=1447111&r2=1447112&view=diff
==============================================================================
---
ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaSetField.java
(original)
+++
ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/EntityEcaSetField.java
Mon Feb 18 01:03:58 2013
@@ -104,4 +104,15 @@ public final class EntityEcaSetField {
Debug.logWarning("Format function not found [" + format + "] return
string unchanged - " + s, module);
return s;
}
+
+ public String getFieldName() {
+ return this.fieldName;
+ }
+
+ public String getRValue() {
+ if (!this.value.isEmpty()) {
+ return "\"".concat(this.value).concat("\"");
+ }
+ return this.envName;
+ }
}