Browse Source

Polish contribution

See gh-31531
pull/30300/head
Sam Brannen 2 years ago
parent
commit
d71853f105
  1. 2
      spring-beans/src/jmh/java/org/springframework/beans/factory/DefaultListableBeanFactoryBenchmark.java
  2. 2
      spring-beans/src/main/java/org/springframework/beans/PropertyAccessorUtils.java
  3. 2
      spring-context/src/main/java/org/springframework/context/annotation/LoadTimeWeavingConfiguration.java
  4. 10
      spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java
  5. 2
      spring-core/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.java
  6. 10
      spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java
  7. 10
      spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java
  8. 8
      spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java
  9. 10
      spring-jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java
  10. 8
      spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java
  11. 10
      spring-orm/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java
  12. 2
      spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java
  13. 2
      spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java
  14. 2
      spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java
  15. 8
      spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java
  16. 8
      spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxy.java
  17. 8
      spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java
  18. 2
      spring-tx/src/main/java/org/springframework/transaction/jta/JtaAfterCompletionSynchronization.java

2
spring-beans/src/jmh/java/org/springframework/beans/factory/DefaultListableBeanFactoryBenchmark.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 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.

2
spring-beans/src/main/java/org/springframework/beans/PropertyAccessorUtils.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2023 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.

2
spring-context/src/main/java/org/springframework/context/annotation/LoadTimeWeavingConfiguration.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 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.

10
spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java

@ -269,7 +269,7 @@ public class DateFormatter implements Formatter<Date> { @@ -269,7 +269,7 @@ public class DateFormatter implements Formatter<Date> {
if (timeStyle != -1) {
return DateFormat.getTimeInstance(timeStyle, locale);
}
throw new IllegalStateException("Unsupported style pattern '" + this.stylePattern + "'");
throw unsupportedStylePatternException();
}
return DateFormat.getDateInstance(this.style, locale);
@ -284,10 +284,14 @@ public class DateFormatter implements Formatter<Date> { @@ -284,10 +284,14 @@ public class DateFormatter implements Formatter<Date> {
case 'L' -> DateFormat.LONG;
case 'F' -> DateFormat.FULL;
case '-' -> -1;
default -> throw new IllegalStateException("Unsupported style pattern '" + this.stylePattern + "'");
default -> throw unsupportedStylePatternException();
};
}
throw new IllegalStateException("Unsupported style pattern '" + this.stylePattern + "'");
throw unsupportedStylePatternException();
}
private IllegalStateException unsupportedStylePatternException() {
return new IllegalStateException("Unsupported style pattern '" + this.stylePattern + "'");
}
}

2
spring-core/src/main/java/org/springframework/util/xml/ListBasedXMLEventReader.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2023 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.

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

