Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java Wed Dec 17 12:13:46 2014 @@ -64,6 +64,7 @@ import org.ofbiz.entity.transaction.Gene import org.ofbiz.entity.transaction.TransactionUtil; import org.ofbiz.entity.util.EntityFindOptions; import org.ofbiz.entity.util.EntityListIterator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntitySaxReader; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.entity.util.SequenceUtil; @@ -119,8 +120,11 @@ public class EntityTestSuite extends Ent delegator.storeAll(newValues); // finds a List of newly created values. the second parameter specifies the fields to order results by. - EntityCondition condition = EntityCondition.makeCondition("testingTypeId", EntityOperator.LIKE, "TEST-MAKE-%"); - List<GenericValue> newlyCreatedValues = delegator.findList("TestingType", condition, null, UtilMisc.toList("testingTypeId"), null, false); + List<GenericValue> newlyCreatedValues = EntityQuery.use(delegator) + .from("TestingType") + .where(EntityCondition.makeCondition("testingTypeId", EntityOperator.LIKE, "TEST-MAKE-%")) + .orderBy("testingTypeId") + .queryList(); assertEquals("4 TestingTypes(for make) found", 4, newlyCreatedValues.size()); } @@ -130,10 +134,10 @@ public class EntityTestSuite extends Ent public void testUpdateValue() throws Exception { // retrieve a sample GenericValue, make sure it's correct delegator.removeByCondition("TestingType", EntityCondition.makeCondition("testingTypeId", EntityOperator.LIKE, "TEST-UPDATE-%")); - GenericValue testValue = delegator.findOne("TestingType", false, "testingTypeId", "TEST-UPDATE-1"); + GenericValue testValue = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "TEST-UPDATE-1").queryOne(); assertNull("No pre-existing type value", testValue); delegator.create("TestingType", "testingTypeId", "TEST-UPDATE-1", "description", "Testing Type #Update-1"); - testValue = delegator.findOne("TestingType", false, "testingTypeId", "TEST-UPDATE-1"); + testValue = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "TEST-UPDATE-1").queryOne(); assertEquals("Retrieved value has the correct description", "Testing Type #Update-1", testValue.getString("description")); // Test Observable aspect assertFalse("Observable has not changed", testValue.hasChanged()); @@ -151,17 +155,17 @@ public class EntityTestSuite extends Ent testValue.store(); assertFalse("Observable has not changed", testValue.hasChanged()); // now retrieve it again and make sure that the updated value is correct - testValue = delegator.findOne("TestingType", false, "testingTypeId", "TEST-UPDATE-1"); + testValue = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "TEST-UPDATE-1").queryOne(); assertEquals("Retrieved value has the correct description", "New Testing Type #Update-1", testValue.getString("description")); } public void testRemoveValue() throws Exception { // Retrieve a sample GenericValue, make sure it's correct delegator.removeByCondition("TestingType", EntityCondition.makeCondition("testingTypeId", EntityOperator.LIKE, "TEST-REMOVE-%")); - GenericValue testValue = delegator.findOne("TestingType", false, "testingTypeId", "TEST-REMOVE-1"); + GenericValue testValue = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "TEST-REMOVE-1").queryOne(); assertNull("No pre-existing type value", testValue); delegator.create("TestingType", "testingTypeId", "TEST-REMOVE-1", "description", "Testing Type #Remove-1"); - testValue = delegator.findOne("TestingType", false, "testingTypeId", "TEST-REMOVE-1"); + testValue = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "TEST-REMOVE-1").queryOne(); assertEquals("Retrieved value has the correct description", "Testing Type #Remove-1", testValue.getString("description")); testValue.remove(); assertFalse("Observable has not changed", testValue.hasChanged()); @@ -176,7 +180,7 @@ public class EntityTestSuite extends Ent fail("Modified an immutable GenericValue"); } catch (UnsupportedOperationException e) { } - testValue = delegator.findOne("TestingType", false, "testingTypeId", "TEST-REMOVE-1"); + testValue = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "TEST-REMOVE-1").queryOne(); assertEquals("Finding removed value returns null", null, testValue); } @@ -187,10 +191,10 @@ public class EntityTestSuite extends Ent // Test primary key cache delegator.removeByCondition("TestingType", EntityCondition.makeCondition("testingTypeId", EntityOperator.LIKE, "TEST-CACHE-%")); delegator.removeByCondition("TestingSubtype", EntityCondition.makeCondition("testingTypeId", EntityOperator.LIKE, "TEST-CACHE-%")); - GenericValue testValue = delegator.findOne("TestingType", true, "testingTypeId", "TEST-CACHE-1"); + GenericValue testValue = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "TEST-CACHE-1").cache(true).queryOne(); assertNull("No pre-existing type value", testValue); delegator.create("TestingType", "testingTypeId", "TEST-CACHE-1", "description", "Testing Type #Cache-1"); - testValue = delegator.findOne("TestingType", true, "testingTypeId", "TEST-CACHE-1"); + testValue = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "TEST-CACHE-1").cache(true).queryOne(); assertEquals("Retrieved from cache value has the correct description", "Testing Type #Cache-1", testValue.getString("description")); // Test immutable try { @@ -207,32 +211,40 @@ public class EntityTestSuite extends Ent testValue = (GenericValue) testValue.clone(); testValue.put("description", "New Testing Type #Cache-1"); testValue.store(); - testValue = delegator.findOne("TestingType", true, "testingTypeId", "TEST-CACHE-1"); + testValue = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "TEST-CACHE-1").cache(true).queryOne(); assertEquals("Retrieved from cache value has the correct description", "New Testing Type #Cache-1", testValue.getString("description")); // Test storeByCondition updates the cache - testValue = EntityUtil.getFirst(delegator.findByAnd("TestingType", UtilMisc.toMap("testingTypeId", "TEST-CACHE-1"), null, true)); + testValue = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "TEST-CACHE-1").cache(true).queryFirst(); EntityCondition storeByCondition = EntityCondition.makeCondition(UtilMisc.toMap("testingTypeId", "TEST-CACHE-1", "lastUpdatedStamp", testValue.get("lastUpdatedStamp"))); int qtyChanged = delegator.storeByCondition("TestingType", UtilMisc.toMap("description", "New Testing Type #Cache-0"), storeByCondition); assertEquals("Delegator.storeByCondition updated one value", 1, qtyChanged); - testValue = EntityUtil.getFirst(delegator.findByAnd("TestingType", UtilMisc.toMap("testingTypeId", "TEST-CACHE-1"), null, true)); + testValue = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "TEST-CACHE-1").cache(true).queryFirst(); + assertEquals("Retrieved from cache value has the correct description", "New Testing Type #Cache-0", testValue.getString("description")); // Test removeByCondition updates the cache qtyChanged = delegator.removeByCondition("TestingType", storeByCondition); assertEquals("Delegator.removeByCondition removed one value", 1, qtyChanged); - testValue = EntityUtil.getFirst(delegator.findByAnd("TestingType", UtilMisc.toMap("testingTypeId", "TEST-CACHE-1"), null, true)); + testValue = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "TEST-CACHE-1").cache(true).queryFirst(); assertEquals("Retrieved from cache value is null", null, testValue); // Test entity value remove operation updates the cache testValue = delegator.create("TestingType", "testingTypeId", "TEST-CACHE-1", "description", "Testing Type #Cache-1"); testValue.remove(); - testValue = delegator.findOne("TestingType", true, "testingTypeId", "TEST-CACHE-1"); + testValue = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "TEST-CACHE-1").cache(true).queryOne(); assertEquals("Retrieved from cache value is null", null, testValue); // Test entity condition cache - EntityCondition testCondition = EntityCondition.makeCondition("description", EntityOperator.EQUALS, "Testing Type #Cache-2"); - List<GenericValue> testList = delegator.findList("TestingType", testCondition, null, null, null, true); + List<GenericValue> testList = EntityQuery.use(delegator) + .from("TestingType") + .where(EntityCondition.makeCondition("description", EntityOperator.EQUALS, "Testing Type #Cache-2")) + .cache(true) + .queryList(); assertEquals("Delegator findList returned no values", 0, testList.size()); delegator.create("TestingType", "testingTypeId", "TEST-CACHE-2", "description", "Testing Type #Cache-2"); - testList = delegator.findList("TestingType", testCondition, null, null, null, true); + testList = EntityQuery.use(delegator) + .from("TestingType") + .where(EntityCondition.makeCondition("description", EntityOperator.EQUALS, "Testing Type #Cache-2")) + .cache(true) + .queryList(); assertEquals("Delegator findList returned one value", 1, testList.size()); testValue = testList.get(0); assertEquals("Retrieved from cache value has the correct description", "Testing Type #Cache-2", testValue.getString("description")); @@ -251,34 +263,46 @@ public class EntityTestSuite extends Ent testValue = (GenericValue) testValue.clone(); testValue.put("testingTypeId", "TEST-CACHE-3"); testValue.create(); - testList = delegator.findList("TestingType", testCondition, null, null, null, true); + testList = EntityQuery.use(delegator) + .from("TestingType") + .where(EntityCondition.makeCondition("description", EntityOperator.EQUALS, "Testing Type #Cache-2")) + .cache(true) + .queryList(); assertEquals("Delegator findList returned two values", 2, testList.size()); // Test entity value update operation updates the cache testValue.put("description", "New Testing Type #Cache-3"); testValue.store(); - testList = delegator.findList("TestingType", testCondition, null, null, null, true); + testList = EntityQuery.use(delegator) + .from("TestingType") + .where(EntityCondition.makeCondition("description", EntityOperator.EQUALS, "Testing Type #Cache-2")) + .cache(true) + .queryList(); assertEquals("Delegator findList returned one value", 1, testList.size()); // Test entity value remove operation updates the cache testValue = testList.get(0); testValue = (GenericValue) testValue.clone(); testValue.remove(); - testList = delegator.findList("TestingType", testCondition, null, null, null, true); + testList = EntityQuery.use(delegator) + .from("TestingType") + .where(EntityCondition.makeCondition("description", EntityOperator.EQUALS, "Testing Type #Cache-2")) + .cache(true) + .queryList(); assertEquals("Delegator findList returned empty list", 0, testList.size()); // Test view entities in the pk cache - updating an entity should clear pk caches for all view entities containing that entity. - testValue = delegator.findOne("TestingSubtype", true, "testingTypeId", "TEST-CACHE-3"); + testValue = EntityQuery.use(delegator).from("TestingSubtype").where("testingTypeId", "TEST-CACHE-3").cache(true).queryOne(); assertNull("No pre-existing TestingSubtype", testValue); testValue = delegator.create("TestingSubtype", "testingTypeId", "TEST-CACHE-3", "subtypeDescription", "Testing Subtype #Cache-3"); assertNotNull("TestingSubtype created", testValue); // Confirm member entity appears in the view - testValue = delegator.findOne("TestingViewPks", true, "testingTypeId", "TEST-CACHE-3"); + testValue = EntityQuery.use(delegator).from("TestingViewPks").where("testingTypeId", "TEST-CACHE-3").cache(true).queryOne(); assertEquals("View retrieved from cache has the correct member description", "Testing Subtype #Cache-3", testValue.getString("subtypeDescription")); - testValue = delegator.findOne("TestingSubtype", true, "testingTypeId", "TEST-CACHE-3"); + testValue = EntityQuery.use(delegator).from("TestingSubtype").where("testingTypeId", "TEST-CACHE-3").cache(true).queryOne(); // Modify member entity testValue = (GenericValue) testValue.clone(); testValue.put("subtypeDescription", "New Testing Subtype #Cache-3"); testValue.store(); // Check if cached view contains the modification - testValue = delegator.findOne("TestingViewPks", true, "testingTypeId", "TEST-CACHE-3"); + testValue = EntityQuery.use(delegator).from("TestingViewPks").where("testingTypeId", "TEST-CACHE-3").cache(true).queryOne(); assertEquals("View retrieved from cache has the correct member description", "New Testing Subtype #Cache-3", testValue.getString("subtypeDescription")); } @@ -291,14 +315,14 @@ public class EntityTestSuite extends Ent Delegator localDelegator = DelegatorFactory.getDelegator("default"); boolean transBegin = TransactionUtil.begin(); localDelegator.create("TestingType", "testingTypeId", "TEST-5", "description", "Testing Type #5"); - GenericValue testValue = localDelegator.findOne("TestingType", false, "testingTypeId", "TEST-5"); + GenericValue testValue = EntityQuery.use(localDelegator).from("TestingType").where("testingTypeId", "TEST-5").queryOne(); assertEquals("Retrieved value has the correct description", "Testing Type #5", testValue.getString("description")); String newValueStr = UtilXml.toXml(testValue); GenericValue newValue = (GenericValue) UtilXml.fromXml(newValueStr); assertEquals("Retrieved value has the correct description", "Testing Type #5", newValue.getString("description")); newValue.put("description", "XML Testing Type #5"); newValue.store(); - newValue = localDelegator.findOne("TestingType", false, "testingTypeId", "TEST-5"); + newValue = EntityQuery.use(localDelegator).from("TestingType").where("testingTypeId", "TEST-5").queryOne(); assertEquals("Retrieved value has the correct description", "XML Testing Type #5", newValue.getString("description")); TransactionUtil.rollback(transBegin, null, null); } @@ -331,8 +355,10 @@ public class EntityTestSuite extends Ent // get how many child nodes did we have before creating the tree delegator.removeByCondition("TestingNode", EntityCondition.makeCondition("description", EntityOperator.LIKE, "create:")); long created = flushAndRecreateTree("create"); - long newlyStored = delegator.findCountByCondition("TestingNode", EntityCondition.makeCondition("description", EntityOperator.LIKE, "create:%"), null, null); - + long newlyStored = EntityQuery.use(delegator) + .from("TestingNode") + .where(EntityCondition.makeCondition("description", EntityOperator.LIKE, "create:%")) + .queryCount(); assertEquals("Created/Stored Nodes", created, newlyStored); } @@ -341,12 +367,14 @@ public class EntityTestSuite extends Ent */ public void testAddMembersToTree() throws Exception { delegator.removeByCondition("TestingType", EntityCondition.makeCondition("testingTypeId", EntityOperator.LIKE, "TEST-TREE-%")); - GenericValue testValue = delegator.findOne("TestingType", true, "testingTypeId", "TEST-TREE-1"); + GenericValue testValue = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "TEST-TREE-1").cache(true).queryOne(); assertNull("No pre-existing type value", testValue); delegator.create("TestingType", "testingTypeId", "TEST-TREE-1", "description", "Testing Type #Tree-1"); // get the level1 nodes - EntityCondition isLevel1 = EntityCondition.makeCondition("primaryParentNodeId", EntityOperator.NOT_EQUAL, GenericEntity.NULL_FIELD); - List<GenericValue> nodeLevel1 = delegator.findList("TestingNode", isLevel1, null, null, null, false); + List<GenericValue> nodeLevel1 = EntityQuery.use(delegator) + .from("TestingNode") + .where(EntityCondition.makeCondition("primaryParentNodeId", EntityOperator.NOT_EQUAL, GenericEntity.NULL_FIELD)) + .queryList(); List<GenericValue> newValues = new LinkedList<GenericValue>(); Timestamp now = UtilDateTime.nowTimestamp(); @@ -387,7 +415,12 @@ public class EntityTestSuite extends Ent delegator.create("TestingType", "testingTypeId", typeId, "description", typeDescription); int i = 0; Timestamp now = UtilDateTime.nowTimestamp(); - for (GenericValue node: delegator.findList("TestingNode", EntityCondition.makeCondition("description", EntityOperator.LIKE, descriptionPrefix + "%"), null, null, null, false)) { + + for (GenericValue node: EntityQuery.use(delegator) + .from("TestingNode") + .where(EntityCondition.makeCondition("description", EntityOperator.LIKE, descriptionPrefix + "%")) + .queryList() + ) { if (i % 2 == 0) { GenericValue testing = delegator.create("Testing", "testingId", descriptionPrefix + ":" + node.get("testingNodeId"), "testingTypeId", typeId, "description", node.get("description")); GenericValue member = delegator.makeValue("TestingNodeMember", @@ -416,7 +449,7 @@ public class EntityTestSuite extends Ent EntityOperator.AND, EntityCondition.makeCondition("description", EntityOperator.LIKE, "count-views:%") ); - List<GenericValue> nodeWithMembers = delegator.findList("TestingNodeAndMember", isNodeWithMember, null, null, null, false); + List<GenericValue> nodeWithMembers = EntityQuery.use(delegator).from("TestingNodeAndMember").where(isNodeWithMember).queryList(); for (GenericValue v: nodeWithMembers) { Map<String, Object> fields = v.getAllFields(); @@ -428,7 +461,7 @@ public class EntityTestSuite extends Ent Debug.logInfo(field.toString() + " = " + ((value == null) ? "[null]" : value), module); } } - long testingcount = delegator.findCountByCondition("Testing", EntityCondition.makeCondition("testingTypeId", EntityOperator.EQUALS, "TEST-COUNT-VIEW"), null, null); + long testingcount = EntityQuery.use(delegator).from("Testing").where("testingTypeId", EntityOperator.EQUALS, "TEST-COUNT-VIEW").queryCount(); assertEquals("Number of views should equal number of created entities in the test.", testingcount, nodeWithMembers.size()); } @@ -437,28 +470,31 @@ public class EntityTestSuite extends Ent */ public void testFindDistinct() throws Exception { delegator.removeByCondition("Testing", EntityCondition.makeCondition("testingTypeId", EntityOperator.LIKE, "TEST-DISTINCT-%")); - List<GenericValue> testingDistinctList = delegator.findList("Testing", EntityCondition.makeCondition("testingTypeId", EntityOperator.LIKE, "TEST-DISTINCT-%"), null, null, null, false); + List<GenericValue> testingDistinctList = EntityQuery.use(delegator) + .from("Testing") + .where("testingTypeId", EntityOperator.LIKE, "TEST-DISTINCT-%") + .queryList(); + assertEquals("No existing Testing entities for distinct", 0, testingDistinctList.size()); delegator.removeByCondition("TestingType", EntityCondition.makeCondition("testingTypeId", EntityOperator.LIKE, "TEST-DISTINCT-%")); - GenericValue testValue = delegator.findOne("TestingType", true, "testingTypeId", "TEST-DISTINCT-1"); + GenericValue testValue = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "TEST-DISTINCT-1").cache(true).queryOne(); assertNull("No pre-existing type value", testValue); delegator.create("TestingType", "testingTypeId", "TEST-DISTINCT-1", "description", "Testing Type #Distinct-1"); - testValue = delegator.findOne("TestingType", true, "testingTypeId", "TEST-DISTINCT-1"); + testValue = EntityQuery.use(delegator).from("TestingType").where("testingTypeId", "TEST-DISTINCT-1").cache(true).queryOne(); assertNotNull("Found newly created type value", testValue); delegator.create("Testing", "testingId", "TEST-DISTINCT-1", "testingTypeId", "TEST-DISTINCT-1", "testingSize", Long.valueOf(10), "comments", "No-comments"); delegator.create("Testing", "testingId", "TEST-DISTINCT-2", "testingTypeId", "TEST-DISTINCT-1", "testingSize", Long.valueOf(10), "comments", "Some-comments"); delegator.create("Testing", "testingId", "TEST-DISTINCT-3", "testingTypeId", "TEST-DISTINCT-1", "testingSize", Long.valueOf(9), "comments", "No-comments"); delegator.create("Testing", "testingId", "TEST-DISTINCT-4", "testingTypeId", "TEST-DISTINCT-1", "testingSize", Long.valueOf(11), "comments", "Some-comments"); - List<EntityExpr> exprList = UtilMisc.toList( - EntityCondition.makeCondition("testingSize", EntityOperator.EQUALS, Long.valueOf(10)), - EntityCondition.makeCondition("comments", EntityOperator.EQUALS, "No-comments")); - EntityConditionList<EntityExpr> condition = EntityCondition.makeCondition(exprList); - - EntityFindOptions findOptions = new EntityFindOptions(); - findOptions.setDistinct(true); - List<GenericValue> testingSize10 = delegator.findList("Testing", condition, UtilMisc.toSet("testingSize", "comments"), null, findOptions, false); + List<GenericValue> testingSize10 = EntityQuery.use(delegator) + .select("testingSize", "comments") + .from("Testing") + .where("testingSize", Long.valueOf(10), "comments", "No-comments") + .distinct() + .cache() + .queryList(); Debug.logInfo("testingSize10 is " + testingSize10.size(), module); assertEquals("There should only be 1 result found by findDistinct()", 1, testingSize10.size()); @@ -468,8 +504,10 @@ public class EntityTestSuite extends Ent * Tests a findByCondition using not like */ public void testNotLike() throws Exception { - EntityCondition cond = EntityCondition.makeCondition("description", EntityOperator.NOT_LIKE, "root%"); - List<GenericValue> nodes = delegator.findList("TestingNode", cond, null, null, null, false); + List<GenericValue> nodes = EntityQuery.use(delegator) + .from("TestingNode") + .where(EntityCondition.makeCondition("description", EntityOperator.NOT_LIKE, "root%")) + .queryList(); assertNotNull("Found nodes", nodes); for (GenericValue product: nodes) { @@ -542,8 +580,10 @@ public class EntityTestSuite extends Ent // // Find the testing entities tru the node member and build a list of them // - EntityCondition isNodeWithMember = EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "rnmat:%"); - List<GenericValue> values = delegator.findList("TestingNodeMember", isNodeWithMember, null, null, null, false); + List<GenericValue> values = EntityQuery.use(delegator) + .from("TestingNodeMember") + .where(EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "rnmat:%")) + .queryList(); ArrayList<GenericValue> testings = new ArrayList<GenericValue>(); @@ -552,11 +592,17 @@ public class EntityTestSuite extends Ent } // and remove the nodeMember afterwards delegator.removeAll(values); - values = delegator.findList("TestingNodeMember", isNodeWithMember, null, null, null, false); + values = EntityQuery.use(delegator) + .from("TestingNodeMember") + .where(EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "rnmat:%")) + .queryList(); assertEquals("No more Node Member entities", 0, values.size()); delegator.removeAll(testings); - values = delegator.findList("Testing", EntityCondition.makeCondition("description", EntityOperator.LIKE, "rnmat:%"), null, null, null, false); + values = EntityQuery.use(delegator) + .from("Testing") + .where(EntityCondition.makeCondition("description", EntityOperator.LIKE, "rnmat:%")) + .queryList(); assertEquals("No more Testing entities", 0, values.size()); } @@ -570,7 +616,7 @@ public class EntityTestSuite extends Ent EntityCondition isLevel1 = EntityCondition.makeCondition("description", EntityOperator.LIKE, "store-by-condition-a:%"); Map<String, String> fieldsToSet = UtilMisc.toMap("description", "store-by-condition-a:updated"); delegator.storeByCondition("TestingNode", fieldsToSet, isLevel1); - List<GenericValue> updatedNodes = delegator.findByAnd("TestingNode", fieldsToSet, null, false); + List<GenericValue> updatedNodes = EntityQuery.use(delegator).from("TestingNode").where(fieldsToSet).queryList(); int n = updatedNodes.size(); assertTrue("testStoreByCondition updated nodes > 0", n > 0); } @@ -602,7 +648,7 @@ public class EntityTestSuite extends Ent EntityOperator.AND, EntityCondition.makeCondition("primaryParentNodeId", EntityOperator.NOT_EQUAL, GenericEntity.NULL_FIELD) ); - List<GenericValue> rootValues = delegator.findList("TestingNode", isRoot, UtilMisc.toSet("testingNodeId"), null, null, false); + List<GenericValue> rootValues = EntityQuery.use(delegator).select("testingNodeId").from("TestingNode").where(isRoot).queryList(); for (GenericValue value: rootValues) { GenericPK pk = value.getPrimaryKey(); @@ -612,7 +658,7 @@ public class EntityTestSuite extends Ent // no more TestingNode should be in the data base anymore. - List<GenericValue> testingNodes = delegator.findList("TestingNode", isRoot, null, null, null, false); + List<GenericValue> testingNodes = EntityQuery.use(delegator).from("TestingNode").where(isRoot).queryList(); assertEquals("No more TestingNode after removing the roots", 0, testingNodes.size()); } @@ -620,20 +666,20 @@ public class EntityTestSuite extends Ent * Tests the .removeAll method only. */ public void testRemoveType() throws Exception { - List<GenericValue> values = delegator.findList("TestingRemoveAll", null, null, null, null, false); + List<GenericValue> values = EntityQuery.use(delegator).from("TestingRemoveAll").queryList(); delegator.removeAll(values); - values = delegator.findList("TestingRemoveAll", null, null, null, null, false); + values = EntityQuery.use(delegator).from("TestingRemoveAll").queryList(); assertEquals("No more TestingRemoveAll: setup", 0, values.size()); for (int i = 0; i < 10; i++) { delegator.create("TestingRemoveAll", "testingRemoveAllId", "prefix:" + i); } - values = delegator.findList("TestingRemoveAll", null, null, null, null, false); + values = EntityQuery.use(delegator).from("TestingRemoveAll").queryList(); assertEquals("No more TestingRemoveAll: create", 10, values.size()); delegator.removeAll(values); // now make sure there are no more of these - values = delegator.findList("TestingRemoveAll", null, null, null, null, false); + values = EntityQuery.use(delegator).from("TestingRemoveAll").queryList(); assertEquals("No more TestingRemoveAll: finish", 0, values.size()); } @@ -641,17 +687,24 @@ public class EntityTestSuite extends Ent * This test will create a large number of unique items and add them to the delegator at once */ public void testCreateManyAndStoreAtOnce() throws Exception { - EntityCondition condition = EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T1-%"); try { List<GenericValue> newValues = new LinkedList<GenericValue>(); for (int i = 0; i < TEST_COUNT; i++) { newValues.add(delegator.makeValue("Testing", "testingId", getTestId("T1-", i))); } delegator.storeAll(newValues); - List<GenericValue> newlyCreatedValues = delegator.findList("Testing", condition, null, UtilMisc.toList("testingId"), null, false); + List<GenericValue> newlyCreatedValues = EntityQuery.use(delegator) + .from("Testing") + .where(EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T1-%")) + .orderBy("testingId") + .queryList(); assertEquals("Test to create " + TEST_COUNT + " and store all at once", TEST_COUNT, newlyCreatedValues.size()); } finally { - List<GenericValue> newlyCreatedValues = delegator.findList("Testing", condition, null, UtilMisc.toList("testingId"), null, false); + List<GenericValue> newlyCreatedValues = EntityQuery.use(delegator) + .from("Testing") + .where(EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T1-%")) + .orderBy("testingId") + .queryList(); delegator.removeAll(newlyCreatedValues); } } @@ -660,15 +713,22 @@ public class EntityTestSuite extends Ent * This test will create a large number of unique items and add them to the delegator at once */ public void testCreateManyAndStoreOneAtATime() throws Exception { - EntityCondition condition = EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T2-%"); try { for (int i = 0; i < TEST_COUNT; i++) { delegator.create(delegator.makeValue("Testing", "testingId", getTestId("T2-", i))); } - List<GenericValue> newlyCreatedValues = delegator.findList("Testing", condition, null, UtilMisc.toList("testingId"), null, false); + List<GenericValue> newlyCreatedValues = EntityQuery.use(delegator) + .from("Testing") + .where(EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T2-%")) + .orderBy("testingId") + .queryList(); assertEquals("Test to create " + TEST_COUNT + " and store one at a time: ", TEST_COUNT, newlyCreatedValues.size()); } finally { - List<GenericValue> newlyCreatedValues = delegator.findList("Testing", condition, null, UtilMisc.toList("testingId"), null, false); + List<GenericValue> newlyCreatedValues = EntityQuery.use(delegator) + .from("Testing") + .where(EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T2-%")) + .orderBy("testingId") + .queryList(); delegator.removeAll(newlyCreatedValues); } } @@ -677,19 +737,26 @@ public class EntityTestSuite extends Ent * This test will use the large number of unique items from above and test the EntityListIterator looping through the list */ public void testEntityListIterator() throws Exception { - EntityCondition condition = EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T3-%"); try { List<GenericValue> newValues = new LinkedList<GenericValue>(); for (int i = 0; i < TEST_COUNT; i++) { newValues.add(delegator.makeValue("Testing", "testingId", getTestId("T3-", i))); } delegator.storeAll(newValues); - List<GenericValue> newlyCreatedValues = delegator.findList("Testing", condition, null, UtilMisc.toList("testingId"), null, false); + List<GenericValue> newlyCreatedValues = EntityQuery.use(delegator) + .from("Testing") + .where(EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T3-%")) + .orderBy("testingId") + .queryList(); assertEquals("Test to create " + TEST_COUNT + " and store all at once", TEST_COUNT, newlyCreatedValues.size()); boolean beganTransaction = false; try { beganTransaction = TransactionUtil.begin(); - EntityListIterator iterator = delegator.find("Testing", condition, null, null, UtilMisc.toList("testingId"), null); + EntityListIterator iterator = EntityQuery.use(delegator) + .from("Testing") + .where(EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T3-%")) + .orderBy("testingId") + .queryIterator(); assertNotNull("Test if EntityListIterator was created: ", iterator); int i = 0; @@ -709,7 +776,10 @@ public class EntityTestSuite extends Ent TransactionUtil.commit(beganTransaction); } } finally { - List<GenericValue> entitiesToRemove = delegator.findList("Testing", condition, null, null, null, false); + List<GenericValue> entitiesToRemove = EntityQuery.use(delegator) + .from("Testing") + .where(EntityCondition.makeCondition("testingId", EntityOperator.LIKE, "T3-%")) + .queryList(); delegator.removeAll(entitiesToRemove); } } @@ -722,7 +792,7 @@ public class EntityTestSuite extends Ent boolean transBegin = TransactionUtil.begin(); delegator.create(testValue); TransactionUtil.rollback(transBegin, null, null); - GenericValue testValueOut = delegator.findOne("Testing", false, "testingId", "rollback-test"); + GenericValue testValueOut = EntityQuery.use(delegator).from("Testing").where("testingId", "rollback-test").queryOne(); assertEquals("Test that transaction rollback removes value: ", null, testValueOut); } @@ -802,7 +872,7 @@ public class EntityTestSuite extends Ent testValue.set("numericField", numeric); testValue.set("clobField", clobStr); testValue.store(); - testValue = delegator.findOne("TestFieldType", UtilMisc.toMap("testFieldTypeId", id), false); + testValue = EntityQuery.use(delegator).from("TestFieldType").where("testFieldTypeId", id).queryOne(); assertEquals("testFieldTypeId", id, testValue.get("testFieldTypeId")); Blob blob = (Blob) testValue.get("blobField"); byte[] c = blob.getBytes(1, (int) blob.length()); @@ -834,7 +904,7 @@ public class EntityTestSuite extends Ent testValue.set("numericField", null); testValue.set("clobField", null); testValue.store(); - testValue = delegator.findOne("TestFieldType", UtilMisc.toMap("testFieldTypeId", id), false); + testValue = EntityQuery.use(delegator).from("TestFieldType").where("testFieldTypeId", id).queryOne(); assertEquals("testFieldTypeId", id, testValue.get("testFieldTypeId")); assertNull("blobField null", testValue.get("blobField")); assertNull("byteArrayField null", testValue.get("byteArrayField")); @@ -848,7 +918,7 @@ public class EntityTestSuite extends Ent assertNull("clobField null", testValue.get("clobField")); } finally { // Remove all our newly inserted values. - List<GenericValue> values = delegator.findList("TestFieldType", null, null, null, null, false); + List<GenericValue> values = EntityQuery.use(delegator).from("TestFieldType").queryList(); delegator.removeAll(values); } } @@ -980,8 +1050,8 @@ public class EntityTestSuite extends Ent EntitySaxReader reader = new EntitySaxReader(delegator); long numberLoaded = reader.parse(xmlContentLoad); assertEquals("Create Entity loaded ", 4, numberLoaded); - GenericValue t1 = delegator.findOne("Testing", UtilMisc.toMap("testingId", "T1"), false); - GenericValue t2 = delegator.findOne("Testing", UtilMisc.toMap("testingId", "T2"), true); + GenericValue t1 = EntityQuery.use(delegator).from("Testing").where("testingId", "T1").queryOne(); + GenericValue t2 = EntityQuery.use(delegator).from("Testing").where("testingId", "T2").cache(true).queryOne(); assertNotNull("Create Testing(T1)", t1); assertEquals("Create Testing(T1).testingTypeId", "JUNIT-TEST", t1.getString("testingTypeId")); assertEquals("Create Testing(T1).testingName", "First test", t1.getString("testingName")); @@ -1008,7 +1078,7 @@ public class EntityTestSuite extends Ent reader = new EntitySaxReader(delegator); numberLoaded += reader.parse(xmlContentLoad); assertEquals("Create Skip Entity loaded ", 3, numberLoaded); - GenericValue t1 = delegator.findOne("Testing", UtilMisc.toMap("testingId", "reader-create-skip"), false); + GenericValue t1 = EntityQuery.use(delegator).from("Testing").where("testingId", "reader-create-skip").queryOne(); assertNotNull("Create Skip Testing(T1)", t1); assertEquals("Create Skip Testing(T1).testingTypeId", "reader-create-skip", t1.getString("testingTypeId")); assertEquals("Create Skip Testing(T1).testingName", "reader create skip", t1.getString("testingName")); @@ -1028,8 +1098,8 @@ public class EntityTestSuite extends Ent EntitySaxReader reader = new EntitySaxReader(delegator); long numberLoaded = reader.parse(xmlContentLoad); assertEquals("Update Entity loaded ", 5, numberLoaded); - GenericValue t1 = delegator.findOne("Testing", UtilMisc.toMap("testingId", "create-update-T1"), false); - GenericValue t3 = delegator.findOne("Testing", UtilMisc.toMap("testingId", "create-update-T3"), false); + GenericValue t1 = EntityQuery.use(delegator).from("Testing").where("testingId", "create-update-T1").queryOne(); + GenericValue t3 = EntityQuery.use(delegator).from("Testing").where("testingId", "create-update-T3").queryOne(); assertNotNull("Update Testing(T1)", t1); assertEquals("Update Testing(T1).testingTypeId", "create-update", t1.getString("testingTypeId")); assertEquals("Update Testing(T1).testingName", "First test update", t1.getString("testingName")); @@ -1054,8 +1124,8 @@ public class EntityTestSuite extends Ent EntitySaxReader reader = new EntitySaxReader(delegator); long numberLoaded = reader.parse(xmlContentLoad); assertEquals("Replace Entity loaded ", 4, numberLoaded); - GenericValue t1 = delegator.findOne("Testing", UtilMisc.toMap("testingId", "create-replace-T1"), false); - GenericValue t2 = delegator.findOne("Testing", UtilMisc.toMap("testingId", "create-replace-T2"), false); + GenericValue t1 = EntityQuery.use(delegator).from("Testing").where("testingId", "create-replace-T1").queryOne(); + GenericValue t2 = EntityQuery.use(delegator).from("Testing").where("testingId", "create-replace-T2").queryOne(); assertNotNull("Replace Testing(T1)", t1); assertEquals("Replace Testing(T1).testingTypeId", "create-replace", t1.getString("testingTypeId")); assertEquals("Replace Testing(T1).testingName", "First test replace", t1.getString("testingName")); @@ -1081,15 +1151,15 @@ public class EntityTestSuite extends Ent EntitySaxReader reader = new EntitySaxReader(delegator); long numberLoaded = reader.parse(xmlContentLoad); assertEquals("Delete Entity loaded ", 5, numberLoaded); - GenericValue t1 = delegator.findOne("Testing", UtilMisc.toMap("testingId", "T1"), false); - GenericValue t2 = delegator.findOne("Testing", UtilMisc.toMap("testingId", "T2"), false); - GenericValue t3 = delegator.findOne("Testing", UtilMisc.toMap("testingId", "T2"), false); + GenericValue t1 = EntityQuery.use(delegator).from("Testing").where("testingId", "T1").queryOne(); + GenericValue t2 = EntityQuery.use(delegator).from("Testing").where("testingId", "T2").queryOne(); + GenericValue t3 = EntityQuery.use(delegator).from("Testing").where("testingId", "T3").queryOne(); assertNull("Delete Testing(T1)", t1); assertNull("Delete Testing(T2)", t2); assertNull("Delete Testing(T3)", t3); - GenericValue testType = delegator.findOne("TestingType", UtilMisc.toMap("testingTypeId", "JUNIT-TEST"), false); + GenericValue testType = EntityQuery.use(delegator).from("TestingType").where("testingId", "JUNIT-TEST").queryOne(); assertNull("Delete TestingType 1", testType); - testType = delegator.findOne("TestingType", UtilMisc.toMap("testingTypeId", "JUNIT-TEST2"), false); + testType = EntityQuery.use(delegator).from("TestingType").where("testingId", "JUNIT-TEST2").queryOne(); assertNull("Delete TestingType 2", testType); } @@ -1174,7 +1244,7 @@ public class EntityTestSuite extends Ent try { transactionStarted = TransactionUtil.begin(); for (int i = 1; i <= numberOfQueries; i++) { - List rows = delegator.findAll("SequenceValueItem", false); + List rows = EntityQuery.use(delegator).from("SequenceValueItem").queryList(); totalNumberOfRows = totalNumberOfRows + rows.size(); } TransactionUtil.commit(transactionStarted); @@ -1194,7 +1264,7 @@ public class EntityTestSuite extends Ent try { for (int i = 1; i <= numberOfQueries; i++) { transactionStarted = TransactionUtil.begin(); - List rows = delegator.findAll("SequenceValueItem", false); + List rows = EntityQuery.use(delegator).from("SequenceValueItem").queryList(); totalNumberOfRows = totalNumberOfRows + rows.size(); TransactionUtil.commit(transactionStarted); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java Wed Dec 17 12:13:46 2014 @@ -85,7 +85,7 @@ public class EntityDataAssert { try { checkPK = checkValue.getPrimaryKey(); - GenericValue currentValue = delegator.findOne(checkPK.getEntityName(), checkPK, false); + GenericValue currentValue = EntityQuery.use(delegator).from(checkPK.getEntityName()).where(checkPK).queryOne(); if (currentValue == null) { errorMessages.add("Entity [" + checkPK.getEntityName() + "] record not found for pk: " + checkPK); return; Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityTypeUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityTypeUtil.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityTypeUtil.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityTypeUtil.java Wed Dec 17 12:13:46 2014 @@ -133,7 +133,7 @@ public class EntityTypeUtil { public static boolean hasParentType(Delegator delegator, String entityName, String primaryKey, String childType, String parentTypeField, String parentType) { GenericValue childTypeValue = null; try { - childTypeValue = delegator.findOne(entityName, UtilMisc.toMap(primaryKey, childType), true); + childTypeValue = EntityQuery.use(delegator).from(entityName).where(primaryKey, childType).cache(true).queryOne(); } catch (GenericEntityException e) { Debug.logError("Error finding "+entityName+" record for type "+childType, module); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java Wed Dec 17 12:13:46 2014 @@ -430,7 +430,7 @@ public class EntityUtil { public static List<GenericValue> findDatedInclusionEntity(Delegator delegator, String entityName, Map<String, ? extends Object> search, Timestamp now) throws GenericEntityException { EntityCondition searchCondition = EntityCondition.makeCondition(UtilMisc.toList( EntityCondition.makeCondition(search), EntityUtil.getFilterByDateExpr(now))); - return delegator.findList(entityName, searchCondition, null, UtilMisc.toList("-fromDate"), null, false); + return EntityQuery.use(delegator).from(entityName).where(searchCondition).orderBy("-fromDate").queryList(); } public static GenericValue newDatedInclusionEntity(Delegator delegator, String entityName, Map<String, ? extends Object> search) throws GenericEntityException { @@ -466,7 +466,7 @@ public class EntityUtil { search.putAll(find); } if (now.equals(search.get("fromDate"))) { - return EntityUtil.getOnly(delegator.findByAnd(entityName, search, null, false)); + return EntityUtil.getOnly(EntityQuery.use(delegator).from(entityName).where(search).queryList()); } else { search.put("fromDate",now); search.remove("thruDate"); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtilProperties.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtilProperties.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtilProperties.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtilProperties.java Wed Dec 17 12:13:46 2014 @@ -55,7 +55,11 @@ public class EntityUtilProperties implem // find system property try { - GenericValue systemProperty = EntityQuery.use(delegator).from("SystemProperty").where("systemResourceId", resource, "systemPropertyId", name).cache().queryOne(); + GenericValue systemProperty = EntityQuery.use(delegator) + .from("SystemProperty") + .where("systemResourceId", resource, "systemPropertyId", name) + .cache() + .queryOne(); if (systemProperty != null) { String systemPropertyValue = systemProperty.getString("systemPropertyValue"); if (UtilValidate.isNotEmpty(systemPropertyValue)) { Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityGroupUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityGroupUtil.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityGroupUtil.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityGroupUtil.java Wed Dec 17 12:13:46 2014 @@ -30,6 +30,7 @@ import org.ofbiz.entity.GenericEntityExc import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.model.ModelViewEntity; +import org.ofbiz.entity.util.EntityQuery; /** * EntityEcaUtil @@ -41,8 +42,7 @@ public class EntityGroupUtil { public static Set<String> getEntityNamesByGroup(String entityGroupId, Delegator delegator, boolean requireStampFields) throws GenericEntityException { Set<String> entityNames = new HashSet<String>(); - List<GenericValue> entitySyncGroupIncludes = delegator.findByAnd("EntityGroupEntry", UtilMisc.toMap("entityGroupId", entityGroupId), null, false); - + List<GenericValue> entitySyncGroupIncludes = EntityQuery.use(delegator).from("EntityGroupEntry").where("entityGroupId", entityGroupId).queryList(); List<ModelEntity> modelEntities = getModelEntitiesFromRecords(entitySyncGroupIncludes, delegator, requireStampFields); for (ModelEntity modelEntity: modelEntities) { entityNames.add(modelEntity.getEntityName()); Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java Wed Dec 17 12:13:46 2014 @@ -49,6 +49,7 @@ import org.ofbiz.entity.datasource.Gener import org.ofbiz.entity.jdbc.DatabaseUtil; import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.util.EntityDataLoader; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.service.ServiceDispatcher; @@ -232,7 +233,7 @@ public class EntityDataLoadContainer imp expr.add(EntityCondition.makeCondition("disabled", EntityOperator.EQUALS, null)); List<GenericValue> tenantList; try { - tenantList = delegator.findList("Tenant", EntityCondition.makeCondition(expr, EntityOperator.OR), null, null, null, false); + tenantList = EntityQuery.use(delegator).from("Tenant").where(expr, EntityOperator.OR).queryList(); } catch (GenericEntityException e) { throw new ContainerException(e.getMessage()); } @@ -311,7 +312,7 @@ public class EntityDataLoadContainer imp componentEntry.set("componentName", config.getComponentName()); componentEntry.set("rootLocation", config.getRootLocation()); try { - GenericValue componentCheck = baseDelegator.findOne("Component", UtilMisc.toMap("componentName", config.getComponentName()), false); + GenericValue componentCheck = EntityQuery.use(baseDelegator).from("Component").where("componentName", config.getComponentName()).queryOne(); if (UtilValidate.isEmpty(componentCheck)) { componentEntry.create(); } else { @@ -329,14 +330,13 @@ public class EntityDataLoadContainer imp for (ComponentConfig config : allComponents) { loadComponents.add(config.getComponentName()); } - List<GenericValue> tenantComponents = baseDelegator.findByAnd("TenantComponent", UtilMisc.toMap("tenantId", delegator.getDelegatorTenantId()), UtilMisc.toList("sequenceNum"), false); + List<GenericValue> tenantComponents = EntityQuery.use(baseDelegator).from("TenantComponent").where("tenantId", delegator.getDelegatorTenantId()).orderBy("sequenceNum").queryList(); for (GenericValue tenantComponent : tenantComponents) { loadComponents.add(tenantComponent.getString("componentName")); } Debug.logInfo("Loaded components by tenantId : " + delegator.getDelegatorTenantId() + ", " + tenantComponents.size() + " components", module); } else { - List<GenericValue> tenantComponents = baseDelegator.findByAnd("TenantComponent", UtilMisc.toMap("tenantId", delegator.getDelegatorTenantId(), "componentName", this.component), - UtilMisc.toList("sequenceNum"), false); + List<GenericValue> tenantComponents = EntityQuery.use(baseDelegator).from("TenantComponent").where("tenantId", delegator.getDelegatorTenantId(), "componentName", this.component).orderBy("sequenceNum").queryList(); for (GenericValue tenantComponent : tenantComponents) { loadComponents.add(tenantComponent.getString("componentName")); } Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java Wed Dec 17 12:13:46 2014 @@ -45,6 +45,7 @@ import org.ofbiz.entity.datasource.Gener import org.ofbiz.entity.jdbc.DatabaseUtil; import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.util.EntityListIterator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.security.Security; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; @@ -419,7 +420,7 @@ public class EntityDataServices { Locale locale = (Locale) context.get("locale"); EntityListIterator eli = null; try { - eli = delegator.find(entityName, null, null, null, null, null); + eli = EntityQuery.use(delegator).from(entityName).queryIterator(); GenericValue currentValue; while ((currentValue = eli.next()) != null) { byte[] bytes = currentValue.getBytes(fieldName); Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/permission/EntityPermissionChecker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/permission/EntityPermissionChecker.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/permission/EntityPermissionChecker.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/permission/EntityPermissionChecker.java Wed Dec 17 12:13:46 2014 @@ -265,9 +265,12 @@ public class EntityPermissionChecker { //} //EntityCondition opCond = EntityCondition.makeCondition(condList, EntityOperator.OR); - EntityCondition opCond = EntityCondition.makeCondition(lcEntityName + "OperationId", EntityOperator.IN, targetOperationList); - List<GenericValue> targetOperationEntityList = delegator.findList(modelOperationEntity.getEntityName(), opCond, null, null, null, true); + List<GenericValue> targetOperationEntityList = EntityQuery.use(delegator) + .from(modelOperationEntity.getEntityName()) + .where(EntityCondition.makeCondition(lcEntityName + "OperationId", EntityOperator.IN, targetOperationList)) + .cache(true) + .queryList(); Map<String, GenericValue> entities = new HashMap<String, GenericValue>(); String pkFieldName = modelEntity.getFirstPkFieldName(); @@ -609,7 +612,7 @@ public class EntityPermissionChecker { String entityId = (String)obj; if (entities != null) entity = entities.get(entityId); - if (entity == null) entity = delegator.findOne(entityName,UtilMisc.toMap(pkFieldName, entityId), true); + if (entity == null) entity = EntityQuery.use(delegator).from(entityName).where(pkFieldName, entityId).cache(true).queryOne(); } else if (obj instanceof GenericValue) { entity = (GenericValue)obj; } @@ -648,7 +651,7 @@ public class EntityPermissionChecker { if (hasNeed) { try { if (UtilValidate.isNotEmpty(partyId)) { - List<GenericValue> partyRoleList = delegator.findByAnd("PartyRole", UtilMisc.toMap("partyId", partyId), null, true); + List<GenericValue> partyRoleList = EntityQuery.use(delegator).from("PartyRole").where("partyId", partyId).cache(true).queryList(); for (GenericValue partyRole: partyRoleList) { String roleTypeId = partyRole.getString("roleTypeId"); for (String thisRole: newHasRoleList) { @@ -884,9 +887,6 @@ public class EntityPermissionChecker { // thruDate = (Timestamp)partyRelationshipValues.get("thruDate") ; //} - EntityExpr partyFromExpr = EntityCondition.makeCondition("partyIdFrom", partyIdFrom); - EntityExpr partyToExpr = EntityCondition.makeCondition("partyIdTo", partyIdTo); - //EntityExpr relationExpr = EntityCondition.makeCondition("partyRelationshipTypeId", "CONTENT_PERMISSION"); //EntityExpr roleTypeIdFromExpr = EntityCondition.makeCondition("roleTypeIdFrom", "CONTENT_PERMISSION_GROUP_MEMBER"); //EntityExpr roleTypeIdToExpr = EntityCondition.makeCondition("roleTypeIdTo", "CONTENT_PERMISSION_GROUP"); @@ -896,12 +896,10 @@ public class EntityPermissionChecker { // This method is simplified to make it work, these conditions need to be added back in. //List joinList = UtilMisc.toList(fromExpr, thruCond, partyFromExpr, partyToExpr, relationExpr); - List<? extends EntityCondition> joinList = UtilMisc.toList(partyFromExpr, partyToExpr); - EntityCondition condition = EntityCondition.makeCondition(joinList); List<GenericValue> partyRelationships = null; try { - partyRelationships = delegator.findList("PartyRelationship", condition, null, null, null, false); + partyRelationships = EntityQuery.use(delegator).from("PartyRelationship").where("partyIdFrom", partyIdFrom, "partyIdTo", partyIdTo).queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Problem finding PartyRelationships. ", module); return false; @@ -1041,8 +1039,11 @@ public class EntityPermissionChecker { } public void init(Delegator delegator) throws GenericEntityException { - EntityCondition opCond = EntityCondition.makeCondition(operationFieldName, EntityOperator.IN, this.operationList); - this.entityList = delegator.findList(this.entityName, opCond, null, null, null, true); + this.entityList = EntityQuery.use(delegator) + .from(this.entityName) + .where(EntityCondition.makeCondition(operationFieldName, EntityOperator.IN, this.operationList)) + .cache(true) + .queryList(); } public void restart() { @@ -1180,7 +1181,7 @@ public class EntityPermissionChecker { if (UtilValidate.isEmpty(this.entityName)) { return; } - List<GenericValue> values = delegator.findByAnd(this.entityName, UtilMisc.toMap(this.entityIdName, entityId), null, true); + List<GenericValue> values = EntityQuery.use(delegator).from(this.entityName).where(this.entityIdName, entityId).cache(true).queryList(); for (GenericValue entity: values) { this.entityList.add(entity.getString(this.auxiliaryFieldName)); } @@ -1328,8 +1329,11 @@ public class EntityPermissionChecker { EntityExpr expr = EntityCondition.makeCondition(entityIdFieldName, EntityOperator.IN, idList); EntityExpr expr2 = EntityCondition.makeCondition(partyIdFieldName, partyId); - EntityConditionList<EntityExpr> condList = EntityCondition.makeCondition(UtilMisc.toList(expr, expr2)); - List<GenericValue> roleList = delegator.findList(entityName, condList, null, null, null, true); + List<GenericValue> roleList = EntityQuery.use(delegator) + .from(entityName) + .where(EntityCondition.makeCondition(UtilMisc.toList(expr, expr2))) + .cache(true) + .queryList(); List<GenericValue> roleListFiltered = EntityUtil.filterByDate(roleList); Set<String> distinctSet = new HashSet<String>(); for (GenericValue contentRole: roleListFiltered) { @@ -1347,7 +1351,7 @@ public class EntityPermissionChecker { contentOwnerList.add(ownerContentId); ModelEntity modelEntity = delegator.getModelEntity(entityName); String pkFieldName = modelEntity.getFirstPkFieldName(); - GenericValue ownerContent = delegator.findOne(entityName, UtilMisc.toMap(pkFieldName, ownerContentId), true); + GenericValue ownerContent = EntityQuery.use(delegator).from(entityName).where(pkFieldName, ownerContentId).cache(true).queryOne(); if (ownerContent != null) { getEntityOwners(delegator, ownerContent, contentOwnerList, entityName, ownerIdFieldName); } Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java Wed Dec 17 12:13:46 2014 @@ -57,6 +57,7 @@ import org.ofbiz.service.ModelService; import org.ofbiz.service.ServiceUtil; import org.xml.sax.SAXException; + /** * Entity Engine Sync Services */ @@ -348,7 +349,11 @@ public class EntitySyncContext { EntityCondition findValCondition = EntityCondition.makeCondition( EntityCondition.makeCondition(ModelEntity.CREATE_STAMP_TX_FIELD, EntityOperator.GREATER_THAN_EQUAL_TO, currentRunStartTime), EntityCondition.makeCondition(ModelEntity.CREATE_STAMP_TX_FIELD, EntityOperator.LESS_THAN, currentRunEndTime)); - EntityListIterator eli = delegator.find(modelEntity.getEntityName(), findValCondition, null, null, UtilMisc.toList(ModelEntity.CREATE_STAMP_TX_FIELD, ModelEntity.CREATE_STAMP_FIELD), null); + EntityListIterator eli = EntityQuery.use(delegator) + .from(modelEntity.getEntityName()) + .where(findValCondition) + .orderBy(ModelEntity.CREATE_STAMP_TX_FIELD, ModelEntity.CREATE_STAMP_FIELD) + .queryIterator(); GenericValue nextValue = null; long valuesPerEntity = 0; while ((nextValue = eli.next()) != null) { @@ -377,7 +382,11 @@ public class EntitySyncContext { EntityCondition findNextCondition = EntityCondition.makeCondition( EntityCondition.makeCondition(ModelEntity.CREATE_STAMP_TX_FIELD, EntityOperator.NOT_EQUAL, null), EntityCondition.makeCondition(ModelEntity.CREATE_STAMP_TX_FIELD, EntityOperator.GREATER_THAN_EQUAL_TO, currentRunEndTime)); - EntityListIterator eliNext = delegator.find(modelEntity.getEntityName(), findNextCondition, null, null, UtilMisc.toList(ModelEntity.CREATE_STAMP_TX_FIELD), null); + EntityListIterator eliNext = EntityQuery.use(delegator) + .from(modelEntity.getEntityName()) + .where(findNextCondition) + .orderBy(ModelEntity.CREATE_STAMP_TX_FIELD) + .queryIterator(); // get the first element and it's tx time value... GenericValue firstVal = eliNext.next(); eliNext.close(); @@ -491,7 +500,11 @@ public class EntitySyncContext { EntityCondition.makeCondition(ModelEntity.STAMP_TX_FIELD, EntityOperator.GREATER_THAN_EQUAL_TO, currentRunStartTime), EntityCondition.makeCondition(ModelEntity.STAMP_TX_FIELD, EntityOperator.LESS_THAN, currentRunEndTime), createdBeforeStartCond); - EntityListIterator eli = delegator.find(modelEntity.getEntityName(), findValCondition, null, null, UtilMisc.toList(ModelEntity.STAMP_TX_FIELD, ModelEntity.STAMP_FIELD), null); + EntityListIterator eli = EntityQuery.use(delegator) + .from(modelEntity.getEntityName()) + .where(findValCondition) + .orderBy(ModelEntity.STAMP_TX_FIELD, ModelEntity.STAMP_FIELD) + .queryIterator(); GenericValue nextValue = null; long valuesPerEntity = 0; while ((nextValue = eli.next()) != null) { @@ -522,7 +535,11 @@ public class EntitySyncContext { EntityCondition.makeCondition(ModelEntity.STAMP_TX_FIELD, EntityOperator.GREATER_THAN_EQUAL_TO, currentRunEndTime), EntityCondition.makeCondition(ModelEntity.CREATE_STAMP_TX_FIELD, EntityOperator.NOT_EQUAL, null), EntityCondition.makeCondition(ModelEntity.CREATE_STAMP_TX_FIELD, EntityOperator.LESS_THAN, currentRunEndTime)); - EntityListIterator eliNext = delegator.find(modelEntity.getEntityName(), findNextCondition, null, null, UtilMisc.toList(ModelEntity.STAMP_TX_FIELD), null); + EntityListIterator eliNext = EntityQuery.use(delegator) + .from(modelEntity.getEntityName()) + .where(findNextCondition) + .orderBy(ModelEntity.STAMP_TX_FIELD) + .queryIterator(); // get the first element and it's tx time value... GenericValue firstVal = eliNext.next(); eliNext.close(); @@ -617,7 +634,11 @@ public class EntitySyncContext { EntityCondition findValCondition = EntityCondition.makeCondition( EntityCondition.makeCondition(ModelEntity.STAMP_TX_FIELD, EntityOperator.GREATER_THAN_EQUAL_TO, currentRunStartTime), EntityCondition.makeCondition(ModelEntity.STAMP_TX_FIELD, EntityOperator.LESS_THAN, currentRunEndTime)); - EntityListIterator removeEli = delegator.find("EntitySyncRemove", findValCondition, null, null, UtilMisc.toList(ModelEntity.STAMP_TX_FIELD, ModelEntity.STAMP_FIELD), null); + EntityListIterator removeEli = EntityQuery.use(delegator) + .from("EntitySyncRemove") + .where(findValCondition) + .orderBy(ModelEntity.STAMP_TX_FIELD, ModelEntity.STAMP_FIELD) + .queryIterator(); GenericValue entitySyncRemove = null; while ((entitySyncRemove = removeEli.next()) != null) { // pull the PK from the EntitySyncRemove in the primaryKeyRemoved field, de-XML-serialize it @@ -658,7 +679,11 @@ public class EntitySyncContext { // if we didn't find anything for this entity, find the next value's Timestamp and keep track of it if (keysToRemove.size() == 0) { EntityCondition findNextCondition = EntityCondition.makeCondition(ModelEntity.STAMP_TX_FIELD, EntityOperator.GREATER_THAN_EQUAL_TO, currentRunEndTime); - EntityListIterator eliNext = delegator.find("EntitySyncRemove", findNextCondition, null, null, UtilMisc.toList(ModelEntity.STAMP_TX_FIELD), null); + EntityListIterator eliNext = EntityQuery.use(delegator) + .from("EntitySyncRemove") + .where(findNextCondition) + .orderBy(ModelEntity.STAMP_TX_FIELD) + .queryIterator(); // get the first element and it's tx time value... GenericValue firstVal = eliNext.next(); eliNext.close(); @@ -866,7 +891,12 @@ public class EntitySyncContext { Set<String> fieldsToSelect = UtilMisc.toSet(modelEntity.getPkFieldNames()); // find all instances of this entity with the STAMP_TX_FIELD != null, sort ascending to get lowest/oldest value first, then grab first and consider as candidate currentRunStartTime fieldsToSelect.add(ModelEntity.STAMP_TX_FIELD); - EntityListIterator eli = delegator.find(modelEntity.getEntityName(), EntityCondition.makeCondition(ModelEntity.STAMP_TX_FIELD, EntityOperator.NOT_EQUAL, null), null, fieldsToSelect, UtilMisc.toList(ModelEntity.STAMP_TX_FIELD), null); + EntityListIterator eli = EntityQuery.use(delegator) + .select(fieldsToSelect) + .from(modelEntity.getEntityName()) + .where(ModelEntity.STAMP_TX_FIELD, EntityOperator.NOT_EQUAL, null) + .orderBy(ModelEntity.STAMP_TX_FIELD) + .queryIterator(); GenericValue nextValue = eli.next(); eli.close(); if (nextValue != null) { @@ -1009,7 +1039,7 @@ public class EntitySyncContext { } else { try { // set the latest values from the EntitySyncHistory, based on the values on the EntitySync - GenericValue entitySyncHistory = delegator.findOne("EntitySyncHistory", false, "entitySyncId", entitySyncId, "startDate", startDate); + GenericValue entitySyncHistory = EntityQuery.use(delegator).from("EntitySyncHistory").where("entitySyncId", entitySyncId, "startDate", startDate).queryOne(); this.toCreateInserted = UtilMisc.toLong(entitySyncHistory.getLong("toCreateInserted")); this.toCreateUpdated = UtilMisc.toLong(entitySyncHistory.getLong("toCreateUpdated")); this.toCreateNotUpdated = UtilMisc.toLong(entitySyncHistory.getLong("toCreateNotUpdated")); Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncServices.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncServices.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncServices.java Wed Dec 17 12:13:46 2014 @@ -51,6 +51,7 @@ import org.ofbiz.entity.condition.Entity import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.serialize.SerializeException; import org.ofbiz.entity.serialize.XmlSerializer; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entityext.synchronization.EntitySyncContext.SyncAbortException; import org.ofbiz.entityext.synchronization.EntitySyncContext.SyncErrorException; import org.ofbiz.service.DispatchContext; @@ -172,7 +173,10 @@ public class EntitySyncServices { // check to make sure all foreign keys are created; if not create dummy values as place holders valueToCreate.checkFks(true); - GenericValue existingValue = delegator.findOne(valueToCreate.getEntityName(), valueToCreate.getPrimaryKey(), false); + GenericValue existingValue = EntityQuery.use(delegator) + .from(valueToCreate.getEntityName()) + .where(valueToCreate.getPrimaryKey()) + .queryOne(); if (existingValue == null) { delegator.create(valueToCreate); toCreateInserted++; @@ -197,7 +201,10 @@ public class EntitySyncServices { // check to make sure all foreign keys are created; if not create dummy values as place holders valueToStore.checkFks(true); - GenericValue existingValue = delegator.findOne(valueToStore.getEntityName(), valueToStore.getPrimaryKey(), false); + GenericValue existingValue = EntityQuery.use(delegator) + .from(valueToStore.getEntityName()) + .where(valueToStore.getPrimaryKey()) + .queryOne(); if (existingValue == null) { delegator.create(valueToStore); toStoreInserted++; @@ -596,7 +603,7 @@ public class EntitySyncServices { // find the largest keepRemoveInfoHours value on an EntitySyncRemove and kill everything before that, if none found default to 10 days (240 hours) double keepRemoveInfoHours = 24; - List<GenericValue> entitySyncRemoveList = delegator.findList("EntitySync", null, null, null, null, false); + List<GenericValue> entitySyncRemoveList = EntityQuery.use(delegator).from("EntitySync").queryList(); for (GenericValue entitySyncRemove: entitySyncRemoveList) { Double curKrih = entitySyncRemove.getDouble("keepRemoveInfoHours"); if (curKrih != null) { Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityCount.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityCount.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityCount.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityCount.java Wed Dec 17 12:13:46 2014 @@ -30,6 +30,7 @@ import org.ofbiz.entity.finder.EntityFin import org.ofbiz.entity.finder.EntityFinderUtil.ConditionList; import org.ofbiz.entity.finder.EntityFinderUtil.ConditionObject; import org.ofbiz.entity.model.ModelEntity; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.minilang.MiniLangException; import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; @@ -103,7 +104,7 @@ public final class EntityCount extends E if (this.havingCondition != null) { havingEntityCondition = this.havingCondition.createCondition(methodContext.getEnvMap(), modelEntity, delegator.getModelFieldTypeReader(modelEntity)); } - long count = delegator.findCountByCondition(entityName, whereEntityCondition, havingEntityCondition, null); + long count = EntityQuery.use(delegator).from(entityName).where(whereEntityCondition).having(havingEntityCondition).queryCount(); this.countFma.put(methodContext.getEnvMap(), count); } catch (GeneralException e) { String errMsg = "Exception thrown while performing entity count: " + e.getMessage(); Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/FindByAnd.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/FindByAnd.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/FindByAnd.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/FindByAnd.java Wed Dec 17 12:13:46 2014 @@ -29,6 +29,7 @@ import org.ofbiz.base.util.string.Flexib import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.condition.EntityCondition; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.minilang.MiniLangException; import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; @@ -76,7 +77,6 @@ public final class FindByAnd extends Ent boolean useCache = "true".equals(useCacheFse.expandString(methodContext.getEnvMap())); boolean useIterator = "true".equals(useIteratorFse.expandString(methodContext.getEnvMap())); List<String> orderByNames = orderByListFma.get(methodContext.getEnvMap()); - Collection<String> fieldsToSelectList = fieldsToSelectListFma.get(methodContext.getEnvMap()); Delegator delegator = getDelegator(methodContext); try { EntityCondition whereCond = null; @@ -85,9 +85,20 @@ public final class FindByAnd extends Ent whereCond = EntityCondition.makeCondition(fieldMap); } if (useIterator) { - listFma.put(methodContext.getEnvMap(), delegator.find(entityName, whereCond, null, UtilMisc.toSet(fieldsToSelectList), orderByNames, null)); + listFma.put(methodContext.getEnvMap(), EntityQuery.use(delegator) + .select(UtilMisc.toSet(fieldsToSelectListFma.get(methodContext.getEnvMap()))) + .from(entityName) + .where(whereCond) + .orderBy(orderByNames) + .queryList()); } else { - listFma.put(methodContext.getEnvMap(), delegator.findList(entityName, whereCond, UtilMisc.toSet(fieldsToSelectList), orderByNames, null, useCache)); + listFma.put(methodContext.getEnvMap(), EntityQuery.use(delegator) + .select(UtilMisc.toSet(fieldsToSelectListFma.get(methodContext.getEnvMap()))) + .from(entityName) + .where(whereCond) + .orderBy(orderByNames) + .cache(useCache) + .queryList()); } } catch (GenericEntityException e) { String errMsg = "Exception thrown while performing entity find: " + e.getMessage(); Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/FindByPrimaryKey.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/FindByPrimaryKey.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/FindByPrimaryKey.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/FindByPrimaryKey.java Wed Dec 17 12:13:46 2014 @@ -29,6 +29,7 @@ import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntity; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.minilang.MiniLangException; import org.ofbiz.minilang.MiniLangRuntimeException; import org.ofbiz.minilang.MiniLangValidate; @@ -88,7 +89,7 @@ public final class FindByPrimaryKey exte if (fieldsToSelectList != null) { valueFma.put(methodContext.getEnvMap(), delegator.findByPrimaryKeyPartial(delegator.makePK(entityName, inMap), UtilMisc.toSet(fieldsToSelectList))); } else { - valueFma.put(methodContext.getEnvMap(), delegator.findOne(entityName, inMap, useCache)); + valueFma.put(methodContext.getEnvMap(), EntityQuery.use(delegator).from(entityName).where(inMap).cache(useCache).queryOne()); } } catch (GenericEntityException e) { String errMsg = "Exception thrown while performing entity find: " + e.getMessage(); Modified: ofbiz/trunk/framework/security/src/org/ofbiz/security/SecurityFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/security/src/org/ofbiz/security/SecurityFactory.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/security/src/org/ofbiz/security/SecurityFactory.java (original) +++ ofbiz/trunk/framework/security/src/org/ofbiz/security/SecurityFactory.java Wed Dec 17 12:13:46 2014 @@ -38,6 +38,7 @@ import org.ofbiz.entity.condition.Entity import org.ofbiz.entity.condition.EntityConditionList; import org.ofbiz.entity.condition.EntityExpr; import org.ofbiz.entity.condition.EntityOperator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; /** @@ -104,7 +105,7 @@ public final class SecurityFactory { @Override public Iterator<GenericValue> findUserLoginSecurityGroupByUserLoginId(String userLoginId) { try { - List<GenericValue> collection = EntityUtil.filterByDate(delegator.findByAnd("UserLoginSecurityGroup", UtilMisc.toMap("userLoginId", userLoginId), null, true)); + List<GenericValue> collection = EntityUtil.filterByDate(EntityQuery.use(delegator).from("UserLoginSecurityGroup").where("userLoginId", userLoginId).cache(true).queryList()); return collection.iterator(); } catch (GenericEntityException e) { Debug.logWarning(e, module); @@ -197,7 +198,7 @@ public final class SecurityFactory { if (hasEntityPermission(application + "_ROLE", action, userLogin)) { // we have the permission now, we check to make sure we are allowed access try { - List<GenericValue> roleTest = delegator.findList(entityName, condition, null, null, null, false); + List<GenericValue> roleTest = EntityQuery.use(delegator).from(entityName).where(condition).queryList(); if (!roleTest.isEmpty()) { return true; } @@ -263,7 +264,7 @@ public final class SecurityFactory { @Override public boolean securityGroupPermissionExists(String groupId, String permission) { try { - return delegator.findOne("SecurityGroupPermission", UtilMisc.toMap("groupId", groupId, "permissionId", permission), true) != null; + return EntityQuery.use(delegator).from("SecurityGroupPermission").where("groupId", groupId, "permissionId", permission).cache(true).queryOne() != null; } catch (GenericEntityException e) { Debug.logWarning(e, module); return false; |
Free forum by Nabble | Edit this page |