Nested Callback Handlers?

I am getting a set of data from the database where the query produces a repetition of data with a different “Special” value. For example the user “A” can be repeated twice, having three different “Special” values under the “Special Column”.

I am using a callback handler to retrieve the data and put it into a list, now additionally I want the Special column to have its own callback where for each user the specials list will be stored, so therefore the user data wont be repeatedly taken and stored into the list and I wont have to manually filter it out. Can anyone point me to a direction of achieving this?

Another way of achieving this is to concatenate the results into a string there itself, which would be easier, but the query seems to be complex and messy when I include the joins.

The code is below

    String query   = getQuery(SPECIALS_REPORT_QUERY);

    getJdbcTemplate().query(query, parameters, dataTypes, new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet rs) throws SQLException {

            SpecialsResultsSetDTO dto = new SpecialsResultsSetDTO();

            dto.setRoomNo(rs.getString("ROOM_NO"));
            dto.setGuestName(rs.getString("GUEST_NAME")); 
            dto.setNoOfAdults((rs.getInt("NO_OF_ADULTS"))); 
            dto.setNoOfChildren(rs.getInt("NO_OF_CHILDREN"));
            dto.setNoOfInfants(rs.getInt("NO_OF_INFANTS"));
            dto.setMealPlanCode(rs.getString("MEAL_PLAN_CODE"));
            dto.setArrivalDateTime(rs.getDate("ARRIVAL_DATE_TIME"));
            dto.setDepartureDate(rs.getString("DEPARTURE_DATE"));

            //there should be a callback handler or something to store the data to a list in the dto bean object (for the specials)

            dtoList.add(dto);
        }
    });

Any advice on solving this problem would be helpful

Regards, Milinda

Answer

In your dto cant you create an hashmap which would have the user as the key and special value as the column.

Leave a Reply

Your email address will not be published. Required fields are marked *