From f107f75aedbcf236bf35c07d455ea1ae4d6b0bb8 Mon Sep 17 00:00:00 2001 From: Adam Heath Date: Sun, 21 Oct 2007 03:52:32 +0000 Subject: [PATCH] All things delegator/entity are now generified. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@586848 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/org/ofbiz/service/ServiceUtil.java | 28 ++++++++----------- .../service/engine/GenericAsyncEngine.java | 3 +- .../src/org/ofbiz/service/job/JobManager.java | 28 ++++++++----------- .../service/job/PersistedServiceJob.java | 6 ++-- .../service/semaphore/ServiceSemaphore.java | 3 +- 5 files changed, 28 insertions(+), 40 deletions(-) diff --git a/framework/service/src/org/ofbiz/service/ServiceUtil.java b/framework/service/src/org/ofbiz/service/ServiceUtil.java index 2e47a85423..cb87462f7c 100644 --- a/framework/service/src/org/ofbiz/service/ServiceUtil.java +++ b/framework/service/src/org/ofbiz/service/ServiceUtil.java @@ -361,17 +361,17 @@ public class ServiceUtil { // create the conditions to query EntityCondition pool = new EntityExpr("poolId", EntityOperator.EQUALS, sendPool); - List finExp = UtilMisc.toList(new EntityExpr("finishDateTime", EntityOperator.NOT_EQUAL, null)); + List finExp = UtilMisc.toList(new EntityExpr("finishDateTime", EntityOperator.NOT_EQUAL, null)); finExp.add(new EntityExpr("finishDateTime", EntityOperator.LESS_THAN, purgeTime)); - List canExp = UtilMisc.toList(new EntityExpr("cancelDateTime", EntityOperator.NOT_EQUAL, null)); + List canExp = UtilMisc.toList(new EntityExpr("cancelDateTime", EntityOperator.NOT_EQUAL, null)); canExp.add(new EntityExpr("cancelDateTime", EntityOperator.LESS_THAN, purgeTime)); - EntityCondition cancelled = new EntityConditionList(canExp, EntityOperator.AND); - EntityCondition finished = new EntityConditionList(finExp, EntityOperator.AND); + EntityCondition cancelled = new EntityConditionList(canExp, EntityOperator.AND); + EntityCondition finished = new EntityConditionList(finExp, EntityOperator.AND); - EntityCondition doneCond = new EntityConditionList(UtilMisc.toList(cancelled, finished), EntityOperator.OR); - EntityCondition mainCond = new EntityConditionList(UtilMisc.toList(doneCond, pool), EntityOperator.AND); + EntityCondition doneCond = new EntityConditionList(UtilMisc.toList(cancelled, finished), EntityOperator.OR); + EntityCondition mainCond = new EntityConditionList(UtilMisc.toList(doneCond, pool), EntityOperator.AND); // configure the find options EntityFindOptions findOptions = new EntityFindOptions(); @@ -391,7 +391,7 @@ public class ServiceUtil { boolean beganTx1 = false; while (!noMoreResults) { // current list of records - List curList = null; + List curList = null; try { // begin this transaction beganTx1 = TransactionUtil.begin(); @@ -419,11 +419,9 @@ public class ServiceUtil { // remove each from the list in its own transaction if (curList != null && curList.size() > 0) { // list of runtime data IDs to attempt to delete - List runtimeToDelete = FastList.newInstance(); + List runtimeToDelete = FastList.newInstance(); - Iterator curIter = curList.iterator(); - while (curIter.hasNext()) { - GenericValue job = (GenericValue) curIter.next(); + for (GenericValue job: curList) { String runtimeId = job.getString("runtimeDataId"); String jobId = job.getString("jobId"); boolean beganTx2 = false; @@ -451,9 +449,7 @@ public class ServiceUtil { // we do this so that the ones which cannot be deleted to not cause // the entire group to rollback; some may be attached to multiple jobs. if (runtimeToDelete.size() > 0) { - Iterator delIter = runtimeToDelete.iterator(); - while (delIter.hasNext()) { - String runtimeId = (String) delIter.next(); + for (String runtimeId: runtimeToDelete) { boolean beganTx3 = false; try { beganTx3 = TransactionUtil.begin(); @@ -507,7 +503,7 @@ public class ServiceUtil { } String jobId = (String) context.get("jobId"); - Map fields = UtilMisc.toMap("jobId", jobId); + Map fields = UtilMisc.toMap("jobId", jobId); GenericValue job = null; try { @@ -545,7 +541,7 @@ public class ServiceUtil { } String jobId = (String) context.get("jobId"); - Map fields = UtilMisc.toMap("jobId", jobId); + Map fields = UtilMisc.toMap("jobId", jobId); GenericValue job = null; try { diff --git a/framework/service/src/org/ofbiz/service/engine/GenericAsyncEngine.java b/framework/service/src/org/ofbiz/service/engine/GenericAsyncEngine.java index 90c6b8391d..3120ab63bf 100644 --- a/framework/service/src/org/ofbiz/service/engine/GenericAsyncEngine.java +++ b/framework/service/src/org/ofbiz/service/engine/GenericAsyncEngine.java @@ -91,8 +91,7 @@ public abstract class GenericAsyncEngine extends AbstractEngine { // Create the runtime data String dataId = dispatcher.getDelegator().getNextSeqId("RuntimeData"); - GenericValue runtimeData = dispatcher.getDelegator().makeValue("RuntimeData", - UtilMisc.toMap("runtimeDataId", dataId)); + GenericValue runtimeData = dispatcher.getDelegator().makeValue("RuntimeData", "runtimeDataId", dataId); runtimeData.set("runtimeInfo", XmlSerializer.serialize(context)); runtimeData.create(); diff --git a/framework/service/src/org/ofbiz/service/job/JobManager.java b/framework/service/src/org/ofbiz/service/job/JobManager.java index 5756e002c0..ef743fbd55 100644 --- a/framework/service/src/org/ofbiz/service/job/JobManager.java +++ b/framework/service/src/org/ofbiz/service/job/JobManager.java @@ -106,20 +106,20 @@ public class JobManager { public synchronized Iterator poll() { List poll = FastList.newInstance(); - Collection jobEnt = null; + Collection jobEnt = null; // sort the results by time - List order = UtilMisc.toList("runTime"); + List order = UtilMisc.toList("runTime"); // basic query - List expressions = UtilMisc.toList(new EntityExpr("runTime", EntityOperator.LESS_THAN_EQUAL_TO, + List expressions = UtilMisc.toList(new EntityExpr("runTime", EntityOperator.LESS_THAN_EQUAL_TO, UtilDateTime.nowTimestamp()), new EntityExpr("startDateTime", EntityOperator.EQUALS, null), new EntityExpr("cancelDateTime", EntityOperator.EQUALS, null), new EntityExpr("runByInstanceId", EntityOperator.EQUALS, null)); // limit to just defined pools List pools = ServiceConfigUtil.getRunPools(); - List poolsExpr = UtilMisc.toList(new EntityExpr("poolId", EntityOperator.EQUALS, null)); + List poolsExpr = UtilMisc.toList(new EntityExpr("poolId", EntityOperator.EQUALS, null)); if (pools != null) { Iterator poolsIter = pools.iterator(); while (poolsIter.hasNext()) { @@ -129,9 +129,9 @@ public class JobManager { } // make the conditions - EntityCondition baseCondition = new EntityConditionList(expressions, EntityOperator.AND); - EntityCondition poolCondition = new EntityConditionList(poolsExpr, EntityOperator.OR); - EntityCondition mainCondition = new EntityConditionList(UtilMisc.toList(baseCondition, poolCondition), EntityOperator.AND); + EntityCondition baseCondition = new EntityConditionList(expressions, EntityOperator.AND); + EntityCondition poolCondition = new EntityConditionList(poolsExpr, EntityOperator.OR); + EntityCondition mainCondition = new EntityConditionList(UtilMisc.toList(baseCondition, poolCondition), EntityOperator.AND); // we will loop until we have no more to do boolean pollDone = false; @@ -156,9 +156,7 @@ public class JobManager { //jobEnt = delegator.findByCondition("JobSandbox", mainCondition, null, order); if (jobEnt != null && jobEnt.size() > 0) { - Iterator i = jobEnt.iterator(); - while (i.hasNext()) { - GenericValue v = (GenericValue) i.next(); + for (GenericValue v: jobEnt) { DispatchContext dctx = getDispatcher().getDispatchContext(); if (dctx == null) { Debug.logError("Unable to locate DispatchContext object; not running job!", module); @@ -204,9 +202,9 @@ public class JobManager { public synchronized void reloadCrashedJobs() { String instanceId = UtilProperties.getPropertyValue("general.properties", "unique.instanceId", "ofbiz0"); - List crashed = null; + List crashed = null; - List exprs = UtilMisc.toList(new EntityExpr("finishDateTime", EntityOperator.EQUALS, null)); + List exprs = UtilMisc.toList(new EntityExpr("finishDateTime", EntityOperator.EQUALS, null)); exprs.add(new EntityExpr("cancelDateTime", EntityOperator.EQUALS, null)); exprs.add(new EntityExpr("runByInstanceId", EntityOperator.EQUALS, instanceId)); try { @@ -218,9 +216,7 @@ public class JobManager { if (crashed != null && crashed.size() > 0) { try { int rescheduled = 0; - Iterator i = crashed.iterator(); - while (i.hasNext()) { - GenericValue job = (GenericValue) i.next(); + for (GenericValue job: crashed) { long runtime = job.getTimestamp("runTime").getTime(); RecurrenceInfo ri = JobManager.getRecurrenceInfo(job); if (ri != null) { @@ -401,7 +397,7 @@ public class JobManager { if (UtilValidate.isEmpty(jobName)) { jobName = Long.toString((new Date().getTime())); } - Map jFields = UtilMisc.toMap("jobName", jobName, "runTime", new java.sql.Timestamp(startTime), + Map jFields = UtilMisc.toMap("jobName", jobName, "runTime", new java.sql.Timestamp(startTime), "serviceName", serviceName, "recurrenceInfoId", infoId, "runtimeDataId", dataId); // set the pool ID diff --git a/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java b/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java index b903f96c00..f1f86ee58d 100644 --- a/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java +++ b/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java @@ -268,8 +268,7 @@ public class PersistedServiceJob extends GenericServiceJob { // gets the job value object private GenericValue getJob() throws InvalidJobException { try { - Map fields = UtilMisc.toMap("jobId", getJobId()); - GenericValue jobObj = delegator.findByPrimaryKey("JobSandbox", fields); + GenericValue jobObj = delegator.findByPrimaryKey("JobSandbox", "jobId", getJobId()); if (jobObj == null) { throw new InvalidJobException("Job [" + getJobId() + "] came back null from datasource"); @@ -288,10 +287,9 @@ public class PersistedServiceJob extends GenericServiceJob { return 0; } - Map fields = UtilMisc.toMap("parentJobId", pJobId, "statusId", "SERVICE_FAILED"); long count = 0; try { - count = delegator.findCountByAnd("JobSandbox", fields); + count = delegator.findCountByAnd("JobSandbox", "parentJobId", pJobId, "statusId", "SERVICE_FAILED"); } catch (GenericEntityException e) { Debug.logError(e, module); } diff --git a/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java b/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java index 1e3571f4d1..fcbe8ce850 100644 --- a/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java +++ b/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java @@ -109,8 +109,7 @@ public class ServiceSemaphore { } if (semaphore == null) { - Map fields = UtilMisc.toMap("serviceName", model.name, "lockThread", threadName, "lockTime", lockTime); - semaphore = delegator.makeValue("ServiceSemaphore", fields); + semaphore = delegator.makeValue("ServiceSemaphore", "serviceName", model.name, "lockThread", threadName, "lockTime", lockTime); // use the special method below so we can reuse the unqiue tx functions dbWrite(semaphore, false);