Polishing

This commit is contained in:
Juergen Hoeller
2020-08-28 19:58:56 +02:00
parent 6d9d4157ef
commit bb9e79daa7
6 changed files with 32 additions and 50 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -114,8 +114,6 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
/**
* Create a new {@code BeanPropertyRowMapper}, accepting unpopulated
* properties in the target bean.
* <p>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<T> mappedClass) {
@@ -222,8 +220,8 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
this.mappedClass = mappedClass;
this.mappedFields = new HashMap<>();
this.mappedProperties = new HashSet<>();
PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(mappedClass);
for (PropertyDescriptor pd : pds) {
for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(mappedClass)) {
if (pd.getWriteMethod() != null) {
this.mappedFields.put(lowerCaseName(pd.getName()), pd);
String underscoredName = underscoreName(pd.getName());
@@ -247,6 +245,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
if (!StringUtils.hasLength(name)) {
return "";
}
StringBuilder result = new StringBuilder();
result.append(lowerCaseName(name.substring(0, 1)));
for (int i = 1; i < name.length(); i++) {
@@ -337,8 +336,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) {
throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields " +
"necessary to populate object of class [" + this.mappedClass.getName() + "]: " +
this.mappedProperties);
"necessary to populate object of " + this.mappedClass + ": " + this.mappedProperties);
}
return mappedObject;
@@ -380,8 +378,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
/**
* Static factory method to create a new {@code BeanPropertyRowMapper}
* (with the mapped class specified only once).
* Static factory method to create a new {@code BeanPropertyRowMapper}.
* @param mappedClass the class that each row should be mapped to
* @see #newInstance(Class, ConversionService)
*/
@@ -390,8 +387,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
}
/**
* Static factory method to create a new {@code BeanPropertyRowMapper}
* (with the required type specified only once).
* Static factory method to create a new {@code BeanPropertyRowMapper}.
* @param mappedClass the class that each row should be mapped to
* @param conversionService the {@link ConversionService} for binding
* JDBC values to bean properties, or {@code null} for none

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -62,8 +62,6 @@ public class SingleColumnRowMapper<T> implements RowMapper<T> {
/**
* Create a new {@code SingleColumnRowMapper}.
* <p>Consider using the {@link #newInstance} factory method instead,
* which allows for specifying the required type once only.
* @param requiredType the type that each result object is expected to match
*/
public SingleColumnRowMapper(Class<T> requiredType) {
@@ -216,8 +214,7 @@ public class SingleColumnRowMapper<T> implements RowMapper<T> {
/**
* Static factory method to create a new {@code SingleColumnRowMapper}
* (with the required type specified only once).
* Static factory method to create a new {@code SingleColumnRowMapper}.
* @param requiredType the type that each result object is expected to match
* @since 4.1
* @see #newInstance(Class, ConversionService)
@@ -227,8 +224,7 @@ public class SingleColumnRowMapper<T> implements RowMapper<T> {
}
/**
* Static factory method to create a new {@code SingleColumnRowMapper}
* (with the required type specified only once).
* Static factory method to create a new {@code SingleColumnRowMapper}.
* @param requiredType the type that each result object is expected to match
* @param conversionService the {@link ConversionService} for converting a
* fetched value, or {@code null} for none

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -37,9 +37,8 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
*/
public class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
public void testOverridingDifferentClassDefinedForMapping() {
BeanPropertyRowMapper mapper = new BeanPropertyRowMapper(Person.class);
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() ->