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:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user