From 701e9e410fdd3427f7416fca42f8d45d385b96a9 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 28 Feb 2024 21:13:10 +0100 Subject: [PATCH] Polishing --- .../factory/support/ConstructorResolver.java | 11 ++--- .../support/DefaultSingletonBeanRegistry.java | 12 ++--- .../annotation/ConfigurationClass.java | 27 +++++------ .../support/AbstractApplicationContext.java | 45 ++++++++++--------- ...ncorrectResultSetColumnCountException.java | 4 +- ...ffectedIncorrectNumberOfRowsException.java | 4 +- ...rruptibleBatchPreparedStatementSetter.java | 4 +- .../jdbc/object/RdbmsOperation.java | 8 ++-- .../jdbc/object/StoredProcedure.java | 4 +- .../CustomSQLExceptionTranslatorRegistry.java | 10 ++--- .../jdbc/support/JdbcUtils.java | 14 +++--- .../jdbc/support/SQLErrorCodesFactory.java | 5 ++- ...ocalContainerEntityManagerFactoryBean.java | 11 +++-- .../jpa/LocalEntityManagerFactoryBean.java | 26 ++++------- .../connection/SingleConnectionFactory.java | 8 ++-- ...ectUpdateSemanticsDataAccessException.java | 7 +-- .../ServletRequestMethodArgumentResolver.java | 3 +- 17 files changed, 98 insertions(+), 105 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java index ce54ef0b3eb..9ad0ab826ed 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -600,13 +600,10 @@ class ConstructorResolver { String argDesc = StringUtils.collectionToCommaDelimitedString(argTypes); throw new BeanCreationException(mbd.getResourceDescription(), beanName, "No matching factory method found on class [" + factoryClass.getName() + "]: " + - (mbd.getFactoryBeanName() != null ? - "factory bean '" + mbd.getFactoryBeanName() + "'; " : "") + + (mbd.getFactoryBeanName() != null ? "factory bean '" + mbd.getFactoryBeanName() + "'; " : "") + "factory method '" + mbd.getFactoryMethodName() + "(" + argDesc + ")'. " + - "Check that a method with the specified name " + - (minNrOfArgs > 0 ? "and arguments " : "") + - "exists and that it is " + - (isStatic ? "static" : "non-static") + "."); + "Check that a method with the specified name " + (minNrOfArgs > 0 ? "and arguments " : "") + + "exists and that it is " + (isStatic ? "static" : "non-static") + "."); } else if (void.class == factoryMethodToUse.getReturnType()) { throw new BeanCreationException(mbd.getResourceDescription(), beanName, diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java index 9b189b34312..81e44240497 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -567,16 +567,16 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements */ protected void destroyBean(String beanName, @Nullable DisposableBean bean) { // Trigger destruction of dependent beans first... - Set dependencies; + Set dependentBeanNames; synchronized (this.dependentBeanMap) { // Within full synchronization in order to guarantee a disconnected Set - dependencies = this.dependentBeanMap.remove(beanName); + dependentBeanNames = this.dependentBeanMap.remove(beanName); } - if (dependencies != null) { + if (dependentBeanNames != null) { if (logger.isTraceEnabled()) { - logger.trace("Retrieved dependent beans for bean '" + beanName + "': " + dependencies); + logger.trace("Retrieved dependent beans for bean '" + beanName + "': " + dependentBeanNames); } - for (String dependentBeanName : dependencies) { + for (String dependentBeanName : dependentBeanNames) { destroySingleton(dependentBeanName); } } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java index b6155f6d7bf..494197a37b6 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 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. @@ -72,7 +72,6 @@ final class ConfigurationClass { * Create a new {@link ConfigurationClass} with the given name. * @param metadataReader reader used to parse the underlying {@link Class} * @param beanName must not be {@code null} - * @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass) */ ConfigurationClass(MetadataReader metadataReader, String beanName) { Assert.notNull(beanName, "Bean name must not be null"); @@ -86,10 +85,10 @@ final class ConfigurationClass { * using the {@link Import} annotation or automatically processed as a nested * configuration class (if importedBy is not {@code null}). * @param metadataReader reader used to parse the underlying {@link Class} - * @param importedBy the configuration class importing this one or {@code null} + * @param importedBy the configuration class importing this one * @since 3.1.1 */ - ConfigurationClass(MetadataReader metadataReader, @Nullable ConfigurationClass importedBy) { + ConfigurationClass(MetadataReader metadataReader, ConfigurationClass importedBy) { this.metadata = metadataReader.getAnnotationMetadata(); this.resource = metadataReader.getResource(); this.importedBy.add(importedBy); @@ -99,7 +98,6 @@ final class ConfigurationClass { * Create a new {@link ConfigurationClass} with the given name. * @param clazz the underlying {@link Class} to represent * @param beanName name of the {@code @Configuration} class bean - * @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass) */ ConfigurationClass(Class clazz, String beanName) { Assert.notNull(beanName, "Bean name must not be null"); @@ -113,10 +111,10 @@ final class ConfigurationClass { * using the {@link Import} annotation or automatically processed as a nested * configuration class (if imported is {@code true}). * @param clazz the underlying {@link Class} to represent - * @param importedBy the configuration class importing this one (or {@code null}) + * @param importedBy the configuration class importing this one * @since 3.1.1 */ - ConfigurationClass(Class clazz, @Nullable ConfigurationClass importedBy) { + ConfigurationClass(Class clazz, ConfigurationClass importedBy) { this.metadata = AnnotationMetadata.introspect(clazz); this.resource = new DescriptiveResource(clazz.getName()); this.importedBy.add(importedBy); @@ -126,7 +124,6 @@ final class ConfigurationClass { * Create a new {@link ConfigurationClass} with the given name. * @param metadata the metadata for the underlying class to represent * @param beanName name of the {@code @Configuration} class bean - * @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass) */ ConfigurationClass(AnnotationMetadata metadata, String beanName) { Assert.notNull(beanName, "Bean name must not be null"); @@ -148,12 +145,12 @@ final class ConfigurationClass { return ClassUtils.getShortName(getMetadata().getClassName()); } - void setBeanName(String beanName) { + void setBeanName(@Nullable String beanName) { this.beanName = beanName; } @Nullable - public String getBeanName() { + String getBeanName() { return this.beanName; } @@ -163,7 +160,7 @@ final class ConfigurationClass { * @since 3.1.1 * @see #getImportedBy() */ - public boolean isImported() { + boolean isImported() { return !this.importedBy.isEmpty(); } @@ -197,6 +194,10 @@ final class ConfigurationClass { this.importedResources.put(importedResource, readerClass); } + Map> getImportedResources() { + return this.importedResources; + } + void addImportBeanDefinitionRegistrar(ImportBeanDefinitionRegistrar registrar, AnnotationMetadata importingClassMetadata) { this.importBeanDefinitionRegistrars.put(registrar, importingClassMetadata); } @@ -205,10 +206,6 @@ final class ConfigurationClass { return this.importBeanDefinitionRegistrars; } - Map> getImportedResources() { - return this.importedResources; - } - void validate(ProblemReporter problemReporter) { // A configuration class may not be final (CGLIB limitation) unless it declares proxyBeanMethods=false Map attributes = this.metadata.getAnnotationAttributes(Configuration.class.getName()); diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java index a9b190f227d..a10937c45ca 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -136,17 +136,6 @@ import org.springframework.util.ReflectionUtils; public abstract class AbstractApplicationContext extends DefaultResourceLoader implements ConfigurableApplicationContext { - /** - * The name of the {@link LifecycleProcessor} bean in the context. - * If none is supplied, a {@link DefaultLifecycleProcessor} is used. - * @since 3.0 - * @see org.springframework.context.LifecycleProcessor - * @see org.springframework.context.support.DefaultLifecycleProcessor - * @see #start() - * @see #stop() - */ - public static final String LIFECYCLE_PROCESSOR_BEAN_NAME = "lifecycleProcessor"; - /** * The name of the {@link MessageSource} bean in the context. * If none is supplied, message resolution is delegated to the parent. @@ -167,6 +156,18 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader */ public static final String APPLICATION_EVENT_MULTICASTER_BEAN_NAME = "applicationEventMulticaster"; + /** + * The name of the {@link LifecycleProcessor} bean in the context. + * If none is supplied, a {@link DefaultLifecycleProcessor} is used. + * @since 3.0 + * @see org.springframework.context.LifecycleProcessor + * @see org.springframework.context.support.DefaultLifecycleProcessor + * @see #start() + * @see #stop() + */ + public static final String LIFECYCLE_PROCESSOR_BEAN_NAME = "lifecycleProcessor"; + + /** * Boolean flag controlled by a {@code spring.spel.ignore} system property that * instructs Spring to ignore SpEL, i.e. to not initialize the SpEL infrastructure. @@ -570,7 +571,6 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader StartupStep beanPostProcess = this.applicationStartup.start("spring.context.beans.post-process"); // Invoke factory processors registered as beans in the context. invokeBeanFactoryPostProcessors(beanFactory); - // Register bean processors that intercept bean creation. registerBeanPostProcessors(beanFactory); beanPostProcess.end(); @@ -774,8 +774,9 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader } /** - * Initialize the MessageSource. - * Use parent's if none defined in this context. + * Initialize the {@link MessageSource}. + *

Uses parent's {@code MessageSource} if none defined in this context. + * @see #MESSAGE_SOURCE_BEAN_NAME */ protected void initMessageSource() { ConfigurableListableBeanFactory beanFactory = getBeanFactory(); @@ -807,8 +808,9 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader } /** - * Initialize the ApplicationEventMulticaster. - * Uses SimpleApplicationEventMulticaster if none defined in the context. + * Initialize the {@link ApplicationEventMulticaster}. + *

Uses {@link SimpleApplicationEventMulticaster} if none defined in the context. + * @see #APPLICATION_EVENT_MULTICASTER_BEAN_NAME * @see org.springframework.context.event.SimpleApplicationEventMulticaster */ protected void initApplicationEventMulticaster() { @@ -831,15 +833,16 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader } /** - * Initialize the LifecycleProcessor. - * Uses DefaultLifecycleProcessor if none defined in the context. + * Initialize the {@link LifecycleProcessor}. + *

Uses {@link DefaultLifecycleProcessor} if none defined in the context. + * @since 3.0 + * @see #LIFECYCLE_PROCESSOR_BEAN_NAME * @see org.springframework.context.support.DefaultLifecycleProcessor */ protected void initLifecycleProcessor() { ConfigurableListableBeanFactory beanFactory = getBeanFactory(); if (beanFactory.containsLocalBean(LIFECYCLE_PROCESSOR_BEAN_NAME)) { - this.lifecycleProcessor = - beanFactory.getBean(LIFECYCLE_PROCESSOR_BEAN_NAME, LifecycleProcessor.class); + this.lifecycleProcessor = beanFactory.getBean(LIFECYCLE_PROCESSOR_BEAN_NAME, LifecycleProcessor.class); if (logger.isTraceEnabled()) { logger.trace("Using LifecycleProcessor [" + this.lifecycleProcessor + "]"); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/IncorrectResultSetColumnCountException.java b/spring-jdbc/src/main/java/org/springframework/jdbc/IncorrectResultSetColumnCountException.java index 3cc779b1976..562140faf02 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/IncorrectResultSetColumnCountException.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/IncorrectResultSetColumnCountException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2024 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. @@ -20,7 +20,7 @@ import org.springframework.dao.DataRetrievalFailureException; /** * Data access exception thrown when a result set did not have the correct column count, - * for example when expecting a single column but getting 0 or more than 1 columns. + * for example when expecting a single column but getting 0 or more than 1 column. * * @author Juergen Hoeller * @since 2.0 diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/JdbcUpdateAffectedIncorrectNumberOfRowsException.java b/spring-jdbc/src/main/java/org/springframework/jdbc/JdbcUpdateAffectedIncorrectNumberOfRowsException.java index 4b88b4159fa..d7549b0f5cf 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/JdbcUpdateAffectedIncorrectNumberOfRowsException.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/JdbcUpdateAffectedIncorrectNumberOfRowsException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2024 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. @@ -20,7 +20,7 @@ import org.springframework.dao.IncorrectUpdateSemanticsDataAccessException; /** * Exception thrown when a JDBC update affects an unexpected number of rows. - * Typically we expect an update to affect a single row, meaning it's an + * Typically, we expect an update to affect a single row, meaning it is an * error if it affects multiple rows. * * @author Rod Johnson diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/InterruptibleBatchPreparedStatementSetter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/InterruptibleBatchPreparedStatementSetter.java index 9de0357d641..9a304e1cf11 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/InterruptibleBatchPreparedStatementSetter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/InterruptibleBatchPreparedStatementSetter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2024 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. @@ -22,7 +22,7 @@ package org.springframework.jdbc.core; * *

This interface allows you to signal the end of a batch rather than * having to determine the exact batch size upfront. Batch size is still - * being honored but it is now the maximum size of the batch. + * being honored, but it is now the maximum size of the batch. * *

The {@link #isBatchExhausted} method is called after each call to * {@link #setValues} to determine whether there were some values added, diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java index cba88a46040..fe7b05b1113 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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. @@ -128,8 +128,8 @@ public abstract class RdbmsOperation implements InitializingBean { /** * Set the maximum number of rows for this RDBMS operation. This is important - * for processing subsets of large result sets, avoiding to read and hold - * the entire result set in the database or in the JDBC driver. + * for processing subsets of large result sets, in order to avoid reading and + * holding the entire result set in the database or in the JDBC driver. *

Default is -1, indicating to use the driver's default. * @see org.springframework.jdbc.core.JdbcTemplate#setMaxRows */ @@ -175,7 +175,7 @@ public abstract class RdbmsOperation implements InitializingBean { public void setUpdatableResults(boolean updatableResults) { if (isCompiled()) { throw new InvalidDataAccessApiUsageException( - "The updateableResults flag must be set before the operation is compiled"); + "The updatableResults flag must be set before the operation is compiled"); } this.updatableResults = updatableResults; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/StoredProcedure.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/StoredProcedure.java index f740eb4b792..d860eb206bd 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/StoredProcedure.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/StoredProcedure.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 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. @@ -29,7 +29,7 @@ import org.springframework.jdbc.core.SqlParameter; /** * Superclass for object abstractions of RDBMS stored procedures. - * This class is abstract and it is intended that subclasses will provide a typed + * This class is abstract, and it is intended that subclasses will provide a typed * method for invocation that delegates to the supplied {@link #execute} method. * *

The inherited {@link #setSql sql} property is the name of the stored procedure diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistry.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistry.java index 2908e65bac3..259353a04f7 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistry.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -25,9 +25,9 @@ import org.apache.commons.logging.LogFactory; import org.springframework.lang.Nullable; /** - * Registry for custom {@link org.springframework.jdbc.support.SQLExceptionTranslator} instances associated with - * specific databases allowing for overriding translation based on values contained in the configuration file - * named "sql-error-codes.xml". + * Registry for custom {@link SQLExceptionTranslator} instances associated with + * specific databases allowing for overriding translation based on values + * contained in the configuration file named "sql-error-codes.xml". * * @author Thomas Risberg * @since 3.1.1 @@ -38,7 +38,7 @@ public final class CustomSQLExceptionTranslatorRegistry { private static final Log logger = LogFactory.getLog(CustomSQLExceptionTranslatorRegistry.class); /** - * Keep track of a single instance so we can return it to classes that request it. + * Keep track of a single instance, so we can return it to classes that request it. */ private static final CustomSQLExceptionTranslatorRegistry instance = new CustomSQLExceptionTranslatorRegistry(); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java index 2deeb4c666f..f35c70318f1 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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. @@ -218,7 +218,7 @@ public abstract class JdbcUtils { return NumberUtils.convertNumberToTargetClass((Number) obj, Integer.class); } else { - // e.g. on Postgres: getObject returns a PGObject but we need a String + // e.g. on Postgres: getObject returns a PGObject, but we need a String return rs.getString(index); } } @@ -416,14 +416,14 @@ public abstract class JdbcUtils { } /** - * Return whether the given JDBC driver supports JDBC 2.0 batch updates. + * Return whether the given JDBC driver supports JDBC batch updates. *

Typically invoked right before execution of a given set of statements: * to decide whether the set of SQL statements should be executed through - * the JDBC 2.0 batch mechanism or simply in a traditional one-by-one fashion. + * the JDBC batch mechanism or simply in a traditional one-by-one fashion. *

Logs a warning if the "supportsBatchUpdates" methods throws an exception * and simply returns {@code false} in that case. * @param con the Connection to check - * @return whether JDBC 2.0 batch updates are supported + * @return whether JDBC batch updates are supported * @see java.sql.DatabaseMetaData#supportsBatchUpdates() */ public static boolean supportsBatchUpdates(Connection con) { @@ -496,8 +496,8 @@ public abstract class JdbcUtils { /** * Determine the column name to use. The column name is determined based on a * lookup using ResultSetMetaData. - *

This method implementation takes into account recent clarifications - * expressed in the JDBC 4.0 specification: + *

This method's implementation takes into account clarifications expressed + * in the JDBC 4.0 specification: *

columnLabel - the label for the column specified with the SQL AS clause. * If the SQL AS clause was not specified, then the label is the name of the column. * @param resultSetMetaData the current meta-data to use diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodesFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodesFactory.java index 2b78fa740f0..a751ef6c10c 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodesFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodesFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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. @@ -67,7 +67,7 @@ public class SQLErrorCodesFactory { private static final Log logger = LogFactory.getLog(SQLErrorCodesFactory.class); /** - * Keep track of a single instance so we can return it to classes that request it. + * Keep track of a single instance, so we can return it to classes that request it. */ private static final SQLErrorCodesFactory instance = new SQLErrorCodesFactory(); @@ -101,6 +101,7 @@ public class SQLErrorCodesFactory { * @see #loadResource(String) */ protected SQLErrorCodesFactory() { + Map errorCodes; try { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java index 6fc17b5c5fd..aded2b9c9f0 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java @@ -253,8 +253,9 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage * @see javax.persistence.spi.PersistenceUnitInfo#getNonJtaDataSource() * @see #setPersistenceUnitManager */ - public void setDataSource(DataSource dataSource) { - this.internalPersistenceUnitManager.setDataSourceLookup(new SingleDataSourceLookup(dataSource)); + public void setDataSource(@Nullable DataSource dataSource) { + this.internalPersistenceUnitManager.setDataSourceLookup( + dataSource != null ? new SingleDataSourceLookup(dataSource) : null); this.internalPersistenceUnitManager.setDefaultDataSource(dataSource); } @@ -270,8 +271,9 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage * @see javax.persistence.spi.PersistenceUnitInfo#getJtaDataSource() * @see #setPersistenceUnitManager */ - public void setJtaDataSource(DataSource jtaDataSource) { - this.internalPersistenceUnitManager.setDataSourceLookup(new SingleDataSourceLookup(jtaDataSource)); + public void setJtaDataSource(@Nullable DataSource jtaDataSource) { + this.internalPersistenceUnitManager.setDataSourceLookup( + jtaDataSource != null ? new SingleDataSourceLookup(jtaDataSource) : null); this.internalPersistenceUnitManager.setDefaultJtaDataSource(jtaDataSource); } @@ -416,6 +418,7 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage } @Override + @Nullable public DataSource getDataSource() { if (this.persistenceUnitInfo != null) { return (this.persistenceUnitInfo.getJtaDataSource() != null ? diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java index dcc9961f55c..398fa693380 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2024 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. @@ -28,28 +28,18 @@ import javax.persistence.spi.PersistenceProvider; * shared JPA EntityManagerFactory in a Spring application context; the * EntityManagerFactory can then be passed to JPA-based DAOs via * dependency injection. Note that switching to a JNDI lookup or to a - * {@link LocalContainerEntityManagerFactoryBean} - * definition is just a matter of configuration! + * {@link LocalContainerEntityManagerFactoryBean} definition based on the + * JPA container contract is just a matter of configuration! * *

Configuration settings are usually read from a {@code META-INF/persistence.xml} * config file, residing in the class path, according to the JPA standalone bootstrap - * contract. Additionally, most JPA providers will require a special VM agent - * (specified on JVM startup) that allows them to instrument application classes. - * See the Java Persistence API specification and your provider documentation - * for setup details. - * - *

This EntityManagerFactory bootstrap is appropriate for standalone applications - * which solely use JPA for data access. If you want to set up your persistence - * provider for an external DataSource and/or for global transactions which span - * multiple resources, you will need to either deploy it into a full Java EE - * application server and access the deployed EntityManagerFactory via JNDI, - * or use Spring's {@link LocalContainerEntityManagerFactoryBean} with appropriate - * configuration for local setup according to JPA's container contract. + * contract. See the Java Persistence API specification and your persistence provider + * documentation for setup details. Additionally, JPA properties can also be added + * on this FactoryBean via {@link #setJpaProperties}/{@link #setJpaPropertyMap}. * *

Note: This FactoryBean has limited configuration power in terms of - * what configuration it is able to pass to the JPA provider. If you need more - * flexible configuration, for example passing a Spring-managed JDBC DataSource - * to the JPA provider, consider using Spring's more powerful + * the configuration that it is able to pass to the JPA provider. If you need + * more flexible configuration options, consider using Spring's more powerful * {@link LocalContainerEntityManagerFactoryBean} instead. * *

NOTE: Spring's JPA support requires JPA 2.1 or higher, as of Spring 5.0. diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java index 527da9d9b00..6d16e8c1b6f 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -70,13 +70,15 @@ public class SingleConnectionFactory extends DelegatingConnectionFactory private boolean suppressClose; /** Override auto-commit state?. */ - private @Nullable Boolean autoCommit; + @Nullable + private Boolean autoCommit; /** Wrapped Connection. */ private final AtomicReference target = new AtomicReference<>(); /** Proxy Connection. */ - private @Nullable Connection connection; + @Nullable + private Connection connection; private final Mono connectionEmitter; diff --git a/spring-tx/src/main/java/org/springframework/dao/IncorrectUpdateSemanticsDataAccessException.java b/spring-tx/src/main/java/org/springframework/dao/IncorrectUpdateSemanticsDataAccessException.java index 70689977cd2..2eb1749da9e 100644 --- a/spring-tx/src/main/java/org/springframework/dao/IncorrectUpdateSemanticsDataAccessException.java +++ b/spring-tx/src/main/java/org/springframework/dao/IncorrectUpdateSemanticsDataAccessException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2024 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. @@ -44,10 +44,11 @@ public class IncorrectUpdateSemanticsDataAccessException extends InvalidDataAcce super(msg, cause); } + /** * Return whether data was updated. - * If this method returns false, there's nothing to roll back. - *

The default implementation always returns true. + * If this method returns {@code false}, there is nothing to roll back. + *

The default implementation always returns {@code true}. * This can be overridden in subclasses. */ public boolean wasDataUpdated() { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java index 45ca54595ef..0377612b57f 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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. @@ -203,7 +203,6 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume "Current push builder is not of type [" + paramType.getName() + "]: " + pushBuilder); } return pushBuilder; - } }