Skip to content

Commit e19dff1

Browse files
committed
Polishing
1 parent 02d727f commit e19dff1

File tree

9 files changed

+73
-78
lines changed

9 files changed

+73
-78
lines changed

spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -73,10 +73,6 @@ public class EhCacheFactoryBean extends CacheConfiguration implements FactoryBea
7373

7474
private Set<CacheEventListener> cacheEventListeners;
7575

76-
private boolean statisticsEnabled = false;
77-
78-
private boolean sampledStatisticsEnabled = false;
79-
8076
private boolean disabled = false;
8177

8278
private String beanName;

spring-context/src/main/java/org/springframework/context/MessageSource.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,11 +42,11 @@ public interface MessageSource {
4242
* @param code the code to lookup up, such as 'calculator.noRateSet'. Users of
4343
* this class are encouraged to base message names on the relevant fully
4444
* qualified class name, thus avoiding conflict and ensuring maximum clarity.
45-
* @param args array of arguments that will be filled in for params within
45+
* @param args an array of arguments that will be filled in for params within
4646
* the message (params look like "{0}", "{1,date}", "{2,time}" within a message),
4747
* or {@code null} if none.
48-
* @param defaultMessage String to return if the lookup fails
49-
* @param locale the Locale in which to do the lookup
48+
* @param defaultMessage a default message to return if the lookup fails
49+
* @param locale the locale in which to do the lookup
5050
* @return the resolved message if the lookup was successful;
5151
* otherwise the default message passed as a parameter
5252
* @see java.text.MessageFormat
@@ -56,10 +56,10 @@ public interface MessageSource {
5656
/**
5757
* Try to resolve the message. Treat as an error if the message can't be found.
5858
* @param code the code to lookup up, such as 'calculator.noRateSet'
59-
* @param args Array of arguments that will be filled in for params within
59+
* @param args an array of arguments that will be filled in for params within
6060
* the message (params look like "{0}", "{1,date}", "{2,time}" within a message),
6161
* or {@code null} if none.
62-
* @param locale the Locale in which to do the lookup
62+
* @param locale the locale in which to do the lookup
6363
* @return the resolved message
6464
* @throws NoSuchMessageException if the message wasn't found
6565
* @see java.text.MessageFormat
@@ -71,9 +71,9 @@ public interface MessageSource {
7171
* {@code MessageSourceResolvable} argument that was passed in.
7272
* <p>NOTE: We must throw a {@code NoSuchMessageException} on this method
7373
* since at the time of calling this method we aren't able to determine if the
74-
* {@code defaultMessage} property of the resolvable is null or not.
75-
* @param resolvable value object storing attributes required to properly resolve a message
76-
* @param locale the Locale in which to do the lookup
74+
* {@code defaultMessage} property of the resolvable is {@code null} or not.
75+
* @param resolvable the value object storing attributes required to resolve a message
76+
* @param locale the locale in which to do the lookup
7777
* @return the resolved message
7878
* @throws NoSuchMessageException if the message wasn't found
7979
* @see java.text.MessageFormat

spring-context/src/main/java/org/springframework/context/MessageSourceResolvable.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@
2727
* @see org.springframework.validation.ObjectError
2828
* @see org.springframework.validation.FieldError
2929
*/
30+
@FunctionalInterface
3031
public interface MessageSourceResolvable {
3132

3233
/**
@@ -38,16 +39,26 @@ public interface MessageSourceResolvable {
3839

3940
/**
4041
* Return the array of arguments to be used to resolve this message.
42+
* <p>The default implementation simply returns {@code null}.
4143
* @return an array of objects to be used as parameters to replace
4244
* placeholders within the message text
4345
* @see java.text.MessageFormat
4446
*/
45-
Object[] getArguments();
47+
default Object[] getArguments() {
48+
return null;
49+
}
4650

4751
/**
4852
* Return the default message to be used to resolve this message.
53+
* <p>The default implementation simply returns {@code null}.
54+
* Note that the default message may be identical to the primary
55+
* message code ({@link #getCodes()}), which effectively enforces
56+
* {@link org.springframework.context.support.AbstractMessageSource#setUseCodeAsDefaultMessage}
57+
* for this particular message.
4958
* @return the default message, or {@code null} if no default
5059
*/
51-
String getDefaultMessage();
60+
default String getDefaultMessage() {
61+
return null;
62+
}
5263

5364
}

spring-context/src/main/java/org/springframework/context/support/MessageSourceSupport.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,13 +52,12 @@ public abstract class MessageSourceSupport {
5252
* Used for passed-in default messages. MessageFormats for resolved
5353
* codes are cached on a specific basis in subclasses.
5454
*/
55-
private final Map<String, Map<Locale, MessageFormat>> messageFormatsPerMessage =
56-
new HashMap<>();
55+
private final Map<String, Map<Locale, MessageFormat>> messageFormatsPerMessage = new HashMap<>();
5756

5857

5958
/**
60-
* Set whether to always apply the MessageFormat rules, parsing even
61-
* messages without arguments.
59+
* Set whether to always apply the {@code MessageFormat} rules,
60+
* parsing even messages without arguments.
6261
* <p>Default is "false": Messages without arguments are by default
6362
* returned as-is, without parsing them through MessageFormat.
6463
* Set this to "true" to enforce MessageFormat for all messages,
@@ -112,7 +111,7 @@ protected String renderDefaultMessage(String defaultMessage, Object[] args, Loca
112111
* @return the formatted message (with resolved arguments)
113112
*/
114113
protected String formatMessage(String msg, Object[] args, Locale locale) {
115-
if (msg == null || (!this.alwaysUseMessageFormat && ObjectUtils.isEmpty(args))) {
114+
if (msg == null || (!isAlwaysUseMessageFormat() && ObjectUtils.isEmpty(args))) {
116115
return msg;
117116
}
118117
MessageFormat messageFormat = null;
@@ -130,12 +129,12 @@ protected String formatMessage(String msg, Object[] args, Locale locale) {
130129
messageFormat = createMessageFormat(msg, locale);
131130
}
132131
catch (IllegalArgumentException ex) {
133-
// invalid message format - probably not intended for formatting,
134-
// rather using a message structure with no arguments involved
135-
if (this.alwaysUseMessageFormat) {
132+
// Invalid message format - probably not intended for formatting,
133+
// rather using a message structure with no arguments involved...
134+
if (isAlwaysUseMessageFormat()) {
136135
throw ex;
137136
}
138-
// silently proceed with raw message if format not enforced
137+
// Silently proceed with raw message if format not enforced...
139138
messageFormat = INVALID_MESSAGE_FORMAT;
140139
}
141140
messageFormatsPerLocale.put(locale, messageFormat);

spring-core/src/main/java/org/springframework/core/CollectionFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
*/
5555
public abstract class CollectionFactory {
5656

57-
private static final Set<Class<?>> approximableCollectionTypes = new HashSet<>(11);
57+
private static final Set<Class<?>> approximableCollectionTypes = new HashSet<>();
5858

59-
private static final Set<Class<?>> approximableMapTypes = new HashSet<>(7);
59+
private static final Set<Class<?>> approximableMapTypes = new HashSet<>();
6060

6161

6262
static {

spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/MySQLMaxValueIncrementer.java

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,7 @@ public class MySQLMaxValueIncrementer extends AbstractColumnMaxValueIncrementer
6767
/** The max id to serve */
6868
private long maxId = 0;
6969

70-
/**
71-
* Whether or not to use a new connection for the incrementer. Defaults to true
72-
* in order to support transactional storage engines. Set this to false if the storage engine
73-
* for the incrementer table is non-transactional like MYISAM and you prefer to not acquire
74-
* an additional database connection
75-
*/
70+
/** Whether or not to use a new connection for the incrementer */
7671
private boolean useNewConnection = true;
7772

7873

@@ -88,41 +83,30 @@ public MySQLMaxValueIncrementer() {
8883
/**
8984
* Convenience constructor.
9085
* @param dataSource the DataSource to use
91-
* @param incrementerName the name of the sequence/table to use
86+
* @param incrementerName the name of the sequence table to use
9287
* @param columnName the name of the column in the sequence table to use
9388
*/
9489
public MySQLMaxValueIncrementer(DataSource dataSource, String incrementerName, String columnName) {
9590
super(dataSource, incrementerName, columnName);
9691
}
9792

98-
/**
99-
* Convenience constructor for setting whether to use a new connection for the incrementer.
100-
* @param dataSource the DataSource to use
101-
* @param incrementerName the name of the sequence/table to use
102-
* @param columnName the name of the column in the sequence table to use
103-
* @param useNewConnection whether to use a new connection for the incrementer
104-
*/
105-
public MySQLMaxValueIncrementer(DataSource dataSource, String incrementerName, String columnName,
106-
boolean useNewConnection) {
107-
super(dataSource, incrementerName, columnName);
108-
this.useNewConnection = useNewConnection;
109-
}
110-
111-
112-
/**
113-
* Return whether to use a new connection for the incrementer.
114-
*/
115-
public boolean isUseNewConnection() {
116-
return useNewConnection;
117-
}
11893

11994
/**
12095
* Set whether to use a new connection for the incrementer.
96+
* <p>{@code true} is necessary to support transactional storage engines,
97+
* using an isolated separate transaction for the increment operation.
98+
* {@code false} is sufficient if the storage engine of the sequence table
99+
* is non-transactional (like MYISAM), avoiding the effort of acquiring an
100+
* extra {@code Connection} for the increment operation.
101+
* <p>Default is {@code true} since Spring Framework 5.0.
102+
* @since 4.3.6
103+
* @see DataSource#getConnection()
121104
*/
122105
public void setUseNewConnection(boolean useNewConnection) {
123106
this.useNewConnection = useNewConnection;
124107
}
125108

109+
126110
@Override
127111
protected synchronized long getNextKey() throws DataAccessException {
128112
if (this.maxId == this.nextId) {
@@ -138,7 +122,7 @@ protected synchronized long getNextKey() throws DataAccessException {
138122
Statement stmt = null;
139123
boolean mustRestoreAutoCommit = false;
140124
try {
141-
if (useNewConnection) {
125+
if (this.useNewConnection) {
142126
con = getDataSource().getConnection();
143127
if (con.getAutoCommit()) {
144128
mustRestoreAutoCommit = true;
@@ -149,7 +133,7 @@ protected synchronized long getNextKey() throws DataAccessException {
149133
con = DataSourceUtils.getConnection(getDataSource());
150134
}
151135
stmt = con.createStatement();
152-
if (!useNewConnection) {
136+
if (!this.useNewConnection) {
153137
DataSourceUtils.applyTransactionTimeout(stmt, getDataSource());
154138
}
155139
// Increment the sequence column...
@@ -180,23 +164,23 @@ protected synchronized long getNextKey() throws DataAccessException {
180164
}
181165
finally {
182166
JdbcUtils.closeStatement(stmt);
183-
if (useNewConnection) {
184-
try {
185-
con.commit();
186-
if (mustRestoreAutoCommit) {
187-
con.setAutoCommit(true);
167+
if (con != null) {
168+
if (this.useNewConnection) {
169+
try {
170+
con.commit();
171+
if (mustRestoreAutoCommit) {
172+
con.setAutoCommit(true);
173+
}
174+
}
175+
catch (SQLException ignore) {
176+
throw new DataAccessResourceFailureException(
177+
"Unable to commit new sequence value changes for " + getIncrementerName());
188178
}
179+
JdbcUtils.closeConnection(con);
189180
}
190-
catch (SQLException ignore) {
191-
throw new DataAccessResourceFailureException(
192-
"Unable to commit new sequence value changes for " + getIncrementerName());
181+
else {
182+
DataSourceUtils.releaseConnection(con, getDataSource());
193183
}
194-
try {
195-
con.close();
196-
} catch (SQLException ignore) {}
197-
}
198-
else {
199-
DataSourceUtils.releaseConnection(con, getDataSource());
200184
}
201185
}
202186
}

spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -124,8 +124,8 @@ public void tearDown() throws Exception {
124124
public static void closeContext() {
125125
if (applicationContext != null) {
126126
applicationContext.close();
127+
applicationContext = null;
127128
}
128-
applicationContext = null;
129129
}
130130

131131

@@ -164,9 +164,9 @@ protected void startNewTransaction() throws TransactionException {
164164
this.transactionStatus = this.transactionManager.getTransaction(this.transactionDefinition);
165165
}
166166

167-
protected void deleteFromTables(String... names) {
168-
for (String name : names) {
169-
this.jdbcTemplate.update("DELETE FROM " + name);
167+
protected void deleteFromTables(String... tableNames) {
168+
for (String tableName : tableNames) {
169+
this.jdbcTemplate.update("DELETE FROM " + tableName);
170170
}
171171
this.zappedTables = true;
172172
}

spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -215,6 +215,7 @@ public int getContentLength() {
215215
return (int) this.contentLength;
216216
}
217217

218+
@Override
218219
public void setContentLengthLong(long contentLength) {
219220
this.contentLength = contentLength;
220221
doAddHeaderValue(CONTENT_LENGTH_HEADER, contentLength, true);

spring-web/src/main/java/org/springframework/http/MediaType.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,13 @@ public class MediaType extends MimeType implements Serializable {
126126

127127
/**
128128
* Public constant media type for {@code application/rss+xml}.
129+
* @since 4.3.6
129130
*/
130131
public final static MediaType APPLICATION_RSS_XML;
131132

132133
/**
133134
* A String equivalent of {@link MediaType#APPLICATION_RSS_XML}.
135+
* @since 4.3.6
134136
*/
135137
public final static String APPLICATION_RSS_XML_VALUE = "application/rss+xml";
136138

@@ -196,12 +198,14 @@ public class MediaType extends MimeType implements Serializable {
196198

197199
/**
198200
* Public constant media type for {@code text/event-stream}.
201+
* @since 4.3.6
199202
* @see <a href="https://www.w3.org/TR/eventsource/">Server-Sent Events W3C recommendation</a>
200203
*/
201204
public final static MediaType TEXT_EVENT_STREAM;
202205

203206
/**
204207
* A String equivalent of {@link MediaType#TEXT_EVENT_STREAM}.
208+
* @since 4.3.6
205209
*/
206210
public final static String TEXT_EVENT_STREAM_VALUE = "text/event-stream";
207211

0 commit comments

Comments
 (0)