Skip to content

Commit 3da9a31

Browse files
committed
Polishing
(cherry picked from commit 749b65b)
1 parent 7e9cb51 commit 3da9a31

File tree

5 files changed

+49
-72
lines changed

5 files changed

+49
-72
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,14 +27,17 @@
2727
import org.springframework.core.NamedThreadLocal;
2828

2929
/**
30-
* Thread-backed {@link Scope} implementation.
30+
* A simple thread-backed {@link Scope} implementation.
3131
*
32-
* <p><strong>Note</strong> that the {@code SimpleThreadScope} <em>does not clean up any objects</em> associated
33-
* with it. As such, it's typically preferable to use the {@link org.springframework.web.context.request.RequestScope}
34-
* in Web environments.
32+
* <p><strong>Note:</strong> {@code SimpleThreadScope} <em>does not clean up
33+
* any objects</em> associated with it. As such, it is typically preferable to
34+
* use {@link org.springframework.web.context.request.RequestScope RequestScope}
35+
* in web environments.
3536
*
36-
* <p>For a implementation of a thread-based {@code Scope} with support for destruction callbacks, refer to <a
37-
* href="http://www.springbyexample.org/twiki/bin/view/Example/CustomThreadScopeModule">this module</a>.
37+
* <p>For an implementation of a thread-based {@code Scope} with support for
38+
* destruction callbacks, refer to the
39+
* <a href="http://www.springbyexample.org/examples/custom-thread-scope-module.html">
40+
* Spring by Example Custom Thread Scope Module</a>.
3841
*
3942
* <p>Thanks to Eugene Kuleshov for submitting the original prototype for a thread scope!
4043
*
@@ -55,8 +58,9 @@ protected Map<String, Object> initialValue() {
5558
}
5659
};
5760

58-
public Object get(String name, ObjectFactory objectFactory) {
59-
Map<String, Object> scope = threadScope.get();
61+
62+
public Object get(String name, ObjectFactory<?> objectFactory) {
63+
Map<String, Object> scope = this.threadScope.get();
6064
Object object = scope.get(name);
6165
if (object == null) {
6266
object = objectFactory.getObject();
@@ -66,13 +70,13 @@ public Object get(String name, ObjectFactory objectFactory) {
6670
}
6771

6872
public Object remove(String name) {
69-
Map<String, Object> scope = threadScope.get();
73+
Map<String, Object> scope = this.threadScope.get();
7074
return scope.remove(name);
7175
}
7276

7377
public void registerDestructionCallback(String name, Runnable callback) {
74-
logger.warn("SimpleThreadScope does not support descruction callbacks. " +
75-
"Consider using a RequestScope in a Web environment.");
78+
logger.warn("SimpleThreadScope does not support destruction callbacks. " +
79+
"Consider using RequestScope in a web environment.");
7680
}
7781

7882
public Object resolveContextualObject(String key) {

spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,13 @@
1616

1717
package org.springframework.aop.framework;
1818

19-
import static org.hamcrest.CoreMatchers.instanceOf;
20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertNotNull;
22-
import static org.junit.Assert.assertThat;
23-
import static org.junit.Assert.assertTrue;
24-
import static org.junit.Assert.fail;
25-
2619
import java.io.Serializable;
2720

2821
import org.aopalliance.intercept.MethodInterceptor;
2922
import org.aopalliance.intercept.MethodInvocation;
3023
import org.junit.Test;
24+
import test.mixin.LockMixinAdvisor;
25+
3126
import org.springframework.aop.ClassFilter;
3227
import org.springframework.aop.MethodMatcher;
3328
import org.springframework.aop.Pointcut;
@@ -42,10 +37,11 @@
4237
import org.springframework.tests.sample.beans.ITestBean;
4338
import org.springframework.tests.sample.beans.TestBean;
4439

45-
import test.mixin.LockMixinAdvisor;
40+
import static org.hamcrest.CoreMatchers.*;
41+
import static org.junit.Assert.*;
4642

4743
/**
48-
* Additional and overridden tests for the CGLIB proxy.
44+
* Additional and overridden tests for CGLIB proxies.
4945
*
5046
* @author Rod Johnson
5147
* @author Juergen Hoeller
@@ -56,7 +52,8 @@
5652
@SuppressWarnings("serial")
5753
public final class CglibProxyTests extends AbstractAopProxyTests implements Serializable {
5854

59-
private static final String DEPENDENCY_CHECK_CONTEXT = CglibProxyTests.class.getSimpleName() + "-with-dependency-checking.xml";
55+
private static final String DEPENDENCY_CHECK_CONTEXT =
56+
CglibProxyTests.class.getSimpleName() + "-with-dependency-checking.xml";
6057

6158

6259
@Override
@@ -354,7 +351,6 @@ public void testWithDependencyChecking() {
354351
@Test
355352
public void testAddAdviceAtRuntime() {
356353
TestBean bean = new TestBean();
357-
358354
CountingBeforeAdvice cba = new CountingBeforeAdvice();
359355

360356
ProxyFactory pf = new ProxyFactory();
@@ -364,17 +360,13 @@ public void testAddAdviceAtRuntime() {
364360
pf.setProxyTargetClass(true);
365361

366362
TestBean proxy = (TestBean) pf.getProxy();
367-
368363
assertTrue(AopUtils.isCglibProxy(proxy));
369364

370365
proxy.getAge();
371-
372366
assertEquals(0, cba.getCalls());
373367

374368
((Advised) proxy).addAdvice(cba);
375-
376369
proxy.getAge();
377-
378370
assertEquals(1, cba.getCalls());
379371
}
380372

@@ -386,7 +378,6 @@ public void testProxyProtectedMethod() throws Exception {
386378
proxyFactory.setProxyTargetClass(true);
387379

388380
MyBean proxy = (MyBean) proxyFactory.getProxy();
389-
390381
assertEquals(4, proxy.add(1, 3));
391382
assertEquals(1, advice.getCalls("add"));
392383
}
@@ -444,7 +435,6 @@ public static class HasFinalMethod {
444435
public final void foo() {
445436
}
446437
}
447-
448438
}
449439

450440

@@ -481,7 +471,6 @@ public boolean wasCalled() {
481471
public void reset() {
482472
called = false;
483473
}
484-
485474
}
486475

487476

@@ -490,15 +479,11 @@ class ProtectedMethodTestBean {
490479
protected String getString() {
491480
return "foo";
492481
}
493-
494482
}
495483

496484

497485
class UnsupportedInterceptor implements MethodInterceptor {
498486

499-
/**
500-
* @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
501-
*/
502487
@Override
503488
public Object invoke(MethodInvocation mi) throws Throwable {
504489
throw new UnsupportedOperationException(mi.getMethod().getName());

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -311,8 +311,7 @@ public interface JdbcOperations {
311311
* @return a result object returned by the action, or {@code null}
312312
* @throws DataAccessException if there is any problem
313313
*/
314-
<T> T execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action)
315-
throws DataAccessException;
314+
<T> T execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action) throws DataAccessException;
316315

