Skip to content

Commit de97e35

Browse files
committed
Polish Javadoc and internals of R2DBC support
1 parent 45a2c51 commit de97e35

File tree

7 files changed

+142
-188
lines changed

7 files changed

+142
-188
lines changed

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

+39-36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -513,14 +513,50 @@ private static class ExpandedQuery implements PreparedOperation<String> {
513513

514514
private final BindParameterSource parameterSource;
515515

516+
516517
ExpandedQuery(String expandedSql, NamedParameters parameters, BindParameterSource parameterSource) {
517518
this.expandedSql = expandedSql;
518519
this.parameters = parameters;
519520
this.parameterSource = parameterSource;
520521
}
521522

523+
524+
@Override
525+
public String toQuery() {
526+
return this.expandedSql;
527+
}
528+
529+
@Override
530+
public String getSource() {
531+
return this.expandedSql;
532+
}
533+
534+
@Override
535+
public void bindTo(BindTarget target) {
536+
for (String namedParameter : this.parameterSource.getParameterNames()) {
537+
Parameter parameter = this.parameterSource.getValue(namedParameter);
538+
if (parameter.getValue() == null) {
539+
bindNull(target, namedParameter, parameter);
540+
}
541+
else {
542+
bind(target, namedParameter, parameter);
543+
}
544+
}
545+
}
546+
547+
private void bindNull(BindTarget target, String identifier, Parameter parameter) {
548+
List<BindMarker> bindMarkers = getBindMarkers(identifier);
549+
if (bindMarkers == null) {
550+
target.bind(identifier, parameter);
551+
return;
552+
}
553+
for (BindMarker bindMarker : bindMarkers) {
554+
bindMarker.bind(target, parameter);
555+
}
556+
}
557+
522558
@SuppressWarnings({"rawtypes", "unchecked"})
523-
public void bind(BindTarget target, String identifier, Parameter parameter) {
559+
private void bind(BindTarget target, String identifier, Parameter parameter) {
524560
List<BindMarker> bindMarkers = getBindMarkers(identifier);
525561
if (bindMarkers == null) {
526562
target.bind(identifier, parameter);
@@ -555,19 +591,8 @@ private void bind(BindTarget target, Iterator<BindMarker> markers, Object valueT
555591
markers.next().bind(target, valueToBind);
556592
}
557593

558-
public void bindNull(BindTarget target, String identifier, Parameter parameter) {
559-
List<BindMarker> bindMarkers = getBindMarkers(identifier);
560-
if (bindMarkers == null) {
561-
target.bind(identifier, parameter);
562-
return;
563-
}
564-
for (BindMarker bindMarker : bindMarkers) {
565-
bindMarker.bind(target, parameter);
566-
}
567-
}
568-
569594
@Nullable
570-
List<BindMarker> getBindMarkers(String identifier) {
595+
private List<BindMarker> getBindMarkers(String identifier) {
571596
List<NamedParameters.NamedParameter> parameters = this.parameters.getMarker(identifier);
572597
if (parameters == null) {
573598
return null;
@@ -579,28 +604,6 @@ List<BindMarker> getBindMarkers(String identifier) {
579604
return markers;
580605
}
581606

582-
@Override
583-
public String getSource() {
584-
return this.expandedSql;
585-
}
586-
587-
@Override
588-
public void bindTo(BindTarget target) {
589-
for (String namedParameter : this.parameterSource.getParameterNames()) {
590-
Parameter parameter = this.parameterSource.getValue(namedParameter);
591-
if (parameter.getValue() == null) {
592-
bindNull(target, namedParameter, parameter);
593-
}
594-
else {
595-
bind(target, namedParameter, parameter);
596-
}
597-
}
598-
}
599-
600-
@Override
601-
public String toQuery() {
602-
return this.expandedSql;
603-
}
604607
}
605608

606609
}

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,8 +19,9 @@
1919
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
2020

2121
/**
22-
* Anonymous, index-based bind marker using a static placeholder.
23-
* Instances are bound by the ordinal position ordered by the appearance of
22+
* Anonymous, index-based bind markers that use a static placeholder.
23+
*
24+
* <p>Instances are bound by the ordinal position ordered by the appearance of
2425
* the placeholder. This implementation creates indexed bind markers using
2526
* an anonymous placeholder that correlates with an index.
2627
*
@@ -46,7 +47,7 @@ class AnonymousBindMarkers implements BindMarkers {
4647

4748

4849
/**
49-
* Create a new {@link AnonymousBindMarkers} instance given {@code placeholder}.
50+
* Create a new {@link AnonymousBindMarkers} instance for the given {@code placeholder}.
5051
* @param placeholder parameter bind marker
5152
*/
5253
AnonymousBindMarkers(String placeholder) {

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,8 @@
2020

2121
/**
2222
* A bind marker represents a single bindable parameter within a query.
23-
* Bind markers are dialect-specific and provide a
23+
*
24+
* <p>Bind markers are dialect-specific and provide a
2425
* {@link #getPlaceholder() placeholder} that is used in the actual query.
2526
*
2627
* @author Mark Paluch
@@ -37,7 +38,8 @@ public interface BindMarker {
3738
String getPlaceholder();
3839

3940
/**
40-
* Bind the given {@code value} to the {@link Statement} using the underlying binding strategy.
41+
* Bind the given {@code value} to the {@link Statement} using the underlying
42+
* binding strategy.
4143
* @param bindTarget the target to bind the value to
4244
* @param value the actual value (must not be {@code null};
4345
* use {@link #bindNull(BindTarget, Class)} for {@code null} values)
@@ -46,7 +48,8 @@ public interface BindMarker {
4648
void bind(BindTarget bindTarget, Object value);
4749

4850
/**
49-
* Bind a {@code null} value to the {@link Statement} using the underlying binding strategy.
51+
* Bind a {@code null} value to the {@link Statement} using the underlying
52+
* binding strategy.
5053
* @param bindTarget the target to bind the value to
5154
* @param valueType the value type (must not be {@code null})
5255
* @see Statement#bindNull

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,10 +20,10 @@
2020
* Bind markers represent placeholders in SQL queries for substitution
2121
* for an actual parameter. Using bind markers allows creating safe queries
2222
* so query strings are not required to contain escaped values but rather
23-
* the driver encodes parameter in the appropriate representation.
23+
* the driver encodes the parameter in the appropriate representation.
2424
*
2525
* <p>{@link BindMarkers} is stateful and can be only used for a single binding
26-
* pass of one or more parameters. It maintains bind indexes/bind parameter names.
26+
* pass of one or more parameters. It maintains bind indexes or bind parameter names.
2727
*
2828
* @author Mark Paluch
2929
* @since 5.3
@@ -41,7 +41,7 @@ public interface BindMarkers {
4141

4242
/**
4343
* Create a new {@link BindMarker} that accepts a {@code hint}.
44-
* Implementations are allowed to consider/ignore/filter
44+
* <p>Implementations are allowed to consider/ignore/filter
4545
* the name hint to create more expressive bind markers.
4646
* @param hint an optional name hint that can be used as part of the bind marker
4747
* @return a new {@link BindMarker}

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

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,8 +30,8 @@
3030

3131
/**
3232
* Resolves a {@link BindMarkersFactory} from a {@link ConnectionFactory} using
33-
* {@link BindMarkerFactoryProvider}. Dialect resolution uses Spring's
34-
* {@link SpringFactoriesLoader spring.factories} to determine available extensions.
33+
* a {@link BindMarkerFactoryProvider}. Dialect resolution uses Spring's
34+
* {@link SpringFactoriesLoader spring.factories} file to determine available extensions.
3535
*
3636
* @author Mark Paluch
3737
* @since 5.3
@@ -45,8 +45,8 @@ public final class BindMarkersFactoryResolver {
4545

4646

4747
/**
48-
* Retrieve a {@link BindMarkersFactory} by inspecting {@link ConnectionFactory}
49-
* and its metadata.
48+
* Retrieve a {@link BindMarkersFactory} by inspecting the supplied
49+
* {@link ConnectionFactory} and its metadata.
5050
* @param connectionFactory the connection factory to inspect
5151
* @return the resolved {@link BindMarkersFactory}
5252
* @throws NoBindMarkersFactoryException if no {@link BindMarkersFactory} can be resolved
@@ -69,18 +69,21 @@ private BindMarkersFactoryResolver() {
6969

7070

7171
/**
72-
* SPI to extend Spring's default R2DBC BindMarkersFactory discovery mechanism.
73-
* Implementations of this interface are discovered through Spring's
72+
* SPI to extend Spring's default R2DBC {@link BindMarkersFactory} discovery
73+
* mechanism.
74+
*
75+
* <p>Implementations of this interface are discovered through Spring's
7476
* {@link SpringFactoriesLoader} mechanism.
77+
*
7578
* @see SpringFactoriesLoader
7679
*/
7780
@FunctionalInterface
7881
public interface BindMarkerFactoryProvider {
7982

8083
/**
81-
* Return a {@link BindMarkersFactory} for a {@link ConnectionFactory}.
82-
* @param connectionFactory the connection factory to be used with the {@link BindMarkersFactory}
83-
* @return the {@link BindMarkersFactory} if the {@link BindMarkerFactoryProvider}
84+
* Return a {@link BindMarkersFactory} for the given {@link ConnectionFactory}.
85+
* @param connectionFactory the connection factory to be used with the {@code BindMarkersFactory}
86+
* @return the {@code BindMarkersFactory} if this {@code BindMarkerFactoryProvider}
8487
* can provide a bind marker factory object, otherwise {@code null}
8588
*/
8689
@Nullable
@@ -89,7 +92,7 @@ public interface BindMarkerFactoryProvider {
8992

9093

9194
/**
92-
* Exception thrown when {@link BindMarkersFactoryResolver} cannot resolve a
95+
* Exception thrown when a {@link BindMarkersFactoryResolver} cannot resolve a
9396
* {@link BindMarkersFactory}.
9497
*/
9598
@SuppressWarnings("serial")
@@ -106,8 +109,11 @@ public NoBindMarkersFactoryException(String msg) {
106109

107110

108111
/**
109-
* Built-in bind maker factories. Used typically as last {@link BindMarkerFactoryProvider}
110-
* when other providers register with a higher precedence.
112+
* Built-in bind marker factories.
113+
*
114+
* <p>Typically used as the last {@link BindMarkerFactoryProvider} when other
115+
* providers are registered with a higher precedence.
116+
*
111117
* @see org.springframework.core.Ordered
112118
* @see org.springframework.core.annotation.AnnotationAwareOrderComparator
113119
*/

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
2020

2121
/**
22-
* Index-based bind marker. This implementation creates indexed bind
22+
* Index-based bind markers. This implementation creates indexed bind
2323
* markers using a numeric index and an optional prefix for bind markers
2424
* to be represented within the query string.
2525
*
@@ -43,14 +43,15 @@ class IndexedBindMarkers implements BindMarkers {
4343

4444

4545
/**
46-
* Create a new {@link IndexedBindMarker} instance given {@code prefix} and {@code beginWith}.
47-
* @param prefix bind parameter prefix
48-
* @param beginWith the first index to use
46+
* Create a new {@link IndexedBindMarker} instance for the given {@code prefix}
47+
* and {@code beginWith} value.
48+
* @param prefix the bind parameter prefix
49+
* @param beginIndex the first index to use
4950
*/
50-
IndexedBindMarkers(String prefix, int beginWith) {
51+
IndexedBindMarkers(String prefix, int beginIndex) {
5152
this.counter = 0;
5253
this.prefix = prefix;
53-
this.offset = beginWith;
54+
this.offset = beginIndex;
5455
}
5556

5657

0 commit comments

Comments
 (0)