Skip to content

Commit 0ad60a6

Browse files
committed
Incorporate DatabasePopulator feedback
Refactor DatabasePopulatorUtils.execute(…) into default method DatabasePopulator.populate(…). Add support for commentPrefixes in ResourceDatabasePopulator. Consistently use code instead of literal in Javadoc for boolean and null values.
1 parent b4778aa commit 0ad60a6

16 files changed

+31
-24
lines changed

spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/R2dbcTransactionManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public ConnectionFactory getConnectionFactory() {
138138
/**
139139
* Obtain the {@link ConnectionFactory} for actual use.
140140
*
141-
* @return the {@link ConnectionFactory} (never {@literal null})
141+
* @return the {@link ConnectionFactory} (never {@code null})
142142
* @throws IllegalStateException in case of no ConnectionFactory set
143143
*/
144144
protected ConnectionFactory obtainConnectionFactory() {
@@ -382,7 +382,7 @@ protected Mono<Void> doCleanupAfterCompletion(TransactionSynchronizationManager
382382
* Prepare the transactional {@link Connection} right after transaction begin.
383383
* <p>
384384
* The default implementation executes a "SET TRANSACTION READ ONLY" statement if the {@link #setEnforceReadOnly
385-
* "enforceReadOnly"} flag is set to {@literal true} and the transaction definition indicates a read-only transaction.
385+
* "enforceReadOnly"} flag is set to {@code true} and the transaction definition indicates a read-only transaction.
386386
* <p>
387387
* The "SET TRANSACTION READ ONLY" is understood by Oracle, MySQL and Postgres and may work with other databases as
388388
* well. If you'd like to adapt this treatment, override this method accordingly.
@@ -441,7 +441,7 @@ protected Mono<Void> prepareTransactionalConnection(Connection con, TransactionD
441441
* {@link IsolationLevel}s, override this method accordingly.
442442
*
443443
* @param isolationLevel the isolation level to translate.
444-
* @return the resolved isolation level. Can be {@literal null} if not resolvable or the isolation level should remain
444+
* @return the resolved isolation level. Can be {@code null} if not resolvable or the isolation level should remain
445445
* {@link TransactionDefinition#ISOLATION_DEFAULT default}.
446446
* @see TransactionDefinition#getIsolationLevel()
447447
*/

spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ConnectionFactoryInitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void setDatabaseCleaner(DatabasePopulator databaseCleaner) {
8383
* Flag to explicitly enable or disable the {@link #setDatabasePopulator database populator} and
8484
* {@link #setDatabaseCleaner database cleaner}.
8585
*
86-
* @param enabled {@literal true} if the database populator and database cleaner should be called on startup and
86+
* @param enabled {@code true} if the database populator and database cleaner should be called on startup and
8787
* shutdown, respectively
8888
*/
8989
public void setEnabled(boolean enabled) {

spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/DatabasePopulator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public interface DatabasePopulator {
4949

5050
/**
5151
* Execute the given {@link DatabasePopulator} against the given {@link ConnectionFactory}.
52-
* @param populator the {@link DatabasePopulator} to execute
5352
* @param connectionFactory the {@link ConnectionFactory} to execute against
5453
* @return {@link Mono} that initiates {@link DatabasePopulator#populate(Connection)}
5554
* and is notified upon completion

spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public abstract class ScriptUtils {
7676
/**
7777
* End of file (EOF) SQL statement separator: {@code "^^^ END OF SCRIPT ^^^"}.
7878
* <p>This value may be supplied as the {@code separator} to {@link
79-
* #executeSqlScript(Connection, EncodedResource, boolean, boolean, String, String, String, String)}
79+
* #executeSqlScript(Connection, EncodedResource, DataBufferFactory, boolean, boolean, String[], String, String, String)}
8080
* to denote that an SQL script contains a single statement (potentially
8181
* spanning multiple lines) with no explicit statement separator. Note that
8282
* such a script should not actually contain this value; it is merely a
@@ -373,7 +373,6 @@ private static Mono<String> readScript(EncodedResource resource, DataBufferFacto
373373
*/
374374
public static String readScript(LineNumberReader lineNumberReader, @Nullable String lineCommentPrefix,
375375
@Nullable String separator, @Nullable String blockCommentEndDelimiter) throws IOException {
376-
377376
String[] lineCommentPrefixes = (lineCommentPrefix != null) ? new String[] { lineCommentPrefix } : null;
378377
return readScript(lineNumberReader, lineCommentPrefixes, separator, blockCommentEndDelimiter);
379378
}
@@ -480,7 +479,7 @@ public static boolean containsSqlScriptDelimiters(String script, String delim) {
480479
* @param resource the resource to load the SQL script from; encoded with the
481480
* current platform's default encoding
482481
* @throws ScriptException if an error occurred while executing the SQL script
483-
* @see #executeSqlScript(Connection, EncodedResource, boolean, boolean, String, String, String, String)
482+
* @see #executeSqlScript(Connection, EncodedResource, DataBufferFactory, boolean, boolean, String[], String, String, String)
484483
* @see #DEFAULT_STATEMENT_SEPARATOR
485484
* @see #DEFAULT_COMMENT_PREFIX
486485
* @see #DEFAULT_BLOCK_COMMENT_START_DELIMITER
@@ -504,7 +503,7 @@ public static Mono<Void> executeSqlScript(Connection connection, Resource resour
504503
* @param resource the resource (potentially associated with a specific encoding)
505504
* to load the SQL script from
506505
* @throws ScriptException if an error occurred while executing the SQL script
507-
* @see #executeSqlScript(Connection, EncodedResource, boolean, boolean, String, String, String, String)
506+
* @see #executeSqlScript(Connection, EncodedResource, DataBufferFactory, boolean, boolean, String[], String, String, String)
508507
* @see #DEFAULT_STATEMENT_SEPARATOR
509508
* @see #DEFAULT_COMMENT_PREFIX
510509
* @see #DEFAULT_BLOCK_COMMENT_START_DELIMITER

spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/AbstractRoutingConnectionFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ public void setDefaultTargetConnectionFactory(Object defaultTargetConnectionFact
104104
* Specify whether to apply a lenient fallback to the default {@link ConnectionFactory}
105105
* if no specific {@link ConnectionFactory} could be found for the current lookup key.
106106
*
107-
* <p>Default is {@literal true}, accepting lookup keys without a corresponding entry
107+
* <p>Default is {@code true}, accepting lookup keys without a corresponding entry
108108
* in the target {@link ConnectionFactory} map - simply falling back to the default
109109
* {@link ConnectionFactory} in that case.
110110
*
111-
* <p>Switch this flag to {@literal false} if you would prefer the fallback to only
111+
* <p>Switch this flag to {@code false} if you would prefer the fallback to only
112112
* apply when no lookup key was emitted. Lookup keys without a {@link ConnectionFactory}
113113
* entry will then lead to an {@link IllegalStateException}.
114114
* @see #setTargetConnectionFactories

spring-r2dbc/src/main/java/org/springframework/r2dbc/core/BindParameterSource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ interface BindParameterSource {
3939
/**
4040
* Determine whether there is a value for the specified named parameter.
4141
* @param paramName the name of the parameter
42-
* @return {@literal true} if there is a value defined; {@literal false} otherwise
42+
* @return {@code true} if there is a value defined; {@code false} otherwise
4343
*/
4444
boolean hasValue(String paramName);
4545

4646
/**
4747
* Return the parameter value for the requested named parameter.
4848
* @param paramName the name of the parameter
49-
* @return the value of the specified parameter, can be {@literal null}
49+
* @return the value of the specified parameter, can be {@code null}
5050
* @throws IllegalArgumentException if there is no value
5151
* for the requested parameter
5252
*/

spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DatabaseClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ interface Builder {
129129
Builder executeFunction(ExecuteFunction executeFunction);
130130

131131
/**
132-
* Configure whether to use named parameter expansion. Defaults to {@literal true}.
133-
* @param enabled {@literal true} to use named parameter expansion.
134-
* {@literal false} to disable named parameter expansion.
132+
* Configure whether to use named parameter expansion. Defaults to {@code true}.
133+
* @param enabled {@code true} to use named parameter expansion.
134+
* {@code false} to disable named parameter expansion.
135135
* @see NamedParameterExpander
136136
*/
137137
Builder namedParameters(boolean enabled);

spring-r2dbc/src/main/java/org/springframework/r2dbc/core/Parameter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ public Class<?> getType() {
9393

9494
/**
9595
* Returns whether this {@link Parameter} has a value.
96-
* @return whether this {@link Parameter} has a value. {@literal false} if {@link #getValue()} is {@code null}
96+
* @return whether this {@link Parameter} has a value. {@code false} if {@link #getValue()} is {@code null}
9797
*/
9898
public boolean hasValue() {
9999
return this.value != null;
100100
}
101101

102102
/**
103103
* Returns whether this {@link Parameter} has a empty.
104-
* @return whether this {@link Parameter} is empty. {@literal true} if {@link #getValue()} is {@code null}
104+
* @return whether this {@link Parameter} is empty. {@code true} if {@link #getValue()} is {@code null}
105105
*/
106106
public boolean isEmpty() {
107107
return this.value == null;

spring-r2dbc/src/main/java/org/springframework/r2dbc/core/binding/BindMarkersFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public interface BindMarkersFactory {
4848
* Return whether the {@link BindMarkersFactory} uses identifiable
4949
* placeholders.
5050
* @return whether the {@link BindMarkersFactory} uses identifiable
51-
* placeholders. {@literal false} if multiple placeholders cannot be
51+
* placeholders. {@code false} if multiple placeholders cannot be
5252
* distinguished by just the {@link BindMarker#getPlaceholder() placeholder}
5353
* identifier.
5454
*/

spring-r2dbc/src/main/java/org/springframework/r2dbc/core/binding/Bindings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ public BindMarker getBindMarker() {
162162

163163
/**
164164
* Return whether the binding has a value associated with it.
165-
* @return {@literal true} if there is a value present, otherwise {@literal false}
165+
* @return {@code true} if there is a value present, otherwise {@code false}
166166
* for a {@code NULL} binding.
167167
*/
168168
public abstract boolean hasValue();
169169

170170
/**
171171
* Return whether the binding is empty.
172-
* @return {@literal true} if this is is a {@code NULL} binding
172+
* @return {@code true} if this is is a {@code NULL} binding
173173
*/
174174
public boolean isNull() {
175175
return !hasValue();

spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/AbstractDatabaseInitializationTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public abstract class AbstractDatabaseInitializationTests {
3737

3838
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
3939

40+
4041
@Test
4142
public void scriptWithSingleLineCommentsAndFailedDrop() {
4243
databasePopulator.addScript(resource("db-schema-failed-drop-comments.sql"));

spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/CompositeDatabasePopulatorTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class CompositeDatabasePopulatorTests {
4343

4444
DatabasePopulator mockedDatabasePopulator2 = mock(DatabasePopulator.class);
4545

46+
4647
@BeforeEach
4748
public void before() {
4849
when(mockedDatabasePopulator1.populate(mockedConnection)).thenReturn(

spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ConnectionFactoryInitializerUnitTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import reactor.core.publisher.Mono;
2525

2626
import static org.assertj.core.api.Assertions.assertThat;
27-
import static org.mockito.ArgumentMatchers.any;
2827
import static org.mockito.BDDMockito.mock;
2928
import static org.mockito.BDDMockito.when;
3029

@@ -44,9 +43,10 @@ public class ConnectionFactoryInitializerUnitTests {
4443
MockConnectionFactory connectionFactory = MockConnectionFactory.builder().connection(
4544
connection).build();
4645

46+
4747
@Test
4848
public void shouldInitializeConnectionFactory() {
49-
when(populator.populate(any())).thenReturn(
49+
when(populator.populate(connectionFactory)).thenReturn(
5050
Mono.<Void> empty().doOnSubscribe(subscription -> called.set(true)));
5151

5252
ConnectionFactoryInitializer initializer = new ConnectionFactoryInitializer();
@@ -60,7 +60,7 @@ public void shouldInitializeConnectionFactory() {
6060

6161
@Test
6262
public void shouldCleanConnectionFactory() {
63-
when(populator.populate(any())).thenReturn(
63+
when(populator.populate(connectionFactory)).thenReturn(
6464
Mono.<Void> empty().doOnSubscribe(subscription -> called.set(true)));
6565

6666
ConnectionFactoryInitializer initializer = new ConnectionFactoryInitializer();

spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/H2DatabasePopulatorIntegrationTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class H2DatabasePopulatorIntegrationTests
3636
ConnectionFactory connectionFactory = ConnectionFactories.get("r2dbc:h2:mem:///"
3737
+ databaseName + "?options=DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
3838

39+
3940
@Override
4041
ConnectionFactory getConnectionFactory() {
4142
return this.connectionFactory;

spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulatorUnitTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class ResourceDatabasePopulatorUnitTests {
3737

3838
private static final Resource script3 = mock(Resource.class);
3939

40+
4041
@Test
4142
public void constructWithNullResource() {
4243
assertThatIllegalArgumentException().isThrownBy(

spring-r2dbc/src/test/java/org/springframework/r2dbc/connection/init/ScriptUtilsUnitTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
/**
3232
* Unit tests for {@link ScriptUtils}.
3333
*
34+
* @author Thomas Risberg
35+
* @author Sam Brannen
36+
* @author Phillip Webb
37+
* @author Chris Baldwin
38+
* @author Nicolas Debeissat
3439
* @author Mark Paluch
3540
*/
3641
public class ScriptUtilsUnitTests {

0 commit comments

Comments
 (0)