DATAJPA-1171 - Polishing.
Added unit test to verify new behavior. Slightly simplified Stream creation using Streamable. Original pull request: #212.
This commit is contained in:
@@ -58,7 +58,7 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
import org.springframework.data.jpa.domain.JpaSort.JpaOrder;
|
||||
import org.springframework.data.mapping.PropertyPath;
|
||||
import org.springframework.data.util.StreamUtils;
|
||||
import org.springframework.data.util.Streamable;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -185,13 +185,11 @@ public abstract class QueryUtils {
|
||||
public static String getExistsQueryString(String entityName, String countQueryPlaceHolder,
|
||||
Iterable<String> idAttributes) {
|
||||
|
||||
String baseQuery = String.format(COUNT_QUERY_STRING, countQueryPlaceHolder, entityName);
|
||||
|
||||
String whereClause = StreamUtils.createStreamFromIterator(idAttributes.iterator())
|
||||
.map(idAttribute -> String.format(EQUALS_CONDITION_STRING, "x", idAttribute, idAttribute))
|
||||
String whereClause = Streamable.of(idAttributes).stream() //
|
||||
.map(idAttribute -> String.format(EQUALS_CONDITION_STRING, "x", idAttribute, idAttribute)) //
|
||||
.collect(Collectors.joining(" AND ", " WHERE ", ""));
|
||||
|
||||
return baseQuery + whereClause;
|
||||
return String.format(COUNT_QUERY_STRING, countQueryPlaceHolder, entityName) + whereClause;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,10 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.query;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.data.jpa.repository.query.QueryUtils.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
@@ -385,6 +387,13 @@ public class QueryUtilsUnitTests {
|
||||
assertThat(aliases, contains("authority"));
|
||||
}
|
||||
|
||||
@Test // DATAJPA-1171
|
||||
public void doesNotContainStaticClauseInExistsQuery() {
|
||||
|
||||
assertThat(QueryUtils.getExistsQueryString("entity", "x", Collections.singleton("id"))) //
|
||||
.endsWith("WHERE x.id = :id");
|
||||
}
|
||||
|
||||
private static void assertCountQuery(String originalQuery, String countQuery) {
|
||||
assertThat(createCountQueryFor(originalQuery), is(countQuery));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user