Polishing

This commit is contained in:
Juergen Hoeller 2014-02-07 17:42:37 +01:00
parent 99f9dce14a
commit 749b65b0b2
5 changed files with 28 additions and 40 deletions

View File

@ -33,12 +33,12 @@ import org.springframework.core.NamedThreadLocal;
* <p><strong>Note</strong> that the {@code SimpleThreadScope} <em>does not clean * <p><strong>Note</strong> that the {@code SimpleThreadScope} <em>does not clean
* up any objects</em> associated with it. As such, it's typically preferable to * up any objects</em> associated with it. As such, it's typically preferable to
* use the {@link org.springframework.web.context.request.RequestScope RequestScope} * use the {@link org.springframework.web.context.request.RequestScope RequestScope}
* in Web environments. * in web environments.
* *
* <p>For an implementation of a thread-based {@code Scope} with support for * <p>For an implementation of a thread-based {@code Scope} with support for
* destruction callbacks, refer to the <a * destruction callbacks, refer to the
* href="http://www.springbyexample.org/examples/custom-thread-scope-module.html">Spring * <a href="http://www.springbyexample.org/examples/custom-thread-scope-module.html">
* by Example Custom Thread Scope Module</a>. * Spring by Example Custom Thread Scope Module</a>.
* *
* <p>Thanks to Eugene Kuleshov for submitting the original prototype for a thread scope! * <p>Thanks to Eugene Kuleshov for submitting the original prototype for a thread scope!
* *
@ -59,9 +59,10 @@ public class SimpleThreadScope implements Scope {
} }
}; };
@Override @Override
public Object get(String name, ObjectFactory<?> objectFactory) { public Object get(String name, ObjectFactory<?> objectFactory) {
Map<String, Object> scope = threadScope.get(); Map<String, Object> scope = this.threadScope.get();
Object object = scope.get(name); Object object = scope.get(name);
if (object == null) { if (object == null) {
object = objectFactory.getObject(); object = objectFactory.getObject();
@ -72,14 +73,14 @@ public class SimpleThreadScope implements Scope {
@Override @Override
public Object remove(String name) { public Object remove(String name) {
Map<String, Object> scope = threadScope.get(); Map<String, Object> scope = this.threadScope.get();
return scope.remove(name); return scope.remove(name);
} }
@Override @Override
public void registerDestructionCallback(String name, Runnable callback) { public void registerDestructionCallback(String name, Runnable callback) {
logger.warn("SimpleThreadScope does not support destruction callbacks. " + logger.warn("SimpleThreadScope does not support destruction callbacks. " +
"Consider using a RequestScope in a Web environment."); "Consider using RequestScope in a web environment.");
} }
@Override @Override

View File

@ -40,7 +40,7 @@ import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** /**
* Additional and overridden tests for the CGLIB proxy. * Additional and overridden tests for CGLIB proxies.
* *
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
@ -51,7 +51,8 @@ import static org.junit.Assert.*;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public final class CglibProxyTests extends AbstractAopProxyTests implements Serializable { public final class CglibProxyTests extends AbstractAopProxyTests implements Serializable {
private static final String DEPENDENCY_CHECK_CONTEXT = CglibProxyTests.class.getSimpleName() + "-with-dependency-checking.xml"; private static final String DEPENDENCY_CHECK_CONTEXT =
CglibProxyTests.class.getSimpleName() + "-with-dependency-checking.xml";
@Override @Override
@ -317,15 +318,13 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
@Test @Test
@SuppressWarnings("resource") @SuppressWarnings("resource")
public void testWithDependencyChecking() { public void testWithDependencyChecking() {
ApplicationContext ctx = ApplicationContext ctx = new ClassPathXmlApplicationContext(DEPENDENCY_CHECK_CONTEXT, getClass());
new ClassPathXmlApplicationContext(DEPENDENCY_CHECK_CONTEXT, getClass());
ctx.getBean("testBean"); ctx.getBean("testBean");
} }
@Test @Test
public void testAddAdviceAtRuntime() { public void testAddAdviceAtRuntime() {
TestBean bean = new TestBean(); TestBean bean = new TestBean();
CountingBeforeAdvice cba = new CountingBeforeAdvice(); CountingBeforeAdvice cba = new CountingBeforeAdvice();
ProxyFactory pf = new ProxyFactory(); ProxyFactory pf = new ProxyFactory();
@ -335,17 +334,13 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
pf.setProxyTargetClass(true); pf.setProxyTargetClass(true);
TestBean proxy = (TestBean) pf.getProxy(); TestBean proxy = (TestBean) pf.getProxy();
assertTrue(AopUtils.isCglibProxy(proxy)); assertTrue(AopUtils.isCglibProxy(proxy));
proxy.getAge(); proxy.getAge();
assertEquals(0, cba.getCalls()); assertEquals(0, cba.getCalls());
((Advised) proxy).addAdvice(cba); ((Advised) proxy).addAdvice(cba);
proxy.getAge(); proxy.getAge();
assertEquals(1, cba.getCalls()); assertEquals(1, cba.getCalls());
} }
@ -357,7 +352,6 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
proxyFactory.setProxyTargetClass(true); proxyFactory.setProxyTargetClass(true);
MyBean proxy = (MyBean) proxyFactory.getProxy(); MyBean proxy = (MyBean) proxyFactory.getProxy();
assertEquals(4, proxy.add(1, 3)); assertEquals(4, proxy.add(1, 3));
assertEquals(1, advice.getCalls("add")); assertEquals(1, advice.getCalls("add"));
} }
@ -415,7 +409,6 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
public final void foo() { public final void foo() {
} }
} }
} }
@ -452,7 +445,6 @@ class NoArgCtorTestBean {
public void reset() { public void reset() {
called = false; called = false;
} }
} }
@ -461,15 +453,11 @@ class ProtectedMethodTestBean {
protected String getString() { protected String getString() {
return "foo"; return "foo";
} }
} }
class UnsupportedInterceptor implements MethodInterceptor { class UnsupportedInterceptor implements MethodInterceptor {
/**
* @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
*/
@Override @Override
public Object invoke(MethodInvocation mi) throws Throwable { public Object invoke(MethodInvocation mi) throws Throwable {
throw new UnsupportedOperationException(mi.getMethod().getName()); throw new UnsupportedOperationException(mi.getMethod().getName());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -1009,7 +1009,7 @@ public interface JdbcOperations {
* @param batchArgs the List of Object arrays containing the batch of arguments for the query * @param batchArgs the List of Object arrays containing the batch of arguments for the query
* @return an array containing the numbers of rows affected by each update in the batch * @return an array containing the numbers of rows affected by each update in the batch
*/ */
public int[] batchUpdate(String sql, List<Object[]> batchArgs); public int[] batchUpdate(String sql, List<Object[]> batchArgs) throws DataAccessException;
/** /**
* Execute a batch using the supplied SQL statement with the batch of supplied arguments. * Execute a batch using the supplied SQL statement with the batch of supplied arguments.
@ -1019,7 +1019,8 @@ public interface JdbcOperations {
* (constants from {@code java.sql.Types}) * (constants from {@code java.sql.Types})
* @return an array containing the numbers of rows affected by each update in the batch * @return an array containing the numbers of rows affected by each update in the batch
*/ */
public int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes); public int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes)
throws DataAccessException;
/** /**
* Execute multiple batches using the supplied SQL statement with the collect of supplied arguments. * Execute multiple batches using the supplied SQL statement with the collect of supplied arguments.
@ -1032,7 +1033,9 @@ public interface JdbcOperations {
* @return an array containing for each batch another array containing the numbers of rows affected * @return an array containing for each batch another array containing the numbers of rows affected
* by each update in the batch * by each update in the batch
*/ */
public <T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize, ParameterizedPreparedStatementSetter<T> pss); public <T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize,
ParameterizedPreparedStatementSetter<T> pss) throws DataAccessException;
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Methods dealing with callable statements // Methods dealing with callable statements

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -1028,23 +1028,19 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
} }
@Override @Override
public int[] batchUpdate(String sql, List<Object[]> batchArgs) { public int[] batchUpdate(String sql, List<Object[]> batchArgs) throws DataAccessException {
return batchUpdate(sql, batchArgs, new int[0]); return batchUpdate(sql, batchArgs, new int[0]);
} }
@Override @Override
public int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes) { public int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes) throws DataAccessException {
return BatchUpdateUtils.executeBatchUpdate(sql, batchArgs, argTypes, this); return BatchUpdateUtils.executeBatchUpdate(sql, batchArgs, argTypes, this);
} }
/*
* (non-Javadoc)
* @see org.springframework.jdbc.core.JdbcOperations#batchUpdate(java.lang.String, java.util.Collection, int, org.springframework.jdbc.core.ParameterizedPreparedStatementSetter)
*
* Contribution by Nicolas Fabre
*/
@Override @Override
public <T> int[][] batchUpdate(String sql, final Collection<T> batchArgs, final int batchSize, final ParameterizedPreparedStatementSetter<T> pss) { public <T> int[][] batchUpdate(String sql, final Collection<T> batchArgs, final int batchSize,
final ParameterizedPreparedStatementSetter<T> pss) throws DataAccessException {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Executing SQL batch update [" + sql + "] with a batch size of " + batchSize); logger.debug("Executing SQL batch update [" + sql + "] with a batch size of " + batchSize);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,7 +20,8 @@ import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
/** /**
* Parameterized callback interface used by the {@link JdbcTemplate} class for batch updates. * Parameterized callback interface used by the {@link JdbcTemplate} class for
* batch updates.
* *
* <p>This interface sets values on a {@link java.sql.PreparedStatement} provided * <p>This interface sets values on a {@link java.sql.PreparedStatement} provided
* by the JdbcTemplate class, for each of a number of updates in a batch using the * by the JdbcTemplate class, for each of a number of updates in a batch using the
@ -40,7 +41,6 @@ public interface ParameterizedPreparedStatementSetter<T> {
/** /**
* Set parameter values on the given PreparedStatement. * Set parameter values on the given PreparedStatement.
*
* @param ps the PreparedStatement to invoke setter methods on * @param ps the PreparedStatement to invoke setter methods on
* @param argument the object containing the values to be set * @param argument the object containing the values to be set
* @throws SQLException if a SQLException is encountered (i.e. there is no need to catch SQLException) * @throws SQLException if a SQLException is encountered (i.e. there is no need to catch SQLException)