Polishing

This commit is contained in:
Juergen Hoeller 2017-01-12 21:18:01 +01:00
parent 02d727fd7c
commit e19dff179e
9 changed files with 73 additions and 78 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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,10 +73,6 @@ public class EhCacheFactoryBean extends CacheConfiguration implements FactoryBea
private Set<CacheEventListener> cacheEventListeners;
private boolean statisticsEnabled = false;
private boolean sampledStatisticsEnabled = false;
private boolean disabled = false;
private String beanName;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 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.
@ -42,11 +42,11 @@ public interface MessageSource {
* @param code the code to lookup up, such as 'calculator.noRateSet'. Users of
* this class are encouraged to base message names on the relevant fully
* qualified class name, thus avoiding conflict and ensuring maximum clarity.
* @param args array of arguments that will be filled in for params within
* @param args an array of arguments that will be filled in for params within
* the message (params look like "{0}", "{1,date}", "{2,time}" within a message),
* or {@code null} if none.
* @param defaultMessage String to return if the lookup fails
* @param locale the Locale in which to do the lookup
* @param defaultMessage a default message to return if the lookup fails
* @param locale the locale in which to do the lookup
* @return the resolved message if the lookup was successful;
* otherwise the default message passed as a parameter
* @see java.text.MessageFormat
@ -56,10 +56,10 @@ public interface MessageSource {
/**
* Try to resolve the message. Treat as an error if the message can't be found.
* @param code the code to lookup up, such as 'calculator.noRateSet'
* @param args Array of arguments that will be filled in for params within
* @param args an array of arguments that will be filled in for params within
* the message (params look like "{0}", "{1,date}", "{2,time}" within a message),
* or {@code null} if none.
* @param locale the Locale in which to do the lookup
* @param locale the locale in which to do the lookup
* @return the resolved message
* @throws NoSuchMessageException if the message wasn't found
* @see java.text.MessageFormat
@ -71,9 +71,9 @@ public interface MessageSource {
* {@code MessageSourceResolvable} argument that was passed in.
* <p>NOTE: We must throw a {@code NoSuchMessageException} on this method
* since at the time of calling this method we aren't able to determine if the
* {@code defaultMessage} property of the resolvable is null or not.
* @param resolvable value object storing attributes required to properly resolve a message
* @param locale the Locale in which to do the lookup
* {@code defaultMessage} property of the resolvable is {@code null} or not.
* @param resolvable the value object storing attributes required to resolve a message
* @param locale the locale in which to do the lookup
* @return the resolved message
* @throws NoSuchMessageException if the message wasn't found
* @see java.text.MessageFormat

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 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.
@ -27,6 +27,7 @@ package org.springframework.context;
* @see org.springframework.validation.ObjectError
* @see org.springframework.validation.FieldError
*/
@FunctionalInterface
public interface MessageSourceResolvable {
/**
@ -38,16 +39,26 @@ public interface MessageSourceResolvable {
/**
* Return the array of arguments to be used to resolve this message.
* <p>The default implementation simply returns {@code null}.
* @return an array of objects to be used as parameters to replace
* placeholders within the message text
* @see java.text.MessageFormat
*/
Object[] getArguments();
default Object[] getArguments() {
return null;
}
/**
* Return the default message to be used to resolve this message.
* <p>The default implementation simply returns {@code null}.
* Note that the default message may be identical to the primary
* message code ({@link #getCodes()}), which effectively enforces
* {@link org.springframework.context.support.AbstractMessageSource#setUseCodeAsDefaultMessage}
* for this particular message.
* @return the default message, or {@code null} if no default
*/
String getDefaultMessage();
default String getDefaultMessage() {
return null;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@ -52,13 +52,12 @@ public abstract class MessageSourceSupport {
* Used for passed-in default messages. MessageFormats for resolved
* codes are cached on a specific basis in subclasses.
*/
private final Map<String, Map<Locale, MessageFormat>> messageFormatsPerMessage =
new HashMap<>();
private final Map<String, Map<Locale, MessageFormat>> messageFormatsPerMessage = new HashMap<>();
/**
* Set whether to always apply the MessageFormat rules, parsing even
* messages without arguments.
* Set whether to always apply the {@code MessageFormat} rules,
* parsing even messages without arguments.
* <p>Default is "false": Messages without arguments are by default
* returned as-is, without parsing them through MessageFormat.
* Set this to "true" to enforce MessageFormat for all messages,
@ -112,7 +111,7 @@ public abstract class MessageSourceSupport {
* @return the formatted message (with resolved arguments)
*/
protected String formatMessage(String msg, Object[] args, Locale locale) {
if (msg == null || (!this.alwaysUseMessageFormat && ObjectUtils.isEmpty(args))) {
if (msg == null || (!isAlwaysUseMessageFormat() && ObjectUtils.isEmpty(args))) {
return msg;
}
MessageFormat messageFormat = null;
@ -130,12 +129,12 @@ public abstract class MessageSourceSupport {
messageFormat = createMessageFormat(msg, locale);
}
catch (IllegalArgumentException ex) {
// invalid message format - probably not intended for formatting,
// rather using a message structure with no arguments involved
if (this.alwaysUseMessageFormat) {
// Invalid message format - probably not intended for formatting,
// rather using a message structure with no arguments involved...
if (isAlwaysUseMessageFormat()) {
throw ex;
}
// silently proceed with raw message if format not enforced
// Silently proceed with raw message if format not enforced...
messageFormat = INVALID_MESSAGE_FORMAT;
}
messageFormatsPerLocale.put(locale, messageFormat);

View File

@ -54,9 +54,9 @@ import org.springframework.util.ReflectionUtils;
*/
public abstract class CollectionFactory {
private static final Set<Class<?>> approximableCollectionTypes = new HashSet<>(11);
private static final Set<Class<?>> approximableCollectionTypes = new HashSet<>();
private static final Set<Class<?>> approximableMapTypes = new HashSet<>(7);
private static final Set<Class<?>> approximableMapTypes = new HashSet<>();
static {

View File

@ -67,12 +67,7 @@ public class MySQLMaxValueIncrementer extends AbstractColumnMaxValueIncrementer
/** The max id to serve */
private long maxId = 0;
/**
* Whether or not to use a new connection for the incrementer. Defaults to true
* in order to support transactional storage engines. Set this to false if the storage engine
* for the incrementer table is non-transactional like MYISAM and you prefer to not acquire
* an additional database connection
*/
/** Whether or not to use a new connection for the incrementer */
private boolean useNewConnection = true;
@ -88,41 +83,30 @@ public class MySQLMaxValueIncrementer extends AbstractColumnMaxValueIncrementer
/**
* Convenience constructor.
* @param dataSource the DataSource to use
* @param incrementerName the name of the sequence/table to use
* @param incrementerName the name of the sequence table to use
* @param columnName the name of the column in the sequence table to use
*/
public MySQLMaxValueIncrementer(DataSource dataSource, String incrementerName, String columnName) {
super(dataSource, incrementerName, columnName);
}
/**
* Convenience constructor for setting whether to use a new connection for the incrementer.
* @param dataSource the DataSource to use
* @param incrementerName the name of the sequence/table to use
* @param columnName the name of the column in the sequence table to use
* @param useNewConnection whether to use a new connection for the incrementer
*/
public MySQLMaxValueIncrementer(DataSource dataSource, String incrementerName, String columnName,
boolean useNewConnection) {
super(dataSource, incrementerName, columnName);
this.useNewConnection = useNewConnection;
}
/**
* Return whether to use a new connection for the incrementer.
*/
public boolean isUseNewConnection() {
return useNewConnection;
}
/**
* Set whether to use a new connection for the incrementer.
* <p>{@code true} is necessary to support transactional storage engines,
* using an isolated separate transaction for the increment operation.
* {@code false} is sufficient if the storage engine of the sequence table
* is non-transactional (like MYISAM), avoiding the effort of acquiring an
* extra {@code Connection} for the increment operation.
* <p>Default is {@code true} since Spring Framework 5.0.
* @since 4.3.6
* @see DataSource#getConnection()
*/
public void setUseNewConnection(boolean useNewConnection) {
this.useNewConnection = useNewConnection;
}
@Override
protected synchronized long getNextKey() throws DataAccessException {
if (this.maxId == this.nextId) {
@ -138,7 +122,7 @@ public class MySQLMaxValueIncrementer extends AbstractColumnMaxValueIncrementer
Statement stmt = null;
boolean mustRestoreAutoCommit = false;
try {
if (useNewConnection) {
if (this.useNewConnection) {
con = getDataSource().getConnection();
if (con.getAutoCommit()) {
mustRestoreAutoCommit = true;
@ -149,7 +133,7 @@ public class MySQLMaxValueIncrementer extends AbstractColumnMaxValueIncrementer
con = DataSourceUtils.getConnection(getDataSource());
}
stmt = con.createStatement();
if (!useNewConnection) {
if (!this.useNewConnection) {
DataSourceUtils.applyTransactionTimeout(stmt, getDataSource());
}
// Increment the sequence column...
@ -180,7 +164,8 @@ public class MySQLMaxValueIncrementer extends AbstractColumnMaxValueIncrementer
}
finally {
JdbcUtils.closeStatement(stmt);
if (useNewConnection) {
if (con != null) {
if (this.useNewConnection) {
try {
con.commit();
if (mustRestoreAutoCommit) {
@ -191,15 +176,14 @@ public class MySQLMaxValueIncrementer extends AbstractColumnMaxValueIncrementer
throw new DataAccessResourceFailureException(
"Unable to commit new sequence value changes for " + getIncrementerName());
}
try {
con.close();
} catch (SQLException ignore) {}
JdbcUtils.closeConnection(con);
}
else {
DataSourceUtils.releaseConnection(con, getDataSource());
}
}
}
}
else {
this.nextId++;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@ -124,9 +124,9 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests {
public static void closeContext() {
if (applicationContext != null) {
applicationContext.close();
}
applicationContext = null;
}
}
protected EntityManager createContainerManagedEntityManager() {
@ -164,9 +164,9 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests {
this.transactionStatus = this.transactionManager.getTransaction(this.transactionDefinition);
}
protected void deleteFromTables(String... names) {
for (String name : names) {
this.jdbcTemplate.update("DELETE FROM " + name);
protected void deleteFromTables(String... tableNames) {
for (String tableName : tableNames) {
this.jdbcTemplate.update("DELETE FROM " + tableName);
}
this.zappedTables = true;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@ -215,6 +215,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
return (int) this.contentLength;
}
@Override
public void setContentLengthLong(long contentLength) {
this.contentLength = contentLength;
doAddHeaderValue(CONTENT_LENGTH_HEADER, contentLength, true);

View File

@ -126,11 +126,13 @@ public class MediaType extends MimeType implements Serializable {
/**
* Public constant media type for {@code application/rss+xml}.
* @since 4.3.6
*/
public final static MediaType APPLICATION_RSS_XML;
/**
* A String equivalent of {@link MediaType#APPLICATION_RSS_XML}.
* @since 4.3.6
*/
public final static String APPLICATION_RSS_XML_VALUE = "application/rss+xml";
@ -196,12 +198,14 @@ public class MediaType extends MimeType implements Serializable {
/**
* Public constant media type for {@code text/event-stream}.
* @since 4.3.6
* @see <a href="https://www.w3.org/TR/eventsource/">Server-Sent Events W3C recommendation</a>
*/
public final static MediaType TEXT_EVENT_STREAM;
/**
* A String equivalent of {@link MediaType#TEXT_EVENT_STREAM}.
* @since 4.3.6
*/
public final static String TEXT_EVENT_STREAM_VALUE = "text/event-stream";