Browse Source

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
issue/2138-query-with-pageable
Christoph Strobl 2 months ago
parent
commit
12e098d424
No known key found for this signature in database
GPG Key ID: E6054036D0C37A4B
  1. 3
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/aot/JdbcCodeBlocks.java
  2. 6
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/aot/PlaceholderAccessor.java
  3. 3
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/AotJdbcRepositoryIntegrationTests.java
  4. 12
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java
  5. 3
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/aot/AotFragmentTestConfigurationSupport.java

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

@ -65,6 +65,7 @@ import org.springframework.util.StringUtils; @@ -65,6 +65,7 @@ import org.springframework.util.StringUtils;
* Common code blocks for JDBC AOT Fragment generation.
*
* @author Mark Paluch
* @author Christoph Strobl
* @since 4.0
*/
class JdbcCodeBlocks {
@ -368,7 +369,7 @@ class JdbcCodeBlocks { @@ -368,7 +369,7 @@ class JdbcCodeBlocks {
}
if (current.isIgnoreCase()) {
builder.addStatement(".ignoreCase(true)");
builder.add(".ignoreCase(true)");
}
}

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

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
package org.springframework.data.jdbc.repository.aot;
import java.sql.JDBCType;
import java.util.Collection;
import org.jspecify.annotations.Nullable;
@ -37,6 +38,7 @@ import org.springframework.util.Assert; @@ -37,6 +38,7 @@ import org.springframework.util.Assert;
* Utility to access placeholders in AOT processing.
*
* @author Mark Paluch
* @author Christoph Strobl
* @since 4.0
*/
class PlaceholderAccessor {
@ -79,6 +81,10 @@ class PlaceholderAccessor { @@ -79,6 +81,10 @@ class PlaceholderAccessor {
return cp;
}
if(value instanceof Collection<?> c && c.iterator().hasNext()) {
return unwrap(c.iterator().next());
}
throw new IllegalArgumentException("Cannot unwrap value: '%s' to CapturingJdbcValue".formatted(value));
}

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

@ -40,6 +40,7 @@ import org.springframework.data.repository.core.support.RepositoryComposition; @@ -40,6 +40,7 @@ import org.springframework.data.repository.core.support.RepositoryComposition;
* Integration test for {@link DummyEntityRepository} using JavaConfig with mounted AOT-generated repository methods.
*
* @author Mark Paluch
* @author Christoph Strobl
*/
@IntegrationTest
@EnabledOnDatabase(DatabaseType.H2)
@ -59,7 +60,7 @@ class AotJdbcRepositoryIntegrationTests extends JdbcRepositoryIntegrationTests { @@ -59,7 +60,7 @@ class AotJdbcRepositoryIntegrationTests extends JdbcRepositoryIntegrationTests {
@Bean
static AotFragmentTestConfigurationSupport aot() {
return new AotFragmentTestConfigurationSupport(UserRepository.class, JdbcH2Dialect.INSTANCE, AotConfig.class,
return new AotFragmentTestConfigurationSupport(DummyEntityRepository.class, JdbcH2Dialect.INSTANCE, AotConfig.class,
false);
}

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

@ -102,6 +102,7 @@ import org.springframework.test.jdbc.JdbcTestUtils; @@ -102,6 +102,7 @@ import org.springframework.test.jdbc.JdbcTestUtils;
* @author Christopher Klein
* @author Mikhail Polivakha
* @author Paul Jones
* @author Christoph Strobl
*/
@IntegrationTest
public class JdbcRepositoryIntegrationTests {
@ -575,6 +576,15 @@ public class JdbcRepositoryIntegrationTests { @@ -575,6 +576,15 @@ public class JdbcRepositoryIntegrationTests {
assertThat(repository.findByNameContains("a", Limit.unlimited())).hasSize(3);
}
@Test // GH-2155
public void selectContainingIgnoreCase() {
repository.saveAll(Arrays.asList(new DummyEntity("1a1"), new DummyEntity("1B1"), new DummyEntity("1c1")));
Optional<DummyEntity> result = repository.findByNameContainingIgnoreCase("b");
assertThat(result).map(DummyEntity::getName).contains("1B1");
}
@Test // GH-774
public void sliceByNameShouldReturnCorrectResult() {
@ -1567,6 +1577,8 @@ public class JdbcRepositoryIntegrationTests { @@ -1567,6 +1577,8 @@ public class JdbcRepositoryIntegrationTests {
List<DummyEntity> findByNameContains(String name, Limit limit);
Optional<DummyEntity> findByNameContainingIgnoreCase(String partialName);
Page<DummyProjection> findPageProjectionByName(String name, Pageable pageable);
Slice<DummyEntity> findSliceByNameContains(String name, Pageable pageable);

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

@ -65,6 +65,7 @@ import org.springframework.util.ReflectionUtils; @@ -65,6 +65,7 @@ import org.springframework.util.ReflectionUtils;
* invocations to the backing AOT fragment. Note that {@code repositoryInterface} is not a repository proxy.
*
* @author Mark Paluch
* @author Christoph Strobl
*/
public class AotFragmentTestConfigurationSupport implements BeanFactoryPostProcessor {
@ -105,7 +106,7 @@ public class AotFragmentTestConfigurationSupport implements BeanFactoryPostProce @@ -105,7 +106,7 @@ public class AotFragmentTestConfigurationSupport implements BeanFactoryPostProce
jdbcRepositoryContributor.contribute(generationContext);
AbstractBeanDefinition aotGeneratedRepository = BeanDefinitionBuilder
.genericBeanDefinition(repositoryInterface.getName() + "Impl__AotRepository")
.genericBeanDefinition(repositoryInterface.getPackageName() + "." + repositoryInterface.getSimpleName() + "Impl__AotRepository")
.addConstructorArgValue(new RuntimeBeanReference(JdbcAggregateOperations.class))
.addConstructorArgValue(new RuntimeBeanReference(RowMapperFactory.class))
.addConstructorArgValue(

Loading…
Cancel
Save