View Javadoc

1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   
6   package com.rc.celeritas.impleo;
7   
8   import com.rc.celeritas.db.DBHelper;
9   import com.rc.celeritas.exception.CeleritasException;
10  import com.rc.celeritas.query.QueryHelper;
11  import java.util.HashMap;
12  import org.apache.commons.collections.MapUtils;
13  import org.apache.commons.lang.StringUtils;
14  import org.apache.log4j.Logger;
15  import org.webmacro.servlet.WebContext;
16  
17  /**
18   *
19   * @author rchoudhary
20   */
21  public class DeleteImpleo implements Impleo{
22  
23      private static Logger log = Logger.getLogger(DeleteImpleo.class);
24  
25      /**
26       *
27       * @param context
28       * @return
29       * @throws java.lang.Exception
30       */
31      public String implied(WebContext context) throws Exception {
32          context.put("impleo", "delete");
33          String message = "";
34          HashMap rMap = (HashMap)context.get("rMap");
35          if(rMap == null || rMap.size() == 0){
36              new Exception("No Request Object Found!! Cannot proceed with Deletion...");
37          }
38          String table = MapUtils.getString(rMap, ImpleoConstants.TABLE, "table");
39          String pk = MapUtils.getString(rMap, ImpleoConstants.PK, "pk");
40          String pVal = MapUtils.getString(rMap, pk);
41          try {
42              String deleteSQL = QueryHelper.createDeleteSQL(table, pk, pVal);
43              HashMap<String, String> tRow = DBHelper.fetchRow(table, pk, pVal);
44              int i = DBHelper.execute(deleteSQL);
45              if(i < 1){
46                  throw new Exception("Record couldn't be deleted |" + table + " | " + pk + " | " + pVal);
47              }
48              context.put(ImpleoConstants.TROW, tRow);
49          } catch (CeleritasException e) {
50              log.error("Error in Delete Impleo : " + e.toString());
51              throw new Exception(e);
52          }
53          if(StringUtils.isEmpty(message)){
54              message = MapUtils.getString(rMap,ImpleoConstants.SUCCESS,ImpleoConstants.EMPTY_STRING);
55          }
56          return null;
57      }
58  
59  }