Browse Source

Polishing

pull/25187/head
Juergen Hoeller 5 years ago
parent
commit
083dd0e19d
  1. 3
      spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java
  2. 5
      spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java
  3. 10
      spring-core/src/main/java/org/springframework/core/env/AbstractPropertyResolver.java
  4. 12
      spring-core/src/main/java/org/springframework/core/env/EnumerablePropertySource.java
  5. 10
      spring-core/src/main/java/org/springframework/core/env/MapPropertySource.java
  6. 4
      spring-core/src/main/java/org/springframework/core/env/PropertyResolver.java
  7. 4
      spring-core/src/main/java/org/springframework/core/env/PropertySource.java
  8. 5
      spring-core/src/main/java/org/springframework/util/SystemPropertyUtils.java
  9. 16
      spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java
  10. 7
      spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcOperations.java
  11. 6
      spring-orm/src/main/java/org/springframework/orm/hibernate5/support/OpenSessionInViewFilter.java
  12. 4
      spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java
  13. 13
      spring-web/src/main/java/org/springframework/web/util/ServletContextPropertyUtils.java

3
spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java

@ -432,8 +432,7 @@ public abstract class YamlProcessor { @@ -432,8 +432,7 @@ public abstract class YamlProcessor {
/**
* {@link Constructor} that supports filtering of unsupported types.
* <p>If an unsupported type is encountered in a YAML document, an
* {@link IllegalStateException} will be thrown from {@link #getClassForName(String)}.
* @since 5.1.16
* {@link IllegalStateException} will be thrown from {@link #getClassForName}.
*/
private class FilteringConstructor extends Constructor {

5
spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.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.
@ -79,6 +79,7 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver; @@ -79,6 +79,7 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
@ -835,7 +836,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader @@ -835,7 +836,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
// Publish early application events now that we finally have a multicaster...
Set<ApplicationEvent> earlyEventsToProcess = this.earlyApplicationEvents;
this.earlyApplicationEvents = null;
if (earlyEventsToProcess != null) {
if (!CollectionUtils.isEmpty(earlyEventsToProcess)) {
for (ApplicationEvent earlyEvent : earlyEventsToProcess) {
getApplicationEventMulticaster().multicastEvent(earlyEvent);
}

10
spring-core/src/main/java/org/springframework/core/env/AbstractPropertyResolver.java vendored

@ -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.
@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
package org.springframework.core.env;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
@ -136,9 +137,7 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe @@ -136,9 +137,7 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe
@Override
public void setRequiredProperties(String... requiredProperties) {
for (String key : requiredProperties) {
this.requiredProperties.add(key);
}
Collections.addAll(this.requiredProperties, requiredProperties);
}
@Override
@ -224,6 +223,9 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe @@ -224,6 +223,9 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe
* @see #setIgnoreUnresolvableNestedPlaceholders
*/
protected String resolveNestedPlaceholders(String value) {
if (value.isEmpty()) {
return value;
}
return (this.ignoreUnresolvableNestedPlaceholders ?
resolvePlaceholders(value) : resolveRequiredPlaceholders(value));
}

12
spring-core/src/main/java/org/springframework/core/env/EnumerablePropertySource.java vendored

@ -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.
@ -44,10 +44,20 @@ import org.springframework.util.ObjectUtils; @@ -44,10 +44,20 @@ import org.springframework.util.ObjectUtils;
*/
public abstract class EnumerablePropertySource<T> extends PropertySource<T> {
/**
* Create a new {@code EnumerablePropertySource} with the given name and source object.
* @param name the associated name
* @param source the source object
*/
public EnumerablePropertySource(String name, T source) {
super(name, source);
}
/**
* Create a new {@code EnumerablePropertySource} with the given name and with a new
* {@code Object} instance as the underlying source.
* @param name the associated name
*/
protected EnumerablePropertySource(String name) {
super(name);
}

10
spring-core/src/main/java/org/springframework/core/env/MapPropertySource.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 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.
@ -23,6 +23,8 @@ import org.springframework.util.StringUtils; @@ -23,6 +23,8 @@ import org.springframework.util.StringUtils;
/**
* {@link PropertySource} that reads keys and values from a {@code Map} object.
* The underlying map should not contain any {@code null} values in order to
* comply with {@link #getProperty} and {@link #containsProperty} semantics.
*
* @author Chris Beams
* @author Juergen Hoeller
@ -31,6 +33,12 @@ import org.springframework.util.StringUtils; @@ -31,6 +33,12 @@ import org.springframework.util.StringUtils;
*/
public class MapPropertySource extends EnumerablePropertySource<Map<String, Object>> {
/**
* Create a new {@code MapPropertySource} with the given name and {@code Map}.
* @param name the associated name
* @param source the Map source (without {@code null} values in order to get
* consistent {@link #getProperty} and {@link #containsProperty} behavior)
*/
public MapPropertySource(String name, Map<String, Object> source) {
super(name, source);
}

4
spring-core/src/main/java/org/springframework/core/env/PropertyResolver.java vendored

@ -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.
@ -98,7 +98,6 @@ public interface PropertyResolver { @@ -98,7 +98,6 @@ public interface PropertyResolver {
* @return the resolved String (never {@code null})
* @throws IllegalArgumentException if given text is {@code null}
* @see #resolveRequiredPlaceholders
* @see org.springframework.util.SystemPropertyUtils#resolvePlaceholders(String)
*/
String resolvePlaceholders(String text);
@ -109,7 +108,6 @@ public interface PropertyResolver { @@ -109,7 +108,6 @@ public interface PropertyResolver {
* @return the resolved String (never {@code null})
* @throws IllegalArgumentException if given text is {@code null}
* or if any placeholders are unresolvable
* @see org.springframework.util.SystemPropertyUtils#resolvePlaceholders(String, boolean)
*/
String resolveRequiredPlaceholders(String text) throws IllegalArgumentException;

4
spring-core/src/main/java/org/springframework/core/env/PropertySource.java vendored

@ -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.
@ -68,6 +68,8 @@ public abstract class PropertySource<T> { @@ -68,6 +68,8 @@ public abstract class PropertySource<T> {
/**
* Create a new {@code PropertySource} with the given name and source object.
* @param name the associated name
* @param source the source object
*/
public PropertySource(String name, T source) {
Assert.hasText(name, "Property source name must contain at least one character");

5
spring-core/src/main/java/org/springframework/util/SystemPropertyUtils.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.
@ -78,6 +78,9 @@ public abstract class SystemPropertyUtils { @@ -78,6 +78,9 @@ public abstract class SystemPropertyUtils {
* and the "ignoreUnresolvablePlaceholders" flag is {@code false}
*/
public static String resolvePlaceholders(String text, boolean ignoreUnresolvablePlaceholders) {
if (text.isEmpty()) {
return text;
}
PropertyPlaceholderHelper helper = (ignoreUnresolvablePlaceholders ? nonStrictHelper : strictHelper);
return helper.replacePlaceholders(text, new SystemPropertyPlaceholderResolver(text));
}

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

@ -896,6 +896,8 @@ public interface JdbcOperations { @@ -896,6 +896,8 @@ public interface JdbcOperations {
* @param pss object to set parameters on the PreparedStatement
* created by this method
* @return an array of the number of rows affected by each statement
* (may also contain special JDBC-defined negative values for affected rows such as
* {@link java.sql.Statement#SUCCESS_NO_INFO}/{@link java.sql.Statement#EXECUTE_FAILED})
* @throws DataAccessException if there is any problem issuing the update
*/
int[] batchUpdate(String sql, BatchPreparedStatementSetter pss) throws DataAccessException;
@ -905,6 +907,8 @@ public interface JdbcOperations { @@ -905,6 +907,8 @@ public interface JdbcOperations {
* @param sql the SQL statement to execute
* @param batchArgs the List of Object arrays containing the batch of arguments for the query
* @return an array containing the numbers of rows affected by each update in the batch
* (may also contain special JDBC-defined negative values for affected rows such as
* {@link java.sql.Statement#SUCCESS_NO_INFO}/{@link java.sql.Statement#EXECUTE_FAILED})
* @throws DataAccessException if there is any problem issuing the update
*/
int[] batchUpdate(String sql, List<Object[]> batchArgs) throws DataAccessException;
@ -916,20 +920,24 @@ public interface JdbcOperations { @@ -916,20 +920,24 @@ public interface JdbcOperations {
* @param argTypes the SQL types of the arguments
* (constants from {@code java.sql.Types})
* @return an array containing the numbers of rows affected by each update in the batch
* (may also contain special JDBC-defined negative values for affected rows such as
* {@link java.sql.Statement#SUCCESS_NO_INFO}/{@link java.sql.Statement#EXECUTE_FAILED})
* @throws DataAccessException if there is any problem issuing the update
*/
int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes) throws DataAccessException;
/**
* Execute multiple batches using the supplied SQL statement with the collect of supplied arguments.
* The arguments' values will be set using the ParameterizedPreparedStatementSetter.
* Execute multiple batches using the supplied SQL statement with the collect of supplied
* arguments. The arguments' values will be set using the ParameterizedPreparedStatementSetter.
* Each batch should be of size indicated in 'batchSize'.
* @param sql the SQL statement to execute.
* @param batchArgs the List of Object arrays containing the batch of arguments for the query
* @param batchSize batch size
* @param pss the ParameterizedPreparedStatementSetter to use
* @return an array containing for each batch another array containing the numbers of rows affected
* by each update in the batch
* @return an array containing for each batch another array containing the numbers of
* rows affected by each update in the batch
* (may also contain special JDBC-defined negative values for affected rows such as
* {@link java.sql.Statement#SUCCESS_NO_INFO}/{@link java.sql.Statement#EXECUTE_FAILED})
* @throws DataAccessException if there is any problem issuing the update
* @since 3.1
*/

7
spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcOperations.java

@ -498,6 +498,8 @@ public interface NamedParameterJdbcOperations { @@ -498,6 +498,8 @@ public interface NamedParameterJdbcOperations {
* @param sql the SQL statement to execute
* @param batchValues the array of Maps containing the batch of arguments for the query
* @return an array containing the numbers of rows affected by each update in the batch
* (may also contain special JDBC-defined negative values for affected rows such as
* {@link java.sql.Statement#SUCCESS_NO_INFO}/{@link java.sql.Statement#EXECUTE_FAILED})
* @throws DataAccessException if there is any problem issuing the update
*/
int[] batchUpdate(String sql, Map<String, ?>[] batchValues);
@ -505,8 +507,11 @@ public interface NamedParameterJdbcOperations { @@ -505,8 +507,11 @@ public interface NamedParameterJdbcOperations {
/**
* Execute a batch using the supplied SQL statement with the batch of supplied arguments.
* @param sql the SQL statement to execute
* @param batchArgs the array of {@link SqlParameterSource} containing the batch of arguments for the query
* @param batchArgs the array of {@link SqlParameterSource} containing the batch of
* arguments for the query
* @return an array containing the numbers of rows affected by each update in the batch
* (may also contain special JDBC-defined negative values for affected rows such as
* {@link java.sql.Statement#SUCCESS_NO_INFO}/{@link java.sql.Statement#EXECUTE_FAILED})
* @throws DataAccessException if there is any problem issuing the update
*/
int[] batchUpdate(String sql, SqlParameterSource[] batchArgs);

6
spring-orm/src/main/java/org/springframework/orm/hibernate5/support/OpenSessionInViewFilter.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.
@ -51,11 +51,11 @@ import org.springframework.web.filter.OncePerRequestFilter; @@ -51,11 +51,11 @@ import org.springframework.web.filter.OncePerRequestFilter;
* as well as for non-transactional execution (if configured appropriately).
*
* <p><b>NOTE</b>: This filter will by default <i>not</i> flush the Hibernate Session,
* with the flush mode set to {@code FlushMode.NEVER}. It assumes to be used
* with the flush mode set to {@code FlushMode.MANUAL}. It assumes to be used
* in combination with service layer transactions that care for the flushing: The
* active transaction manager will temporarily change the flush mode to
* {@code FlushMode.AUTO} during a read-write transaction, with the flush
* mode reset to {@code FlushMode.NEVER} at the end of each transaction.
* mode reset to {@code FlushMode.MANUAL} at the end of each transaction.
*
* <p><b>WARNING:</b> Applying this filter to existing logic can cause issues that
* have not appeared before, through the use of a single Hibernate Session for the

4
spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.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.
@ -383,7 +383,7 @@ public abstract class TransactionSynchronizationManager { @@ -383,7 +383,7 @@ public abstract class TransactionSynchronizationManager {
* as argument for the {@code beforeCommit} callback, to be able
* to suppress change detection on commit. The present method is meant
* to be used for earlier read-only checks, for example to set the
* flush mode of a Hibernate Session to "FlushMode.NEVER" upfront.
* flush mode of a Hibernate Session to "FlushMode.MANUAL" upfront.
* @see org.springframework.transaction.TransactionDefinition#isReadOnly()
* @see TransactionSynchronization#beforeCommit(boolean)
*/

13
spring-web/src/main/java/org/springframework/web/util/ServletContextPropertyUtils.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.
@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.util;
import javax.servlet.ServletContext;
@ -73,16 +74,18 @@ public abstract class ServletContextPropertyUtils { @@ -73,16 +74,18 @@ public abstract class ServletContextPropertyUtils {
* @see SystemPropertyUtils#PLACEHOLDER_SUFFIX
* @see SystemPropertyUtils#resolvePlaceholders(String, boolean)
*/
public static String resolvePlaceholders(String text, ServletContext servletContext,
boolean ignoreUnresolvablePlaceholders) {
public static String resolvePlaceholders(
String text, ServletContext servletContext, boolean ignoreUnresolvablePlaceholders) {
if (text.isEmpty()) {
return text;
}
PropertyPlaceholderHelper helper = (ignoreUnresolvablePlaceholders ? nonStrictHelper : strictHelper);
return helper.replacePlaceholders(text, new ServletContextPlaceholderResolver(text, servletContext));
}
private static class ServletContextPlaceholderResolver
implements PropertyPlaceholderHelper.PlaceholderResolver {
private static class ServletContextPlaceholderResolver implements PropertyPlaceholderHelper.PlaceholderResolver {
private final String text;

Loading…
Cancel
Save