DATAJPA-938 - Enable DOTALL mode for regular expression detecting constructor expressions in manually declared queries.

The usage of the DOTALL mode makes sure that line breaks in query definitions don't cause any trouble when trying to detect constructor expressions.
This commit is contained in:
Oliver Gierke
2016-08-10 23:33:27 +02:00
parent bcc917867e
commit 7372ffdf2d
2 changed files with 22 additions and 1 deletions

View File

@@ -144,7 +144,7 @@ public abstract class QueryUtils {
builder.append(".*");
builder.append("\\)");
CONSTRUCTOR_EXPRESSION = compile(builder.toString(), CASE_INSENSITIVE);
CONSTRUCTOR_EXPRESSION = compile(builder.toString(), CASE_INSENSITIVE + DOTALL);
}
/**

View File

@@ -331,6 +331,27 @@ public class QueryUtilsUnitTests {
assertThat(hasConstructorExpression("select distinct new Foo() from Bar b"), is(true));
}
/**
* @see DATAJPA-938
*/
@Test
public void detectsComplexConstructorExpression() {
assertThat(hasConstructorExpression("select new foo.bar.Foo(ip.id, ip.name, sum(lp.amount)) " //
+ "from Bar lp join lp.investmentProduct ip " //
+ "where (lp.toDate is null and lp.fromDate <= :now and lp.fromDate is not null) and lp.accountId = :accountId " //
+ "group by ip.id, ip.name, lp.accountId " //
+ "order by ip.name ASC"), is(true));
}
/**
* @see DATAJPA-938
*/
@Test
public void detectsConstructorExpressionWithLineBreaks() {
assertThat(hasConstructorExpression("select new foo.bar.FooBar(\na.id) from DtoA a "), is(true));
}
private static void assertCountQuery(String originalQuery, String countQuery) {
assertThat(createCountQueryFor(originalQuery), is(countQuery));
}