317316
/**
318317
* Execute a JDBC data access operation, implemented as callback action
@@ -354,8 +353,7 @@ <T> T execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action)
354353
* @return an arbitrary result object, as returned by the ResultSetExtractor
355354
* @throws DataAccessException if there is any problem
356355
*/
357-
<T> T query(String sql, PreparedStatementSetter pss, ResultSetExtractor<T> rse)
358-
throws DataAccessException;
356+
<T> T query(String sql, PreparedStatementSetter pss, ResultSetExtractor<T> rse) throws DataAccessException;
359357

360358
/**
361359
* Query given SQL to create a prepared statement from SQL and a list
@@ -370,8 +368,7 @@ <T> T query(String sql, PreparedStatementSetter pss, ResultSetExtractor<T> rse)
370368
* @throws DataAccessException if the query fails
371369
* @see java.sql.Types
372370
*/
373-
<T> T query(String sql, Object[] args, int[] argTypes, ResultSetExtractor<T> rse)
374-
throws DataAccessException;
371+
<T> T query(String sql, Object[] args, int[] argTypes, ResultSetExtractor<T> rse) throws DataAccessException;
375372

376373
/**
377374
* Query given SQL to create a prepared statement from SQL and a list
@@ -428,8 +425,7 @@ <T> T query(String sql, Object[] args, int[] argTypes, ResultSetExtractor<T> rse
428425
* @param rch object that will extract results, one row at a time
429426
* @throws DataAccessException if the query fails
430427
*/
431-
void query(String sql, PreparedStatementSetter pss, RowCallbackHandler rch)
432-
throws DataAccessException;
428+
void query(String sql, PreparedStatementSetter pss, RowCallbackHandler rch) throws DataAccessException;
433429

