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:53:25 GMT
Yes, I'm sure I will have to debug it,

but I would ask you one more time, is this piece of code certainly correct?
Is this the correct way how to call own implementation of BasicRowProcessor?

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)));

Please check out this, because I am not sure, I make with respect to a very
few examples I found so I can't to guarantee there is no problem producing
this (for me weird) behaviour.

On more time my implementation of BeanProcessor

public class MonthOrderCountHandler extends BeanProcessor {

    Logger logger = Logger.getLogger(MonthOrderCountHandler.class);

    public Object toBean(ResultSet rs, MonthOrderCount type) throws
SQLException {

        logger.info(rs.getString("monthAbbreviation") + " - " +
rs.getString("monthName") + " - " + rs.getInt("monthNo"));

        // 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"));

        logge.info(rs.getString("monthAbbreviation") + " - " +
rs.getString("monthName") + " - " + rs.getInt("monthNo"));

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

        return result;

    }
}

Thank you for your time.

B.





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

> So something else must be setting the order count. Do those values match
> what is in the DB?
>
> I'd recommend walking through your program with the debugger. You can get
> the source for DBUtils and see why the toBean method is or is not being
> called.
>
> Bill-
>
>
> On Sun, Mar 10, 2013 at 12:34 PM, Betty User <usrbetty@gmail.com> wrote:
>
> > 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