Skip to content

Commit

Permalink
Improved: Optimization on removeJob service (OFBIZ-13182)
Browse files Browse the repository at this point in the history
On removeJob service when we'll remove a job sandbox, we also delete other element linked (RecurrenceInfo and RuntimeData).

Before their remove we control that no other job are connected to them, but currently we resolve the list and ensure that it empty.

To be fast, we just ask the database through a count and ensure that is zero.
  • Loading branch information
nmalin committed Nov 20, 2024
1 parent 2b684ba commit 2c1dd14
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
*******************************************************************************/
package org.apache.ofbiz.service.job;

import java.util.List;
import javax.transaction.Transaction;
import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.entity.GenericEntityException;
import org.apache.ofbiz.entity.GenericValue;
import org.apache.ofbiz.entity.transaction.GenericTransactionException;
import org.apache.ofbiz.entity.transaction.TransactionUtil;
import org.apache.ofbiz.entity.util.EntityQuery;

public final class JobUtil {

Expand All @@ -43,16 +43,18 @@ public static void removeJob(GenericValue jobValue) {
jobValue.remove();
GenericValue relatedValue = jobValue.getRelatedOne("RecurrenceInfo", false);
if (relatedValue != null) {
List<GenericValue> valueList = relatedValue.getRelated("JobSandbox", null, null, false);
if (valueList.isEmpty()) {
if (EntityQuery.use(jobValue.getDelegator()).from("JobSandbox")
.where("recurrenceInfoId", relatedValue.get("recurrenceInfoId"))
.queryCount() == 0) {
relatedValue.remove();
relatedValue.removeRelated("RecurrenceRule");
}
}
relatedValue = jobValue.getRelatedOne("RuntimeData", false);
if (relatedValue != null) {
List<GenericValue> valueList = relatedValue.getRelated("JobSandbox", null, null, false);
if (valueList.isEmpty()) {
if (EntityQuery.use(jobValue.getDelegator()).from("JobSandbox")
.where("runtimeDataId", relatedValue.get("runtimeDataId"))
.queryCount() == 0) {
relatedValue.remove();
}
}
Expand Down

0 comments on commit 2c1dd14

Please sign in to comment.