@ -1656,20 +1656,20 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { @@ -1656,20 +1656,20 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
// Invocation on ConnectionProxy interface coming in...
return switch (method.getName()) {
// Only consider equal when proxies are identical.
case "equals" -> (proxy == args[0]);
// Only consider equal when proxies are identical.
// Use hashCode of PersistenceManager proxy.
case "hashCode" -> System.identityHashCode(proxy);
// Use hashCode of PersistenceManager proxy.
// Handle close method: suppress, not valid.
case "close" -> null;
// Handle close method: suppress, not valid.
case "isClosed" -> false;
// Handle getTargetConnection method: return underlying Connection.
case "getTargetConnection" -> this.target;
// Handle getTargetConnection method: return underlying Connection.
case "unwrap" -> (((Class<?>) args[0]).isInstance(proxy) ? proxy : this.target.unwrap((Class<?>) args[0]));
case "isWrapperFor" -> (((Class<?>) args[0]).isInstance(proxy) || this.target.isWrapperFor((Class<?>) args[0]));
default -> {
// Invoke method on target Connection.
try {
// Invoke method on target Connection.
Object retVal = method.invoke(this.target, args);
// If return value is a JDBC Statement, apply statement settings

10
spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java

@ -350,20 +350,20 @@ public class SingleConnectionDataSource extends DriverManagerDataSource @@ -350,20 +350,20 @@ public class SingleConnectionDataSource extends DriverManagerDataSource
// Invocation on ConnectionProxy interface coming in...
return switch (method.getName()) {
// Only consider equal when proxies are identical.
case "equals" -> (proxy == args[0]);
// Only consider equal when proxies are identical.
// Use hashCode of Connection proxy.
case "hashCode" -> System.identityHashCode(proxy);
// Use hashCode of Connection proxy.
// Handle close method: don't pass the call on.
case "close" -> null;
// Handle close method: don't pass the call on.
case "isClosed" -> this.target.isClosed();
// Handle getTargetConnection method: return underlying Connection.
case "getTargetConnection" -> this.target;
// Handle getTargetConnection method: return underlying Connection.
case "unwrap" -> (((Class<?>) args[0]).isInstance(proxy) ? proxy : this.target.unwrap((Class<?>) args[0]));
case "isWrapperFor" -> (((Class<?>) args[0]).isInstance(proxy) || this.target.isWrapperFor((Class<?>) args[0]));
default -> {
// Invoke method on target Connection.
try {
// Invoke method on target Connection.
yield method.invoke(this.target, args);
}
catch (InvocationTargetException ex) {

8
spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java

@ -625,7 +625,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti @@ -625,7 +625,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
else {
throw new jakarta.jms.IllegalStateException(
"setClientID call not supported on proxy for shared Connection. " +
"Set the 'clientId' property on the SingleConnectionFactory instead.");
"Set the 'clientId' property on the SingleConnectionFactory instead.");
}
}
case "setExceptionListener" -> {
@ -647,9 +647,9 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti @@ -647,9 +647,9 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
else {
throw new jakarta.jms.IllegalStateException(
"setExceptionListener call not supported on proxy for shared Connection. " +
"Set the 'exceptionListener' property on the SingleConnectionFactory instead. " +
"Alternatively, activate SingleConnectionFactory's 'reconnectOnException' feature, " +
"which will allow for registering further ExceptionListeners to the recovery chain.");
"Set the 'exceptionListener' property on the SingleConnectionFactory instead. " +
"Alternatively, activate SingleConnectionFactory's 'reconnectOnException' feature, " +
"which will allow for registering further ExceptionListeners to the recovery chain.");
}
}
}

10
spring-jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java

@ -332,21 +332,21 @@ public class TransactionAwareConnectionFactoryProxy @@ -332,21 +332,21 @@ public class TransactionAwareConnectionFactoryProxy
// Invocation on SessionProxy interface coming in...
return switch (method.getName()) {
// Only consider equal when proxies are identical.
case "equals" -> (proxy == args[0]);
// Only consider equal when proxies are identical.
// Use hashCode of Connection proxy.
case "hashCode" -> System.identityHashCode(proxy);
// Use hashCode of Connection proxy.
case "commit" ->
throw new TransactionInProgressException("Commit call not allowed within a managed transaction");
case "rollback" ->
throw new TransactionInProgressException("Rollback call not allowed within a managed transaction");
// Handle close method: not to be closed within a transaction.
case "close" -> null;
// Handle close method: not to be closed within a transaction.
// Handle getTargetSession method: return underlying Session.
case "getTargetSession" -> this.target;
// Handle getTargetSession method: return underlying Session.
default -> {
// Invoke method on target Session.
try {
// Invoke method on target Session.
yield method.invoke(this.target, args);
}
catch (InvocationTargetException ex) {

8
spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java

@ -1151,15 +1151,15 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean @@ -1151,15 +1151,15 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean
// Invocation on Session interface coming in...
return switch (method.getName()) {
// Only consider equal when proxies are identical.
case "equals" -> (proxy == args[0]);
// Only consider equal when proxies are identical.
// Use hashCode of Session proxy.
case "hashCode" -> System.identityHashCode(proxy);
// Use hashCode of Session proxy.
// Handle close method: suppress, not valid.
case "close" -> null;
// Handle close method: suppress, not valid.
default -> {
// Invoke method on target Session.
try {
// Invoke method on target Session.
Object retVal = method.invoke(this.target, args);
// If return value is a Query or Criteria, apply transaction timeout.

10
spring-orm/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java

@ -413,17 +413,17 @@ public class LocalSessionFactoryBuilder extends Configuration { @@ -413,17 +413,17 @@ public class LocalSessionFactoryBuilder extends Configuration {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return switch (method.getName()) {
// Only consider equal when proxies are identical.
case "equals" -> (proxy == args[0]);
// Only consider equal when proxies are identical.
// Use hashCode of EntityManagerFactory proxy.
case "hashCode" -> System.identityHashCode(proxy);
// Use hashCode of EntityManagerFactory proxy.
case "getProperties" -> getProperties();
// Call coming in through InfrastructureProxy interface...
case "getWrappedObject" -> getSessionFactory();
// Call coming in through InfrastructureProxy interface...
default -> {
// Regular delegation to the target SessionFactory,
// enforcing its full initialization...
try {
// Regular delegation to the target SessionFactory,
// enforcing its full initialization...
yield method.invoke(getSessionFactory(), args);
}
catch (InvocationTargetException ex) {

2
spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 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.

2
spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 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.

2
spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java

@ -264,7 +264,7 @@ public abstract class SharedEntityManagerCreator { @@ -264,7 +264,7 @@ public abstract class SharedEntityManagerCreator {
case "getTransaction" -> {
throw new IllegalStateException(
"Not allowed to create transaction on shared EntityManager - " +
"use Spring transactions or EJB CMT instead");
"use Spring transactions or EJB CMT instead");
}
}

8
spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java

@ -252,16 +252,16 @@ public class SingleConnectionFactory extends DelegatingConnectionFactory @@ -252,16 +252,16 @@ public class SingleConnectionFactory extends DelegatingConnectionFactory
@Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return switch (method.getName()) {
// Only consider equal when proxies are identical.
case "equals" -> proxy == args[0];
// Only consider equal when proxies are identical.
// Use hashCode of PersistenceManager proxy.
case "hashCode" -> System.identityHashCode(proxy);
// Use hashCode of PersistenceManager proxy.
case "unwrap" -> this.target;
// Handle close method: suppress, not valid.
case "close" -> Mono.empty();
// Handle close method: suppress, not valid.
default -> {
// Invoke method on target Connection.
try {
// Invoke method on target Connection.
yield method.invoke(this.target, args);
}
catch (InvocationTargetException ex) {

8
spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxy.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 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.
@ -145,17 +145,17 @@ public class TransactionAwareConnectionFactoryProxy extends DelegatingConnection @@ -145,17 +145,17 @@ public class TransactionAwareConnectionFactoryProxy extends DelegatingConnection
return switch (method.getName()) {
case "unwrap" -> this.connection;
// Handle close method: only close if not within a transaction.
case "close" -> ConnectionFactoryUtils.doReleaseConnection(this.connection, this.targetConnectionFactory)
.doOnSubscribe(n -> this.closed = true);
// Handle close method: only close if not within a transaction.
case "isClosed" -> this.closed;
default -> {
if (this.closed) {
throw new IllegalStateException("Connection handle already closed");
}
// Invoke method on target Connection.
try {
// Invoke method on target Connection.
yield method.invoke(this.connection, args);
}
catch (InvocationTargetException ex) {
@ -167,7 +167,7 @@ public class TransactionAwareConnectionFactoryProxy extends DelegatingConnection @@ -167,7 +167,7 @@ public class TransactionAwareConnectionFactoryProxy extends DelegatingConnection
private String proxyToString(@Nullable Object proxy) {
// Allow for differentiating between the proxy and the raw Connection.
return "Transaction-aware proxy for target Connection [" + this.connection.toString() + "]";
return "Transaction-aware proxy for target Connection [" + this.connection + "]";
}
}

8
spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java

@ -520,16 +520,16 @@ final class DefaultDatabaseClient implements DatabaseClient { @@ -520,16 +520,16 @@ final class DefaultDatabaseClient implements DatabaseClient {
@Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return switch (method.getName()) {
// Only consider equal when proxies are identical.
case "equals" -> proxy == args[0];
// Only consider equal when proxies are identical.
// Use hashCode of PersistenceManager proxy.
case "hashCode" -> System.identityHashCode(proxy);
// Use hashCode of PersistenceManager proxy.
case "unwrap" -> this.target;
// Handle close method: suppress, not valid.
case "close" -> Mono.error(new UnsupportedOperationException("Close is not supported!"));
// Handle close method: suppress, not valid.
default -> {
// Invoke method on target Connection.
try {
// Invoke method on target Connection.
yield method.invoke(this.target, args);
}
catch (InvocationTargetException ex) {

2
spring-tx/src/main/java/org/springframework/transaction/jta/JtaAfterCompletionSynchronization.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2023 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.

Loading…
Cancel
Save