From 3829a778947857f0de2a466413d3a36e0847ea16 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 12 Apr 2016 16:03:57 +0200 Subject: [PATCH] Polishing (cherry picked from commit 74608e6) --- .../annotation/AnnotationAttributesTests.java | 40 +++++++++++-------- .../jdbc/core/ConnectionCallback.java | 5 +-- .../jdbc/core/PreparedStatementCallback.java | 6 +-- .../jdbc/core/StatementCallback.java | 6 +-- .../jdbc/support/lob/OracleLobHandler.java | 4 +- .../orm/hibernate4/HibernateCallback.java | 4 +- .../orm/hibernate5/HibernateCallback.java | 4 +- .../orm/hibernate3/HibernateCallback.java | 5 +-- .../jca/cci/core/ConnectionCallback.java | 5 +-- .../jca/cci/core/InteractionCallback.java | 5 +-- .../support/TransactionCallback.java | 21 +++++----- 11 files changed, 42 insertions(+), 63 deletions(-) diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java index cb7af8502ff..57cdd7ab2eb 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java @@ -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.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.getNumber("number"), equalTo(42)); assertThat(attributes.getAnnotation("anno").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 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 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 { } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ConnectionCallback.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ConnectionCallback.java index 04ae1ccacc6..55a63039c3a 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ConnectionCallback.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ConnectionCallback.java @@ -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 { * 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. - * *

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. - * *

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 diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCallback.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCallback.java index bd82ddf9e99..9c2cd0e9be0 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCallback.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCallback.java @@ -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 { * 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. - * *

NOTE: 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. - * *

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. - * *

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 diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCallback.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCallback.java index c786232ca96..3edd3c2b67c 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCallback.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCallback.java @@ -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 { * 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. - * *

NOTE: 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. - * *

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. - * *

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 diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/OracleLobHandler.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/OracleLobHandler.java index 0861b92d22e..df836abf1c6 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/OracleLobHandler.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/OracleLobHandler.java @@ -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. diff --git a/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/HibernateCallback.java b/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/HibernateCallback.java index a6cca5ab8e1..66f78d66784 100644 --- a/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/HibernateCallback.java +++ b/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/HibernateCallback.java @@ -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 { * 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. - * *

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 diff --git a/spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/HibernateCallback.java b/spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/HibernateCallback.java index 78074360ca9..54cee881520 100644 --- a/spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/HibernateCallback.java +++ b/spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/HibernateCallback.java @@ -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 { * 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. - * *

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 diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateCallback.java b/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateCallback.java index 8bf4dbeffe1..b0545f15ff4 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateCallback.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateCallback.java @@ -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,18 +47,15 @@ public interface HibernateCallback { * 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. - * *

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. - * *

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 diff --git a/spring-tx/src/main/java/org/springframework/jca/cci/core/ConnectionCallback.java b/spring-tx/src/main/java/org/springframework/jca/cci/core/ConnectionCallback.java index d6dad2a2e45..3be2710f15c 100644 --- a/spring-tx/src/main/java/org/springframework/jca/cci/core/ConnectionCallback.java +++ b/spring-tx/src/main/java/org/springframework/jca/cci/core/ConnectionCallback.java @@ -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 { * 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. - * *

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. - * *

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) diff --git a/spring-tx/src/main/java/org/springframework/jca/cci/core/InteractionCallback.java b/spring-tx/src/main/java/org/springframework/jca/cci/core/InteractionCallback.java index ace6ad0989e..38db29348d5 100644 --- a/spring-tx/src/main/java/org/springframework/jca/cci/core/InteractionCallback.java +++ b/spring-tx/src/main/java/org/springframework/jca/cci/core/InteractionCallback.java @@ -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 { * 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. - * *

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. - * *

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) diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionCallback.java b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionCallback.java index 98841f3cbe9..80e8bde72a1 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionCallback.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionCallback.java @@ -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 { /** * 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. - * - *

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. + *

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