Author: doogie
Date: Tue Jun 24 00:23:46 2014 New Revision: 1604972 URL: http://svn.apache.org/r1604972 Log: Add EntityConditionValue.encryptConditionFields support to EntityConditionValue. Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java?rev=1604972&r1=1604971&r2=1604972&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java Tue Jun 24 00:23:46 2014 @@ -108,7 +108,7 @@ public abstract class EntityCondition ex @Override public String toString() { - return makeWhereString(null, new ArrayList<EntityConditionParam>(), null); + return makeWhereString(null, null, null); } public void accept(EntityConditionVisitor visitor) { Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java?rev=1604972&r1=1604971&r2=1604972&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java Tue Jun 24 00:23:46 2014 @@ -117,6 +117,11 @@ public class EntityConditionSubSelect ex return new EntityConditionSubSelect(localModelEntity, keyFieldName, (whereCond != null ? whereCond.freeze() : null), requireAll); } + @Override + public void encryptConditionFields(ModelEntity modelEntity, Delegator delegator) { + whereCond.encryptConditionFields(modelEntity, delegator); + } + public String getKeyFieldName() { return this.keyFieldName; } 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=1604972&r1=1604971&r2=1604972&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 Tue Jun 24 00:23:46 2014 @@ -60,6 +60,10 @@ public abstract class EntityConditionVal } @Override + public void encryptConditionFields(ModelEntity modelEntity, Delegator delegator) { + } + + @Override public ModelField getModelField(ModelEntity modelEntity) { return null; } @@ -102,6 +106,8 @@ public abstract class EntityConditionVal public abstract EntityConditionValue freeze(); + public abstract void encryptConditionFields(ModelEntity modelEntity, Delegator delegator); + public abstract void visit(EntityConditionVisitor visitor); public void accept(EntityConditionVisitor visitor) { @@ -109,7 +115,7 @@ public abstract class EntityConditionVal } public void toString(StringBuilder sb) { - addSqlValue(sb, null, new ArrayList<EntityConditionParam>(), false, null); + addSqlValue(sb, null, null, false, null); } @Override Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java?rev=1604972&r1=1604971&r2=1604972&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java Tue Jun 24 00:23:46 2014 @@ -160,6 +160,7 @@ public class EntityExpr extends EntityCo return; } if (rhs instanceof EntityConditionValue) { + ((EntityConditionValue) rhs).encryptConditionFields(modelEntity, delegator); return; } ModelField modelField; Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java?rev=1604972&r1=1604971&r2=1604972&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java Tue Jun 24 00:23:46 2014 @@ -194,4 +194,8 @@ public class EntityFieldValue extends En public EntityConditionValue freeze() { return this; } + + @Override + public void encryptConditionFields(ModelEntity modelEntity, Delegator delegator) { + } } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java?rev=1604972&r1=1604971&r2=1604972&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java Tue Jun 24 00:23:46 2014 @@ -63,7 +63,7 @@ public abstract class EntityFunction<T e * Length() entity function. * */ - public static class LENGTH extends EntityFunction<Integer> { + public static class LENGTH extends EntityFunctionSingle<Integer> { public static Fetcher<Integer> FETCHER = new Fetcher<Integer>() { public Integer getValue(Object value) { return value.toString().length(); } }; @@ -77,7 +77,7 @@ public abstract class EntityFunction<T e * Trim() entity function. * */ - public static class TRIM extends EntityFunction<String> { + public static class TRIM extends EntityFunctionSingle<String> { public static Fetcher<String> FETCHER = new Fetcher<String>() { public String getValue(Object value) { return value.toString().trim(); } }; @@ -91,7 +91,7 @@ public abstract class EntityFunction<T e * Upper() entity function. * */ - public static class UPPER extends EntityFunction<String> { + public static class UPPER extends EntityFunctionSingle<String> { public static Fetcher<String> FETCHER = new Fetcher<String>() { public String getValue(Object value) { return value.toString().toUpperCase(); } }; @@ -105,7 +105,7 @@ public abstract class EntityFunction<T e * Lower() entity function. * */ - public static class LOWER extends EntityFunction<String> { + public static class LOWER extends EntityFunctionSingle<String> { public static Fetcher<String> FETCHER = new Fetcher<String>() { public String getValue(Object value) { return value.toString().toLowerCase(); } }; @@ -115,6 +115,24 @@ public abstract class EntityFunction<T e } } + public static abstract class EntityFunctionSingle<T extends Comparable<?>> extends EntityFunction<T> { + protected EntityFunctionSingle(Fetcher<T> fetcher, SQLFunction function, Object value) { + super(fetcher, function, value); + } + + public void encryptConditionFields(ModelEntity modelEntity, Delegator delegator) { + } + } + + public static abstract class EntityFunctionNested<T extends Comparable<?>> extends EntityFunction<T> { + protected EntityFunctionNested(Fetcher<T> fetcher, SQLFunction function, EntityConditionValue nested) { + super(fetcher, function, nested); + } + + public void encryptConditionFields(ModelEntity modelEntity, Delegator delegator) { + } + } + protected final SQLFunction function; protected final EntityConditionValue nested; protected final Object value; @@ -142,9 +160,9 @@ public abstract class EntityFunction<T e @Override public EntityConditionValue freeze() { if (nested != null) { - return new EntityFunction<T>(fetcher, function, nested.freeze()) {}; + return new EntityFunctionNested<T>(fetcher, function, nested.freeze()) {}; } else { - return new EntityFunction<T>(fetcher, function, value) {}; + return new EntityFunctionSingle<T>(fetcher, function, value) {}; } } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java?rev=1604972&r1=1604971&r2=1604972&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java Tue Jun 24 00:23:46 2014 @@ -18,9 +18,12 @@ *******************************************************************************/ package org.ofbiz.entity.test; +import java.util.List; + import org.ofbiz.base.util.UtilMisc; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; +import org.ofbiz.entity.condition.EntityConditionSubSelect; import org.ofbiz.entity.condition.EntityOperator; import org.ofbiz.entity.testtools.EntityTestCase; @@ -108,4 +111,51 @@ public class EntityCryptoTestSuite exten ); assertEquals(1, delegator.findList("TestingCrypto", condition, null, null, null, false).size()); } + + protected EntityCondition makeSubSelectCondition(String nanoTime) { + return EntityCondition.makeCondition( + EntityCondition.makeCondition("testingCryptoTypeId", EntityOperator.IN, UtilMisc.toList("SUB_SELECT_1", "SUB_SELECT_3")), + EntityOperator.AND, + EntityCondition.makeCondition("encryptedValue", EntityOperator.EQUALS, nanoTime) + ); + } + + protected EntityConditionSubSelect makeSubSelect(String nanoTime) { + EntityCondition subCondition = makeSubSelectCondition(nanoTime); + return new EntityConditionSubSelect("TestingCrypto", "testingCryptoId", subCondition, true, delegator); + } + + public void testCryptoSubSelect() throws Exception { + String nanoTime = "" + System.nanoTime(); + EntityCondition condition; + List<GenericValue> results; + + delegator.removeByAnd("TestingCrypto", UtilMisc.toMap("testingCryptoTypeId", "SUB_SELECT_1")); + delegator.removeByAnd("TestingCrypto", UtilMisc.toMap("testingCryptoTypeId", "SUB_SELECT_2")); + delegator.removeByAnd("TestingCrypto", UtilMisc.toMap("testingCryptoTypeId", "SUB_SELECT_3")); + + delegator.create("TestingCrypto", UtilMisc.toMap("testingCryptoId", "SUB_1", "testingCryptoTypeId", "SUB_SELECT_1", "encryptedValue", nanoTime)); + delegator.create("TestingCrypto", UtilMisc.toMap("testingCryptoId", "SUB_2", "testingCryptoTypeId", "SUB_SELECT_2", "encryptedValue", nanoTime)); + delegator.create("TestingCrypto", UtilMisc.toMap("testingCryptoId", "SUB_3", "testingCryptoTypeId", "SUB_SELECT_3", "encryptedValue", "constant")); + + results = delegator.findList("TestingCrypto", EntityCondition.makeCondition("encryptedValue", EntityOperator.EQUALS, nanoTime), null, UtilMisc.toList("testingCryptoId"), null, false); + assertEquals(2, results.size()); + assertEquals("SUB_1", results.get(0).get("testingCryptoId")); + assertEquals("SUB_2", results.get(1).get("testingCryptoId")); + + results = delegator.findList("TestingCrypto", EntityCondition.makeCondition("testingCryptoTypeId", EntityOperator.IN, UtilMisc.toList("SUB_SELECT_1", "SUB_SELECT_3")), null, UtilMisc.toList("testingCryptoId"), null, false); + assertEquals(2, results.size()); + assertEquals("SUB_1", results.get(0).get("testingCryptoId")); + assertEquals("SUB_3", results.get(1).get("testingCryptoId")); + + condition = makeSubSelectCondition(nanoTime); + results = delegator.findList("TestingCrypto", condition, null, UtilMisc.toList("testingCryptoId"), null, false); + assertEquals(1, results.size()); + assertEquals("SUB_1", results.get(0).get("testingCryptoId")); + + condition = EntityCondition.makeCondition("testingCryptoId", EntityOperator.EQUALS, makeSubSelect(nanoTime)); + results = delegator.findList("TestingCrypto", condition, null, UtilMisc.toList("testingCryptoId"), null, false); + assertEquals(1, results.size()); + assertEquals("SUB_1", results.get(0).get("testingCryptoId")); + } } |
Free forum by Nabble | Edit this page |