diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java index 52d363db667..94bdd80c459 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -100,6 +100,8 @@ public class BeanPropertyRowMapper implements RowMapper { /** * Create a new BeanPropertyRowMapper, accepting unpopulated properties * in the target bean. + *

Consider using the {@link #newInstance} factory method instead, + * which allows for specifying the mapped type once only. * @param mappedClass the class that each row should be mapped to */ public BeanPropertyRowMapper(Class mappedClass) { @@ -204,21 +206,22 @@ public class BeanPropertyRowMapper implements RowMapper { } /** - * Set whether we're defaulting Java primitives in the case of mapping a null value from corresponding - * database fields. + * Set whether we're defaulting Java primitives in the case of mapping a null value + * from corresponding database fields. *

Default is false, throwing an exception when nulls are mapped to Java primitives. */ + public void setPrimitivesDefaultedForNullValue(boolean primitivesDefaultedForNullValue) { + this.primitivesDefaultedForNullValue = primitivesDefaultedForNullValue; + } + + /** + * Return whether we're defaulting Java primitives in the case of mapping a null value + * from corresponding database fields. + */ public boolean isPrimitivesDefaultedForNullValue() { return primitivesDefaultedForNullValue; } - /** - * Return whether we're defaulting Java primitives in the case of mapping a null value from corresponding - * database fields. - */ - public void setPrimitivesDefaultedForNullValue(boolean primitivesDefaultedForNullValue) { - this.primitivesDefaultedForNullValue = primitivesDefaultedForNullValue; - } /** * Extract the values for all columns in the current row. @@ -305,4 +308,16 @@ public class BeanPropertyRowMapper implements RowMapper { return JdbcUtils.getResultSetValue(rs, index, pd.getPropertyType()); } + + /** + * Static factory method to create a new BeanPropertyRowMapper + * (with the mapped class specified only once). + * @param mappedClass the class that each row should be mapped to + */ + public static BeanPropertyRowMapper newInstance(Class mappedClass) { + BeanPropertyRowMapper newInstance = new BeanPropertyRowMapper(); + newInstance.setMappedClass(mappedClass); + return newInstance; + } + } diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/simple/ParameterizedBeanPropertyRowMapper.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/simple/ParameterizedBeanPropertyRowMapper.java index 037caf94824..b33aa545ffe 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/simple/ParameterizedBeanPropertyRowMapper.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/simple/ParameterizedBeanPropertyRowMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,9 +35,9 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper; * String, boolean, Boolean, byte, Byte, short, Short, int, Integer, long, Long, * float, Float, double, Double, BigDecimal, java.util.Date, etc. * - *

The mapper can be configured to use the primitives default value when mapping null values by - * passing in 'true' for the 'primitivesDefaultedForNullValue' using the {@link #newInstance(Class, boolean)} method. - * Also see {@link BeanPropertyRowMapper#setPrimitivesDefaultedForNullValue(boolean)} + *

The mapper can be configured to use the primitives default value when mapping null values + * by setting the {@link #setPrimitivesDefaultedForNullValue 'primitivesDefaultedForNullValue'} + * flag to 'true'. * *

To facilitate mapping between columns and fields that don't have matching names, * try using column aliases in the SQL statement like "select fname as first_name from customer". @@ -59,19 +59,8 @@ public class ParameterizedBeanPropertyRowMapper extends BeanPropertyRowMapper * @param mappedClass the class that each row should be mapped to */ public static ParameterizedBeanPropertyRowMapper newInstance(Class mappedClass) { - return newInstance(mappedClass, false); - } - - /** - * Static factory method to create a new ParameterizedBeanPropertyRowMapper - * (with the mapped class specified only once). - * @param mappedClass the class that each row should be mapped to - * @param primitivesDefaultedForNullValue whether we're defaulting primitives when mapping a null value - */ - public static ParameterizedBeanPropertyRowMapper newInstance(Class mappedClass, boolean primitivesDefaultedForNullValue) { ParameterizedBeanPropertyRowMapper newInstance = new ParameterizedBeanPropertyRowMapper(); newInstance.setMappedClass(mappedClass); - newInstance.setPrimitivesDefaultedForNullValue(primitivesDefaultedForNullValue); return newInstance; }