DATAJPA-1171 - Polishing.

Added unit test to verify new behavior. Formatting.

Original pull request: #212.
This commit is contained in:
Oliver Gierke
2017-09-04 15:32:26 +02:00
parent 557ce91b4a
commit 47c72ea19d
2 changed files with 14 additions and 4 deletions

View File

@@ -183,16 +183,18 @@ public abstract class QueryUtils {
public static String getExistsQueryString(String entityName, String countQueryPlaceHolder,
Iterable<String> idAttributes) {
StringBuilder sb = new StringBuilder(String.format(COUNT_QUERY_STRING, countQueryPlaceHolder, entityName));
StringBuilder builder = new StringBuilder(String.format(COUNT_QUERY_STRING, countQueryPlaceHolder, entityName));
String append = " WHERE ";
for (String idAttribute : idAttributes) {
sb.append(append);
sb.append(String.format(EQUALS_CONDITION_STRING, "x", idAttribute, idAttribute));
builder.append(append);
builder.append(String.format(EQUALS_CONDITION_STRING, "x", idAttribute, idAttribute));
append = " AND ";
}
return sb.toString();
return builder.toString();
}
/**

View File

@@ -19,6 +19,7 @@ import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.data.jpa.repository.query.QueryUtils.*;
import java.util.Collections;
import java.util.Set;
import org.hamcrest.Matcher;
@@ -513,6 +514,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));
}