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