Author: ashish
Date: Wed Dec 17 12:13:46 2014 New Revision: 1646212 URL: http://svn.apache.org/r1646212 Log: Applied framework related patch from jira issue - OFBIZ-5844 - Convert java files to EntityQuery. Thanks Arun for the contribution. Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java ofbiz/trunk/framework/common/src/org/ofbiz/common/FindServices.java ofbiz/trunk/framework/common/src/org/ofbiz/common/KeywordSearchUtil.java ofbiz/trunk/framework/common/src/org/ofbiz/common/UrlServletHelper.java ofbiz/trunk/framework/common/src/org/ofbiz/common/geo/GeoWorker.java ofbiz/trunk/framework/common/src/org/ofbiz/common/login/LdapAuthenticationServices.java ofbiz/trunk/framework/common/src/org/ofbiz/common/login/LoginServices.java ofbiz/trunk/framework/common/src/org/ofbiz/common/preferences/PreferenceServices.java ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting/ScriptHelperImpl.java ofbiz/trunk/framework/common/src/org/ofbiz/common/status/StatusServices.java ofbiz/trunk/framework/common/src/org/ofbiz/common/status/StatusWorker.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityTypeUtil.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtil.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityUtilProperties.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/EntityGroupUtil.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataLoadContainer.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/permission/EntityPermissionChecker.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncContext.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/synchronization/EntitySyncServices.java ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityCount.java ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/FindByAnd.java ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/FindByPrimaryKey.java ofbiz/trunk/framework/security/src/org/ofbiz/security/SecurityFactory.java ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/ExpressionUiHelper.java ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/TemporalExpressionWorker.java ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEntityAutoTests.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ProtectViewWorker.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/website/WebSiteWorker.java ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/GenericWebEvent.java ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/PortalPageWorker.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/tree/ModelTree.java Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java Wed Dec 17 12:13:46 2014 @@ -56,6 +56,7 @@ import org.ofbiz.entity.GenericEntityExc import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.transaction.TransactionUtil; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; @@ -506,7 +507,7 @@ public class CommonServices { long count = -1; try { - count = delegator.findCountByCondition("SequenceValueItem", null, null, null); + count = EntityQuery.use(delegator).from("SequenceValueItem").queryCount(); } catch (GenericEntityException e) { Debug.logError(e.getMessage(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "CommonPingDatasourceCannotConnect", locale)); Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonWorkers.java Wed Dec 17 12:13:46 2014 @@ -65,7 +65,7 @@ public class CommonWorkers { List<GenericValue> countriesList = new LinkedList<GenericValue>(); try { - countriesList = delegator.findList("Geo", EntityCondition.makeCondition(exprs), null, UtilMisc.toList("geoName"), null, true); + countriesList = EntityQuery.use(delegator).from("Geo").where(exprs).orderBy("geoName").cache(true).queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Cannot lookup Geo", module); } @@ -93,9 +93,8 @@ public class CommonWorkers { List<GenericValue> geoList = new LinkedList<GenericValue>(); EntityCondition condition = EntityCondition.makeCondition(EntityOperator.OR, EntityCondition.makeCondition("geoTypeId", "STATE"), EntityCondition.makeCondition("geoTypeId", "PROVINCE"), EntityCondition.makeCondition("geoTypeId", "TERRITORY"), EntityCondition.makeCondition("geoTypeId", "MUNICIPALITY")); - List<String> sortList = UtilMisc.toList("geoName"); try { - geoList = delegator.findList("Geo", condition, null, sortList, null, true); + geoList = EntityQuery.use(delegator).from("Geo").where(condition).orderBy("geoName").cache(true).queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Cannot lookup State Geos: " + e.toString(), module); } @@ -124,11 +123,20 @@ public class CommonWorkers { try { // Check if the country is a country group and get recursively the // states - EntityCondition stateRegionFindCond = EntityCondition.makeCondition(EntityCondition.makeCondition("geoIdFrom", country), EntityCondition.makeCondition("geoAssocTypeId", "GROUP_MEMBER"), EntityCondition.makeCondition("geoTypeId", "GROUP")); - List<GenericValue> regionList = delegator.findList("GeoAssocAndGeoToWithState", stateRegionFindCond, null, sortList, null, true); + List<GenericValue> regionList = EntityQuery.use(delegator) + .from("GeoAssocAndGeoToWithState") + .where("geoIdFrom", country, "geoAssocTypeId", "GROUP_MEMBER", "geoTypeId", "GROUP") + .orderBy(sortList) + .cache(true) + .queryList(); if (regionList.size() == 1) { for (GenericValue region : regionList) { - List<GenericValue> tmpState = delegator.findList("GeoAssocAndGeoTo", EntityCondition.makeCondition("geoId", region.getString("geoIdFrom")), null, sortList, null, true); + List<GenericValue> tmpState = EntityQuery.use(delegator) + .from("GeoAssocAndGeoTo") + .where("geoId", region.getString("geoIdFrom")) + .orderBy(sortList) + .cache(true) + .queryList(); for (GenericValue state : tmpState) { geoList.addAll(getAssociatedStateList(delegator, state.getString("geoIdFrom"), listOrderBy)); } @@ -141,8 +149,14 @@ public class CommonWorkers { EntityCondition.makeCondition("geoAssocTypeId", "REGIONS"), EntityCondition.makeCondition(EntityOperator.OR, EntityCondition.makeCondition("geoTypeId", "STATE"), EntityCondition.makeCondition("geoTypeId", "PROVINCE"), EntityCondition.makeCondition("geoTypeId", "MUNICIPALITY"), EntityCondition.makeCondition("geoTypeId", "COUNTY"))); - geoList.addAll(delegator.findList("GeoAssocAndGeoToWithState", stateProvinceFindCond, null, sortList, null, true)); - } catch (GenericEntityException e) { + geoList.addAll(EntityQuery.use(delegator) + .from("GeoAssocAndGeoToWithState") + .where(stateProvinceFindCond) + .orderBy(sortList) + .cache(true) + .queryList() + ); + } catch (GenericEntityException e){ Debug.logError(e, "Cannot lookup Geo", module); } Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/FindServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/FindServices.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/FindServices.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/FindServices.java Wed Dec 17 12:13:46 2014 @@ -53,6 +53,7 @@ import org.ofbiz.entity.model.ModelEntit import org.ofbiz.entity.model.ModelField; import org.ofbiz.entity.util.EntityFindOptions; import org.ofbiz.entity.util.EntityListIterator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.entity.util.EntityUtilProperties; import org.ofbiz.service.DispatchContext; @@ -602,7 +603,6 @@ public class FindServices { EntityConditionList<EntityCondition> entityConditionList = UtilGenerics.cast(context.get("entityConditionList")); List<String> orderByList = checkList(context.get("orderByList"), String.class); boolean noConditionFind = "Y".equals(context.get("noConditionFind")); - boolean distinct = "Y".equals(context.get("distinct")); List<String> fieldList = UtilGenerics.checkList(context.get("fieldList")); Locale locale = (Locale) context.get("locale"); Set<String> fieldSet = null; @@ -617,8 +617,15 @@ public class FindServices { int listSize = 0; try { if (noConditionFind || (entityConditionList != null && entityConditionList.getConditionListSize() > 0)) { - listIt = delegator.find(entityName, entityConditionList, null, fieldSet, orderByList, - new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, -1, maxRows, distinct)); + listIt = EntityQuery.use(delegator) + .select(fieldSet) + .from(entityName) + .where(entityConditionList) + .orderBy(orderByList) + .cursorScrollInsensitive() + .maxRows(maxRows) + .distinct() + .queryIterator(); listSize = listIt.getResultsSizeAfterPartialList(); } } catch (GenericEntityException e) { Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/KeywordSearchUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/KeywordSearchUtil.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/KeywordSearchUtil.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/KeywordSearchUtil.java Wed Dec 17 12:13:46 2014 @@ -33,6 +33,7 @@ import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityQuery; /** * A few utility methods related to Keyword Search. @@ -217,7 +218,7 @@ public class KeywordSearchUtil { boolean replaceEnteredKeyword = false; try { - List<GenericValue> thesaurusList = delegator.findByAnd("KeywordThesaurus", UtilMisc.toMap("enteredKeyword", enteredKeyword), null, true); + List<GenericValue> thesaurusList = EntityQuery.use(delegator).from("KeywordThesaurus").where("enteredKeyword", enteredKeyword).cache(true).queryList(); for (GenericValue keywordThesaurus: thesaurusList) { String relationshipEnumId = (String) keywordThesaurus.get("relationshipEnumId"); if (thesaurusRelsToInclude.contains(relationshipEnumId)) { Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/UrlServletHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/UrlServletHelper.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/UrlServletHelper.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/UrlServletHelper.java Wed Dec 17 12:13:46 2014 @@ -60,7 +60,7 @@ public class UrlServletHelper extends Co //Use base delegator for fetching data from entity of entityGroup org.ofbiz.tenant Delegator baseDelegator = DelegatorFactory.getDelegator(delegator.getDelegatorBaseName()); - GenericValue tenantDomainName = baseDelegator.findOne("TenantDomainName", UtilMisc.toMap("domainName", serverName), false); + GenericValue tenantDomainName = EntityQuery.use(baseDelegator).from("TenantDomainName").where("domainName", serverName).queryOne(); if (UtilValidate.isNotEmpty(tenantDomainName)) { String tenantId = tenantDomainName.getString("tenantId"); @@ -157,7 +157,11 @@ public class UrlServletHelper extends Co // check path alias GenericValue pathAlias = null; try { - pathAlias = EntityQuery.use(delegator).from("WebSitePathAlias").where("webSiteId", webSiteId, "pathAlias", pathInfo).cache().queryOne(); + pathAlias = EntityQuery.use(delegator) + .from("WebSitePathAlias") + .where("webSiteId", webSiteId, "pathAlias", pathInfo) + .cache() + .queryOne(); } catch (GenericEntityException e) { Debug.logError(e, module); } @@ -182,7 +186,10 @@ public class UrlServletHelper extends Co } else { // send 404 error if a URI is alias TO try { - List<GenericValue> aliasTos = delegator.findByAnd("WebSitePathAlias", UtilMisc.toMap("webSiteId", webSiteId, "aliasTo", httpRequest.getRequestURI()), null, false); + List<GenericValue> aliasTos = EntityQuery.use(delegator) + .from("WebSitePathAlias") + .where("webSiteId", webSiteId, "aliasTo", httpRequest.getRequestURI()) + .queryList(); if (UtilValidate.isNotEmpty(aliasTos)) { httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "Not Found"); return; Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/geo/GeoWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/geo/GeoWorker.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/geo/GeoWorker.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/geo/GeoWorker.java Wed Dec 17 12:13:46 2014 @@ -91,7 +91,11 @@ public class GeoWorker { } Map<String, String> geoIdByTypeMapTemp = new LinkedHashMap<String, String>(); for (Map.Entry<String, String> geoIdByTypeEntry: geoIdByTypeMapOrig.entrySet()) { - List<GenericValue> geoAssocList = delegator.findByAnd("GeoAssoc", UtilMisc.toMap("geoIdTo", geoIdByTypeEntry.getValue(), "geoAssocTypeId", "REGIONS"), null, true); + List<GenericValue> geoAssocList = EntityQuery.use(delegator) + .from("GeoAssoc") + .where("geoIdTo", geoIdByTypeEntry.getValue(), "geoAssocTypeId", "REGIONS") + .cache(true) + .queryList(); for (GenericValue geoAssoc: geoAssocList) { GenericValue newGeo = EntityQuery.use(delegator).from("Geo").where("geoId", geoAssoc.get("geoId")).cache().queryOne(); geoIdByTypeMapTemp.put(newGeo.getString("geoTypeId"), newGeo.getString("geoId")); @@ -127,13 +131,17 @@ public class GeoWorker { List<GenericValue> gptList = null; if (UtilValidate.isNotEmpty(secondId) && UtilValidate.isNotEmpty(secondValueId)) { try { - gptList = delegator.findByAnd(entityName, UtilMisc.toMap(mainId, mainValueId, secondId, secondValueId), UtilMisc.toList("-fromDate"), false); + gptList = EntityQuery.use(delegator) + .from(entityName) + .where(mainId, mainValueId, secondId, secondValueId) + .orderBy("-fromDate") + .queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Error while finding latest GeoPoint for " + mainId + " with Id [" + mainValueId + "] and " + secondId + " Id [" + secondValueId + "] " + e.toString(), module); } } else { try { - gptList = delegator.findByAnd(entityName, UtilMisc.toMap(mainId, mainValueId), UtilMisc.toList("-fromDate"), false); + gptList = EntityQuery.use(delegator).from(entityName).where(mainId, mainValueId).orderBy("-fromDate").queryList(); } catch (GenericEntityException e) { Debug.logError(e, "Error while finding latest GeoPoint for " + mainId + " with Id [" + mainValueId + "] " + e.toString(), module); } Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/login/LdapAuthenticationServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/login/LdapAuthenticationServices.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/login/LdapAuthenticationServices.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/login/LdapAuthenticationServices.java Wed Dec 17 12:13:46 2014 @@ -37,6 +37,7 @@ import org.ofbiz.entity.GenericEntityExc import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.transaction.GenericTransactionException; import org.ofbiz.entity.transaction.TransactionUtil; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtilProperties; import org.ofbiz.service.DispatchContext; @@ -62,7 +63,7 @@ public class LdapAuthenticationServices boolean isServiceAuth = context.get("isServiceAuth") != null && ((Boolean) context.get("isServiceAuth")).booleanValue(); GenericValue userLogin = null; try { - userLogin = delegator.findOne("UserLogin", isServiceAuth, "userLoginId", username); + userLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", username).cache(isServiceAuth).queryOne(); } catch (GenericEntityException e) { Debug.logWarning(e, "", module); } Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/login/LoginServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/login/LoginServices.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/login/LoginServices.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/login/LoginServices.java Wed Dec 17 12:13:46 2014 @@ -133,7 +133,7 @@ public class LoginServices { try { // only get userLogin from cache for service calls; for web and other manual logins there is less time sensitivity - userLogin = delegator.findOne("UserLogin", isServiceAuth, "userLoginId", username); + userLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", username).cache(isServiceAuth).queryOne(); } catch (GenericEntityException e) { Debug.logWarning(e, "", module); } @@ -149,7 +149,7 @@ public class LoginServices { // check the user login object again try { - userLogin = delegator.findOne("UserLogin", isServiceAuth, "userLoginId", username); + userLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", username).cache(isServiceAuth).queryOne(); } catch (GenericEntityException e) { Debug.logWarning(e, "", module); } @@ -436,9 +436,12 @@ public class LoginServices { return; } - EntityFindOptions efo = new EntityFindOptions(); - efo.setResultSetType(EntityFindOptions.TYPE_SCROLL_INSENSITIVE); - EntityListIterator eli = delegator.find("UserLoginPasswordHistory", EntityCondition.makeConditionMap("userLoginId", userLoginId), null, null, UtilMisc.toList("-fromDate"), efo); + EntityListIterator eli = EntityQuery.use(delegator) + .from("UserLoginPasswordHistory") + .where("userLoginId", userLoginId) + .orderBy("-fromDate") + .cursorScrollInsensitive() + .queryIterator(); Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); GenericValue pwdHist; if ((pwdHist = eli.next()) != null) { @@ -532,7 +535,7 @@ public class LoginServices { try { EntityCondition condition = EntityCondition.makeCondition(EntityFunction.UPPER_FIELD("userLoginId"), EntityOperator.EQUALS, EntityFunction.UPPER(userLoginId)); - if (UtilValidate.isNotEmpty(delegator.findList("UserLogin", condition, null, null, null, false))) { + if (UtilValidate.isNotEmpty(EntityQuery.use(delegator).from("UserLogin").where(condition).queryList())) { Map<String, String> messageMap = UtilMisc.toMap("userLoginId", userLoginId); errMsg = UtilProperties.getMessage(resource,"loginservices.could_not_create_login_user_with_ID_exists", messageMap, locale); errorMessageList.add(errMsg); @@ -925,7 +928,11 @@ public class LoginServices { if (passwordChangeHistoryLimit > 0 && userLogin != null) { Debug.logInfo(" checkNewPassword Checking if user is tyring to use old password " + passwordChangeHistoryLimit, module); try { - List<GenericValue> pwdHistList = delegator.findByAnd("UserLoginPasswordHistory", UtilMisc.toMap("userLoginId",userLogin.getString("userLoginId")), UtilMisc.toList("-fromDate"), false); + List<GenericValue> pwdHistList = EntityQuery.use(delegator) + .from("UserLoginPasswordHistory") + .where("userLoginId",userLogin.getString("userLoginId")) + .orderBy("-fromDate") + .queryList(); for (GenericValue pwdHistValue : pwdHistList) { if (checkPassword(pwdHistValue.getString("currentPassword"), useEncryption, newPassword)) { Map<String, Integer> messageMap = UtilMisc.toMap("passwordChangeHistoryLimit", passwordChangeHistoryLimit); Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/preferences/PreferenceServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/preferences/PreferenceServices.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/preferences/PreferenceServices.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/preferences/PreferenceServices.java Wed Dec 17 12:13:46 2014 @@ -33,6 +33,7 @@ import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.ServiceUtil; @@ -80,7 +81,7 @@ public class PreferenceServices { Map<String, Object> userPrefMap = null; try { - GenericValue preference = EntityUtil.getFirst(delegator.findByAnd("UserPreference", fieldMap, null, true)); + GenericValue preference = EntityQuery.use(delegator).from("UserPreference").where(fieldMap).cache(true).queryFirst(); if (preference != null) { userPrefMap = PreferenceWorker.createUserPrefMap(preference); } @@ -129,10 +130,10 @@ public class PreferenceServices { Map<String, Object> userPrefMap = null; try { Map<String, String> fieldMap = UtilMisc.toMap("userLoginId", "_NA_", "userPrefGroupTypeId", userPrefGroupTypeId); - userPrefMap = PreferenceWorker.createUserPrefMap(delegator.findByAnd("UserPreference", fieldMap, null, true)); + userPrefMap = PreferenceWorker.createUserPrefMap(EntityQuery.use(delegator).from("UserPreference").where(fieldMap).cache(true).queryList()); if (userLoginId != null) { fieldMap.put("userLoginId", userLoginId); - userPrefMap.putAll(PreferenceWorker.createUserPrefMap(delegator.findByAnd("UserPreference", fieldMap, null, true))); + userPrefMap.putAll(PreferenceWorker.createUserPrefMap(EntityQuery.use(delegator).from("UserPreference").where(fieldMap).cache(true).queryList())); } } catch (GenericEntityException e) { Debug.logWarning(e.getMessage(), module); @@ -207,8 +208,10 @@ public class PreferenceServices { } try { - GenericValue rec = delegator.findOne("UserPreference", - UtilMisc.toMap("userLoginId", userLoginId, "userPrefTypeId", userPrefTypeId), false); + GenericValue rec = EntityQuery.use(delegator) + .from("UserPreference") + .where("userLoginId", userLoginId, "userPrefTypeId", userPrefTypeId) + .queryOne(); if (rec != null) { rec.remove(); } @@ -277,8 +280,10 @@ public class PreferenceServices { } try { - Map<String, String> fieldMap = UtilMisc.toMap("userLoginId", fromUserLoginId, "userPrefGroupTypeId", userPrefGroupTypeId); - List<GenericValue> resultList = delegator.findByAnd("UserPreference", fieldMap, null, false); + List<GenericValue> resultList = EntityQuery.use(delegator) + .from("UserPreference") + .where("userLoginId", fromUserLoginId, "userPrefGroupTypeId", userPrefGroupTypeId) + .queryList(); if (resultList != null) { for (GenericValue preference: resultList) { preference.set("userLoginId", userLoginId); Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting/ScriptHelperImpl.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting/ScriptHelperImpl.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting/ScriptHelperImpl.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/scripting/ScriptHelperImpl.java Wed Dec 17 12:13:46 2014 @@ -38,6 +38,7 @@ import org.ofbiz.entity.GenericEntityExc import org.ofbiz.entity.GenericPK; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.model.ModelEntity; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.ModelService; import org.ofbiz.service.ServiceUtil; @@ -86,12 +87,12 @@ public final class ScriptHelperImpl impl if (entityPK.containsPrimaryKey(true)) { try { if (useCache) { - valueOut = delegator.findOne(entityPK.getEntityName(), entityPK, true); + valueOut = EntityQuery.use(delegator).from(entityPK.getEntityName()).where(entityPK).cache(true).queryOne(); } else { if (fieldsToSelect != null) { valueOut = delegator.findByPrimaryKeyPartial(entityPK, fieldsToSelect); } else { - valueOut = delegator.findOne(entityPK.getEntityName(), entityPK, false); + valueOut = EntityQuery.use(delegator).from(entityPK.getEntityName()).where(entityPK).queryOne(); } } } catch (GenericEntityException e) { Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/status/StatusServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/status/StatusServices.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/status/StatusServices.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/status/StatusServices.java Wed Dec 17 12:13:46 2014 @@ -34,6 +34,7 @@ import org.ofbiz.base.util.UtilMisc; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.ServiceUtil; @@ -56,7 +57,12 @@ public class StatusServices { List<GenericValue> statusItems = new LinkedList<GenericValue>(); for (String statusTypeId: statusTypes) { try { - List<GenericValue> myStatusItems = delegator.findByAnd("StatusItem", UtilMisc.toMap("statusTypeId", statusTypeId), UtilMisc.toList("sequenceId"), true); + List<GenericValue> myStatusItems = EntityQuery.use(delegator) + .from("StatusItem") + .where("statusTypeId", statusTypeId) + .orderBy("sequenceId") + .cache(true) + .queryList(); statusItems.addAll(myStatusItems); } catch (GenericEntityException e) { Debug.logError(e, module); @@ -72,7 +78,12 @@ public class StatusServices { List<GenericValue> statusValidChangeToDetails = null; String statusId = (String) context.get("statusId"); try { - statusValidChangeToDetails = delegator.findByAnd("StatusValidChangeToDetail", UtilMisc.toMap("statusId", statusId), UtilMisc.toList("sequenceId"), true); + statusValidChangeToDetails = EntityQuery.use(delegator) + .from("StatusValidChangeToDetail") + .where("statusId", statusId) + .orderBy("sequenceId") + .cache(true) + .queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); } Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/status/StatusWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/status/StatusWorker.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/status/StatusWorker.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/status/StatusWorker.java Wed Dec 17 12:13:46 2014 @@ -28,6 +28,7 @@ import org.ofbiz.base.util.UtilMisc; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityQuery; /** * StatusWorker @@ -40,8 +41,12 @@ public class StatusWorker { Delegator delegator = (Delegator) pageContext.getRequest().getAttribute("delegator"); try { - List<GenericValue> statusItems = delegator.findByAnd("StatusItem", UtilMisc.toMap("statusTypeId", statusTypeId), UtilMisc.toList("sequenceId"), true); - + List<GenericValue> statusItems = EntityQuery.use(delegator) + .from("StatusItem") + .where("statusTypeId", statusTypeId) + .orderBy("sequenceId") + .cache(true) + .queryList(); if (statusItems != null) pageContext.setAttribute(attributeName, statusItems); } catch (GenericEntityException e) { @@ -54,16 +59,24 @@ public class StatusWorker { List<GenericValue> statusItems = new LinkedList<GenericValue>(); try { - List<GenericValue> calItems = delegator.findByAnd("StatusItem", UtilMisc.toMap("statusTypeId", statusTypeIdOne), UtilMisc.toList("sequenceId"), true); - + List<GenericValue> calItems = EntityQuery.use(delegator) + .from("StatusItem") + .where("statusTypeId", statusTypeIdOne) + .orderBy("sequenceId") + .cache(true) + .queryList(); if (calItems != null) statusItems.addAll(calItems); } catch (GenericEntityException e) { Debug.logError(e, module); } try { - List<GenericValue> taskItems = delegator.findByAnd("StatusItem", UtilMisc.toMap("statusTypeId", statusTypeIdTwo), UtilMisc.toList("sequenceId"), true); - + List<GenericValue> taskItems = EntityQuery.use(delegator) + .from("StatusItem") + .where("statusTypeId", statusTypeIdTwo) + .orderBy("sequenceId") + .cache(true) + .queryList(); if (taskItems != null) statusItems.addAll(taskItems); } catch (GenericEntityException e) { @@ -79,7 +92,12 @@ public class StatusWorker { List<GenericValue> statusValidChangeToDetails = null; try { - statusValidChangeToDetails = delegator.findByAnd("StatusValidChangeToDetail", UtilMisc.toMap("statusId", statusId), UtilMisc.toList("sequenceId"), true); + statusValidChangeToDetails = EntityQuery.use(delegator) + .from("StatusValidChangeToDetail") + .where("statusId", statusId) + .orderBy("sequenceId") + .cache(true) + .queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Wed Dec 17 12:13:46 2014 @@ -77,6 +77,7 @@ import org.ofbiz.entity.util.Distributed import org.ofbiz.entity.util.EntityCrypto; import org.ofbiz.entity.util.EntityFindOptions; import org.ofbiz.entity.util.EntityListIterator; +import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.entity.util.SequenceUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -196,13 +197,13 @@ public class GenericDelegator implements // before continuing, if there is a tenantId use the base delegator to see if it is valid if (UtilValidate.isNotEmpty(this.delegatorTenantId)) { Delegator baseDelegator = DelegatorFactory.getDelegator(this.delegatorBaseName); - GenericValue tenant = baseDelegator.findOne("Tenant", true, "tenantId", this.delegatorTenantId); + GenericValue tenant = EntityQuery.use(baseDelegator).from("Tenant").where("tenantId", this.delegatorTenantId).cache(true).queryOne(); if (tenant == null) { throw new GenericEntityException("No Tenant record found for delegator [" + this.delegatorFullName + "] with tenantId [" + this.delegatorTenantId + "]"); } else if ("Y".equals(tenant.getString("disabled"))) { throw new GenericEntityException("No Tenant record found for delegator [" + this.delegatorFullName + "] with tenantId [" + this.delegatorTenantId + "]"); } - GenericValue kekValue = baseDelegator.findOne("TenantKeyEncryptingKey", true, "tenantId", getDelegatorTenantId()); + GenericValue kekValue = EntityQuery.use(baseDelegator).from("TenantKeyEncryptingKey").where("tenantId", getDelegatorTenantId()).cache(true).queryOne(); if (kekValue != null) { kekText = kekValue.getString("kekText"); } else { @@ -490,7 +491,7 @@ public class GenericDelegator implements // NOTE: instead of caching the GenericHelpInfo object do a cached query here and create a new object each time, will avoid issues when the database data changes during run time // NOTE: always use the base delegator for this to avoid problems when this is being initialized Delegator baseDelegator = DelegatorFactory.getDelegator(this.delegatorBaseName); - GenericValue tenantDataSource = baseDelegator.findOne("TenantDataSource", true, "tenantId", this.delegatorTenantId, "entityGroupName", entityGroupName); + GenericValue tenantDataSource = EntityQuery.use(baseDelegator).from("TenantDataSource").where("tenantId", this.delegatorTenantId, "entityGroupName", entityGroupName).cache(true).queryOne(); if (tenantDataSource != null) { helperInfo.setTenantId(this.delegatorTenantId); helperInfo.setOverrideJdbcUri(tenantDataSource.getString("jdbcUri")); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java Wed Dec 17 12:13:46 2014 @@ -60,6 +60,7 @@ import org.ofbiz.entity.model.ModelViewE import org.ofbiz.entity.transaction.TransactionUtil; import org.ofbiz.entity.util.EntityFindOptions; import org.ofbiz.entity.util.EntityListIterator; +import org.ofbiz.entity.util.EntityQuery; /** * Generic Entity Data Access Object - Handles persistence for any defined entity. @@ -418,7 +419,7 @@ public class GenericDAO { List<GenericValue> meResult = null; try { - meResult = delegator.findByAnd(meName, findByMap, null, false); + meResult = EntityQuery.use(delegator).from(meName).where(findByMap).queryList(); } catch (GenericEntityException e) { throw new GenericEntityException("Error while retrieving partial results for entity member: " + meName, e); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java Wed Dec 17 12:13:46 2014 @@ -35,6 +35,7 @@ import org.ofbiz.entity.GenericPK; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.model.ModelField; +import org.ofbiz.entity.util.EntityQuery; import org.w3c.dom.Element; /** @@ -146,12 +147,12 @@ public class PrimaryKeyFinder extends Fi // make sure we have a full primary key, if any field is null then just log a warning and return null instead of blowing up if (entityPK.containsPrimaryKey(true)) { if (useCache) { - valueOut = delegator.findOne(entityPK.getEntityName(), entityPK, true); + valueOut = EntityQuery.use(delegator).from(entityPK.getEntityName()).where(entityPK).cache(true).queryOne(); } else { if (fieldsToSelect != null) { valueOut = delegator.findByPrimaryKeyPartial(entityPK, fieldsToSelect); } else { - valueOut = delegator.findOne(entityPK.getEntityName(), entityPK, false); + valueOut = EntityQuery.use(delegator).from(entityPK.getEntityName()).where(entityPK).cache(true).queryOne(); } } } else { Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java?rev=1646212&r1=1646211&r2=1646212&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java Wed Dec 17 12:13:46 2014 @@ -92,25 +92,18 @@ public class EntityCryptoTestSuite exten public void testCryptoLookup() throws Exception { String nanoTime = "" + System.nanoTime(); - EntityCondition condition; delegator.removeByAnd("TestingCrypto", UtilMisc.toMap("testingCryptoTypeId", "LOOKUP")); delegator.create("TestingCrypto", UtilMisc.toMap("testingCryptoId", "lookup-null", "testingCryptoTypeId", "LOOKUP")); delegator.create("TestingCrypto", UtilMisc.toMap("testingCryptoId", "lookup-value", "testingCryptoTypeId", "LOOKUP", "encryptedValue", nanoTime, "saltedEncryptedValue", nanoTime)); // This ends up using EntityExpr contained in EntityConditionList - assertEquals(1, delegator.findByAnd("TestingCrypto", UtilMisc.toMap("testingCryptoTypeId", "LOOKUP", "encryptedValue", null), null, false).size()); - assertEquals(1, delegator.findByAnd("TestingCrypto", UtilMisc.toMap("testingCryptoTypeId", "LOOKUP", "saltedEncryptedValue", null), null, false).size()); - assertEquals(1, delegator.findByAnd("TestingCrypto", UtilMisc.toMap("testingCryptoTypeId", "LOOKUP", "encryptedValue", nanoTime), null, false).size()); - assertEquals(0, delegator.findByAnd("TestingCrypto", UtilMisc.toMap("testingCryptoTypeId", "LOOKUP", "saltedEncryptedValue", nanoTime), null, false).size()); - - // This ends up using EntityExpr contained in EntityExpr - condition = EntityCondition.makeCondition( - EntityCondition.makeCondition("testingCryptoTypeId", EntityOperator.EQUALS, "LOOKUP"), - EntityOperator.AND, - EntityCondition.makeCondition("encryptedValue", EntityOperator.EQUALS, nanoTime) - ); - assertEquals(1, delegator.findList("TestingCrypto", condition, null, null, null, false).size()); + assertEquals(1, (EntityQuery.use(delegator).from("TestingCrypto").where("testingCryptoTypeId", "LOOKUP", "encryptedValue", null).queryList()).size()); + assertEquals(1, (EntityQuery.use(delegator).from("TestingCrypto").where("testingCryptoTypeId", "LOOKUP", "saltedEncryptedValue", null).queryList()).size()); + assertEquals(1, (EntityQuery.use(delegator).from("TestingCrypto").where("testingCryptoTypeId", "LOOKUP", "encryptedValue", nanoTime).queryList()).size()); + assertEquals(0, (EntityQuery.use(delegator).from("TestingCrypto").where("testingCryptoTypeId", "LOOKUP", "saltedEncryptedValue", nanoTime).queryList()).size()); + + assertEquals(1, EntityQuery.use(delegator).from("TestingCrypto").where("testingCryptoTypeId", "LOOKUP", "encryptedValue", nanoTime).queryList().size()); } protected EntityCondition makeSubSelectCondition(String nanoTime) { @@ -139,23 +132,23 @@ public class EntityCryptoTestSuite exten delegator.create("TestingCrypto", UtilMisc.toMap("testingCryptoId", "SUB_2", "testingCryptoTypeId", "SUB_SELECT_2", "encryptedValue", nanoTime)); delegator.create("TestingCrypto", UtilMisc.toMap("testingCryptoId", "SUB_3", "testingCryptoTypeId", "SUB_SELECT_3", "encryptedValue", "constant")); - results = delegator.findList("TestingCrypto", EntityCondition.makeCondition("encryptedValue", EntityOperator.EQUALS, nanoTime), null, UtilMisc.toList("testingCryptoId"), null, false); + results = EntityQuery.use(delegator).from("TestingCrypto").where("encryptedValue", nanoTime).orderBy("testingCryptoId").queryList(); assertEquals(2, results.size()); assertEquals("SUB_1", results.get(0).get("testingCryptoId")); assertEquals("SUB_2", results.get(1).get("testingCryptoId")); - results = delegator.findList("TestingCrypto", EntityCondition.makeCondition("testingCryptoTypeId", EntityOperator.IN, UtilMisc.toList("SUB_SELECT_1", "SUB_SELECT_3")), null, UtilMisc.toList("testingCryptoId"), null, false); + results = EntityQuery.use(delegator).from("TestingCrypto").where("testingCryptoTypeId", EntityOperator.IN, UtilMisc.toList("SUB_SELECT_1", "SUB_SELECT_3")).orderBy("testingCryptoId").queryList(); assertEquals(2, results.size()); assertEquals("SUB_1", results.get(0).get("testingCryptoId")); assertEquals("SUB_3", results.get(1).get("testingCryptoId")); condition = makeSubSelectCondition(nanoTime); - results = delegator.findList("TestingCrypto", condition, null, UtilMisc.toList("testingCryptoId"), null, false); + results = EntityQuery.use(delegator).from("TestingCrypto").where(condition).orderBy("testingCryptoId").queryList(); assertEquals(1, results.size()); assertEquals("SUB_1", results.get(0).get("testingCryptoId")); condition = EntityCondition.makeCondition("testingCryptoId", EntityOperator.EQUALS, makeSubSelect(nanoTime)); - results = delegator.findList("TestingCrypto", condition, null, UtilMisc.toList("testingCryptoId"), null, false); + results = EntityQuery.use(delegator).from("TestingCrypto").where(condition).orderBy("testingCryptoId").queryList(); assertEquals(1, results.size()); assertEquals("SUB_1", results.get(0).get("testingCryptoId")); } |
Free forum by Nabble | Edit this page |