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.Column;
11  import com.rc.celeritas.query.QueryHelper;
12  import java.util.ArrayList;
13  import java.util.HashMap;
14  import org.apache.commons.collections.MapUtils;
15  import org.apache.commons.lang.StringUtils;
16  import org.apache.log4j.Logger;
17  import org.webmacro.servlet.WebContext;
18  
19  /**
20   *
21   * @author rchoudhary
22   */
23  public class UpdateImpleo implements Impleo {
24  
25      private static Logger log = Logger.getLogger(UpdateImpleo.class);
26  
27      /**
28       * Update Action Will be Implied Here
29       * @param context
30       * @return
31       * @throws java.lang.Exception
32       */
33      public String implied(WebContext context) throws Exception {
34          String message = "";
35          context.put("impleo", "update");
36          HashMap rMap = (HashMap)context.get("rMap");
37          if(rMap == null || rMap.size() == 0){
38              new Exception("No Request Object Found!! Cannot proceed with Insertion...");
39          }
40          String table = MapUtils.getString(rMap, ImpleoConstants.TABLE, "table");
41          String pk = MapUtils.getString(rMap, ImpleoConstants.PK, "pk");
42          String pVal = MapUtils.getString(rMap, pk);
43          try {
44              ArrayList<Column> columns = DBHelper.getColumns(table);
45              String updateSQL = QueryHelper.createUpdateSQL(table, columns, rMap, pk, pVal);
46              HashMap<String, String> tRow = DBHelper.update(updateSQL, table, pk, pVal);
47              context.put(ImpleoConstants.TROW, tRow);
48          } catch (CeleritasException e) {
49              log.error("Error in Insert Impleo : " + e.toString());
50              throw new Exception(e);
51          }
52          if(StringUtils.isEmpty(message)){
53              message = MapUtils.getString(rMap,ImpleoConstants.SUCCESS,ImpleoConstants.EMPTY_STRING);
54          }
55          return null;
56      }
57  
58  }