|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2008 the original author or authors. |
| 2 | + * Copyright 2002-2009 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -100,6 +100,8 @@ public BeanPropertyRowMapper() {
|
100 | 100 | /**
|
101 | 101 | * Create a new BeanPropertyRowMapper, accepting unpopulated properties
|
102 | 102 | * in the target bean.
|
| 103 | + * <p>Consider using the {@link #newInstance} factory method instead, |
| 104 | + * which allows for specifying the mapped type once only. |
103 | 105 | * @param mappedClass the class that each row should be mapped to
|
104 | 106 | */
|
105 | 107 | public BeanPropertyRowMapper(Class<T> mappedClass) {
|
@@ -204,22 +206,23 @@ public boolean isCheckFullyPopulated() {
|
204 | 206 | }
|
205 | 207 |
|
206 | 208 | /**
|
207 |
| - * Set whether we're defaulting Java primitives in the case of mapping a null value from corresponding |
208 |
| - * database fields. |
| 209 | + * Set whether we're defaulting Java primitives in the case of mapping a null value |
| 210 | + * from corresponding database fields. |
209 | 211 | * <p>Default is <code>false</code>, throwing an exception when nulls are mapped to Java primitives.
|
210 | 212 | */
|
211 |
| - public boolean isPrimitivesDefaultedForNullValue() { |
212 |
| - return primitivesDefaultedForNullValue; |
| 213 | + public void setPrimitivesDefaultedForNullValue(boolean primitivesDefaultedForNullValue) { |
| 214 | + this.primitivesDefaultedForNullValue = primitivesDefaultedForNullValue; |
213 | 215 | }
|
214 | 216 |
|
215 | 217 | /**
|
216 |
| - * Return whether we're defaulting Java primitives in the case of mapping a null value from corresponding |
217 |
| - * database fields. |
| 218 | + * Return whether we're defaulting Java primitives in the case of mapping a null value |
| 219 | + * from corresponding database fields. |
218 | 220 | */
|
219 |
| - public void setPrimitivesDefaultedForNullValue(boolean primitivesDefaultedForNullValue) { |
220 |
| - this.primitivesDefaultedForNullValue = primitivesDefaultedForNullValue; |
| 221 | + public boolean isPrimitivesDefaultedForNullValue() { |
| 222 | + return primitivesDefaultedForNullValue; |
221 | 223 | }
|
222 | 224 |
|
| 225 | + |
223 | 226 | /**
|
224 | 227 | * Extract the values for all columns in the current row.
|
225 | 228 | * <p>Utilizes public setters and result set metadata.
|
@@ -305,4 +308,16 @@ protected Object getColumnValue(ResultSet rs, int index, PropertyDescriptor pd)
|
305 | 308 | return JdbcUtils.getResultSetValue(rs, index, pd.getPropertyType());
|
306 | 309 | }
|
307 | 310 |
|
| 311 | + |
| 312 | + /** |
| 313 | + * Static factory method to create a new BeanPropertyRowMapper |
| 314 | + * (with the mapped class specified only once). |
| 315 | + * @param mappedClass the class that each row should be mapped to |
| 316 | + */ |
| 317 | + public static <T> BeanPropertyRowMapper<T> newInstance(Class<T> mappedClass) { |
| 318 | + BeanPropertyRowMapper<T> newInstance = new BeanPropertyRowMapper<T>(); |
| 319 | + newInstance.setMappedClass(mappedClass); |
| 320 | + return newInstance; |
| 321 | + } |
| 322 | + |
308 | 323 | }
|
0 commit comments