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:
Oliver Gierke
2013-05-08 09:51:42 +02:00
parent d655862251
commit f5f4b6b7ad
2 changed files with 11 additions and 1 deletions

View File

@@ -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);

View File

@@ -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));
}