From 85b5c5a134189a5a72b99b7a02a09ced170a2a5c Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 22 Nov 2018 20:20:36 +0100 Subject: [PATCH] Polishing --- .../beans/ExtendedBeanInfo.java | 6 +++- .../annotation/EnableAsyncTests.java | 5 +-- .../mock/jndi/ExpectedLookupTemplate.java | 27 +++++++-------- .../mock/jndi/SimpleNamingContextBuilder.java | 14 ++++---- .../org/springframework/util/ObjectUtils.java | 16 ++++----- .../springframework/util/ReflectionUtils.java | 3 +- .../util/ObjectUtilsTests.java | 22 ++++++------ .../jdbc/core/JdbcOperations.java | 3 +- .../jdbc/core/JdbcTemplate.java | 8 ++--- .../core/namedparam/NamedParameterUtils.java | 16 ++++----- .../jdbc/object/RdbmsOperation.java | 8 ++--- .../springframework/jdbc/object/SqlCall.java | 31 ++++++++--------- .../namedparam/NamedParameterUtilsTests.java | 34 +++++++++---------- .../broker/DefaultSubscriptionRegistry.java | 4 +-- .../mock/jndi/ExpectedLookupTemplate.java | 3 +- .../mock/jndi/SimpleNamingContextBuilder.java | 12 +++---- .../resource/ResourceHttpRequestHandler.java | 17 ++++++---- .../messaging/StompSubProtocolHandler.java | 4 +-- 18 files changed, 118 insertions(+), 115 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java b/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java index 1411f5569b3..5c0942cffcd 100644 --- a/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java +++ b/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 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. @@ -43,8 +43,10 @@ import org.springframework.util.ObjectUtils; * Decorator for a standard {@link BeanInfo} object, e.g. as created by * {@link Introspector#getBeanInfo(Class)}, designed to discover and register static * and/or non-void returning setter methods. For example: + * *
  * public class Bean {
+ *
  *     private Foo foo;
  *
  *     public Foo getFoo() {
@@ -56,6 +58,7 @@ import org.springframework.util.ObjectUtils;
  *         return this;
  *     }
  * }
+ * * The standard JavaBeans {@code Introspector} will discover the {@code getFoo} read * method, but will bypass the {@code #setFoo(Foo)} write method, because its non-void * returning signature does not comply with the JavaBeans specification. @@ -68,6 +71,7 @@ import org.springframework.util.ObjectUtils; * indexed properties are fully supported. * * @author Chris Beams + * @author Juergen Hoeller * @since 3.1 * @see #ExtendedBeanInfo(BeanInfo) * @see ExtendedBeanInfoFactory diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java index ed5b11fc13c..9eb5aefe35f 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java @@ -161,7 +161,7 @@ public class EnableAsyncTests { Object bean = ctx.getBean(CustomAsyncBean.class); assertTrue(AopUtils.isAopProxy(bean)); boolean isAsyncAdvised = false; - for (Advisor advisor : ((Advised)bean).getAdvisors()) { + for (Advisor advisor : ((Advised) bean).getAdvisors()) { if (advisor instanceof AsyncAnnotationAdvisor) { isAsyncAdvised = true; break; @@ -365,7 +365,8 @@ public class EnableAsyncTests { @EnableAsync static class AsyncConfigWithMockito { - @Bean @Lazy + @Bean + @Lazy public AsyncBean asyncBean() { return Mockito.mock(AsyncBean.class); } diff --git a/spring-context/src/test/java/org/springframework/tests/mock/jndi/ExpectedLookupTemplate.java b/spring-context/src/test/java/org/springframework/tests/mock/jndi/ExpectedLookupTemplate.java index 8cc22aab1b2..00c3d24cfd8 100644 --- a/spring-context/src/test/java/org/springframework/tests/mock/jndi/ExpectedLookupTemplate.java +++ b/spring-context/src/test/java/org/springframework/tests/mock/jndi/ExpectedLookupTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -23,28 +23,29 @@ import javax.naming.NamingException; import org.springframework.jndi.JndiTemplate; /** - * Simple extension of the JndiTemplate class that always returns - * a given object. Very useful for testing. Effectively a mock object. + * Simple extension of the JndiTemplate class that always returns a given object. + * + *

Very useful for testing. Effectively a mock object. * * @author Rod Johnson * @author Juergen Hoeller */ public class ExpectedLookupTemplate extends JndiTemplate { - private final Map jndiObjects = new ConcurrentHashMap(); + private final Map jndiObjects = new ConcurrentHashMap(16); /** - * Construct a new JndiTemplate that will always return given objects - * for given names. To be populated through {@code addObject} calls. + * Construct a new JndiTemplate that will always return given objects for + * given names. To be populated through {@code addObject} calls. * @see #addObject(String, Object) */ public ExpectedLookupTemplate() { } /** - * Construct a new JndiTemplate that will always return the - * given object, but honour only requests for the given name. + * Construct a new JndiTemplate that will always return the given object, + * but honour only requests for the given name. * @param name the name the client is expected to look up * @param object the object that will be returned */ @@ -54,8 +55,7 @@ public class ExpectedLookupTemplate extends JndiTemplate { /** - * Add the given object to the list of JNDI objects that this - * template will expose. + * Add the given object to the list of JNDI objects that this template will expose. * @param name the name the client is expected to look up * @param object the object that will be returned */ @@ -63,11 +63,10 @@ public class ExpectedLookupTemplate extends JndiTemplate { this.jndiObjects.put(name, object); } - /** - * If the name is the expected name specified in the constructor, - * return the object provided in the constructor. If the name is - * unexpected, a respective NamingException gets thrown. + * If the name is the expected name specified in the constructor, return the + * object provided in the constructor. If the name is unexpected, a + * respective NamingException gets thrown. */ @Override public Object lookup(String name) throws NamingException { diff --git a/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContextBuilder.java b/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContextBuilder.java index 1ae3b78d6b1..b4fe464ea00 100644 --- a/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContextBuilder.java +++ b/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContextBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -26,6 +26,7 @@ import javax.naming.spi.NamingManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.util.Assert; import org.springframework.util.ClassUtils; /** @@ -35,13 +36,14 @@ import org.springframework.util.ClassUtils; * configure JNDI appropriately, so that {@code new InitialContext()} * will expose the required objects. Also usable for standalone applications, * e.g. for binding a JDBC DataSource to a well-known JNDI location, to be - * able to use traditional J2EE data access code outside of a J2EE container. + * able to use traditional Java EE data access code outside of a Java EE + * container. * *

There are various choices for DataSource implementations: *

* *

Typical usage in bootstrap code: @@ -98,7 +100,7 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder /** * If no SimpleNamingContextBuilder is already configuring JNDI, - * create and activate one. Otherwise take the existing activate + * create and activate one. Otherwise take the existing activated * SimpleNamingContextBuilder, clear it and return it. *

This is mainly intended for test suites that want to * reinitialize JNDI bindings from scratch repeatedly. @@ -137,12 +139,10 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder logger.info("Activating simple JNDI environment"); synchronized (initializationLock) { if (!initialized) { - if (NamingManager.hasInitialContextFactoryBuilder()) { - throw new IllegalStateException( + Assert.state(!NamingManager.hasInitialContextFactoryBuilder(), "Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. " + "Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, " + "with no reset option. As a consequence, a JNDI provider must only be registered once per JVM."); - } NamingManager.setInitialContextFactoryBuilder(this); initialized = true; } diff --git a/spring-core/src/main/java/org/springframework/util/ObjectUtils.java b/spring-core/src/main/java/org/springframework/util/ObjectUtils.java index 10db9f54f50..05a4622980c 100644 --- a/spring-core/src/main/java/org/springframework/util/ObjectUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ObjectUtils.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. @@ -170,7 +170,7 @@ public abstract class ObjectUtils { /** * Check whether the given array of enum constants contains a constant with the given name, * ignoring case when determining a match. - * @param enumValues the enum values to check, typically the product of a call to MyEnum.values() + * @param enumValues the enum values to check, typically obtained via {@code MyEnum.values()} * @param constant the constant name to find (must not be null or empty string) * @return whether the constant has been found in the given array */ @@ -180,15 +180,14 @@ public abstract class ObjectUtils { /** * Check whether the given array of enum constants contains a constant with the given name. - * @param enumValues the enum values to check, typically the product of a call to MyEnum.values() + * @param enumValues the enum values to check, typically obtained via {@code MyEnum.values()} * @param constant the constant name to find (must not be null or empty string) * @param caseSensitive whether case is significant in determining a match * @return whether the constant has been found in the given array */ public static boolean containsConstant(Enum[] enumValues, String constant, boolean caseSensitive) { for (Enum candidate : enumValues) { - if (caseSensitive ? - candidate.toString().equals(constant) : + if (caseSensitive ? candidate.toString().equals(constant) : candidate.toString().equalsIgnoreCase(constant)) { return true; } @@ -199,7 +198,7 @@ public abstract class ObjectUtils { /** * Case insensitive alternative to {@link Enum#valueOf(Class, String)}. * @param the concrete Enum type - * @param enumValues the array of all Enum constants in question, usually per Enum.values() + * @param enumValues the array of all Enum constants in question, usually per {@code Enum.values()} * @param constant the constant to get the enum value of * @throws IllegalArgumentException if the given constant is not found in the given array * of enum values. Use {@link #containsConstant(Enum[], String)} as a guard to avoid this exception. @@ -210,9 +209,8 @@ public abstract class ObjectUtils { return candidate; } } - throw new IllegalArgumentException( - String.format("constant [%s] does not exist in enum type %s", - constant, enumValues.getClass().getComponentType().getName())); + throw new IllegalArgumentException("Constant [" + constant + "] does not exist in enum type " + + enumValues.getClass().getComponentType().getName()); } /** diff --git a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java index ab1c4a306d6..4d02886ac04 100644 --- a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java @@ -25,7 +25,6 @@ import java.lang.reflect.UndeclaredThrowableException; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -635,7 +634,7 @@ public abstract class ReflectionUtils { for (Method ifcMethod : ifc.getMethods()) { if (!Modifier.isAbstract(ifcMethod.getModifiers())) { if (result == null) { - result = new LinkedList(); + result = new ArrayList(); } result.add(ifcMethod); } diff --git a/spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java b/spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java index d11ea1f7880..c783657c623 100644 --- a/spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java @@ -45,6 +45,7 @@ public class ObjectUtilsTests { @Rule public final ExpectedException exception = ExpectedException.none(); + @Test public void isCheckedException() { assertTrue(ObjectUtils.isCheckedException(new Exception())); @@ -101,8 +102,8 @@ public class ObjectUtilsTests { assertTrue(isEmpty(new Object[0])); assertTrue(isEmpty(new Integer[0])); - assertFalse(isEmpty(new int[] { 42 })); - assertFalse(isEmpty(new Integer[] { new Integer(42) })); + assertFalse(isEmpty(new int[] {42})); + assertFalse(isEmpty(new Integer[] {42})); } @Test @@ -271,7 +272,7 @@ public class ObjectUtilsTests { @Test @Deprecated public void hashCodeWithLong() { - long lng = 883l; + long lng = 883L; int expected = (new Long(lng)).hashCode(); assertEquals(expected, ObjectUtils.hashCode(lng)); } @@ -489,12 +490,12 @@ public class ObjectUtilsTests { @Test public void nullSafeHashCodeWithLongArray() { - long lng = 7993l; + long lng = 7993L; int expected = 31 * 7 + (int) (lng ^ (lng >>> 32)); - lng = 84320l; + lng = 84320L; expected = 31 * expected + (int) (lng ^ (lng >>> 32)); - long[] array = {7993l, 84320l}; + long[] array = {7993L, 84320L}; int actual = ObjectUtils.nullSafeHashCode(array); assertEquals(expected, actual); @@ -715,7 +716,7 @@ public class ObjectUtilsTests { @Test public void nullSafeToStringWithLongArray() { - long[] array = {434l, 23423l}; + long[] array = {434L, 23423L}; assertEquals("{434, 23423}", ObjectUtils.nullSafeToString(array)); } @@ -737,7 +738,7 @@ public class ObjectUtilsTests { @Test public void nullSafeToStringWithObjectArray() { - Object[] array = {"Han", new Long(43)}; + Object[] array = {"Han", Long.valueOf(43)}; assertEquals("{Han, 43}", ObjectUtils.nullSafeToString(array)); } @@ -807,7 +808,8 @@ public class ObjectUtilsTests { assertThat(ObjectUtils.caseInsensitiveValueOf(Tropes.values(), "BAR"), is(Tropes.BAR)); exception.expect(IllegalArgumentException.class); - exception.expectMessage(is("constant [bogus] does not exist in enum type org.springframework.util.ObjectUtilsTests$Tropes")); + exception.expectMessage( + is("Constant [bogus] does not exist in enum type org.springframework.util.ObjectUtilsTests$Tropes")); ObjectUtils.caseInsensitiveValueOf(Tropes.values(), "bogus"); } @@ -818,6 +820,6 @@ public class ObjectUtilsTests { } - enum Tropes { FOO, BAR, baz } + enum Tropes {FOO, BAR, baz} } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java index acd1c0349fe..64aa2a82965 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.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. @@ -914,6 +914,7 @@ public interface JdbcOperations { * @param pss ParameterizedPreparedStatementSetter to use * @return an array containing for each batch another array containing the numbers of rows affected * by each update in the batch + * @since 3.1 */ int[][] batchUpdate(String sql, Collection batchArgs, int batchSize, ParameterizedPreparedStatementSetter pss) throws DataAccessException; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java index 6a2bc943b6a..6f97a196d83 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.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. @@ -1018,11 +1018,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { public int[][] doInPreparedStatement(PreparedStatement ps) throws SQLException { List rowsAffected = new ArrayList(); try { - boolean batchSupported = true; - if (!JdbcUtils.supportsBatchUpdates(ps.getConnection())) { - batchSupported = false; - logger.warn("JDBC Driver does not support Batch updates; resorting to single statement execution"); - } + boolean batchSupported = JdbcUtils.supportsBatchUpdates(ps.getConnection()); int n = 0; for (T obj : batchArgs) { pss.setValues(ps, obj); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java index 41a526fbc29..43d49c87fde 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java @@ -99,25 +99,25 @@ public abstract class NamedParameterUtils { char c = statement[i]; if (c == ':' || c == '&') { int j = i + 1; - if (j < statement.length && statement[j] == ':' && c == ':') { + if (c == ':' && j < statement.length && statement[j] == ':') { // Postgres-style "::" casting operator should be skipped i = i + 2; continue; } String parameter = null; - if (j < statement.length && c == ':' && statement[j] == '{') { + if (c == ':' && j < statement.length && statement[j] == '{') { // :{x} style parameter - while (j < statement.length && statement[j] != '}') { + while (statement[j] != '}') { j++; + if (j >= statement.length) { + throw new InvalidDataAccessApiUsageException("Non-terminated named parameter declaration " + + "at position " + i + " in statement: " + sql); + } if (statement[j] == ':' || statement[j] == '{') { throw new InvalidDataAccessApiUsageException("Parameter name contains invalid character '" + statement[j] + "' at position " + i + " in statement: " + sql); } } - if (j >= statement.length) { - throw new InvalidDataAccessApiUsageException( - "Non-terminated named parameter declaration at position " + i + " in statement: " + sql); - } if (j - i > 2) { parameter = sql.substring(i + 2, j); namedParameterCount = addNewNamedParameter(namedParameters, namedParameterCount, parameter); @@ -190,7 +190,7 @@ public abstract class NamedParameterUtils { } /** - * Skip over comments and quoted names present in an SQL statement + * Skip over comments and quoted names present in an SQL statement. * @param statement character array containing SQL statement * @param position current position of statement * @return next position to process after any comments or quotes are skipped diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java index b6ad500ca43..e285f1b45bd 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.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. @@ -41,7 +41,7 @@ import org.springframework.util.Assert; * arguments. Subclasses should be JavaBeans, allowing easy configuration. * *

This class and subclasses throw runtime exceptions, defined in the - * (and as thrown by the + * {@code org.springframework.dao} package (and as thrown by the * {@code org.springframework.jdbc.core} package, which the classes * in this package use under the hood to perform raw JDBC operations). * @@ -71,7 +71,7 @@ public abstract class RdbmsOperation implements InitializingBean { private boolean returnGeneratedKeys = false; - private String[] generatedKeysColumnNames = null; + private String[] generatedKeysColumnNames; private String sql; @@ -282,7 +282,7 @@ public abstract class RdbmsOperation implements InitializingBean { * Add one or more declared parameters. Used for configuring this operation * when used in a bean factory. Each parameter will specify SQL type and (optionally) * the parameter's name. - * @param parameters Array containing the declared {@link SqlParameter} objects + * @param parameters an array containing the declared {@link SqlParameter} objects * @see #declaredParameters */ public void setParameters(SqlParameter... parameters) { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java index ee70d608d34..eb0d58ffb0e 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -38,12 +38,6 @@ import org.springframework.jdbc.core.SqlParameter; */ public abstract class SqlCall extends RdbmsOperation { - /** - * Object enabling us to create CallableStatementCreators - * efficiently, based on this class's declared parameters. - */ - private CallableStatementCreatorFactory callableStatementFactory; - /** * Flag used to indicate that this call is for a function and to * use the {? = call get_invoice_count(?)} syntax. @@ -51,19 +45,24 @@ public abstract class SqlCall extends RdbmsOperation { private boolean function = false; /** - * Flag used to indicate that the sql for this call should be used exactly as it is - * defined. No need to add the escape syntax and parameter place holders. + * Flag used to indicate that the sql for this call should be used exactly as + * it is defined. No need to add the escape syntax and parameter place holders. */ private boolean sqlReadyForUse = false; /** * Call string as defined in java.sql.CallableStatement. - * String of form {call add_invoice(?, ?, ?)} - * or {? = call get_invoice_count(?)} if isFunction is set to true - * Updated after each parameter is added. + * String of form {call add_invoice(?, ?, ?)} or {? = call get_invoice_count(?)} + * if isFunction is set to true. Updated after each parameter is added. */ private String callString; + /** + * Object enabling us to create CallableStatementCreators + * efficiently, based on this class's declared parameters. + */ + private CallableStatementCreatorFactory callableStatementFactory; + /** * Constructor to allow use as a JavaBean. @@ -79,8 +78,8 @@ public abstract class SqlCall extends RdbmsOperation { /** * Create a new SqlCall object with SQL, but without parameters. * Must add parameters or settle with none. - * @param ds DataSource to obtain connections from - * @param sql SQL to execute + * @param ds the DataSource to obtain connections from + * @param sql the SQL to execute */ public SqlCall(DataSource ds, String sql) { setDataSource(ds); @@ -99,7 +98,7 @@ public abstract class SqlCall extends RdbmsOperation { * Return whether this call is for a function. */ public boolean isFunction() { - return function; + return this.function; } /** @@ -113,7 +112,7 @@ public abstract class SqlCall extends RdbmsOperation { * Return whether the SQL can be used as is. */ public boolean isSqlReadyForUse() { - return sqlReadyForUse; + return this.sqlReadyForUse; } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterUtilsTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterUtilsTests.java index 949634f4bb0..3cf4eba6599 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterUtilsTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterUtilsTests.java @@ -52,11 +52,11 @@ public class NamedParameterUtilsTests { assertEquals(2, psql2.getTotalParameterCount()); assertEquals(1, psql2.getNamedParameterCount()); - String sql3 = "xxx &a+:b" + '\t' + ":c%10 yyyy ? zzzzz"; + String sql3 = "xxx &ä+:ö" + '\t' + ":ü%10 yyyy ? zzzzz"; ParsedSql psql3 = NamedParameterUtils.parseSqlStatement(sql3); - assertEquals("a", psql3.getParameterNames().get(0)); - assertEquals("b", psql3.getParameterNames().get(1)); - assertEquals("c", psql3.getParameterNames().get(2)); + assertEquals("ä", psql3.getParameterNames().get(0)); + assertEquals("ö", psql3.getParameterNames().get(1)); + assertEquals("ü", psql3.getParameterNames().get(2)); } @Test @@ -117,13 +117,13 @@ public class NamedParameterUtilsTests { } @Test(expected = InvalidDataAccessApiUsageException.class) - public void buildValueArrayWithMissingParameterValue() throws Exception { + public void buildValueArrayWithMissingParameterValue() { String sql = "select count(0) from foo where id = :id"; NamedParameterUtils.buildValueArray(sql, Collections.emptyMap()); } @Test - public void substituteNamedParametersWithStringContainingQuotes() throws Exception { + public void substituteNamedParametersWithStringContainingQuotes() { String expectedSql = "select 'first name' from artists where id = ? and quote = 'exsqueeze me?'"; String sql = "select 'first name' from artists where id = :id and quote = 'exsqueeze me?'"; String newSql = NamedParameterUtils.substituteNamedParameters(sql, new MapSqlParameterSource()); @@ -131,7 +131,7 @@ public class NamedParameterUtilsTests { } @Test - public void testParseSqlStatementWithStringContainingQuotes() throws Exception { + public void testParseSqlStatementWithStringContainingQuotes() { String expectedSql = "select 'first name' from artists where id = ? and quote = 'exsqueeze me?'"; String sql = "select 'first name' from artists where id = :id and quote = 'exsqueeze me?'"; ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql); @@ -173,7 +173,7 @@ public class NamedParameterUtilsTests { } @Test // SPR-4612 - public void parseSqlStatementWithPostgresCasting() throws Exception { + public void parseSqlStatementWithPostgresCasting() { String expectedSql = "select 'first name' from artists where id = ? and birth_date=?::timestamp"; String sql = "select 'first name' from artists where id = :id and birth_date=:birthDate::timestamp"; ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql); @@ -181,7 +181,7 @@ public class NamedParameterUtilsTests { } @Test // SPR-13582 - public void parseSqlStatementWithPostgresContainedOperator() throws Exception { + public void parseSqlStatementWithPostgresContainedOperator() { String expectedSql = "select 'first name' from artists where info->'stat'->'albums' = ?? ? and '[\"1\",\"2\",\"3\"]'::jsonb ?? '4'"; String sql = "select 'first name' from artists where info->'stat'->'albums' = ?? :album and '[\"1\",\"2\",\"3\"]'::jsonb ?? '4'"; ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql); @@ -190,7 +190,7 @@ public class NamedParameterUtilsTests { } @Test // SPR-15382 - public void parseSqlStatementWithPostgresAnyArrayStringsExistsOperator() throws Exception { + public void parseSqlStatementWithPostgresAnyArrayStringsExistsOperator() { String expectedSql = "select '[\"3\", \"11\"]'::jsonb ?| '{1,3,11,12,17}'::text[]"; String sql = "select '[\"3\", \"11\"]'::jsonb ?| '{1,3,11,12,17}'::text[]"; @@ -200,7 +200,7 @@ public class NamedParameterUtilsTests { } @Test // SPR-15382 - public void parseSqlStatementWithPostgresAllArrayStringsExistsOperator() throws Exception { + public void parseSqlStatementWithPostgresAllArrayStringsExistsOperator() { String expectedSql = "select '[\"3\", \"11\"]'::jsonb ?& '{1,3,11,12,17}'::text[] AND ? = 'Back in Black'"; String sql = "select '[\"3\", \"11\"]'::jsonb ?& '{1,3,11,12,17}'::text[] AND :album = 'Back in Black'"; @@ -210,7 +210,7 @@ public class NamedParameterUtilsTests { } @Test // SPR-7476 - public void parseSqlStatementWithEscapedColon() throws Exception { + public void parseSqlStatementWithEscapedColon() { String expectedSql = "select '0\\:0' as a, foo from bar where baz < DATE(? 23:59:59) and baz = ?"; String sql = "select '0\\:0' as a, foo from bar where baz < DATE(:p1 23\\:59\\:59) and baz = :p2"; @@ -223,7 +223,7 @@ public class NamedParameterUtilsTests { } @Test // SPR-7476 - public void parseSqlStatementWithBracketDelimitedParameterNames() throws Exception { + public void parseSqlStatementWithBracketDelimitedParameterNames() { String expectedSql = "select foo from bar where baz = b??z"; String sql = "select foo from bar where baz = b:{p1}:{p2}z"; @@ -236,7 +236,7 @@ public class NamedParameterUtilsTests { } @Test // SPR-7476 - public void parseSqlStatementWithEmptyBracketsOrBracketsInQuotes() throws Exception { + public void parseSqlStatementWithEmptyBracketsOrBracketsInQuotes() { String expectedSql = "select foo from bar where baz = b:{}z"; String sql = "select foo from bar where baz = b:{}z"; ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql); @@ -257,7 +257,7 @@ public class NamedParameterUtilsTests { public void parseSqlStatementWithSingleLetterInBrackets() { String expectedSql = "select foo from bar where baz = b?z"; String sql = "select foo from bar where baz = b:{p}z"; - + ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql); assertEquals(1, parsedSql.getParameterNames().size()); assertEquals("p", parsedSql.getParameterNames().get(0)); @@ -273,14 +273,14 @@ public class NamedParameterUtilsTests { } @Test // SPR-2544 - public void substituteNamedParametersWithLogicalAnd() throws Exception { + public void substituteNamedParametersWithLogicalAnd() { String expectedSql = "xxx & yyyy"; String newSql = NamedParameterUtils.substituteNamedParameters(expectedSql, new MapSqlParameterSource()); assertEquals(expectedSql, newSql); } @Test // SPR-3173 - public void variableAssignmentOperator() throws Exception { + public void variableAssignmentOperator() { String expectedSql = "x := 1"; String newSql = NamedParameterUtils.substituteNamedParameters(expectedSql, new MapSqlParameterSource()); assertEquals(expectedSql, newSql); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java index 49673a5ba89..9691ecea40e 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java @@ -65,7 +65,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { public static final int DEFAULT_CACHE_LIMIT = 1024; /** Static evaluation context to reuse */ - private static EvaluationContext messageEvalContext = + private static final EvaluationContext messageEvalContext = SimpleEvaluationContext.forPropertyAccessors(new SimpMessageHeaderPropertyAccessor()).build(); @@ -128,7 +128,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { * @since 4.2 */ public void setSelectorHeaderName(String selectorHeaderName) { - this.selectorHeaderName = StringUtils.hasText(selectorHeaderName) ? selectorHeaderName : null; + this.selectorHeaderName = (StringUtils.hasText(selectorHeaderName) ? selectorHeaderName : null); } /** diff --git a/spring-test/src/main/java/org/springframework/mock/jndi/ExpectedLookupTemplate.java b/spring-test/src/main/java/org/springframework/mock/jndi/ExpectedLookupTemplate.java index 7bffe4de135..0a6b40fa0db 100644 --- a/spring-test/src/main/java/org/springframework/mock/jndi/ExpectedLookupTemplate.java +++ b/spring-test/src/main/java/org/springframework/mock/jndi/ExpectedLookupTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -53,6 +53,7 @@ public class ExpectedLookupTemplate extends JndiTemplate { addObject(name, object); } + /** * Add the given object to the list of JNDI objects that this template will expose. * @param name the name the client is expected to look up diff --git a/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContextBuilder.java b/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContextBuilder.java index d12a968fbd4..fc759e05a69 100644 --- a/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContextBuilder.java +++ b/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContextBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 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. @@ -26,6 +26,7 @@ import javax.naming.spi.NamingManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.util.Assert; import org.springframework.util.ClassUtils; /** @@ -35,7 +36,8 @@ import org.springframework.util.ClassUtils; * configure JNDI appropriately, so that {@code new InitialContext()} * will expose the required objects. Also usable for standalone applications, * e.g. for binding a JDBC DataSource to a well-known JNDI location, to be - * able to use traditional J2EE data access code outside of a J2EE container. + * able to use traditional Java EE data access code outside of a Java EE + * container. * *

There are various choices for DataSource implementations: *