Issue Details (XML | Word | Printable)

Key: DBUTILS-1
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Xinyi-Huang(???)
Votes: 1
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons DbUtils

[dbutils] BeanListHandler and BeanHandler fail to support java.sql.Date()

Created: 14/Mar/06 10:23 PM   Updated: 02/Jan/08 07:29 AM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: 1.1

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works patch-DBUTILS-1-and-3.txt 2006-11-01 04:03 PM Alan B. Canon 1.0 kB
Text File Licensed for inclusion in ASF works Proposed-DBUTILS-1.patch 2006-11-02 06:17 AM Henri Yandell 1 kB
Environment:
Operating System: Windows 2000
Platform: PC

Bugzilla Id: 38963
Resolution Date: 03/Nov/06 05:03 PM


 Description  « Hide
BeanListHandler or BeanHandler fail to support the java.sql.Date type when
read from database.
I just add some codes to callSetter the method callSetter of BeanProcessor as
----------------------
else if(params[0].getName().equals("java.sql.Date")){
value = (value==null)?null:new java.sql.Date
(((java.util.Date)value).getTime());
setter.invoke(target, new Object[] {value});
----------------------


org.apache.commons.dbutils.BeanProcessor

private void callSetter(Object target, PropertyDescriptor prop, Object value)
throws SQLException {

Method setter = prop.getWriteMethod();

if (setter == null) { return; }

Class[] params = setter.getParameterTypes();
try {
// Don't call setter if the value object isn't the right type
if (this.isCompatibleType(value, params[0])) {
setter.invoke(target, new Object[] { value });
}else if(params[0].getName().equals("java.sql.Date")){
value = (value==null)?null:new java.sql.Date
(((java.util.Date)value).getTime());
setter.invoke(target, new Object[] {value});
}

} catch (IllegalArgumentException e) { throw new SQLException( "Cannot set " + prop.getName() + ": " + e.getMessage()); } catch (IllegalAccessException e) { throw new SQLException( "Cannot set " + prop.getName() + ": " + e.getMessage()); } catch (InvocationTargetException e) { throw new SQLException( "Cannot set " + prop.getName() + ": " + e.getMessage()); }
}



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Alan B. Canon added a comment - 01/Nov/06 04:03 PM
This patch also addresses DBUTILS-3. It may not work if the patch recently attached to that issue has already been applied to source.

Henri Yandell added a comment - 02/Nov/06 06:17 AM
I think it needs a bit more work to support java.sql.Time and Timestamp, and I think the code can be expressed a bit differently to keep things clear.

Alan, how does the 'Proposed-DBUTILS-1.patch' that I just uploaded look to you?


Alan B. Canon added a comment - 03/Nov/06 04:49 PM
Agree with Proposed-DBUTILS-1.patch. Much nicer. Apply?

Henri Yandell added a comment - 03/Nov/06 05:03 PM
svn ci -m "Enabling the bean handlers to support java.sql.Date, Time and Timestamp. #DBUTILS-1. "

Sending src/java/org/apache/commons/dbutils/BeanProcessor.java
Transmitting file data .
Committed revision 470904.