Wednesday, January 30, 2013

Json Array Crreate with Pure Java with RowMapper


My Controller Class

    @RequestMapping(value = "/dtvMTH", method = RequestMethod.GET)
    public @ResponseBody
    Object[] showDTVLineChart(Map<String, Object> map,
            HttpServletRequest request, HttpServletResponse response) {
        List<MapTable> list = contactService.dtv_pending();
        List<Integer> five = new ArrayList<Integer>();
        List<Integer> six = new ArrayList<Integer>();
        List<Integer> seven = new ArrayList<Integer>();
        List<Integer> eight = new ArrayList<Integer>();
        List<Integer> nine = new ArrayList<Integer>();
        List<Integer> ten = new ArrayList<Integer>();
       
        Object[] array = new Object[6];
        for (Iterator iterator = list.iterator(); iterator.hasNext();) {
            MapTable table = (MapTable) iterator.next();
            five.add(table.getFive());
            six.add(table.getSix());
            seven.add(table.getSeven());
            eight.add(table.getEight());
            nine.add(table.getNine());
            ten.add(table.getTen());
        }
        array[0] = five.toArray(new Integer[five.size()]);
        array[1] = six.toArray(new Integer[six.size()]);
        array[2] = seven.toArray(new Integer[seven.size()]);
        array[3] = eight.toArray(new Integer[eight.size()]);
        array[4] = nine.toArray(new Integer[nine.size()]);
        array[5] = ten.toArray(new Integer[ten.size()]);
        return array;
       
/*        Object[] object = new Object[1];
        object[0] = array;
        return object;*/
       
    }


My DAOImpl Class

    public List<MapTable> dtv_pending() {
        @SuppressWarnings("unchecked")
        List<MapTable> dashboardBeanList = jdbcTemplate.query(
                "SELECT SuAdfLast5hrsV.HOUR as HOUR,"
                        + "SuAdfLast5hrsV.SEC_00_07 as SEC_00_07,"
                        + "SuAdfLast5hrsV.SEC_08_10 as SEC_08_10,"
                        + "SuAdfLast5hrsV.\"SEC_11_above\" as SEC_11_above "
                        + "FROM SU_ADF_LAST_5HRS_V SuAdfLast5hrsV",
                new Object[] {}, new RowMapper() {
                    public MapTable mapRow(ResultSet rs, int rowNum)
                            throws SQLException {
                        MapTable dashboardBean = new MapTable();
                        dashboardBean.setHour(rs.getString("HOUR"));
                        dashboardBean.setSec_00_07(rs.getInt("SEC_00_07"));
                        dashboardBean.setSec_08_10(rs.getInt("SEC_08_10"));
                        dashboardBean.setSec_12_More(rs.getInt("SEC_11_above"));
                        return dashboardBean;
                    }
                });
        return dashboardBeanList;
    }