Polishing
This commit is contained in:
@@ -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:
|
||||
*
|
||||
* <pre class="code">
|
||||
* public class Bean {
|
||||
*
|
||||
* private Foo foo;
|
||||
*
|
||||
* public Foo getFoo() {
|
||||
@@ -56,6 +58,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* return this;
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* 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</a> are fully supported.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
* @see #ExtendedBeanInfo(BeanInfo)
|
||||
* @see ExtendedBeanInfoFactory
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* <p>Very useful for testing. Effectively a mock object.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class ExpectedLookupTemplate extends JndiTemplate {
|
||||
|
||||
private final Map<String, Object> jndiObjects = new ConcurrentHashMap<String, Object>();
|
||||
private final Map<String, Object> jndiObjects = new ConcurrentHashMap<String, Object>(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 {
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* <p>There are various choices for DataSource implementations:
|
||||
* <ul>
|
||||
* <li>{@code SingleConnectionDataSource} (using the same Connection for all getConnection calls)
|
||||
* <li>{@code DriverManagerDataSource} (creating a new Connection on each getConnection call)
|
||||
* <li>Apache's Jakarta Commons DBCP offers {@code org.apache.commons.dbcp.BasicDataSource} (a real pool)
|
||||
* <li>Apache's Commons DBCP offers {@code org.apache.commons.dbcp.BasicDataSource} (a real pool)
|
||||
* </ul>
|
||||
*
|
||||
* <p>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.
|
||||
* <p>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;
|
||||
}
|
||||
|
||||
@@ -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 <E> 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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<Method>();
|
||||
result = new ArrayList<Method>();
|
||||
}
|
||||
result.add(ifcMethod);
|
||||
}
|
||||
|
||||
@@ -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}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
<T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize,
|
||||
ParameterizedPreparedStatementSetter<T> pss) throws DataAccessException;
|
||||
|
||||
@@ -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<int[]> rowsAffected = new ArrayList<int[]>();
|
||||
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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* <p>This class and subclasses throw runtime exceptions, defined in the
|
||||
* <codeorg.springframework.dao package</code> (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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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.<String, Object>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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* <p>There are various choices for DataSource implementations:
|
||||
* <ul>
|
||||
@@ -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.
|
||||
* <p>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;
|
||||
}
|
||||
|
||||
@@ -641,22 +641,25 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
|
||||
*/
|
||||
protected boolean isInvalidPath(String path) {
|
||||
if (path.contains("WEB-INF") || path.contains("META-INF")) {
|
||||
logger.trace("Path contains \"WEB-INF\" or \"META-INF\".");
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Path with \"WEB-INF\" or \"META-INF\": [" + path + "]");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (path.contains(":/")) {
|
||||
String relativePath = (path.charAt(0) == '/' ? path.substring(1) : path);
|
||||
if (ResourceUtils.isUrl(relativePath) || relativePath.startsWith("url:")) {
|
||||
logger.trace("Path represents URL or has \"url:\" prefix.");
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Path represents URL or has \"url:\" prefix: [" + path + "]");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (path.contains("..")) {
|
||||
path = StringUtils.cleanPath(path);
|
||||
if (path.contains("../")) {
|
||||
logger.trace("Path contains \"../\" after call to StringUtils#cleanPath.");
|
||||
return true;
|
||||
if (path.contains("..") && StringUtils.cleanPath(path).contains("../")) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Path contains \"../\" after call to StringUtils#cleanPath: [" + path + "]");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -435,7 +435,7 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE
|
||||
else if (StompCommand.CONNECTED.equals(command)) {
|
||||
this.stats.incrementConnectedCount();
|
||||
accessor = afterStompSessionConnected(message, accessor, session);
|
||||
if (this.eventPublisher != null && StompCommand.CONNECTED.equals(command)) {
|
||||
if (this.eventPublisher != null) {
|
||||
try {
|
||||
SimpAttributes simpAttributes = new SimpAttributes(session.getId(), session.getAttributes());
|
||||
SimpAttributesContextHolder.setAttributes(simpAttributes);
|
||||
|
||||
Reference in New Issue
Block a user