434430
/**
435431
* Query given SQL to create a prepared statement from SQL and a list of
@@ -443,8 +439,7 @@ void query(String sql, PreparedStatementSetter pss, RowCallbackHandler rch)
443439
* @throws DataAccessException if the query fails
444440
* @see java.sql.Types
445441
*/
446-
void query(String sql, Object[] args, int[] argTypes, RowCallbackHandler rch)
447-
throws DataAccessException;
442+
void query(String sql, Object[] args, int[] argTypes, RowCallbackHandler rch) throws DataAccessException;
448443

449444
/**
450445
* Query given SQL to create a prepared statement from SQL and a list of
@@ -500,8 +495,7 @@ void query(String sql, Object[] args, int[] argTypes, RowCallbackHandler rch)
500495
* @return the result List, containing mapped objects
501496
* @throws DataAccessException if the query fails
502497
*/
503-
<T> List<T> query(String sql, PreparedStatementSetter pss, RowMapper<T> rowMapper)
504-
throws DataAccessException;
498+
<T> List<T> query(String sql, PreparedStatementSetter pss, RowMapper<T> rowMapper) throws DataAccessException;
505499

506500
/**
507501
* Query given SQL to create a prepared statement from SQL and a list
@@ -516,8 +510,7 @@ <T> List<T> query(String sql, PreparedStatementSetter pss, RowMapper<T> rowMappe
516510
* @throws DataAccessException if the query fails
517511
* @see java.sql.Types
518512
*/
519-
<T> List<T> query(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper)
520-
throws DataAccessException;
513+
<T> List<T> query(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper) throws DataAccessException;
521514

522515
/**
523516
* Query given SQL to create a prepared statement from SQL and a list
@@ -582,8 +575,7 @@ <T> T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper<T> row
582575
* return exactly one row
583576
* @throws DataAccessException if the query fails
584577
*/
585-
<T> T queryForObject(String sql, Object[] args, RowMapper<T> rowMapper)
586-
throws DataAccessException;
578+
<T> T queryForObject(String sql, Object[] args, RowMapper<T> rowMapper) throws DataAccessException;
587579

588580
/**
589581
* Query given SQL to create a prepared statement from SQL and a list
@@ -600,8 +592,7 @@ <T> T queryForObject(String sql, Object[] args, RowMapper<T> rowMapper)
600592
* return exactly one row
601593
* @throws DataAccessException if the query fails
602594
*/
603-
<T> T queryForObject(String sql, RowMapper<T> rowMapper, Object... args)
604-
throws DataAccessException;
595+
<T> T queryForObject(String sql, RowMapper<T> rowMapper, Object... args) throws DataAccessException;
605596

606597
/**
607598
* Query given SQL to create a prepared statement from SQL and a
@@ -1009,7 +1000,7 @@ <T>List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> elem
10091000
* @param batchArgs the List of Object arrays containing the batch of arguments for the query
10101001
* @return an array containing the numbers of rows affected by each update in the batch
10111002
*/
1012-
public int[] batchUpdate(String sql, List<Object[]> batchArgs);
1003+
public int[] batchUpdate(String sql, List<Object[]> batchArgs) throws DataAccessException;
10131004

10141005
/**
10151006
* Execute a batch using the supplied SQL statement with the batch of supplied arguments.
@@ -1019,7 +1010,7 @@ <T>List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> elem
10191010
* (constants from {@code java.sql.Types})
10201011
* @return an array containing the numbers of rows affected by each update in the batch
10211012
*/
1022-
public int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes);
1013+
public int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes) throws DataAccessException;
10231014

