mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-05-03 20:09:26 +01:00
Add nullability annotations to module/spring-boot-sql
See gh-46587
This commit is contained in:
+5
-2
@@ -18,6 +18,8 @@ package org.springframework.boot.sql.autoconfigure.init;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
||||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
||||
@@ -68,7 +70,8 @@ public abstract class OnDatabaseInitializationCondition extends SpringBootCondit
|
||||
return !mode.equals(DatabaseInitializationMode.NEVER);
|
||||
}
|
||||
|
||||
private DatabaseInitializationMode getDatabaseInitializationMode(Environment environment, String propertyName) {
|
||||
private DatabaseInitializationMode getDatabaseInitializationMode(Environment environment,
|
||||
@Nullable String propertyName) {
|
||||
if (StringUtils.hasText(propertyName)) {
|
||||
String candidate = environment.getProperty(propertyName, "embedded").toUpperCase(Locale.ENGLISH);
|
||||
if (StringUtils.hasText(candidate)) {
|
||||
@@ -78,7 +81,7 @@ public abstract class OnDatabaseInitializationCondition extends SpringBootCondit
|
||||
return DatabaseInitializationMode.EMBEDDED;
|
||||
}
|
||||
|
||||
private String getConfiguredProperty(Environment environment) {
|
||||
private @Nullable String getConfiguredProperty(Environment environment) {
|
||||
for (String propertyName : this.propertyNames) {
|
||||
if (environment.containsProperty(propertyName)) {
|
||||
return propertyName;
|
||||
|
||||
+3
-1
@@ -19,6 +19,8 @@ package org.springframework.boot.sql.autoconfigure.init;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.boot.sql.init.DatabaseInitializationSettings;
|
||||
|
||||
/**
|
||||
@@ -44,7 +46,7 @@ final class SettingsCreator {
|
||||
return settings;
|
||||
}
|
||||
|
||||
private static List<String> scriptLocations(List<String> locations, String fallback, String platform) {
|
||||
private static List<String> scriptLocations(@Nullable List<String> locations, String fallback, String platform) {
|
||||
if (locations != null) {
|
||||
return locations;
|
||||
}
|
||||
|
||||
+17
-15
@@ -19,6 +19,8 @@ package org.springframework.boot.sql.autoconfigure.init;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.sql.init.DatabaseInitializationMode;
|
||||
|
||||
@@ -35,12 +37,12 @@ public class SqlInitializationProperties {
|
||||
/**
|
||||
* Locations of the schema (DDL) scripts to apply to the database.
|
||||
*/
|
||||
private List<String> schemaLocations;
|
||||
private @Nullable List<String> schemaLocations;
|
||||
|
||||
/**
|
||||
* Locations of the data (DML) scripts to apply to the database.
|
||||
*/
|
||||
private List<String> dataLocations;
|
||||
private @Nullable List<String> dataLocations;
|
||||
|
||||
/**
|
||||
* Platform to use in the default schema or data script locations,
|
||||
@@ -52,13 +54,13 @@ public class SqlInitializationProperties {
|
||||
* Username of the database to use when applying initialization scripts (if
|
||||
* different).
|
||||
*/
|
||||
private String username;
|
||||
private @Nullable String username;
|
||||
|
||||
/**
|
||||
* Password of the database to use when applying initialization scripts (if
|
||||
* different).
|
||||
*/
|
||||
private String password;
|
||||
private @Nullable String password;
|
||||
|
||||
/**
|
||||
* Whether initialization should continue when an error occurs.
|
||||
@@ -73,26 +75,26 @@ public class SqlInitializationProperties {
|
||||
/**
|
||||
* Encoding of the schema and data scripts.
|
||||
*/
|
||||
private Charset encoding;
|
||||
private @Nullable Charset encoding;
|
||||
|
||||
/**
|
||||
* Mode to apply when determining whether initialization should be performed.
|
||||
*/
|
||||
private DatabaseInitializationMode mode = DatabaseInitializationMode.EMBEDDED;
|
||||
|
||||
public List<String> getSchemaLocations() {
|
||||
public @Nullable List<String> getSchemaLocations() {
|
||||
return this.schemaLocations;
|
||||
}
|
||||
|
||||
public void setSchemaLocations(List<String> schemaLocations) {
|
||||
public void setSchemaLocations(@Nullable List<String> schemaLocations) {
|
||||
this.schemaLocations = schemaLocations;
|
||||
}
|
||||
|
||||
public List<String> getDataLocations() {
|
||||
public @Nullable List<String> getDataLocations() {
|
||||
return this.dataLocations;
|
||||
}
|
||||
|
||||
public void setDataLocations(List<String> dataLocations) {
|
||||
public void setDataLocations(@Nullable List<String> dataLocations) {
|
||||
this.dataLocations = dataLocations;
|
||||
}
|
||||
|
||||
@@ -104,19 +106,19 @@ public class SqlInitializationProperties {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
public @Nullable String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
public void setUsername(@Nullable String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
public @Nullable String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
public void setPassword(@Nullable String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@@ -136,11 +138,11 @@ public class SqlInitializationProperties {
|
||||
this.separator = separator;
|
||||
}
|
||||
|
||||
public Charset getEncoding() {
|
||||
public @Nullable Charset getEncoding() {
|
||||
return this.encoding;
|
||||
}
|
||||
|
||||
public void setEncoding(Charset encoding) {
|
||||
public void setEncoding(@Nullable Charset encoding) {
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.boot.sql.autoconfigure.init;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
|
||||
@@ -27,7 +29,7 @@ import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
class SqlInitializationScriptsRuntimeHints implements RuntimeHintsRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
|
||||
hints.resources().registerPattern("schema.sql").registerPattern("schema-*.sql");
|
||||
hints.resources().registerPattern("data.sql").registerPattern("data-*.sql");
|
||||
}
|
||||
|
||||
+3
@@ -17,4 +17,7 @@
|
||||
/**
|
||||
* Auto-configuration for basic script-based initialization of an SQL database.
|
||||
*/
|
||||
@NullMarked
|
||||
package org.springframework.boot.sql.autoconfigure.init;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
+10
-5
@@ -24,6 +24,8 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ResourceLoaderAware;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -45,6 +47,7 @@ public abstract class AbstractScriptDatabaseInitializer implements ResourceLoade
|
||||
|
||||
private final DatabaseInitializationSettings settings;
|
||||
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private volatile ResourceLoader resourceLoader;
|
||||
|
||||
/**
|
||||
@@ -102,7 +105,8 @@ public abstract class AbstractScriptDatabaseInitializer implements ResourceLoade
|
||||
return applyScripts(this.settings.getDataLocations(), "data", locationResolver);
|
||||
}
|
||||
|
||||
private boolean applyScripts(List<String> locations, String type, ScriptLocationResolver locationResolver) {
|
||||
private boolean applyScripts(@Nullable List<String> locations, String type,
|
||||
ScriptLocationResolver locationResolver) {
|
||||
List<Resource> scripts = getScripts(locations, type, locationResolver);
|
||||
if (!scripts.isEmpty() && isEnabled()) {
|
||||
runScripts(scripts);
|
||||
@@ -111,7 +115,8 @@ public abstract class AbstractScriptDatabaseInitializer implements ResourceLoade
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<Resource> getScripts(List<String> locations, String type, ScriptLocationResolver locationResolver) {
|
||||
private List<Resource> getScripts(@Nullable List<String> locations, String type,
|
||||
ScriptLocationResolver locationResolver) {
|
||||
if (CollectionUtils.isEmpty(locations)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -192,7 +197,7 @@ public abstract class AbstractScriptDatabaseInitializer implements ResourceLoade
|
||||
|
||||
private String separator = ";";
|
||||
|
||||
private Charset encoding;
|
||||
private @Nullable Charset encoding;
|
||||
|
||||
public Scripts(List<Resource> resources) {
|
||||
this.resources = resources;
|
||||
@@ -221,12 +226,12 @@ public abstract class AbstractScriptDatabaseInitializer implements ResourceLoade
|
||||
return this.separator;
|
||||
}
|
||||
|
||||
public Scripts encoding(Charset encoding) {
|
||||
public Scripts encoding(@Nullable Charset encoding) {
|
||||
this.encoding = encoding;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Charset getEncoding() {
|
||||
public @Nullable Charset getEncoding() {
|
||||
return this.encoding;
|
||||
}
|
||||
|
||||
|
||||
+11
-9
@@ -19,6 +19,8 @@ package org.springframework.boot.sql.init;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Settings for initializing an SQL database.
|
||||
*
|
||||
@@ -27,15 +29,15 @@ import java.util.List;
|
||||
*/
|
||||
public class DatabaseInitializationSettings {
|
||||
|
||||
private List<String> schemaLocations;
|
||||
private @Nullable List<String> schemaLocations;
|
||||
|
||||
private List<String> dataLocations;
|
||||
private @Nullable List<String> dataLocations;
|
||||
|
||||
private boolean continueOnError;
|
||||
|
||||
private String separator = ";";
|
||||
|
||||
private Charset encoding;
|
||||
private @Nullable Charset encoding;
|
||||
|
||||
private DatabaseInitializationMode mode = DatabaseInitializationMode.EMBEDDED;
|
||||
|
||||
@@ -43,7 +45,7 @@ public class DatabaseInitializationSettings {
|
||||
* Returns the locations of the schema (DDL) scripts to apply to the database.
|
||||
* @return the locations of the schema scripts
|
||||
*/
|
||||
public List<String> getSchemaLocations() {
|
||||
public @Nullable List<String> getSchemaLocations() {
|
||||
return this.schemaLocations;
|
||||
}
|
||||
|
||||
@@ -53,7 +55,7 @@ public class DatabaseInitializationSettings {
|
||||
* location can be made optional by prefixing it with {@code optional:}.
|
||||
* @param schemaLocations locations of the schema scripts
|
||||
*/
|
||||
public void setSchemaLocations(List<String> schemaLocations) {
|
||||
public void setSchemaLocations(@Nullable List<String> schemaLocations) {
|
||||
this.schemaLocations = schemaLocations;
|
||||
}
|
||||
|
||||
@@ -61,7 +63,7 @@ public class DatabaseInitializationSettings {
|
||||
* Returns the locations of data (DML) scripts to apply to the database.
|
||||
* @return the locations of the data scripts
|
||||
*/
|
||||
public List<String> getDataLocations() {
|
||||
public @Nullable List<String> getDataLocations() {
|
||||
return this.dataLocations;
|
||||
}
|
||||
|
||||
@@ -71,7 +73,7 @@ public class DatabaseInitializationSettings {
|
||||
* location can be made optional by prefixing it with {@code optional:}.
|
||||
* @param dataLocations locations of the data scripts
|
||||
*/
|
||||
public void setDataLocations(List<String> dataLocations) {
|
||||
public void setDataLocations(@Nullable List<String> dataLocations) {
|
||||
this.dataLocations = dataLocations;
|
||||
}
|
||||
|
||||
@@ -113,7 +115,7 @@ public class DatabaseInitializationSettings {
|
||||
* Returns the encoding to use when reading the schema and data scripts.
|
||||
* @return the script encoding
|
||||
*/
|
||||
public Charset getEncoding() {
|
||||
public @Nullable Charset getEncoding() {
|
||||
return this.encoding;
|
||||
}
|
||||
|
||||
@@ -121,7 +123,7 @@ public class DatabaseInitializationSettings {
|
||||
* Sets the encoding to use when reading the schema and data scripts.
|
||||
* @param encoding encoding to use when reading the schema and data scripts
|
||||
*/
|
||||
public void setEncoding(Charset encoding) {
|
||||
public void setEncoding(@Nullable Charset encoding) {
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -26,6 +26,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.aot.AotDetector;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
@@ -82,6 +84,7 @@ public class DatabaseInitializationDependencyConfigurer implements ImportBeanDef
|
||||
static class DependsOnDatabaseInitializationPostProcessor
|
||||
implements BeanFactoryPostProcessor, EnvironmentAware, Ordered {
|
||||
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private Environment environment;
|
||||
|
||||
@Override
|
||||
@@ -118,7 +121,7 @@ public class DatabaseInitializationDependencyConfigurer implements ImportBeanDef
|
||||
}
|
||||
}
|
||||
|
||||
private String[] merge(String[] source, Set<String> additional) {
|
||||
private String @Nullable [] merge(String @Nullable [] source, @Nullable Set<String> additional) {
|
||||
if (CollectionUtils.isEmpty(additional)) {
|
||||
return source;
|
||||
}
|
||||
|
||||
+3
@@ -17,4 +17,7 @@
|
||||
/**
|
||||
* Infrastructure for establishing database initialization bean dependencies.
|
||||
*/
|
||||
@NullMarked
|
||||
package org.springframework.boot.sql.init.dependency;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
+3
@@ -17,4 +17,7 @@
|
||||
/**
|
||||
* Support for initialization of an SQL database.
|
||||
*/
|
||||
@NullMarked
|
||||
package org.springframework.boot.sql.init;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
Reference in New Issue
Block a user