Skip to content

Commit 2d1ed8a

Browse files
committed
Refactoring.
1 parent a2d2e3e commit 2d1ed8a

File tree

9 files changed

+316
-246
lines changed

9 files changed

+316
-246
lines changed

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

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515
*/
1616
package org.springframework.data.jdbc.repository.aot;
1717

18-
import java.lang.reflect.Array;
1918
import java.lang.reflect.Method;
2019
import java.sql.SQLType;
21-
import java.util.ArrayList;
2220
import java.util.Collection;
2321
import java.util.List;
2422
import java.util.Optional;
25-
import java.util.function.UnaryOperator;
2623
import java.util.stream.Stream;
2724

2825
import org.jspecify.annotations.Nullable;
@@ -83,10 +80,6 @@ public class AotRepositoryFragmentSupport {
8380

8481
private final JdbcAggregateOperations aggregateOperations;
8582

86-
private final RepositoryMetadata repositoryMetadata;
87-
88-
private final ValueExpressionDelegate valueExpressions;
89-
9083
private final StatementFactory statementFactory;
9184

9285
private final ProjectionFactory projectionFactory;
@@ -109,8 +102,6 @@ protected AotRepositoryFragmentSupport(RowMapperFactory rowMapperFactory, JdbcAg
109102

110103
this.rowMapperFactory = rowMapperFactory;
111104
this.aggregateOperations = aggregateOperations;
112-
this.repositoryMetadata = repositoryMetadata;
113-
this.valueExpressions = valueExpressions;
114105
this.statementFactory = new StatementFactory(aggregateOperations.getConverter(),
115106
aggregateOperations.getDataAccessStrategy().getDialect());
116107
this.projectionFactory = projectionFactory;
@@ -210,41 +201,6 @@ private static SQLType getSqlType(Class<?> valueType) {
210201
return JdbcUtil.targetSqlTypeFor(JdbcColumnTypes.INSTANCE.resolvePrimitiveType(valueType));
211202
}
212203

213-
protected @Nullable Object mapIgnoreCase(@Nullable Object source, UnaryOperator<String> mapper) {
214-
215-
if (source == null) {
216-
return null;
217-
}
218-
219-
if (source.getClass().isArray()) {
220-
int length = Array.getLength(source);
221-
Collection<Object> result = new ArrayList<>(length);
222-
223-
for (int i = 0; i < length; i++) {
224-
result.add(Array.get(source, i));
225-
}
226-
source = result;
227-
}
228-
229-
if (source instanceof Collection<?> c) {
230-
231-
Collection<@Nullable Object> result = new ArrayList<>(c.size());
232-
233-
for (Object o : c) {
234-
235-
if (o instanceof String s) {
236-
result.add(mapper.apply(s));
237-
} else {
238-
result.add(o != null ? mapper.apply(o.toString()) : null);
239-
}
240-
}
241-
242-
return result;
243-
}
244-
245-
return source;
246-
}
247-
248204
protected <T> @Nullable T convertOne(@Nullable Object result, Class<T> projection) {
249205

250206
if (result == null) {
@@ -294,8 +250,20 @@ private static SQLType getSqlType(Class<?> valueType) {
294250
throw new UnsupportedOperationException("Cannot create projection for %s".formatted(result));
295251
}
296252

253+
/**
254+
* Interface for binding values to a {@link MapSqlParameterSource}.
255+
*/
297256
protected interface BindValue {
257+
258+
/**
259+
* Bind the value to the given {@link MapSqlParameterSource} using the given parameter name. Can apply further value
260+
* customization such as providing SQL types or type names.
261+
*
262+
* @param parameterName
263+
* @param parameterSource
264+
*/
298265
void bind(String parameterName, MapSqlParameterSource parameterSource);
266+
299267
}
300268

301269
}

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

Lines changed: 0 additions & 101 deletions
This file was deleted.

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
import org.springframework.data.domain.Limit;
66
import org.springframework.data.domain.Sort;
7-
import org.springframework.data.jdbc.repository.query.ParameterBinding;
7+
import org.springframework.data.jdbc.repository.query.ParametrizedQuery;
88
import org.springframework.data.relational.core.query.CriteriaDefinition;
9+
import org.springframework.data.repository.query.parser.PartTree;
910

1011
/**
1112
* PartTree (derived) Query with a limit associated.
1213
*
1314
* @author Mark Paluch
1415
*/
15-
public class DerivedAotQuery extends StringAotQuery {
16+
class DerivedAotQuery extends StringAotQuery {
1617

1718
private final String queryString;
1819
private final CriteriaDefinition criteria;
@@ -22,9 +23,9 @@ public class DerivedAotQuery extends StringAotQuery {
2223
private final boolean count;
2324
private final boolean exists;
2425

25-
DerivedAotQuery(String queryString, List<ParameterBinding> parameterBindings, CriteriaDefinition criteria, Sort sort,
26+
DerivedAotQuery(String queryString, CriteriaDefinition criteria, Sort sort,
2627
Limit limit, boolean delete, boolean count, boolean exists) {
27-
super(parameterBindings);
28+
super(List.of());
2829
this.queryString = queryString;
2930
this.criteria = criteria;
3031
this.sort = sort;
@@ -34,6 +35,13 @@ public class DerivedAotQuery extends StringAotQuery {
3435
this.exists = exists;
3536
}
3637

38+
DerivedAotQuery(ParametrizedQuery query, PartTree partTree, boolean countQuery) {
39+
40+
this(query.getQuery(), query.getCriteria(), partTree.getSort(), partTree.getResultLimit(), partTree.isDelete(),
41+
countQuery, partTree.isExistsProjection());
42+
43+
}
44+
3745
@Override
3846
public String getQueryString() {
3947
return queryString;

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.springframework.data.domain.SliceImpl;
3535
import org.springframework.data.domain.Sort;
3636
import org.springframework.data.jdbc.core.JdbcAggregateOperations;
37-
import org.springframework.data.jdbc.repository.aot.CapturingParameterMetadataProvider.CapturingJdbcValue;
3837
import org.springframework.data.jdbc.repository.query.JdbcQueryMethod;
3938
import org.springframework.data.jdbc.repository.query.Modifying;
4039
import org.springframework.data.jdbc.repository.query.ParameterBinding;
@@ -204,11 +203,10 @@ private CodeBlock buildQuery(boolean count, DerivedAotQuery aotQuery, CriteriaDe
204203

205204
Builder builder = CodeBlock.builder();
206205
String selection = context.localVariable(count ? "countSelection" : "selection");
207-
208206
String rawParameterSource = context.localVariable(count ? "countRawParameterSource" : "rawParameterSource");
209207

210208
String method;
211-
if (aotQuery.isCount() || count) {
209+
if (aotQuery.isCount()) {
212210
method = "count($T.class)";
213211
} else if (aotQuery.isExists()) {
214212
method = "exists($T.class)";
@@ -221,7 +219,7 @@ private CodeBlock buildQuery(boolean count, DerivedAotQuery aotQuery, CriteriaDe
221219
builder.addStatement("$T $L = getStatementFactory()." + method, StatementFactory.Selection.class, selection,
222220
context.getRepositoryInformation().getDomainType());
223221

224-
if (!count && !aotQuery.isCount() && !aotQuery.isExists()) {
222+
if (!aotQuery.isCount() && !aotQuery.isExists()) {
225223

226224
if (aotQuery.isLimited()) {
227225
builder.addStatement("$1L.limit($2L)", selection, aotQuery.getLimit().max());
@@ -377,7 +375,7 @@ private void appendCriteria(CriteriaDefinition current, Builder builder) {
377375

378376
private void applyLike(Builder builder, String method, @Nullable Object value) {
379377

380-
CapturingJdbcValue captured = CapturingJdbcValue.unwrap(value);
378+
PlaceholderAccessor.CapturingJdbcValue captured = PlaceholderAccessor.unwrap(value);
381379

382380
String likeValue = "$L";
383381
if (captured.getBinding() instanceof ParameterBinding.LikeParameterBinding lpb) {
@@ -396,7 +394,7 @@ private void applyLike(Builder builder, String method, @Nullable Object value) {
396394

397395
private @Nullable String renderPlaceholder(@Nullable Object value) {
398396

399-
CapturingJdbcValue captured = CapturingJdbcValue.unwrap(value);
397+
PlaceholderAccessor.CapturingJdbcValue captured = PlaceholderAccessor.unwrap(value);
400398

401399
ParameterBinding binding = captured.getBinding();
402400
ParameterBinding.MethodInvocationArgument argument = (ParameterBinding.MethodInvocationArgument) binding

0 commit comments

Comments
 (0)