DATAJPA-343 - Fixed count query projection for queries with subselects.
Switched from an accidentally greedy quantifier for the query variable pickup with a possessive one.
This commit is contained in:
@@ -92,7 +92,7 @@ public abstract class QueryUtils {
|
||||
ALIAS_MATCH = compile(builder.toString(), CASE_INSENSITIVE);
|
||||
|
||||
builder = new StringBuilder();
|
||||
builder.append("(select\\s+((distinct )?(.+)?)\\s+)?(from\\s+");
|
||||
builder.append("(select\\s+((distinct )?(.+?)?)\\s+)?(from\\s+");
|
||||
builder.append(IDENTIFIER);
|
||||
builder.append("(?:\\s+as)?\\s+)");
|
||||
builder.append(IDENTIFIER_GROUP);
|
||||
|
||||
@@ -213,6 +213,16 @@ public class QueryUtilsUnitTests {
|
||||
"select count(distinct m.genre) from Media m where m.user = ?1 order by m.genre asc");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-343
|
||||
*/
|
||||
@Test
|
||||
public void projectsCOuntQueriesForQueriesWithSubselects() {
|
||||
|
||||
assertCountQuery("select o from Foo o where cb.id in (select b from Bar b)",
|
||||
"select count(o) from Foo o where cb.id in (select b from Bar b)");
|
||||
}
|
||||
|
||||
private void assertCountQuery(String originalQuery, String countQuery) {
|
||||
assertThat(createCountQueryFor(originalQuery), is(countQuery));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user