Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D2947D2A3 for ; Sun, 10 Mar 2013 17:02:35 +0000 (UTC) Received: (qmail 53021 invoked by uid 500); 10 Mar 2013 17:02:34 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 52816 invoked by uid 500); 10 Mar 2013 17:02:33 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 52788 invoked by uid 99); 10 Mar 2013 17:02:32 -0000 Received: from minotaur.apache.org (HELO minotaur.apache.org) (140.211.11.9) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Mar 2013 17:02:32 +0000 Received: from localhost (HELO mail-ie0-f169.google.com) (127.0.0.1) (smtp-auth username wspeirs, mechanism plain) by minotaur.apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Mar 2013 17:02:31 +0000 Received: by mail-ie0-f169.google.com with SMTP id 13so3933089iea.0 for ; Sun, 10 Mar 2013 10:02:31 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.50.135.74 with SMTP id pq10mr4824696igb.46.1362934951140; Sun, 10 Mar 2013 10:02:31 -0700 (PDT) Received: by 10.64.103.34 with HTTP; Sun, 10 Mar 2013 10:02:31 -0700 (PDT) In-Reply-To: References: Date: Sun, 10 Mar 2013 13:02:31 -0400 Message-ID: Subject: Re: [dbutils] From: William Speirs To: Commons Users List Content-Type: multipart/alternative; boundary=e89a8f838b359d795404d795055e --e89a8f838b359d795404d795055e Content-Type: text/plain; charset=ISO-8859-1 I'm not sure why you don't just have MonthOrderCountHandler extend BasicRowProcessor, but what you have looks correct at first glance. Not much help I realize... sorry. Bill- On Sun, Mar 10, 2013 at 12:53 PM, Betty User wrote: > 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 retList = new LinkedList<>(); > BasicRowProcessor brp = new BasicRowProcessor(new > MonthOrderCountHandler()); > BeanListHandler 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 > > > 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 wrote: > > > > > Yes, you understand it correcetly and that is what I find weird. > > > > > > This is a dump of result List. 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 > > > > > > > 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 > > 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 > > > > > > > > > > > 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 > > > > > wrote: > > > > > > > > > > > > > Hello, > > > > > > > > > > > > > > I am creating MVC web application in Spring. > > > > > > > > > > > > > > With this Java code I'm trying to convert resultset int > > JavaBeans. > > > > > > > > > > > > > > List retList = new LinkedList<>(); > > > > > > > BasicRowProcessor brp = new BasicRowProcessor(new > > > > > > > MonthOrderCountHandler()); > > > > > > > BeanListHandler 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> 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. > > > > > > > > > > > > > > > > > > > > > > > > > > > > --e89a8f838b359d795404d795055e--