First, remove as primary key
/ ** * delete the primary key * @param dctx * @param context * @return * / public static the Map <String, Object> deleteUomByPrimaryKey ( DispatchContext dctx, the Map <String, Object> context) { // acquired entity engine instance GenericDelegator = dctx.getDelegator delegator (); // TODO here is not very comprehensive consideration, but also need to discuss: 1) MiscMap mode 2) delegator.makePKSingle method the Map <String, Object> pkFields = FastMap.newInstance (); pkFields. put ( "uomId", "BaseLineProduct "); // here to remove products created earlier baseline GenericPK primaryKey = delegator.makePK ( "Uom", pkFields); the try { // perform primary key deletion delegator.removeByPrimaryKey (primaryKey) ; } catch (GenericEntityException e) { // put Error Error message to the printing level to the log file Debug.logError (E, Module1); // the description information corresponding to the specified error code returned to the service the caller return ReturnMapUtil.getErrorMap (DemoErrorMapping.BASE0002, primaryKey. toString ()); } // indicating the success of the service information back to the caller return ReturnMapUtil.getSuccessMap (); }
Second, remove as much condition
/ ** * delete performed in multiple conditions, and these conditions the relationship 'with', typically when the deletion condition is non-primary key * @param dctx * @param context * @return * / public static the Map <String, Object > deleteUomByOtherFields (DispatchContext dctx, the Map <String, Object> context) { // get entity engine instance GenericDelegator delegator = dctx.getDelegator (); // TODO here is not very comprehensive consideration, but also need to discuss: MiscMap way // here to remove cash management information system created in front of the Map <String, Object> deleteFields = FastMap.newInstance (); deleteFields.put ( "both the abbreviation", "Cashm"); deleteFields.put ( "the Description", "cash management system") ; the try { // perform the deletion condition setting delegator.removeByAnd ( "Uom", deleteFields); } catch (GenericEntityException e) { // put Error Error message to the printing level to the log file Debug.logError (E, Module1); // the description information corresponding to the specified error code returned to the service the caller return ReturnMapUtil.getErrorMap (DemoErrorMapping.BASE0002, deleteFields. toString ()); } // indicating the success of the service information back to the caller return ReturnMapUtil.getSuccessMap (); }
Third, according to delete when a field has a plurality of values
/ ** * values according to a plurality of fields, delete records * @param dctx * @param context * @return * / public static the Map <String, Object> deleteUomByMoreValues (DispatchContext dctx, the Map <String, Object> context) { / / acquired entity engine instance GenericDelegator delegator = dctx.getDelegator (); // here to remove "baseline product information" and "cash management information system" created earlier the Map <String, Object> deleteFields = FastMap.newInstance (); deleteFields.put ( "both the abbreviation", "BLP"); deleteFields.put ( "both the abbreviation", "Cashm"); // delete the collected condition EntityCondition deleteBLPCon = EntityCondition.makeCondition ( "abbreviation" , EntityOperator.EQUALS, "BLP"); EntityCondition deleteCashmCon = EntityCondition.makeCondition ( "abbreviation" , EntityOperator.EQUALS, "Cashm"); EntityCondition deleteCondition = EntityCondition.makeCondition (deleteBLPCon, EntityOperator.OR, deleteCashmCon); the try { System.err.println ( "deletion condition:" + deleteCondition.toString ()); // perform the deletion condition setting delegator.removeByCondition ( "Uom", deleteCondition); } the catch (GenericEntityException E) { // error level to put the print error information to the log file Debug .logError (E, Module1); // the description information corresponding to the specified error code returned to the service the caller return ReturnMapUtil.getErrorMap (DemoErrorMapping.BASE0002, deleteCondition.toString ()); } // returns information indicating success to the The caller service return ReturnMapUtil.getSuccessMap (); }
Fourth, remove as time
/ ** * Delete a period of data * @param dctx * @param context * @return * / public static the Map <String, Object> deleteUomByDate (DispatchContext dctx, the Map <String, Object> context) { // get entity examples engine GenericDelegator a delegator dctx.getDelegator = (); // start date and end date extracted from the input parameters String beginDateStr = (String) context.get ( "the beginDate"); String endDateStr = (String) context.get ( "endDate "); // set query conditions: recording time is more than beginDate, recording time is less than endDate List <EntityCondition> conList = FastList.newInstance (); // If the incoming start date is not empty, then set the deletion criteria: deleted records We can not be earlier than the start date if (UtilValidate.isNotEmpty (beginDateStr)) { try { // put the start date of the string converted to Timestamp format = UtilDateTime.stringToTimeStamp the beginDate timestamp (beginDateStr, InnerConstant.DATE_FORMAT, TimeZone.getDefault (), Locale.CHINA); // time of the whole date is then set to 00: 00: 00.000 the beginDate = UtilDateTime.getDayStart (the beginDate); / / set query: recording time is greater than the beginDate EntityCondition startDateCon = EntityCondition.makeCondition ( "createdStamp", EntityOperator.GREATER_THAN_EQUAL_TO, the beginDate); conList.add (startDateCon); } the catch (a ParseException E) { // put level error information error printed to the log file Debug.logError (E, Module1); return ReturnMapUtil.getErrorMap (DemoErrorMapping.BASE0003, beginDateStr, e.getMessage ()); } } // If the incoming end date is not empty, the deletion condition is provided: delete the recording end date is not later than the IF (UtilValidate.isNotEmpty (endDateStr)) { the try { // first string end date turn into Timestamp format Timestamp endDate = UtilDateTime.stringToTimeStamp (endDateStr, InnerConstant.DATE_FORMAT, TimeZone.getDefault (), Locale.CHINA); System.err.println (endDate.toString ()); the time portion // then the end date is set to: 23 is: 59: 59.999 endDate = UtilDateTime.getDayEnd (UtilDateTime.nowTimestamp ()); // set the search criteria: recording time is less than endDate EntityCondition endTimeCon = EntityCondition.makeCondition ( "createdStamp", EntityOperator.LESS_THAN_EQUAL_TO, endDate); conList.add ( endTimeCon); The catch} (a ParseException E) { // Error level to put the print error information to the log file Debug.logError (E, Module1); return ReturnMapUtil.getErrorMap (DemoErrorMapping.BASE0004, endDateStr, e.getMessage ()); } } EntityCondition = EntityCondition.makeCondition deleteCondition (conList, EntityOperator.AND); the try { // delete operation in accordance with the conditions set delegator.removeByCondition ( "Uom", deleteCondition); } the catch (GenericEntityException E) { // put the error information error printed to the log file level Debug.logError (E, Module1); // the description information corresponding to the specified error code returned to the service the caller return ReturnMapUtil.getErrorMap (DemoErrorMapping.BASE0002, deleteCondition.toString ()); } / / indicating the success of the service information back to the caller ); ReturnMapUtil.getSuccessMap return (); }
XML configuration
<service name="deleteUomByDate" engine="java" location="com.giantstone.bosent.demo.delegator.DelegatorDeleteDemoService" invoke="deleteUomByDate"> <attribute name="beginDate" type="String" mode="IN" optional="true" /> <attribute name="endDate" type="String" mode="IN" optional="true" /> <attribute name="returnCode" type="Map" mode="OUT" optional="true" /> </service>