commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Betty User <usrbe...@gmail.com>
Subject Re: [dbutils]
Date Sun, 10 Mar 2013 16:34:49 GMT
Yes, you understand it correcetly and that is what I find weird.

This is a dump of result List<MonthOrderCount>. As you can see there is set
orderCount value in all objects and month object is not set everywhere.

2013-03-10 17:09:46 INFO  ChartDataService:29 -
[MonthOrderCount{month=null, orderCount=1863}, MonthOrderCount{month=null,
orderCount=2262}, MonthOrderCount{month=null, orderCount=2531},
MonthOrderCount{month=null, orderCount=2379}, MonthOrderCount{month=null,
orderCount=2106}, MonthOrderCount{month=null, orderCount=1498},
MonthOrderCount{month=null, orderCount=1300}, MonthOrderCount{month=null,
orderCount=1578}, MonthOrderCount{month=null, orderCount=2385},
MonthOrderCount{month=null, orderCount=2991}, MonthOrderCount{month=null,
orderCount=2219}, MonthOrderCount{month=null, orderCount=1943},
MonthOrderCount{month=null, orderCount=264}]

I added log into toBean() method and there is really no invocation of this
method. I can't unserstand how it can be done..

I would like to provide more details to solve the problem, beacuse I'm
struggling with it for a few hours.

B.

2013/3/10 William Speirs <wspeirs@apache.org>

> In your other e-mail you said that the "value orderCount is correct" so the
> toBean method must be getting called, or else it wouldn't be set...
> correct? Are you saying that the toBean method is never called?
>
> Not sure how to help without more details...
>
> Bill-
>
>
> On Sun, Mar 10, 2013 at 12:20 PM, Betty User <usrbetty@gmail.com> wrote:
>
> > Hello Bill,
> >
> > I don't thinkh there is a problem with getter/setter method - when I
> > simulate this by hand it works correctly. I think that main point of my
> > problem is in its implementayion of BeanProcessor. When I log activity of
> > my toBean() method in MonthOrderCountHandler class there is no record
> about
> > its invokation. I am not sure if the way how I call my implementation of
> > toBean() method is correct, rather I am sure there is some problem in
> > calling it but I don't know where.
> >
> > B.
> >
> > 2013/3/10 William Speirs <wspeirs@apache.org>
> >
> > > You're missing something as you're creating a new Month() and then
> > calling
> > > result.setMonth(m); however, I don't see the code for setMonth.
> > >
> > > I think this is an issue with a getter/setting rather than an issue
> with
> > > DBUtils.
> > >
> > > Can you add debug statements and see what the calls to rs.
> > > getString("monthAbbreviation"), rs.getString("monthName"), and
> > > rs.getInt("monthNo")
> > > return?
> > >
> > > Bill-
> > >
> > >
> > > On Sun, Mar 10, 2013 at 11:32 AM, Betty User <usrbetty@gmail.com>
> wrote:
> > >
> > > > 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