Improved: Replace all delegator findByAnd and findOne method calling by EntityQuery methods (OFBIZ-10029)

Applied slightly modified patch, rearrange import properly, 
Thanks Suraj Khurana for your contribution

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-plugins/trunk@1817986 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Deepak Dixit
2017-12-13 09:02:59 +00:00
parent bced76ed99
commit f1557bef30
18 changed files with 62 additions and 61 deletions
@@ -68,7 +68,7 @@ import org.apache.ofbiz.entity.GenericEntityException;
import org.apache.ofbiz.entity.GenericValue;
import org.apache.ofbiz.entity.condition.EntityCondition;
import org.apache.ofbiz.entity.condition.EntityOperator;
import org.apache.ofbiz.entity.util.EntityUtil;
import org.apache.ofbiz.entity.util.EntityQuery;
import org.apache.ofbiz.service.LocalDispatcher;
import org.apache.ofbiz.service.ServiceUtil;
@@ -556,10 +556,9 @@ public abstract class AbstractPricatParser implements InterfacePricatParser {
try {
GenericValue historyValue = null;
if (sequenceNum < 1L) {
historyValue = EntityUtil.getFirst(EntityUtil.filterByDate(delegator.findByAnd("ExcelImportHistory",
UtilMisc.toMap("userLoginId", userLoginId, "logFileName", logFileName), UtilMisc.toList("sequenceNum DESC"), false)));
historyValue = EntityQuery.use(delegator).from("ExcelImportHistory").where("userLoginId", userLoginId, "logFileName", logFileName).orderBy("sequenceNum DESC").filterByDate().queryFirst();
} else {
historyValue = delegator.findOne("ExcelImportHistory", UtilMisc.toMap("userLoginId", userLoginId, "sequenceNum", (Long) sequenceNum), false);
historyValue = EntityQuery.use(delegator).from("ExcelImportHistory").where("userLoginId", userLoginId, "sequenceNum", (Long) sequenceNum).queryOne();
}
Timestamp now = UtilDateTime.nowTimestamp();
if (UtilValidate.isEmpty(historyValue)) {
@@ -601,7 +600,7 @@ public abstract class AbstractPricatParser implements InterfacePricatParser {
Delegator delegator = (Delegator) request.getAttribute("delegator");
GenericValue historyValue = null;
try {
historyValue = delegator.findOne("ExcelImportHistory", UtilMisc.toMap("userLoginId", userLoginId, "sequenceNum", Long.valueOf(sequenceNum)), false);
historyValue = EntityQuery.use(delegator).from("ExcelImportHistory").where("userLoginId", userLoginId, "sequenceNum", Long.valueOf(sequenceNum)).queryOne();
} catch (NumberFormatException e) {
Debug.logError(e.getMessage(), module);
return false;
@@ -623,7 +622,7 @@ public abstract class AbstractPricatParser implements InterfacePricatParser {
protected void cleanupLogAndCommentedExcel() {
try {
report.print(UtilProperties.getMessage(resource, "CLEANUP_LOGANDEXCEL_BEGIN", locale), InterfaceReport.FORMAT_DEFAULT);
List<GenericValue> historyValues = delegator.findByAnd("ExcelImportHistory", UtilMisc.toMap("userLoginId", userLoginId), UtilMisc.toList("sequenceNum DESC"), false);
List<GenericValue> historyValues = EntityQuery.use(delegator).from("ExcelImportHistory").where("userLoginId", userLoginId).orderBy("sequenceNum DESC").queryList();
if (UtilValidate.isEmpty(historyValues) || historyValues.size() <= HISTORY_MAX_FILENUMBER) {
report.print(UtilProperties.getMessage(resource, "HistoryLessThan", new Object[] {String.valueOf(HISTORY_MAX_FILENUMBER)}, locale), InterfaceReport.FORMAT_NOTE);
report.println(" ... " + UtilProperties.getMessage(resource, "skipped", locale), InterfaceReport.FORMAT_NOTE);
@@ -34,12 +34,12 @@ import org.apache.ofbiz.base.location.ComponentLocationResolver;
import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.base.util.FileUtil;
import org.apache.ofbiz.base.util.UtilHttp;
import org.apache.ofbiz.base.util.UtilMisc;
import org.apache.ofbiz.base.util.UtilProperties;
import org.apache.ofbiz.base.util.UtilValidate;
import org.apache.ofbiz.entity.Delegator;
import org.apache.ofbiz.entity.GenericEntityException;
import org.apache.ofbiz.entity.GenericValue;
import org.apache.ofbiz.entity.util.EntityQuery;
public class PricatEvents {
@@ -149,7 +149,7 @@ public class PricatEvents {
Delegator delegator = (Delegator) request.getAttribute("delegator");
GenericValue historyValue = null;
try {
historyValue = delegator.findOne("ExcelImportHistory", UtilMisc.toMap("userLoginId", userLoginId, "sequenceNum", Long.valueOf(sequenceNum)), false);
historyValue = EntityQuery.use(delegator).from("ExcelImportHistory").where("userLoginId", userLoginId, "sequenceNum", Long.valueOf(sequenceNum)).queryOne();
} catch (NumberFormatException e) {
Debug.logError(e.getMessage(), module);
return "error";
@@ -57,6 +57,7 @@ import org.apache.ofbiz.entity.GenericValue;
import org.apache.ofbiz.entity.condition.EntityCondition;
import org.apache.ofbiz.entity.condition.EntityOperator;
import org.apache.ofbiz.entity.util.EntityUtil;
import org.apache.ofbiz.entity.util.EntityQuery;
import org.apache.ofbiz.service.LocalDispatcher;
/**
@@ -341,8 +342,7 @@ public class PricatParseExcelHtmlThread extends AbstractReportThread {
public synchronized long addExcelImportHistory() {
long latestId = 1;
try {
List<GenericValue> historyValues = delegator.findByAnd("ExcelImportHistory", UtilMisc.toMap("userLoginId", userLoginId), UtilMisc.toList("sequenceNum DESC"), false);
GenericValue latestHistoryValue = EntityUtil.getFirst(historyValues);
GenericValue latestHistoryValue = EntityQuery.use(delegator).from("ExcelImportHistory").where("userLoginId", userLoginId).orderBy("sequenceNum DESC").queryFirst();
if (UtilValidate.isNotEmpty(latestHistoryValue)) {
latestId = latestHistoryValue.getLong("sequenceNum") + 1;
}
@@ -36,6 +36,7 @@ import org.apache.ofbiz.entity.Delegator;
import org.apache.ofbiz.entity.GenericEntityException;
import org.apache.ofbiz.entity.GenericValue;
import org.apache.ofbiz.entity.transaction.GenericTransactionException;
import org.apache.ofbiz.entity.util.EntityQuery;
import org.apache.ofbiz.htmlreport.InterfaceReport;
import org.apache.ofbiz.order.finaccount.FinAccountHelper;
import org.apache.ofbiz.pricat.AbstractPricatParser;
@@ -165,7 +166,7 @@ public class SamplePricatParser extends AbstractPricatParser {
return false;
} else {
try {
GenericValue currencyUom = delegator.findOne("Uom", UtilMisc.toMap("uomId", currencyId), false);
GenericValue currencyUom = EntityQuery.use(delegator).from("Uom").where("uomId", currencyId).queryOne();
if (!"CURRENCY_MEASURE".equals(currencyUom.getString("uomTypeId"))) {
String errorMessage = UtilProperties.getMessage(resource, "CurrencyIdNotCurrency", new Object[] {currencyId}, locale);
report.println(errorMessage, InterfaceReport.FORMAT_ERROR);