|
Author: bibryam
Date: Mon Feb 15 16:41:35 2010 New Revision: 910256 URL: http://svn.apache.org/viewvc?rev=910256&view=rev Log: Revert cascadeDelete service after Adam and Adrian's feedback. Modified: ofbiz/trunk/framework/common/servicedef/services_test.xml ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java Modified: ofbiz/trunk/framework/common/servicedef/services_test.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/servicedef/services_test.xml?rev=910256&r1=910255&r2=910256&view=diff ============================================================================== --- ofbiz/trunk/framework/common/servicedef/services_test.xml (original) +++ ofbiz/trunk/framework/common/servicedef/services_test.xml Mon Feb 15 16:41:35 2010 @@ -210,11 +210,4 @@ <description>Test Ping Service</description> <attribute name="message" type="String" mode="INOUT" optional="true"/> </service> - - <service name="cascadeDelete" engine="java" - location="org.ofbiz.common.CommonServices" invoke="cascadeDelete"> - <description>Remove generic value and its related values</description> - <attribute name="entityName" type="String" mode="IN"/> - <attribute name="pkFields" type="Map" mode="IN"/> - </service> </services> 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=910256&r1=910255&r2=910256&view=diff ============================================================================== --- ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java (original) +++ ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java Mon Feb 15 16:41:35 2010 @@ -45,7 +45,6 @@ import org.apache.log4j.Logger; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilDateTime; -import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilValidate; import static org.ofbiz.base.util.UtilGenerics.checkList; @@ -55,8 +54,6 @@ import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.model.ModelEntity; -import org.ofbiz.entity.model.ModelRelation; -import org.ofbiz.entity.model.ModelViewEntity; import org.ofbiz.entity.transaction.TransactionUtil; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.GenericServiceException; @@ -537,42 +534,5 @@ return ServiceUtil.returnError("Invalid count returned from database"); } } - - public static Map<String, Object> cascadeDelete(DispatchContext dctx, Map<String, Object> context) { - Delegator delegator = dctx.getDelegator(); - String entityName = (String) context.get("entityName"); - Map<String, Object> pkFields = UtilGenerics.checkMap(context.get("pkFields")); - - try { - GenericValue value = delegator.findByPrimaryKey(entityName, pkFields); - ModelEntity modelEntity = delegator.getModelEntity(entityName); - List<ModelRelation> relations = modelEntity.getRelationsManyList(); - - if (value == null || modelEntity instanceof ModelViewEntity) { - return ServiceUtil.returnSuccess(); - } - - for (ModelRelation relation : relations) { - String combinedName = relation.getCombinedName(); - List<GenericValue> relatedValues = value.getRelated(combinedName); - for (GenericValue relatedValue : relatedValues) { - pkFields = relatedValue.getPrimaryKey().getAllFields(); - entityName = relatedValue.getEntityName(); - Map<String, Object> newContext = UtilMisc.toMap("entityName", entityName, "pkFields", pkFields); - Map<String, Object>result = CommonServices.cascadeDelete(dctx, newContext); - if (ServiceUtil.isError(result)) { - return result; - } - } - } - - Debug.logInfo("Removing value: " + value , module); - delegator.removeValue(value); - } catch (GenericEntityException e) { - return ServiceUtil.returnError(e.getMessage()); - } - - return ServiceUtil.returnSuccess(); - } } |
| Free forum by Nabble | Edit this page |
