You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2012/05/22 10:28:03 UTC
svn commit: r1341348 - in /ofbiz/trunk/framework/minilang:
dtd/simple-methods-v2.xsd
src/org/ofbiz/minilang/method/entityops/EntityOne.java
Author: adrianc
Date: Tue May 22 08:28:02 2012
New Revision: 1341348
URL: http://svn.apache.org/viewvc?rev=1341348&view=rev
Log:
Overhauled Mini-language <entity-one> element.
Modified:
ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityOne.java
Modified: ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd?rev=1341348&r1=1341347&r2=1341348&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd (original)
+++ ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd Tue May 22 08:28:02 2012
@@ -210,7 +210,7 @@ under the License.
<xs:attribute name="entity-name" type="xs:string" use="required">
<xs:annotation>
<xs:documentation>
- Name of entity to search in.
+ Name of the entity to search in.
<br/><br/>
Required. Attribute type: constant, ${expression}.
</xs:documentation>
@@ -2192,7 +2192,9 @@ under the License.
<xs:element name="entity-one" substitutionGroup="EntityFindOperations">
<xs:annotation>
<xs:documentation>
- Does a find-by-primarykey, always returns a single generic value object if it's found, otherwise returns null.
+ Returns a single entity value that is retrieved from the database by using the primary key.
+ The primary key can be specified in the field-map child elements, or if they are absent,
+ the primary key will be constructed from matching environment fields.
</xs:documentation>
</xs:annotation>
<xs:complexType>
@@ -2212,48 +2214,53 @@ under the License.
</xs:annotation>
</xs:element>
</xs:sequence>
- <xs:attributeGroup ref="attlist.entity-one"/>
+ <xs:attribute name="entity-name" type="xs:string" use="required">
+ <xs:annotation>
+ <xs:documentation>
+ Name of the entity to search in.
+ <br/><br/>
+ Required. Attribute type: constant, ${expression}.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="value-field" type="xs:string" use="required">
+ <xs:annotation>
+ <xs:documentation>
+ Name of the target field to put the entity value in.
+ <br/><br/>
+ Required. Attribute type: expression.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute type="xs:string" name="use-cache">
+ <xs:annotation>
+ <xs:documentation>
+ Specifies whether or not the delegator's cache should be searched before going to the database.
+ This results in much faster retrieval times, but can return stale data that is not the most current in the database.
+ Must be "true" or "false", defaults to "false".
+ <br/><br/>
+ Optional. Attribute type: constant, ${expression}.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="auto-field-map">
+ <xs:annotation>
+ <xs:documentation>
+ When "true", the operation looks for all primary key field names in the current context as well as in the parameters map.
+ Defaults to "true".
+ <br/><br/>
+ Optional. Attribute type: constant, ${expression}.
+ </xs:documentation>
+ </xs:annotation>
+ <xs:simpleType>
+ <xs:restriction base="xs:token">
+ <xs:enumeration value="true" />
+ <xs:enumeration value="false" />
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:attribute>
</xs:complexType>
</xs:element>
- <xs:attributeGroup name="attlist.entity-one">
- <xs:attribute name="entity-name" type="xs:string" use="required">
- <xs:annotation>
- <xs:documentation>
- Name of the entity to query on.
- </xs:documentation>
- </xs:annotation>
- </xs:attribute>
- <xs:attribute name="value-field" type="xs:string" use="required">
- <xs:annotation>
- <xs:documentation>
- Name of the variable to put result record in.
- </xs:documentation>
- </xs:annotation>
- </xs:attribute>
- <xs:attribute type="xs:string" name="use-cache" default="false">
- <xs:annotation>
- <xs:documentation>
- Specifies whether or not the delegator's cache should be searched before going to the database.
- This results in much faster retrieval times, but can return stale data that is not the most current in the database.
- Must be "true" or "false", defaults to "false".
- </xs:documentation>
- </xs:annotation>
- </xs:attribute>
- <xs:attribute name="auto-field-map" default="true">
- <xs:annotation>
- <xs:documentation>
- Looks for all primary key field names in the current context as well as in the parameters map or not.
- Defaults to true.
- </xs:documentation>
- </xs:annotation>
- <xs:simpleType>
- <xs:restriction base="xs:token">
- <xs:enumeration value="true"/>
- <xs:enumeration value="false"/>
- </xs:restriction>
- </xs:simpleType>
- </xs:attribute>
- </xs:attributeGroup>
<xs:element name="entity-and" substitutionGroup="EntityFindOperations">
<xs:annotation>
<xs:documentation>
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityOne.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityOne.java?rev=1341348&r1=1341347&r2=1341348&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityOne.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityOne.java Tue May 22 08:28:02 2012
@@ -21,25 +21,33 @@ package org.ofbiz.minilang.method.entity
import org.ofbiz.minilang.artifact.ArtifactInfoContext;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
+import org.ofbiz.base.util.string.FlexibleStringExpander;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.finder.PrimaryKeyFinder;
import org.ofbiz.minilang.MiniLangException;
+import org.ofbiz.minilang.MiniLangValidate;
import org.ofbiz.minilang.SimpleMethod;
import org.ofbiz.minilang.method.MethodContext;
import org.ofbiz.minilang.method.MethodOperation;
import org.w3c.dom.Element;
/**
- * Uses the delegator to find entity values by a primary key
+ * Implements the <entity-one> element.
*/
-public class EntityOne extends MethodOperation {
+public final class EntityOne extends MethodOperation {
public static final String module = EntityOne.class.getName();
- protected PrimaryKeyFinder finder;
+ private final PrimaryKeyFinder finder;
public EntityOne(Element element, SimpleMethod simpleMethod) throws MiniLangException {
super(element, simpleMethod);
+ if (MiniLangValidate.validationOn()) {
+ MiniLangValidate.attributeNames(simpleMethod, element, "entity-name", "use-cache", "auto-field-map", "value-field");
+ MiniLangValidate.requiredAttributes(simpleMethod, element, "entity-name", "value-field");
+ MiniLangValidate.expressionAttributes(simpleMethod, element, "value-field");
+ MiniLangValidate.childElements(simpleMethod, element, "field-map", "select-field");
+ }
this.finder = new PrimaryKeyFinder(element);
}
@@ -49,15 +57,9 @@ public class EntityOne extends MethodOpe
Delegator delegator = methodContext.getDelegator();
this.finder.runFind(methodContext.getEnvMap(), delegator);
} catch (GeneralException e) {
- Debug.logError(e, module);
- String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process: " + e.getMessage();
- if (methodContext.getMethodType() == MethodContext.EVENT) {
- methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg);
- methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode());
- } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
- methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg);
- methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode());
- }
+ String errMsg = "Exception thrown while performing entity find: " + e.getMessage();
+ Debug.logWarning(e, errMsg, module);
+ simpleMethod.addErrorMessage(methodContext, errMsg);
return false;
}
return true;
@@ -65,8 +67,7 @@ public class EntityOne extends MethodOpe
@Override
public String expandedString(MethodContext methodContext) {
- // TODO: something more than a stub/dummy
- return this.rawString();
+ return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap());
}
@Override
@@ -76,15 +77,26 @@ public class EntityOne extends MethodOpe
@Override
public String rawString() {
- // TODO: something more than the empty tag
- return "<entity-one/>";
+ return toString();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("<entity-one ");
+ sb.append("entity-name=\"").append(this.finder.getEntityName()).append("\" />");
+ return sb.toString();
}
+ /**
+ * A factory for the <entity-one> element.
+ */
public static final class EntityOneFactory implements Factory<EntityOne> {
+ @Override
public EntityOne createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
return new EntityOne(element, simpleMethod);
}
+ @Override
public String getName() {
return "entity-one";
}