Polishing

This commit is contained in:
Juergen Hoeller 2016-04-12 16:03:57 +02:00
parent 831f09cf48
commit 74608e6b49
12 changed files with 43 additions and 65 deletions

View File

@ -594,8 +594,7 @@ public class AnnotatedElementUtilsTests {
@Test
public void findMergedAnnotationAttributesOnClassWithAttributeAliasInComposedAnnotationAndNestedAnnotationsInTargetAnnotation() {
AnnotationAttributes attributes = assertComponentScanAttributes(TestComponentScanClass.class,
"com.example.app.test");
AnnotationAttributes attributes = assertComponentScanAttributes(TestComponentScanClass.class, "com.example.app.test");
Filter[] excludeFilters = attributes.getAnnotationArray("excludeFilters", Filter.class);
assertNotNull(excludeFilters);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -54,23 +54,23 @@ public class AnnotationAttributesTests {
nestedAttributes.put("name", "algernon");
attributes.put("name", "dave");
attributes.put("names", new String[] { "dave", "frank", "hal" });
attributes.put("names", new String[] {"dave", "frank", "hal"});
attributes.put("bool1", true);
attributes.put("bool2", false);
attributes.put("color", Color.RED);
attributes.put("class", Integer.class);
attributes.put("classes", new Class<?>[] { Number.class, Short.class, Integer.class });
attributes.put("classes", new Class<?>[] {Number.class, Short.class, Integer.class});
attributes.put("number", 42);
attributes.put("anno", nestedAttributes);
attributes.put("annoArray", new AnnotationAttributes[] { nestedAttributes });
attributes.put("annoArray", new AnnotationAttributes[] {nestedAttributes});
assertThat(attributes.getString("name"), equalTo("dave"));
assertThat(attributes.getStringArray("names"), equalTo(new String[] { "dave", "frank", "hal" }));
assertThat(attributes.getStringArray("names"), equalTo(new String[] {"dave", "frank", "hal"}));
assertThat(attributes.getBoolean("bool1"), equalTo(true));
assertThat(attributes.getBoolean("bool2"), equalTo(false));
assertThat(attributes.<Color>getEnum("color"), equalTo(Color.RED));
assertTrue(attributes.getClass("class").equals(Integer.class));
assertThat(attributes.getClassArray("classes"), equalTo(new Class[] { Number.class, Short.class, Integer.class }));
assertThat(attributes.getClassArray("classes"), equalTo(new Class<?>[] {Number.class, Short.class, Integer.class}));
assertThat(attributes.<Integer>getNumber("number"), equalTo(42));
assertThat(attributes.getAnnotation("anno").<Integer>getNumber("value"), equalTo(10));
assertThat(attributes.getAnnotationArray("annoArray")[0].getString("name"), equalTo("algernon"));
@ -99,8 +99,8 @@ public class AnnotationAttributesTests {
attributes.put("filters", filter);
// Get back arrays of single elements
assertThat(attributes.getStringArray("names"), equalTo(new String[] { "Dogbert" }));
assertThat(attributes.getClassArray("classes"), equalTo(new Class[] { Number.class }));
assertThat(attributes.getStringArray("names"), equalTo(new String[] {"Dogbert"}));
assertThat(attributes.getClassArray("classes"), equalTo(new Class<?>[] {Number.class}));
AnnotationAttributes[] array = attributes.getAnnotationArray("nestedAttributes");
assertNotNull(array);
@ -118,7 +118,7 @@ public class AnnotationAttributesTests {
Filter filter = FilteredClass.class.getAnnotation(Filter.class);
attributes.put("filter", filter);
attributes.put("filters", new Filter[] { filter, filter });
attributes.put("filters", new Filter[] {filter, filter});
Filter retrievedFilter = attributes.getAnnotation("filter", Filter.class);
assertThat(retrievedFilter, equalTo(filter));
@ -257,7 +257,7 @@ public class AnnotationAttributesTests {
@Test
public void getAliasedStringArray() {
final String[] INPUT = new String[] { "test.xml" };
final String[] INPUT = new String[] {"test.xml"};
final String[] EMPTY = new String[0];
attributes.clear();
@ -297,7 +297,7 @@ public class AnnotationAttributesTests {
@Test
public void getAliasedStringArrayWithImplicitAliases() {
final String[] INPUT = new String[] { "test.xml" };
final String[] INPUT = new String[] {"test.xml"};
final String[] EMPTY = new String[0];
final List<String> aliases = Arrays.asList("value", "location1", "location2", "location3", "xmlFile", "groovyScript");
@ -352,8 +352,8 @@ public class AnnotationAttributesTests {
@Test
public void getAliasedStringArrayWithDifferentAliasedValues() {
attributes.put("location", new String[] { "1.xml" });
attributes.put("value", new String[] { "2.xml" });
attributes.put("location", new String[] {"1.xml"});
attributes.put("value", new String[] {"2.xml"});
exception.expect(AnnotationConfigurationException.class);
exception.expectMessage(containsString("In annotation [" + ContextConfig.class.getName() + "]"));
@ -382,7 +382,7 @@ public class AnnotationAttributesTests {
@Test
public void getAliasedClassArray() {
final Class<?>[] INPUT = new Class<?>[] { String.class };
final Class<?>[] INPUT = new Class<?>[] {String.class};
final Class<?>[] EMPTY = new Class<?>[0];
attributes.clear();
@ -422,7 +422,7 @@ public class AnnotationAttributesTests {
@Test
public void getAliasedClassArrayWithImplicitAliases() {
final Class<?>[] INPUT = new Class<?>[] { String.class };
final Class<?>[] INPUT = new Class<?>[] {String.class};
final Class<?>[] EMPTY = new Class<?>[0];
final List<String> aliases = Arrays.asList("value", "location1", "location2", "location3", "xmlFile", "groovyScript");
@ -465,8 +465,8 @@ public class AnnotationAttributesTests {
@Test
public void getAliasedClassArrayWithDifferentAliasedValues() {
attributes.put("classes", new Class[] { String.class });
attributes.put("value", new Class[] { Number.class });
attributes.put("classes", new Class<?>[] {String.class});
attributes.put("value", new Class<?>[] {Number.class});
exception.expect(AnnotationConfigurationException.class);
exception.expectMessage(containsString("In annotation [" + Filter.class.getName() + "]"));
@ -477,6 +477,7 @@ public class AnnotationAttributesTests {
getAliasedClassArray("classes");
}
private Class<?>[] getAliasedClassArray(String attributeName) {
return attributes.getAliasedClassArray(attributeName, Filter.class, null);
}
@ -491,9 +492,11 @@ public class AnnotationAttributesTests {
enum Color {
RED, WHITE, BLUE
}
@Retention(RetentionPolicy.RUNTIME)
@interface Filter {
@ -506,10 +509,12 @@ public class AnnotationAttributesTests {
String pattern();
}
@Filter(pattern = "foo")
static class FilteredClass {
}
/**
* Mock of {@code org.springframework.context.annotation.Scope}.
*/
@ -523,6 +528,7 @@ public class AnnotationAttributesTests {
String name() default "singleton";
}
@Scope(name = "custom")
static class ScopedComponent {
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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,19 +43,16 @@ public interface ConnectionCallback<T> {
* Gets called by {@code JdbcTemplate.execute} with an active JDBC
* Connection. Does not need to care about activating or closing the
* Connection, or handling transactions.
*
* <p>If called without a thread-bound JDBC transaction (initiated by
* DataSourceTransactionManager), the code will simply get executed on the
* JDBC connection with its transactional semantics. If JdbcTemplate is
* configured to use a JTA-aware DataSource, the JDBC Connection and thus
* the callback code will be transactional if a JTA transaction is active.
*
* <p>Allows for returning a result object created within the callback, i.e.
* a domain object or a collection of domain objects. Note that there's special
* support for single step actions: see {@code JdbcTemplate.queryForObject}
* etc. A thrown RuntimeException is treated as application exception:
* it gets propagated to the caller of the template.
*
* @param con active JDBC Connection
* @return a result object, or {@code null} if none
* @throws SQLException if thrown by a JDBC method, to be auto-converted

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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.
@ -47,26 +47,22 @@ public interface PreparedStatementCallback<T> {
* PreparedStatement. Does not need to care about closing the Statement
* or the Connection, or about handling transactions: this will all be
* handled by Spring's JdbcTemplate.
*
* <p><b>NOTE:</b> Any ResultSets opened should be closed in finally blocks
* within the callback implementation. Spring will close the Statement
* object after the callback returned, but this does not necessarily imply
* that the ResultSet resources will be closed: the Statement objects might
* get pooled by the connection pool, with {@code close} calls only
* returning the object to the pool but not physically closing the resources.
*
* <p>If called without a thread-bound JDBC transaction (initiated by
* DataSourceTransactionManager), the code will simply get executed on the
* JDBC connection with its transactional semantics. If JdbcTemplate is
* configured to use a JTA-aware DataSource, the JDBC connection and thus
* the callback code will be transactional if a JTA transaction is active.
*
* <p>Allows for returning a result object created within the callback, i.e.
* a domain object or a collection of domain objects. Note that there's
* special support for single step actions: see JdbcTemplate.queryForObject etc.
* A thrown RuntimeException is treated as application exception, it gets
* propagated to the caller of the template.
*
* @param ps active JDBC PreparedStatement
* @return a result object, or {@code null} if none
* @throws SQLException if thrown by a JDBC method, to be auto-converted

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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.
@ -40,26 +40,22 @@ public interface StatementCallback<T> {
* Statement. Does not need to care about closing the Statement or the
* Connection, or about handling transactions: this will all be handled
* by Spring's JdbcTemplate.
*
* <p><b>NOTE:</b> Any ResultSets opened should be closed in finally blocks
* within the callback implementation. Spring will close the Statement
* object after the callback returned, but this does not necessarily imply
* that the ResultSet resources will be closed: the Statement objects might
* get pooled by the connection pool, with {@code close} calls only
* returning the object to the pool but not physically closing the resources.
*
* <p>If called without a thread-bound JDBC transaction (initiated by
* DataSourceTransactionManager), the code will simply get executed on the
* JDBC connection with its transactional semantics. If JdbcTemplate is
* configured to use a JTA-aware DataSource, the JDBC connection and thus
* the callback code will be transactional if a JTA transaction is active.
*
* <p>Allows for returning a result object created within the callback, i.e.
* a domain object or a collection of domain objects. Note that there's
* special support for single step actions: see JdbcTemplate.queryForObject etc.
* A thrown RuntimeException is treated as application exception, it gets
* propagated to the caller of the template.
*
* @param stmt active JDBC Statement
* @return a result object, or {@code null} if none
* @throws SQLException if thrown by a JDBC method, to be auto-converted

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2016 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.
@ -613,7 +613,7 @@ public class OracleLobHandler extends AbstractLobHandler {
/**
* Internal callback interface for use with createLob.
*/
protected static interface LobCallback {
protected interface LobCallback {
/**
* Populate the given BLOB or CLOB instance with content.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@ -36,12 +36,10 @@ public interface HibernateCallback<T> {
* Gets called by {@code HibernateTemplate.execute} with an active
* Hibernate {@code Session}. Does not need to care about activating
* or closing the {@code Session}, or handling transactions.
*
* <p>Allows for returning a result object created within the callback,
* i.e. a domain object or a collection of domain objects.
* A thrown custom RuntimeException is treated as an application exception:
* It gets propagated to the caller of the template.
*
* @param session active Hibernate session
* @return a result object, or {@code null} if none
* @throws HibernateException if thrown by the Hibernate API

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -36,12 +36,10 @@ public interface HibernateCallback<T> {
* Gets called by {@code HibernateTemplate.execute} with an active
* Hibernate {@code Session}. Does not need to care about activating
* or closing the {@code Session}, or handling transactions.
*
* <p>Allows for returning a result object created within the callback,
* i.e. a domain object or a collection of domain objects.
* A thrown custom RuntimeException is treated as an application exception:
* It gets propagated to the caller of the template.
*
* @param session active Hibernate session
* @return a result object, or {@code null} if none
* @throws HibernateException if thrown by the Hibernate API

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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.
@ -49,18 +49,15 @@ public interface HibernateCallback<T> {
* Gets called by {@code HibernateTemplate.execute} with an active
* Hibernate {@code Session}. Does not need to care about activating
* or closing the {@code Session}, or handling transactions.
*
* <p>If called without a thread-bound Hibernate transaction (initiated
* by HibernateTransactionManager), the code will simply get executed on the
* underlying JDBC connection with its transactional semantics. If Hibernate
* is configured to use a JTA-aware DataSource, the JDBC connection and thus
* the callback code will be transactional if a JTA transaction is active.
*
* <p>Allows for returning a result object created within the callback,
* i.e. a domain object or a collection of domain objects.
* A thrown custom RuntimeException is treated as an application exception:
* It gets propagated to the caller of the template.
*
* @param session active Hibernate session
* @return a result object, or {@code null} if none
* @throws HibernateException if thrown by the Hibernate API

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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.
@ -46,19 +46,16 @@ public interface ConnectionCallback<T> {
* Gets called by {@code CciTemplate.execute} with an active CCI Connection.
* Does not need to care about activating or closing the Connection, or handling
* transactions.
*
* <p>If called without a thread-bound CCI transaction (initiated by
* CciLocalTransactionManager), the code will simply get executed on the CCI
* Connection with its transactional semantics. If CciTemplate is configured
* to use a JTA-aware ConnectionFactory, the CCI Connection and thus the callback
* code will be transactional if a JTA transaction is active.
*
* <p>Allows for returning a result object created within the callback, i.e.
* a domain object or a collection of domain objects. Note that there's special
* support for single step actions: see the {@code CciTemplate.execute}
* variants. A thrown RuntimeException is treated as application exception:
* it gets propagated to the caller of the template.
*
* @param connection active CCI Connection
* @param connectionFactory the CCI ConnectionFactory that the Connection was
* created with (gives access to RecordFactory and ResourceAdapterMetaData)

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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.
@ -47,19 +47,16 @@ public interface InteractionCallback<T> {
* Gets called by {@code CciTemplate.execute} with an active CCI Interaction.
* Does not need to care about activating or closing the Interaction, or
* handling transactions.
*
* <p>If called without a thread-bound CCI transaction (initiated by
* CciLocalTransactionManager), the code will simply get executed on the CCI
* Interaction with its transactional semantics. If CciTemplate is configured
* to use a JTA-aware ConnectionFactory, the CCI Interaction and thus the callback
* code will be transactional if a JTA transaction is active.
*
* <p>Allows for returning a result object created within the callback, i.e.
* a domain object or a collection of domain objects. Note that there's special
* support for single step actions: see the {@code CciTemplate.execute}
* variants. A thrown RuntimeException is treated as application exception:
* it gets propagated to the caller of the template.
*
* @param interaction active CCI Interaction
* @param connectionFactory the CCI ConnectionFactory that the Connection was
* created with (gives access to RecordFactory and ResourceAdapterMetaData)

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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.
@ -36,17 +36,14 @@ public interface TransactionCallback<T> {
/**
* Gets called by {@link TransactionTemplate#execute} within a transactional context.
* Does not need to care about transactions itself, although it can retrieve
* and influence the status of the current transaction via the given status
* object, e.g. setting rollback-only.
*
* <p>Allows for returning a result object created within the transaction, i.e.
* a domain object or a collection of domain objects. A RuntimeException thrown
* by the callback is treated as application exception that enforces a rollback.
* Any such exception will be propagated to the caller of the template, unless
* there is a problem rolling back, in which case a TransactionException will be
* thrown.
*
* Does not need to care about transactions itself, although it can retrieve and
* influence the status of the current transaction via the given status object,
* e.g. setting rollback-only.
* <p>Allows for returning a result object created within the transaction, i.e. a
* domain object or a collection of domain objects. A RuntimeException thrown by the
* callback is treated as application exception that enforces a rollback. Any such
* exception will be propagated to the caller of the template, unless there is a
* problem rolling back, in which case a TransactionException will be thrown.
* @param status associated transaction status
* @return a result object, or {@code null}
* @see TransactionTemplate#execute