Skip to content

Commit

Permalink
Avoid unnecessary DatabasePopulator init/destroy processing
Browse files Browse the repository at this point in the history
Closes gh-23405
  • Loading branch information
jhoeller committed Dec 23, 2023
1 parent 4afac17 commit a428955
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -48,6 +48,7 @@ public static void setDatabasePopulator(Element element, BeanDefinitionBuilder b
}
}

@Nullable
private static BeanDefinition createDatabasePopulator(Element element, List<Element> scripts, String execution) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CompositeDatabasePopulator.class);

Expand Down Expand Up @@ -80,8 +81,12 @@ private static BeanDefinition createDatabasePopulator(Element element, List<Elem
}
delegates.add(delegate.getBeanDefinition());
}
builder.addPropertyValue("populators", delegates);

if (delegates.isEmpty()) {
return null;
}

builder.addPropertyValue("populators", delegates);
return builder.getBeanDefinition();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -58,21 +58,22 @@ public void setDataSource(DataSource dataSource) {
}

/**
* Set the {@link DatabasePopulator} to execute during the bean initialization phase.
* Set the {@link DatabasePopulator} to execute during the bean initialization phase,
* if any.
* @param databasePopulator the {@code DatabasePopulator} to use during initialization
* @see #setDatabaseCleaner
*/
public void setDatabasePopulator(DatabasePopulator databasePopulator) {
public void setDatabasePopulator(@Nullable DatabasePopulator databasePopulator) {
this.databasePopulator = databasePopulator;
}

/**
* Set the {@link DatabasePopulator} to execute during the bean destruction
* phase, cleaning up the database and leaving it in a known state for others.
* Set the {@link DatabasePopulator} to execute during the bean destruction phase,
* if any, cleaning up the database and leaving it in a known state for others.
* @param databaseCleaner the {@code DatabasePopulator} to use during destruction
* @see #setDatabasePopulator
*/
public void setDatabaseCleaner(DatabasePopulator databaseCleaner) {
public void setDatabaseCleaner(@Nullable DatabasePopulator databaseCleaner) {
this.databaseCleaner = databaseCleaner;
}

Expand Down

0 comments on commit a428955

Please sign in to comment.