From d4af8c86b2f02a18806c3bb8f7ba7dfeaa51ebe2 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sun, 25 Feb 2018 21:44:34 +0100 Subject: [PATCH] Polishing --- .../factory/CannotLoadBeanClassException.java | 4 +- .../core/CallableStatementCreatorFactory.java | 3 +- .../core/PreparedStatementCreatorFactory.java | 10 ++--- .../NamedParameterJdbcTemplate.java | 21 +++++----- .../user/DefaultUserDestinationResolver.java | 39 +++++++++---------- .../UnknownHttpStatusCodeException.java | 2 +- 6 files changed, 40 insertions(+), 39 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java b/spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java index 26de990a68..17b8f16296 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java @@ -46,7 +46,7 @@ public class CannotLoadBeanClassException extends FatalBeanException { public CannotLoadBeanClassException( String resourceDescription, String beanName, String beanClassName, ClassNotFoundException cause) { - super("Cannot find class [" + String.valueOf(beanClassName) + "] for bean with name '" + beanName + "'" + + super("Cannot find class [" + beanClassName + "] for bean with name '" + beanName + "'" + (resourceDescription != null ? " defined in " + resourceDescription : ""), cause); this.resourceDescription = resourceDescription; this.beanName = beanName; @@ -64,7 +64,7 @@ public class CannotLoadBeanClassException extends FatalBeanException { public CannotLoadBeanClassException( String resourceDescription, String beanName, String beanClassName, LinkageError cause) { - super("Error loading class [" + String.valueOf(beanClassName) + "] for bean with name '" + beanName + "'" + + super("Error loading class [" + beanClassName + "] for bean with name '" + beanName + "'" + (resourceDescription != null ? " defined in " + resourceDescription : "") + ": problem with class file or dependent class", cause); this.resourceDescription = resourceDescription; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java index a7ba226f03..c225ef5644 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -55,6 +55,7 @@ public class CallableStatementCreatorFactory { /** * Create a new factory. Will need to add parameters via the * {@link #addParameter} method or have no parameters. + * @param callString the SQL call string */ public CallableStatementCreatorFactory(String callString) { this.callString = callString; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java index 4eca708ef1..0e65bf8d2e 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -56,7 +56,7 @@ public class PreparedStatementCreatorFactory { private boolean returnGeneratedKeys = false; - private String[] generatedKeysColumnNames = null; + private String[] generatedKeysColumnNames; private NativeJdbcExtractor nativeJdbcExtractor; @@ -64,6 +64,7 @@ public class PreparedStatementCreatorFactory { /** * Create a new factory. Will need to add parameters via the * {@link #addParameter} method or have no parameters. + * @param sql the SQL statement to execute */ public PreparedStatementCreatorFactory(String sql) { this.sql = sql; @@ -72,7 +73,7 @@ public class PreparedStatementCreatorFactory { /** * Create a new factory with the given SQL and JDBC types. - * @param sql SQL to execute + * @param sql the SQL statement to execute * @param types int array of JDBC types */ public PreparedStatementCreatorFactory(String sql, int... types) { @@ -82,9 +83,8 @@ public class PreparedStatementCreatorFactory { /** * Create a new factory with the given SQL and parameters. - * @param sql SQL + * @param sql the SQL statement to execute * @param declaredParameters list of {@link SqlParameter} objects - * @see SqlParameter */ public PreparedStatementCreatorFactory(String sql, List declaredParameters) { this.sql = sql; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java index 9159d3c61d..9a9909543d 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -104,8 +104,8 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations /** - * Expose the classic Spring JdbcTemplate to allow invocation of - * less commonly used methods. + * Expose the classic Spring JdbcTemplate operations to allow invocation + * of less commonly used methods. */ @Override public JdbcOperations getJdbcOperations() { @@ -329,12 +329,14 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations getParsedSql(sql), batchArgs, getJdbcOperations()); } + /** - * Build a PreparedStatementCreator based on the given SQL and named parameters. - *

Note: Not used for the {@code update} variant with generated key handling. - * @param sql SQL to execute + * Build a {@link PreparedStatementCreator} based on the given SQL and named parameters. + *

Note: Directly called from all {@code query} variants. + * Not used for the {@code update} variant with generated key handling. + * @param sql the SQL statement to execute * @param paramSource container of arguments to bind - * @return the corresponding PreparedStatementCreator + * @return the corresponding {@link PreparedStatementCreator} */ protected PreparedStatementCreator getPreparedStatementCreator(String sql, SqlParameterSource paramSource) { ParsedSql parsedSql = getParsedSql(sql); @@ -347,9 +349,8 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations /** * Obtain a parsed representation of the given SQL statement. - *

The default implementation uses an LRU cache with an upper limit - * of 256 entries. - * @param sql the original SQL + *

The default implementation uses an LRU cache with an upper limit of 256 entries. + * @param sql the original SQL statement * @return a representation of the parsed SQL statement */ protected ParsedSql getParsedSql(String sql) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java index c1e4b6210a..432a1eba60 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -67,7 +67,7 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver { * @param userRegistry the registry, never {@code null} */ public DefaultUserDestinationResolver(SimpUserRegistry userRegistry) { - Assert.notNull(userRegistry, "'userRegistry' must not be null"); + Assert.notNull(userRegistry, "SimpUserRegistry must not be null"); this.userRegistry = userRegistry; } @@ -86,8 +86,8 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver { * @param prefix the prefix to use */ public void setUserDestinationPrefix(String prefix) { - Assert.hasText(prefix, "prefix must not be empty"); - this.prefix = prefix.endsWith("/") ? prefix : prefix + "/"; + Assert.hasText(prefix, "Prefix must not be empty"); + this.prefix = (prefix.endsWith("/") ? prefix : prefix + "/"); } /** @@ -101,11 +101,11 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver { * Use this property to indicate whether the leading slash from translated * user destinations should be removed or not. This depends on the * destination prefixes the message broker is configured with. - *

By default this is set to {@code false}, i.e. "do not change the - * target destination", although + *

By default this is set to {@code false}, i.e. + * "do not change the target destination", although * {@link org.springframework.messaging.simp.config.AbstractMessageBrokerConfiguration - * AbstractMessageBrokerConfiguration} may change that to {@code true} if - * the configured destinations do not have a leading slash. + * AbstractMessageBrokerConfiguration} may change that to {@code true} + * if the configured destinations do not have a leading slash. * @param remove whether to remove the leading slash * @since 4.3.14 */ @@ -115,6 +115,7 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver { /** * Whether to remove the leading slash from target destinations. + * @since 4.3.14 */ public boolean isRemoveLeadingSlash() { return this.removeLeadingSlash; @@ -198,18 +199,18 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver { Principal principal = SimpMessageHeaderAccessor.getUser(headers); String user = (principal != null ? principal.getName() : null); Set sessionIds = Collections.singleton(sessionId); - return new ParseResult(sourceDestination, actualDestination, sourceDestination, - sessionIds, user); + return new ParseResult(sourceDestination, actualDestination, sourceDestination, sessionIds, user); } - private ParseResult parseMessage(MessageHeaders headers, String sourceDestination) { + private ParseResult parseMessage(MessageHeaders headers, String sourceDest) { int prefixEnd = this.prefix.length(); - int userEnd = sourceDestination.indexOf('/', prefixEnd); + int userEnd = sourceDest.indexOf('/', prefixEnd); Assert.isTrue(userEnd > 0, "Expected destination pattern \"/user/{userId}/**\""); - String actualDestination = sourceDestination.substring(userEnd); - String subscribeDestination = this.prefix.substring(0, prefixEnd - 1) + actualDestination; - String userName = sourceDestination.substring(prefixEnd, userEnd); + String actualDest = sourceDest.substring(userEnd); + String subscribeDest = this.prefix.substring(0, prefixEnd - 1) + actualDest; + String userName = sourceDest.substring(prefixEnd, userEnd); userName = StringUtils.replace(userName, "%2F", "/"); + String sessionId = SimpMessageHeaderAccessor.getSessionId(headers); Set sessionIds; if (userName.equals(sessionId)) { @@ -219,11 +220,11 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver { else { sessionIds = getSessionIdsByUser(userName, sessionId); } + if (isRemoveLeadingSlash()) { - actualDestination = actualDestination.substring(1); + actualDest = actualDest.substring(1); } - return new ParseResult(sourceDestination, actualDestination, subscribeDestination, - sessionIds, userName); + return new ParseResult(sourceDest, actualDest, subscribeDest, sessionIds, userName); } private Set getSessionIdsByUser(String userName, String sessionId) { @@ -288,7 +289,6 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver { private final String user; - public ParseResult(String sourceDest, String actualDest, String subscribeDest, Set sessionIds, String user) { @@ -299,7 +299,6 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver { this.user = user; } - public String getSourceDestination() { return this.sourceDestination; } diff --git a/spring-web/src/main/java/org/springframework/web/client/UnknownHttpStatusCodeException.java b/spring-web/src/main/java/org/springframework/web/client/UnknownHttpStatusCodeException.java index e23a433884..a17630c091 100644 --- a/spring-web/src/main/java/org/springframework/web/client/UnknownHttpStatusCodeException.java +++ b/spring-web/src/main/java/org/springframework/web/client/UnknownHttpStatusCodeException.java @@ -44,7 +44,7 @@ public class UnknownHttpStatusCodeException extends RestClientResponseException public UnknownHttpStatusCodeException(int rawStatusCode, String statusText, HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) { - super("Unknown status code [" + String.valueOf(rawStatusCode) + "]" + " " + statusText, + super("Unknown status code [" + rawStatusCode + "]" + " " + statusText, rawStatusCode, statusText, responseHeaders, responseBody, responseCharset); }