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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 Set<CacheEventListener> cacheEventListeners;
private boolean statisticsEnabled = false;
private boolean sampledStatisticsEnabled = false;
private boolean disabled = false; private boolean disabled = false;
private String beanName; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * @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 * this class are encouraged to base message names on the relevant fully
* qualified class name, thus avoiding conflict and ensuring maximum clarity. * 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), * the message (params look like "{0}", "{1,date}", "{2,time}" within a message),
* or {@code null} if none. * or {@code null} if none.
* @param defaultMessage String to return if the lookup fails * @param defaultMessage a default message to return if the lookup fails
* @param locale the Locale in which to do the lookup * @param locale the locale in which to do the lookup
* @return the resolved message if the lookup was successful; * @return the resolved message if the lookup was successful;
* otherwise the default message passed as a parameter * otherwise the default message passed as a parameter
* @see java.text.MessageFormat * @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. * 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 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), * the message (params look like "{0}", "{1,date}", "{2,time}" within a message),
* or {@code null} if none. * 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 * @return the resolved message
* @throws NoSuchMessageException if the message wasn't found * @throws NoSuchMessageException if the message wasn't found
* @see java.text.MessageFormat * @see java.text.MessageFormat
@ -71,9 +71,9 @@ public interface MessageSource {
* {@code MessageSourceResolvable} argument that was passed in. * {@code MessageSourceResolvable} argument that was passed in.
* <p>NOTE: We must throw a {@code NoSuchMessageException} on this method * <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 * 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. * {@code defaultMessage} property of the resolvable is {@code null} or not.
* @param resolvable value object storing attributes required to properly resolve a message * @param resolvable the value object storing attributes required to resolve a message
* @param locale the Locale in which to do the lookup * @param locale the locale in which to do the lookup
* @return the resolved message * @return the resolved message
* @throws NoSuchMessageException if the message wasn't found * @throws NoSuchMessageException if the message wasn't found
* @see java.text.MessageFormat * @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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.ObjectError
* @see org.springframework.validation.FieldError * @see org.springframework.validation.FieldError
*/ */
@FunctionalInterface
public interface MessageSourceResolvable { public interface MessageSourceResolvable {
/** /**
@ -38,16 +39,26 @@ public interface MessageSourceResolvable {
/** /**
* Return the array of arguments to be used to resolve this message. * 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 * @return an array of objects to be used as parameters to replace
* placeholders within the message text * placeholders within the message text
* @see java.text.MessageFormat * @see java.text.MessageFormat
*/ */
Object[] getArguments(); default Object[] getArguments() {
return null;
}
/** /**
* Return the default message to be used to resolve this message. * 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 * @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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * Used for passed-in default messages. MessageFormats for resolved
* codes are cached on a specific basis in subclasses. * codes are cached on a specific basis in subclasses.
*/ */
private final Map<String, Map<Locale, MessageFormat>> messageFormatsPerMessage = private final Map<String, Map<Locale, MessageFormat>> messageFormatsPerMessage = new HashMap<>();
new HashMap<>();
/** /**
* Set whether to always apply the MessageFormat rules, parsing even * Set whether to always apply the {@code MessageFormat} rules,
* messages without arguments. * parsing even messages without arguments.
* <p>Default is "false": Messages without arguments are by default * <p>Default is "false": Messages without arguments are by default
* returned as-is, without parsing them through MessageFormat. * returned as-is, without parsing them through MessageFormat.
* Set this to "true" to enforce MessageFormat for all messages, * 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) * @return the formatted message (with resolved arguments)
*/ */
protected String formatMessage(String msg, Object[] args, Locale locale) { 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; return msg;
} }
MessageFormat messageFormat = null; MessageFormat messageFormat = null;
@ -130,12 +129,12 @@ public abstract class MessageSourceSupport {
messageFormat = createMessageFormat(msg, locale); messageFormat = createMessageFormat(msg, locale);
} }
catch (IllegalArgumentException ex) { catch (IllegalArgumentException ex) {
// invalid message format - probably not intended for formatting, // Invalid message format - probably not intended for formatting,
// rather using a message structure with no arguments involved // rather using a message structure with no arguments involved...
if (this.alwaysUseMessageFormat) { if (isAlwaysUseMessageFormat()) {
throw ex; throw ex;
} }
// silently proceed with raw message if format not enforced // Silently proceed with raw message if format not enforced...
messageFormat = INVALID_MESSAGE_FORMAT; messageFormat = INVALID_MESSAGE_FORMAT;
} }
messageFormatsPerLocale.put(locale, messageFormat); messageFormatsPerLocale.put(locale, messageFormat);

View File

@ -54,9 +54,9 @@ import org.springframework.util.ReflectionUtils;
*/ */
public abstract class CollectionFactory { 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 { static {

View File

@ -67,12 +67,7 @@ public class MySQLMaxValueIncrementer extends AbstractColumnMaxValueIncrementer
/** The max id to serve */ /** The max id to serve */
private long maxId = 0; private long maxId = 0;
/** /** Whether or not to use a new connection for the incrementer */
* 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
*/
private boolean useNewConnection = true; private boolean useNewConnection = true;
@ -88,41 +83,30 @@ public class MySQLMaxValueIncrementer extends AbstractColumnMaxValueIncrementer
/** /**
* Convenience constructor. * Convenience constructor.
* @param dataSource the DataSource to use * @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 * @param columnName the name of the column in the sequence table to use
*/ */
public MySQLMaxValueIncrementer(DataSource dataSource, String incrementerName, String columnName) { public MySQLMaxValueIncrementer(DataSource dataSource, String incrementerName, String columnName) {
super(dataSource, incrementerName, 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. * 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) { public void setUseNewConnection(boolean useNewConnection) {
this.useNewConnection = useNewConnection; this.useNewConnection = useNewConnection;
} }
@Override @Override
protected synchronized long getNextKey() throws DataAccessException { protected synchronized long getNextKey() throws DataAccessException {
if (this.maxId == this.nextId) { if (this.maxId == this.nextId) {
@ -138,7 +122,7 @@ public class MySQLMaxValueIncrementer extends AbstractColumnMaxValueIncrementer
Statement stmt = null; Statement stmt = null;
boolean mustRestoreAutoCommit = false; boolean mustRestoreAutoCommit = false;
try { try {
if (useNewConnection) { if (this.useNewConnection) {
con = getDataSource().getConnection(); con = getDataSource().getConnection();
if (con.getAutoCommit()) { if (con.getAutoCommit()) {
mustRestoreAutoCommit = true; mustRestoreAutoCommit = true;
@ -149,7 +133,7 @@ public class MySQLMaxValueIncrementer extends AbstractColumnMaxValueIncrementer
con = DataSourceUtils.getConnection(getDataSource()); con = DataSourceUtils.getConnection(getDataSource());
} }
stmt = con.createStatement(); stmt = con.createStatement();
if (!useNewConnection) { if (!this.useNewConnection) {
DataSourceUtils.applyTransactionTimeout(stmt, getDataSource()); DataSourceUtils.applyTransactionTimeout(stmt, getDataSource());
} }
// Increment the sequence column... // Increment the sequence column...
@ -180,23 +164,23 @@ public class MySQLMaxValueIncrementer extends AbstractColumnMaxValueIncrementer
} }
finally { finally {
JdbcUtils.closeStatement(stmt); JdbcUtils.closeStatement(stmt);
if (useNewConnection) { if (con != null) {
try { if (this.useNewConnection) {
con.commit(); try {
if (mustRestoreAutoCommit) { con.commit();
con.setAutoCommit(true); if (mustRestoreAutoCommit) {
con.setAutoCommit(true);
}
} }
catch (SQLException ignore) {
throw new DataAccessResourceFailureException(
"Unable to commit new sequence value changes for " + getIncrementerName());
}
JdbcUtils.closeConnection(con);
} }
catch (SQLException ignore) { else {
throw new DataAccessResourceFailureException( DataSourceUtils.releaseConnection(con, getDataSource());
"Unable to commit new sequence value changes for " + getIncrementerName());
} }
try {
con.close();
} catch (SQLException ignore) {}
}
else {
DataSourceUtils.releaseConnection(con, getDataSource());
} }
} }
} }

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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -124,8 +124,8 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests {
public static void closeContext() { public static void closeContext() {
if (applicationContext != null) { if (applicationContext != null) {
applicationContext.close(); applicationContext.close();
applicationContext = null;
} }
applicationContext = null;
} }
@ -164,9 +164,9 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests {
this.transactionStatus = this.transactionManager.getTransaction(this.transactionDefinition); this.transactionStatus = this.transactionManager.getTransaction(this.transactionDefinition);
} }
protected void deleteFromTables(String... names) { protected void deleteFromTables(String... tableNames) {
for (String name : names) { for (String tableName : tableNames) {
this.jdbcTemplate.update("DELETE FROM " + name); this.jdbcTemplate.update("DELETE FROM " + tableName);
} }
this.zappedTables = true; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; return (int) this.contentLength;
} }
@Override
public void setContentLengthLong(long contentLength) { public void setContentLengthLong(long contentLength) {
this.contentLength = contentLength; this.contentLength = contentLength;
doAddHeaderValue(CONTENT_LENGTH_HEADER, contentLength, true); 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}. * Public constant media type for {@code application/rss+xml}.
* @since 4.3.6
*/ */
public final static MediaType APPLICATION_RSS_XML; public final static MediaType APPLICATION_RSS_XML;
/** /**
* A String equivalent of {@link 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"; 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}. * 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> * @see <a href="https://www.w3.org/TR/eventsource/">Server-Sent Events W3C recommendation</a>
*/ */
public final static MediaType TEXT_EVENT_STREAM; public final static MediaType TEXT_EVENT_STREAM;
/** /**
* A String equivalent of {@link 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"; public final static String TEXT_EVENT_STREAM_VALUE = "text/event-stream";