commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Betty User <usrbe...@gmail.com>
Subject [dbutils]
Date Sun, 10 Mar 2013 15:32:41 GMT
Hello,

I am creating MVC web application in Spring.

With this Java code I'm trying to convert resultset int JavaBeans.

List<MonthOrderCount> retList = new LinkedList<>();
BasicRowProcessor brp = new BasicRowProcessor(new MonthOrderCountHandler());
BeanListHandler<MonthOrderCount> m = new
BeanListHandler<>(MonthOrderCount.class, brp);
retList.addAll(queryRunner.query(sql, m, Util.utilDateToSqlDate(dateFrom),
Util.utilDateToSqlDate(dateTo)));

But it doesn't work for me - List is filled with objects (MonthOrderCount),
value orderCount is correct but month variable is null.

My implementation of MonthOrderCountHandler class:

public class MonthOrderCountHandler extends BeanProcessor {

    @Override
    public Object toBean(ResultSet rs, Class type) throws SQLException {

        // Year
        Year year = new Year();
        year.setYearNo(rs.getInt("yearNo"));
        year.setYear4(rs.getString("year4"));
        year.setYear2(rs.getString("year2"));

        // Quarter
        Quarter quarter = new Quarter();
        quarter.setQuarterNo(rs.getInt("quarterNo"));

        // Month
        Month m = new Month();
        m.setYear(year);
        m.setQuarter(quarter);
        m.setMonthAbbreviation(rs.getString("monthAbbreviation"));
        m.setMonthName(rs.getString("monthName"));
        m.setMonthNo(rs.getInt("monthNo"));

        // Final bean
        MonthOrderCount result = new MonthOrderCount();
        result.setMonth(m);
        result.setOrderCount(rs.getInt("orderCount"));

        return result;

    }
}

Structure of my domain objects is:

MonthOrderCount class:

public class MonthOrderCount {
    private Month month;
    private int orderCount;
}
Month class:

public class Month {
    private Quarter quarter;
    private Year year;
    private int monthNo;
    private String monthName;
    private String monthAbbreviation;
}

Quarter class:

public class Quarter {
    private int quarter;
    private String abbreviation;
}

Year class:

public class Year {
    private int yearNo;
    private String year2;
    private String year4;
}

I cannot use standard method:

ResultSetHandler<List<MonthOrderCount>> listUrlHandler = new
BeanListHandler<>(MonthOrderCount.class);

beacuse instances of MonthOrderCount class contains another objects created
from values from a row and I need to create them.

What am I doing wrong with MonthOrderCountHandler class?

Thanks.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message