DATAJDBC-604 - Support empty IN lists.

We now support empty IN lists by rendering a condition that evaluates to FALSE using 1 = 0. For NOT IN, we render a condition that evaluates to TRUE using 1 = 1.
This commit is contained in:
Mark Paluch
2020-09-22 09:58:10 +02:00
parent 38139d7d83
commit 842a309f27
8 changed files with 243 additions and 5 deletions

View File

@@ -18,7 +18,6 @@ package org.springframework.data.jdbc.repository;
import static java.util.Arrays.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.*;
import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature.*;
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;
import lombok.Data;
@@ -44,7 +43,6 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
import org.springframework.data.jdbc.testing.AssumeFeatureRule;
import org.springframework.data.jdbc.testing.EnabledOnFeature;
import org.springframework.data.jdbc.testing.TestConfiguration;
import org.springframework.data.relational.core.mapping.event.AbstractRelationalEvent;
import org.springframework.data.relational.core.mapping.event.AfterLoadEvent;
@@ -339,6 +337,38 @@ public class JdbcRepositoryIntegrationTests {
});
}
@Test // DATAJDBC-604
public void existsInWorksAsExpected() {
DummyEntity dummy = repository.save(createDummyEntity());
assertSoftly(softly -> {
softly.assertThat(repository.existsByNameIn(dummy.getName())) //
.describedAs("Positive") //
.isTrue();
softly.assertThat(repository.existsByNameIn()) //
.describedAs("Negative") //
.isFalse();
});
}
@Test // DATAJDBC-604
public void existsNotInWorksAsExpected() {
DummyEntity dummy = repository.save(createDummyEntity());
assertSoftly(softly -> {
softly.assertThat(repository.existsByNameNotIn(dummy.getName())) //
.describedAs("Positive") //
.isFalse();
softly.assertThat(repository.existsByNameNotIn()) //
.describedAs("Negative") //
.isTrue();
});
}
@Test // DATAJDBC-534
public void countByQueryDerivation() {
@@ -370,6 +400,10 @@ public class JdbcRepositoryIntegrationTests {
@Query("SELECT id_Prop from dummy_entity where id_Prop = :id")
DummyEntity withMissingColumn(@Param("id") Long id);
boolean existsByNameIn(String... names);
boolean existsByNameNotIn(String... names);
boolean existsByName(String name);
int countByName(String name);