Browse Source

Polishing

5.0.x
Juergen Hoeller 6 years ago
parent
commit
94f3c96bc1
  1. 13
      spring-beans/src/main/java/org/springframework/beans/BeanUtils.java
  2. 8
      spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.java
  3. 16
      spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java
  4. 11
      spring-jdbc/src/main/java/org/springframework/jdbc/core/SingleColumnRowMapper.java
  5. 4
      spring-jdbc/src/test/java/org/springframework/jdbc/core/BeanPropertyRowMapperTests.java

13
spring-beans/src/main/java/org/springframework/beans/BeanUtils.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 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.
@ -192,7 +192,6 @@ public abstract class BeanUtils { @@ -192,7 +192,6 @@ public abstract class BeanUtils {
* @since 5.0
* @see <a href="https://kotlinlang.org/docs/reference/classes.html#constructors">Kotlin docs</a>
*/
@SuppressWarnings("unchecked")
@Nullable
public static <T> Constructor<T> findPrimaryConstructor(Class<T> clazz) {
Assert.notNull(clazz, "Class must not be null");
@ -407,8 +406,7 @@ public abstract class BeanUtils { @@ -407,8 +406,7 @@ public abstract class BeanUtils {
* @throws BeansException if PropertyDescriptor look fails
*/
public static PropertyDescriptor[] getPropertyDescriptors(Class<?> clazz) throws BeansException {
CachedIntrospectionResults cr = CachedIntrospectionResults.forClass(clazz);
return cr.getPropertyDescriptors();
return CachedIntrospectionResults.forClass(clazz).getPropertyDescriptors();
}
/**
@ -419,11 +417,8 @@ public abstract class BeanUtils { @@ -419,11 +417,8 @@ public abstract class BeanUtils {
* @throws BeansException if PropertyDescriptor lookup fails
*/
@Nullable
public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String propertyName)
throws BeansException {
CachedIntrospectionResults cr = CachedIntrospectionResults.forClass(clazz);
return cr.getPropertyDescriptor(propertyName);
public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String propertyName) throws BeansException {
return CachedIntrospectionResults.forClass(clazz).getPropertyDescriptor(propertyName);
}
/**

8
spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 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.
@ -60,12 +60,13 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor { @@ -60,12 +60,13 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
@Nullable
private Class<?> propertyType;
@Nullable
private final Class<?> propertyEditorClass;
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
@Nullable Method readMethod, @Nullable Method writeMethod, Class<?> propertyEditorClass)
throws IntrospectionException {
@Nullable Method readMethod, @Nullable Method writeMethod,
@Nullable Class<?> propertyEditorClass) throws IntrospectionException {
super(propertyName, null, null);
this.beanClass = beanClass;
@ -157,6 +158,7 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor { @@ -157,6 +158,7 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
}
@Override
@Nullable
public Class<?> getPropertyEditorClass() {
return this.propertyEditorClass;
}

16
spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 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.
@ -73,6 +73,7 @@ import org.springframework.util.StringUtils; @@ -73,6 +73,7 @@ import org.springframework.util.StringUtils;
* @author Thomas Risberg
* @author Juergen Hoeller
* @since 2.5
* @param <T> the result type
*/
public class BeanPropertyRowMapper<T> implements RowMapper<T> {
@ -113,8 +114,6 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> { @@ -113,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) {
@ -221,8 +220,8 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> { @@ -221,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());
@ -246,6 +245,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> { @@ -246,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++) {
@ -336,8 +336,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> { @@ -336,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;
@ -379,8 +378,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> { @@ -379,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
*/
public static <T> BeanPropertyRowMapper<T> newInstance(Class<T> mappedClass) {

11
spring-jdbc/src/main/java/org/springframework/jdbc/core/SingleColumnRowMapper.java

@ -1,5 +1,5 @@ @@ -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.
@ -41,6 +41,7 @@ import org.springframework.util.NumberUtils; @@ -41,6 +41,7 @@ import org.springframework.util.NumberUtils;
* @author Juergen Hoeller
* @author Kazuki Shimizu
* @since 1.2
* @param <T> the result type
* @see JdbcTemplate#queryForList(String, Class)
* @see JdbcTemplate#queryForObject(String, Class)
*/
@ -61,8 +62,6 @@ public class SingleColumnRowMapper<T> implements RowMapper<T> { @@ -61,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) {
@ -215,8 +214,7 @@ public class SingleColumnRowMapper<T> implements RowMapper<T> { @@ -215,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)
@ -226,8 +224,7 @@ public class SingleColumnRowMapper<T> implements RowMapper<T> { @@ -226,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

4
spring-jdbc/src/test/java/org/springframework/jdbc/core/BeanPropertyRowMapperTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 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.
@ -43,7 +43,7 @@ public class BeanPropertyRowMapperTests extends AbstractRowMapperTests { @@ -43,7 +43,7 @@ public class BeanPropertyRowMapperTests extends AbstractRowMapperTests {
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
public void testOverridingDifferentClassDefinedForMapping() {
BeanPropertyRowMapper mapper = new BeanPropertyRowMapper(Person.class);
thrown.expect(InvalidDataAccessApiUsageException.class);

Loading…
Cancel
Save