dgraham     2003/10/17 16:37:57

  Modified:    dbutils/src/java/org/apache/commons/dbutils
                        BasicResultSetConverter.java
  Log:
  Don't call a bean property's setter method if the type of object returned 
  from the database doesn't match the setter method signature.  This
  allows clients to use toBean() to populate most properties and then
  fill in the rest with custom code without having to catch an exception
  from toBean().
  
  Revision  Changes    Path
  1.5       +12 -6     
jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/BasicResultSetConverter.java
  
  Index: BasicResultSetConverter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/BasicResultSetConverter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BasicResultSetConverter.java      17 Oct 2003 23:22:44 -0000      1.4
  +++ BasicResultSetConverter.java      17 Oct 2003 23:37:57 -0000      1.5
  @@ -253,11 +253,17 @@
        * @throws DbException if an error occurs setting the property.
        */
       private void callSetter(PropertyDescriptor pd, Object target, Object value) {
  +        Method setter = pd.getWriteMethod();
   
  -        try {
  -            Method setter = pd.getWriteMethod();
  +        if (setter == null) {
  +            return;
  +        }
  +        
  +        Class[] params = setter.getParameterTypes();
   
  -            if (setter != null) {
  +        try {
  +            // Don't call setter if the value object isn't the right type 
  +            if (value == null || params[0].isInstance(value)) {
                   setter.invoke(target, new Object[] { value });
               }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to