Skip to content

Commit 41d11de

Browse files
committed
Address review comments.
1 parent 65c3f3b commit 41d11de

File tree

7 files changed

+30
-96
lines changed

7 files changed

+30
-96
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/aot/AotRepositoryFragmentSupport.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
import org.springframework.data.jdbc.core.mapping.JdbcValue;
4141
import org.springframework.data.jdbc.repository.query.EscapingParameterSource;
4242
import org.springframework.data.jdbc.repository.query.JdbcParameters;
43+
import org.springframework.data.jdbc.repository.query.JdbcValueBindUtil;
4344
import org.springframework.data.jdbc.repository.query.RowMapperFactory;
4445
import org.springframework.data.jdbc.repository.query.StatementFactory;
45-
import org.springframework.data.jdbc.repository.query.StringValueUtil;
4646
import org.springframework.data.jdbc.support.JdbcUtil;
4747
import org.springframework.data.projection.ProjectionFactory;
4848
import org.springframework.data.relational.core.dialect.Dialect;
@@ -164,8 +164,7 @@ protected BindValue getBindableValue(Method method, @Nullable Object value, int
164164

165165
private BindValue getBindableValue(JdbcParameters.JdbcParameter parameter, @Nullable Object value) {
166166

167-
JdbcValue jdbcValue = StringValueUtil.getBindValue(operations.getConverter(), value,
168-
parameter.getTypeInformation(), parameter.getSqlType(), parameter.getActualSqlType());
167+
JdbcValue jdbcValue = JdbcValueBindUtil.getBindValue(operations.getConverter(), value, parameter);
169168
SQLType jdbcType = jdbcValue.getJdbcType();
170169

171170
return (parameterName, parameterSource) -> {

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/JdbcQueryMethod.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ public RelationalEntityMetadata<?> getEntityInformation() {
8484
Class<?> domainClass = getDomainClass();
8585

8686
if (ClassUtils.isPrimitiveOrWrapper(returnedObjectType)) {
87-
88-
this.metadata = new SimpleRelationalEntityMetadata<>((Class<Object>) domainClass,
89-
mappingContext.getRequiredPersistentEntity(domainClass));
90-
87+
this.metadata = new SimpleRelationalEntityMetadata<>(mappingContext.getRequiredPersistentEntity(domainClass));
9188
} else {
9289

9390
RelationalPersistentEntity<?> returnedEntity = mappingContext.getPersistentEntity(returnedObjectType);
Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,26 @@
3737
* @author Mark Paluch
3838
* @since 4.0
3939
*/
40-
public class StringValueUtil {
41-
40+
public abstract class JdbcValueBindUtil {
41+
42+
private JdbcValueBindUtil() {}
43+
44+
/**
45+
* Obtains a {@link JdbcValue} for the given {@code value} and {@link JdbcParameters.JdbcParameter} to be bound to a
46+
* query.
47+
*
48+
* @param converter
49+
* @param value
50+
* @param parameter
51+
* @return
52+
*/
4253
public static JdbcValue getBindValue(JdbcConverter converter, @Nullable Object value,
54+
JdbcParameters.JdbcParameter parameter) {
55+
return getBindValue(converter, value, parameter.getTypeInformation(), parameter.getSqlType(),
56+
parameter.getActualSqlType());
57+
}
58+
59+
private static JdbcValue getBindValue(JdbcConverter converter, @Nullable Object value,
4360
TypeInformation<?> typeInformation, SQLType sqlType, SQLType actualSqlType) {
4461

4562
if (value == null) {
@@ -55,19 +72,19 @@ public static JdbcValue getBindValue(JdbcConverter converter, @Nullable Object v
5572
if (actualType != null && actualType.getType().isArray() && !actualType.getType().equals(byte[].class)) {
5673

5774
TypeInformation<?> nestedElementType = actualType.getRequiredActualType();
58-
return writeCollection(converter, collection, actualSqlType,
75+
return writeCollection(collection, actualSqlType,
5976
array -> writeArrayValue(converter, actualSqlType, array, nestedElementType));
6077
}
6178

6279
// parameter expansion
63-
return writeCollection(converter, collection, actualSqlType,
80+
return writeCollection(collection, actualSqlType,
6481
it -> converter.writeJdbcValue(it, typeInformation.getRequiredActualType(), actualSqlType));
6582
}
6683

6784
return converter.writeJdbcValue(value, typeInformation, sqlType);
6885
}
6986

70-
private static JdbcValue writeCollection(JdbcConverter converter, Collection<?> value, SQLType defaultType,
87+
private static JdbcValue writeCollection(Collection<?> value, SQLType defaultType,
7188
Function<Object, Object> mapper) {
7289

7390
if (value.isEmpty()) {

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/ParameterBinding.java

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import java.util.Arrays;
2121
import java.util.List;
22-
import java.util.function.Function;
2322

2423
import org.jspecify.annotations.Nullable;
2524

@@ -107,7 +106,6 @@ public ParameterOrigin getOrigin() {
107106

108107
/**
109108
* @return {@literal true} if the binding identifier is associated with a name.
110-
* @since 4.0
111109
*/
112110
boolean hasName() {
113111
return identifier.hasName();
@@ -116,7 +114,6 @@ boolean hasName() {
116114
/**
117115
* @return the name
118116
* @throws IllegalStateException if the name is not available.
119-
* @since 2.0
120117
*/
121118
String getRequiredName() throws IllegalStateException {
122119

@@ -140,7 +137,6 @@ Integer getPosition() {
140137
/**
141138
* @return the position
142139
* @throws IllegalStateException if the position is not available.
143-
* @since 2.0
144140
*/
145141
int getRequiredPosition() throws IllegalStateException {
146142

@@ -245,34 +241,13 @@ public String toString() {
245241
return String.format("LikeBinding [identifier: %s, origin: %s, type: %s]", getIdentifier(), getOrigin(),
246242
getType());
247243
}
248-
249-
/**
250-
* Extracts the like {@link Type} from the given like expression.
251-
*
252-
* @param expression must not be {@literal null} or empty.
253-
*/
254-
static Type getLikeTypeFrom(String expression) {
255-
256-
Assert.hasText(expression, "Expression must not be null or empty");
257-
258-
if (expression.startsWith("%")) {
259-
return expression.endsWith("%") ? Type.CONTAINING : Type.ENDING_WITH;
260-
}
261-
262-
if (expression.endsWith("%")) {
263-
return Type.STARTING_WITH;
264-
}
265-
266-
return Type.LIKE;
267-
}
268244
}
269245

270246
/**
271247
* Identifies a binding parameter by name, position or both. Used to bind parameters to a query or to describe a
272248
* {@link MethodInvocationArgument} origin.
273249
*
274250
* @author Mark Paluch
275-
* @since 3.1.2
276251
*/
277252
public sealed interface BindingIdentifier permits Named, ParameterBinding.Indexed, NamedAndIndexed {
278253

@@ -349,25 +324,6 @@ default int getPosition() {
349324
throw new IllegalStateException("No position associated");
350325
}
351326

352-
/**
353-
* Map the name of the binding to a new name using the given {@link Function} if the binding has a name. If the
354-
* binding is not associated with a name, then the binding is returned unchanged.
355-
*
356-
* @param nameMapper must not be {@literal null}.
357-
* @return the transformed {@link BindingIdentifier} if the binding has a name, otherwise the binding itself.
358-
* @since 4.0
359-
*/
360-
BindingIdentifier mapName(Function<? super String, ? extends String> nameMapper);
361-
362-
/**
363-
* Associate a position with the binding.
364-
*
365-
* @param position
366-
* @return the new binding identifier with the position.
367-
* @since 4.0
368-
*/
369-
BindingIdentifier withPosition(int position);
370-
371327
}
372328

373329
private record Named(String name) implements BindingIdentifier {
@@ -387,15 +343,6 @@ public String toString() {
387343
return name();
388344
}
389345

390-
@Override
391-
public BindingIdentifier mapName(Function<? super String, ? extends String> nameMapper) {
392-
return new Named(nameMapper.apply(name()));
393-
}
394-
395-
@Override
396-
public BindingIdentifier withPosition(int position) {
397-
return new NamedAndIndexed(name, position);
398-
}
399346
}
400347

401348
private record Indexed(int position) implements BindingIdentifier {
@@ -410,16 +357,6 @@ public int getPosition() {
410357
return position();
411358
}
412359

413-
@Override
414-
public BindingIdentifier mapName(Function<? super String, ? extends String> nameMapper) {
415-
return this;
416-
}
417-
418-
@Override
419-
public BindingIdentifier withPosition(int position) {
420-
return new Indexed(position);
421-
}
422-
423360
@Override
424361
public String toString() {
425362
return "[" + position() + "]";
@@ -448,16 +385,6 @@ public int getPosition() {
448385
return position();
449386
}
450387

451-
@Override
452-
public BindingIdentifier mapName(Function<? super String, ? extends String> nameMapper) {
453-
return new NamedAndIndexed(nameMapper.apply(name), position);
454-
}
455-
456-
@Override
457-
public BindingIdentifier withPosition(int position) {
458-
return new NamedAndIndexed(name, position);
459-
}
460-
461388
@Override
462389
public String toString() {
463390
return "[" + name() + ", " + position() + "]";
@@ -468,7 +395,6 @@ public String toString() {
468395
* Value type hierarchy to describe where a binding parameter comes from, either method call or an expression.
469396
*
470397
* @author Mark Paluch
471-
* @since 3.1.2
472398
*/
473399
public sealed interface ParameterOrigin permits Expression, MethodInvocationArgument, Synthetic {
474400

@@ -578,7 +504,6 @@ static MethodInvocationArgument ofParameter(BindingIdentifier identifier) {
578504
*
579505
* @param expression
580506
* @author Mark Paluch
581-
* @since 3.1.2
582507
*/
583508
public record Expression(ValueExpression expression) implements ParameterOrigin {
584509

@@ -628,7 +553,6 @@ public boolean isSynthetic() {
628553
*
629554
* @param identifier
630555
* @author Mark Paluch
631-
* @since 3.1.2
632556
*/
633557
public record MethodInvocationArgument(BindingIdentifier identifier) implements ParameterOrigin {
634558

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQuery.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static org.springframework.data.jdbc.repository.query.JdbcQueryExecution.*;
1919

2020
import java.lang.reflect.Constructor;
21+
import java.sql.JDBCType;
2122
import java.sql.SQLType;
2223
import java.util.LinkedHashMap;
2324
import java.util.function.Function;
@@ -257,10 +258,10 @@ private MapSqlParameterSource bindParameters(RelationalParameterAccessor accesso
257258
JdbcParameters.JdbcParameter parameter = getQueryMethod().getParameters()
258259
.getParameter(bindableParameter.getIndex());
259260

260-
JdbcValue jdbcValue = StringValueUtil.getBindValue(converter, value, parameter.getTypeInformation(), parameter.getSqlType(), parameter.getActualSqlType());
261+
JdbcValue jdbcValue = JdbcValueBindUtil.getBindValue(converter, value, parameter);
261262
SQLType jdbcType = jdbcValue.getJdbcType();
262263

263-
if (jdbcType == null) {
264+
if (jdbcType == JDBCType.OTHER) {
264265
parameters.addValue(parameterName, jdbcValue.getValue());
265266
} else {
266267
parameters.addValue(parameterName, jdbcValue.getValue(), jdbcType.getVendorTypeNumber());

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryMethod.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,7 @@ public RelationalEntityMetadata<?> getEntityInformation() {
171171
Class<?> domainClass = getDomainClass();
172172

173173
if (ClassUtils.isPrimitiveOrWrapper(returnedObjectType) || ReflectionUtils.isVoid(returnedObjectType)) {
174-
175-
this.metadata = new SimpleRelationalEntityMetadata<>((Class<Object>) domainClass,
176-
mappingContext.getRequiredPersistentEntity(domainClass));
177-
174+
this.metadata = new SimpleRelationalEntityMetadata<>(mappingContext.getRequiredPersistentEntity(domainClass));
178175
} else {
179176

180177
RelationalPersistentEntity<?> returnedEntity = mappingContext.getPersistentEntity(returnedObjectType);

src/main/antora/modules/ROOT/pages/jdbc/aot.adoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Do not use them directly in your code as generation and implementation details m
4444
=== Running with AOT Repositories
4545

4646
AOT is a mandatory step to transform a Spring application to a native executable, so it is automatically enabled when running in this mode.
47-
When AOT is enabled (either for native compilation or by setting `spring.aot.enabled=true`), AOT repositories are automatically enabled by default.
47+
When AOT is enabled (either for native compilation or by setting `spring.aot.enabled=true`), AOT repositories are generated as well.
4848

4949
You can disable AOT repository generation entirely or only disable JDBC AOT repositories:
5050

@@ -81,7 +81,6 @@ These are typically all query methods that are not backed by an xref:repositorie
8181

8282
* `CrudRepository`, Querydsl, Query by Example, and other base interface methods as their implementation is provided by the base class respective fragments
8383
* Methods whose implementation would be overly complex
84-
** Methods accepting `ScrollPosition` (e.g. `Keyset` pagination)
8584

8685
[[aot.repositories.json]]
8786
== Repository Metadata

0 commit comments

Comments
 (0)