Monday, March 30, 2015

Create and Insert Rows Programmatically in AMImpl ADF

 // This is the method in AMImpl

    public void addUser(BigDecimal userRefId,String exCode){
        String query="SELECT  userUtils.getUserID("+userRefId+") from dual";
        System.out.println("This is the USER_ID query"+query);
        BigDecimal userId=executeQuery(query);

        ADFContext adfCtx = ADFContext.getCurrent();
        Map sessionScope = adfCtx.getSessionScope();
        BigDecimal createdBy= new BigDecimal(sessionScope.get("UserId").toString());

        java.sql.Timestamp datetime = new java.sql.Timestamp(System.currentTimeMillis());
       

          AdminWBVOImpl adminWBVO = this.getAdminWBVO();
//create Row
        AdminWBVOImpl adminRow=(AdminWBVOImpl)adminWBVO .createRow();
// initialize Row
        adminRow.setUserId(userId);
        adminRow.setExCode(exCode);
        adminRow.setAttributeCode("ADD_USER");
        adminRow.setAttributeValue("N");
        adminRow.setCreatedBy(createdBy);
        adminRow.setCreationDate(datetime);
        adminRow.setLastUpdatedBy(createdBy);

//get the datetime timestamp programmatically
        adminRow.setLastUpdatedDate(datetime);

//Add the initilized ROW to the View Object 
        AdminWBVO.insertRow(adminRow);

//Commit the Transaction
        this.getDBTransaction().commit();
          }


    /**Method to Execute DB SQL Query using DBTransaction
       * @param query
       * @return
       */
      protected BigDecimal executeQuery(String query) {
          ResultSet rs;
          BigDecimal code = null;
          try {
              rs = getDBTransaction().createStatement(0).executeQuery(query);
              if (rs.next()) {
                  code = new BigDecimal( rs.getObject(1).toString());
              }

              rs.close();
              return code;

          } catch (SQLException e) {
              throw new JboException(e);
          }
      }

No comments: