OAF Basic Data Type Conversion Methods For Frequent Usage

Source Data Type Target Data Type Conversion Sample
oracle.jbo.domain.Number int Number Id = row.getId();  int idIntValue = Id.intValue();
oracle.jbo.domain.Date String  Date dobDomainDate = row.getDob();   String dobStr = dobDomainDate.toString();
     
     
     

1.      Conversion of java String to java.sql.date

    private java.sql.Date stringToDate(String dateS)

    {

    ///String into  Java.util.date

    // java.util.Date into java.SQL.Date

        java.sql.Date sqlStartDate = null;

        if (dateS != null && !””.equals(dateS)) {

           String dateFormat = “yyyy-MM-dd”;

            SimpleDateFormat df = new SimpleDateFormat(dateFormat);

            java.util.Date parsedDate1 = null;

              {

                try {

                    parsedDate1 = df.parse(dateS);  // String into DB

                } catch (ParseException e) {

                  System.out.println(“exception occurred in conversion “);

                  throw new OAException(“Formatting Issue, Unable to Parse Data”) ;

                    // TODO

                }

                sqlStartDate = new java.sql.Date(parsedDate1.getTime());

            }

        }

        return sqlStartDate;

    }

2.      Comparison of dates

//Below code will compare To Date with From Date and will throw an error if it is less than from date

// compareTo  method return values are : -1  , 0  , 1 for : lessthan, equalto, greater than

    if(pageContext.getParameter(“go”)!=null)

      {

        String fromDateStr = pageContext.getParameter(“fromDate”) ;

        Date fromDate = stringToDate(fromDateStr);

        String toDateStr  = pageContext.getParameter(“toDate”) ;

        Date toDate = stringToDate(toDateStr);

        pageContext.writeDiagnostics(this , ”   From Date –>” + fromDate +   ”  To Date–>”+  toDate  , 1);

          if(toDate!=null && fromDate!=null )

             {

                if(toDate.compareTo(fromDate) <0  )

                     {

                         throw new OAException(“XXCUS”,”XXDHG_SSHR_EXP_DATE_ERR”,null,OAException.ERROR,null);

                      }

             } 

**this document is still under preparation, gets updated frequently.

Comments |0|

Legend *) Required fields are marked
**) You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Category: OAF