You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2013/06/28 21:08:39 UTC
svn commit: r1497893 -
/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java
Author: doogie
Date: Fri Jun 28 19:08:39 2013
New Revision: 1497893
URL: http://svn.apache.org/r1497893
Log:
FEATURE: Allow constant numbers to be directly added to a query, instead
of having to deal with some kind of map/generic value. This makes it
simpler to use full-text-search queries thru the entity
engine(postgresql and oracle).
Modified:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java?rev=1497893&r1=1497892&r2=1497893&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java Fri Jun 28 19:08:39 2013
@@ -22,6 +22,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import javolution.context.ObjectFactory;
+import javolution.lang.Reusable;
+
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericEntity;
import org.ofbiz.entity.GenericModelException;
@@ -36,6 +39,65 @@ import org.ofbiz.entity.model.ModelField
@SuppressWarnings("serial")
public abstract class EntityConditionValue extends EntityConditionBase {
+ public static EntityConditionValue CONSTANT_NUMBER(Number value) { return ConstantNumberValue.createConstantNumberValue(value); }
+ public static class ConstantNumberValue extends EntityConditionValue implements Reusable {
+ protected static ConstantNumberValue createConstantNumberValue(Number value) {
+ ConstantNumberValue cnv = factory.object();
+ cnv.init(value);
+ return cnv;
+ }
+ protected static final ObjectFactory<ConstantNumberValue> factory = new ObjectFactory<ConstantNumberValue>() {
+ protected ConstantNumberValue create() {
+ return new ConstantNumberValue();
+ }
+ };
+
+ private Number value;
+
+ protected void init(Number value) {
+ this.value = value;
+ }
+
+ @Override
+ public void accept(EntityConditionVisitor visitor) {
+ visitor.acceptEntityConditionValue(this);
+ }
+
+ @Override
+ public void addSqlValue(StringBuilder sql, Map<String, String> tableAliases, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, boolean includeTableNamePrefix, Datasource datasourceinfo) {
+ sql.append(value);
+ }
+
+ @Override
+ public EntityConditionValue freeze() {
+ return this;
+ }
+
+ @Override
+ public ModelField getModelField(ModelEntity modelEntity) {
+ return null;
+ }
+
+ @Override
+ public Object getValue(Delegator delegator, Map<String, ? extends Object> map) {
+ return value;
+ }
+
+ @Override
+ public void reset() {
+ this.value = value;
+ }
+
+ @Override
+ public void validateSql(org.ofbiz.entity.model.ModelEntity modelEntity) {
+ }
+
+ @Override
+ public void visit(EntityConditionVisitor visitor) {
+ visitor.acceptObject(value);
+ }
+ }
+
public abstract ModelField getModelField(ModelEntity modelEntity);
public void addSqlValue(StringBuilder sql, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, boolean includeTableNamePrefix,