Skip to content

Commit 12e098d

Browse files
AOT query creation for IgnoreCase generates invalid code block.
Fix AOT jdbc repository integration test setup that generated code for a different repository. Closes: #2155
1 parent c6bb723 commit 12e098d

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
* Common code blocks for JDBC AOT Fragment generation.
6666
*
6767
* @author Mark Paluch
68+
* @author Christoph Strobl
6869
* @since 4.0
6970
*/
7071
class JdbcCodeBlocks {
@@ -368,7 +369,7 @@ private void appendCriteria(CriteriaDefinition current, Builder builder) {
368369
}
369370

370371
if (current.isIgnoreCase()) {
371-
builder.addStatement(".ignoreCase(true)");
372+
builder.add(".ignoreCase(true)");
372373
}
373374
}
374375

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.springframework.data.jdbc.repository.aot;
1717

1818
import java.sql.JDBCType;
19+
import java.util.Collection;
1920

2021
import org.jspecify.annotations.Nullable;
2122

@@ -37,6 +38,7 @@
3738
* Utility to access placeholders in AOT processing.
3839
*
3940
* @author Mark Paluch
41+
* @author Christoph Strobl
4042
* @since 4.0
4143
*/
4244
class PlaceholderAccessor {
@@ -79,6 +81,10 @@ public static CapturingJdbcValue unwrap(@Nullable Object value) {
7981
return cp;
8082
}
8183

84+
if(value instanceof Collection<?> c && c.iterator().hasNext()) {
85+
return unwrap(c.iterator().next());
86+
}
87+
8288
throw new IllegalArgumentException("Cannot unwrap value: '%s' to CapturingJdbcValue".formatted(value));
8389
}
8490

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/AotJdbcRepositoryIntegrationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* Integration test for {@link DummyEntityRepository} using JavaConfig with mounted AOT-generated repository methods.
4141
*
4242
* @author Mark Paluch
43+
* @author Christoph Strobl
4344
*/
4445
@IntegrationTest
4546
@EnabledOnDatabase(DatabaseType.H2)
@@ -59,7 +60,7 @@ TestClass testClass() {
5960

6061
@Bean
6162
static AotFragmentTestConfigurationSupport aot() {
62-
return new AotFragmentTestConfigurationSupport(UserRepository.class, JdbcH2Dialect.INSTANCE, AotConfig.class,
63+
return new AotFragmentTestConfigurationSupport(DummyEntityRepository.class, JdbcH2Dialect.INSTANCE, AotConfig.class,
6364
false);
6465
}
6566

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
* @author Christopher Klein
103103
* @author Mikhail Polivakha
104104
* @author Paul Jones
105+
* @author Christoph Strobl
105106
*/
106107
@IntegrationTest
107108
public class JdbcRepositoryIntegrationTests {
@@ -575,6 +576,15 @@ public void selectWithLimitShouldReturnCorrectResult() {
575576
assertThat(repository.findByNameContains("a", Limit.unlimited())).hasSize(3);
576577
}
577578

579+
@Test // GH-2155
580+
public void selectContainingIgnoreCase() {
581+
582+
repository.saveAll(Arrays.asList(new DummyEntity("1a1"), new DummyEntity("1B1"), new DummyEntity("1c1")));
583+
584+
Optional<DummyEntity> result = repository.findByNameContainingIgnoreCase("b");
585+
assertThat(result).map(DummyEntity::getName).contains("1B1");
586+
}
587+
578588
@Test // GH-774
579589
public void sliceByNameShouldReturnCorrectResult() {
580590

@@ -1567,6 +1577,8 @@ public interface DummyEntityRepository
15671577

15681578
List<DummyEntity> findByNameContains(String name, Limit limit);
15691579

1580+
Optional<DummyEntity> findByNameContainingIgnoreCase(String partialName);
1581+
15701582
Page<DummyProjection> findPageProjectionByName(String name, Pageable pageable);
15711583

15721584
Slice<DummyEntity> findSliceByNameContains(String name, Pageable pageable);

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/aot/AotFragmentTestConfigurationSupport.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
* invocations to the backing AOT fragment. Note that {@code repositoryInterface} is not a repository proxy.
6666
*
6767
* @author Mark Paluch
68+
* @author Christoph Strobl
6869
*/
6970
public class AotFragmentTestConfigurationSupport implements BeanFactoryPostProcessor {
7071

@@ -105,7 +106,7 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
105106
jdbcRepositoryContributor.contribute(generationContext);
106107

107108
AbstractBeanDefinition aotGeneratedRepository = BeanDefinitionBuilder
108-
.genericBeanDefinition(repositoryInterface.getName() + "Impl__AotRepository")
109+
.genericBeanDefinition(repositoryInterface.getPackageName() + "." + repositoryInterface.getSimpleName() + "Impl__AotRepository")
109110
.addConstructorArgValue(new RuntimeBeanReference(JdbcAggregateOperations.class))
110111
.addConstructorArgValue(new RuntimeBeanReference(RowMapperFactory.class))
111112
.addConstructorArgValue(

0 commit comments

Comments
 (0)