10241015
/**
10251016
* Execute multiple batches using the supplied SQL statement with the collect of supplied arguments.
@@ -1032,7 +1023,9 @@ <T>List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> elem
10321023
* @return an array containing for each batch another array containing the numbers of rows affected
10331024
* by each update in the batch
10341025
*/
1035-
public <T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize, ParameterizedPreparedStatementSetter<T> pss);
1026+
public <T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize,
1027+
ParameterizedPreparedStatementSetter<T> pss) throws DataAccessException;
1028+
10361029

10371030
//-------------------------------------------------------------------------
10381031
// Methods dealing with callable statements
@@ -1051,8 +1044,7 @@ <T>List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> elem
10511044
* @return a result object returned by the action, or {@code null}
10521045
* @throws DataAccessException if there is any problem
10531046
*/
1054-
<T> T execute(CallableStatementCreator csc, CallableStatementCallback<T> action)
1055-
throws DataAccessException;
1047+
<T> T execute(CallableStatementCreator csc, CallableStatementCallback<T> action) throws DataAccessException;
10561048

10571049
/**
10581050
* Execute a JDBC data access operation, implemented as callback action

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -367,7 +367,7 @@ public <T> T execute(ConnectionCallback<T> action) throws DataAccessException {
367367
protected Connection createConnectionProxy(Connection con) {
368368
return (Connection) Proxy.newProxyInstance(
369369
ConnectionProxy.class.getClassLoader(),
370-
new Class[] {ConnectionProxy.class},
370+
new Class<?>[] {ConnectionProxy.class},
371371
new CloseSuppressingInvocationHandler(con));
372372
}
373373

@@ -929,21 +929,17 @@ public int[] doInPreparedStatement(PreparedStatement ps) throws SQLException {
929929
});
930930
}
931931

932-
public int[] batchUpdate(String sql, List<Object[]> batchArgs) {
932+
public int[] batchUpdate(String sql, List<Object[]> batchArgs) throws DataAccessException {
933933
return batchUpdate(sql, batchArgs, new int[0]);
934934
}
935935

936-
public int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes) {
936+
public int[] batchUpdate(String sql, List<Object[]> batchArgs, int[] argTypes) throws DataAccessException {
937937
return BatchUpdateUtils.executeBatchUpdate(sql, batchArgs, argTypes, this);
938938
}
939939

940-
/*
941-
* (non-Javadoc)
942-
* @see org.springframework.jdbc.core.JdbcOperations#batchUpdate(java.lang.String, java.util.Collection, int, org.springframework.jdbc.core.ParameterizedPreparedStatementSetter)
943-
*
944-
* Contribution by Nicolas Fabre
945-
*/
946-
public <T> int[][] batchUpdate(String sql, final Collection<T> batchArgs, final int batchSize, final ParameterizedPreparedStatementSetter<T> pss) {
940+
public <T> int[][] batchUpdate(String sql, final Collection<T> batchArgs, final int batchSize,
941+
final ParameterizedPreparedStatementSetter<T> pss) throws DataAccessException {
942+
947943
if (logger.isDebugEnabled()) {
948944
logger.debug("Executing SQL batch update [" + sql + "] with a batch size of " + batchSize);
949945
}

spring-jdbc/src/main/java/org/springframework/jdbc/core/ParameterizedPreparedStatementSetter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,8 @@
2020
import java.sql.SQLException;
2121

2222
/**
23-
* Parameterized callback interface used by the {@link JdbcTemplate} class for batch updates.
23+
* Parameterized callback interface used by the {@link JdbcTemplate} class for
24+
* batch updates.
2425
*
2526
* <p>This interface sets values on a {@link java.sql.PreparedStatement} provided
2627
* by the JdbcTemplate class, for each of a number of updates in a batch using the
@@ -40,7 +41,6 @@ public interface ParameterizedPreparedStatementSetter<T> {
4041

4142
/**
4243
* Set parameter values on the given PreparedStatement.
43-
*
4444
* @param ps the PreparedStatement to invoke setter methods on
4545
* @param argument the object containing the values to be set
4646
* @throws SQLException if a SQLException is encountered (i.e. there is no need to catch SQLException)

0 commit comments

Comments
 (0)