Repository: quarkusio/quarkus
Issue: Method countQuery does not create select if where are line break characters (\\n)

I have base functional for create where string, it create string with line break characters (\\n). 

code:
 

>  PanacheQuery<MyEntity> myEntityPanacheQuery = MyEntity.find(whereStr, whereParameters);
   

> myEntityPanacheQuery.page(Page.of(pageNumber, pageSize)).list(); // it is good work

  
>  myEntityPanacheQuery.count(); // it is return exception

method count() is return exception: 
`io.quarkus.panache.common.exception.PanacheQueryException: Count query not supported for select query: FROM com.MyEntity WHERE field like :field 
 and (1 = :value1 OR (field2 = :field2))
        at io.quarkus.hibernate.orm.panache.common.runtime.CommonPanacheQueryImpl.countQuery(CommonPanacheQueryImpl.java:252)
        at io.quarkus.hibernate.orm.panache.common.runtime.CommonPanacheQueryImpl.count(CommonPanacheQueryImpl.java:214)
        at io.quarkus.hibernate.orm.panache.runtime.PanacheQueryImpl.count(PanacheQueryImpl.java:144)
        at com.bivgroup.soglacie.rra.service.journal.jra.WorkAgentJournalService.lambda$loadJournalResult$1(WorkAgentJournalService.java:39)
        at io.smallrye.mutiny.operators.UniMapOnResult$1.onItem(UniMapOnResult.java:31)
`
If remove  line break characters from where string, when countQuery will be to work well.
I think FROM_PATTERN in CommonPanacheQueryImpl class it should be replaced `Pattern.compile("^\\\\s*FROM\\\\s+.*", Pattern.CASE_INSENSITIVE);` on `Pattern.compile("^\\s*FROM\\s+(.|\\n)*", Pattern.CASE_INSENSITIVE)`; or similar that patter processed line break characters (\\n).

Quarkus version 1.5.2

Changed files:
extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java
extensions/panache/hibernate-orm-panache-common/runtime/src/test/java/io/quarkus/hibernate/orm/panache/common/runtime/QueryMatcherTest.java

diff --git a/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java b/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java
index c0fa321b1d5..b9c82510ba8 100644
--- a/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java
+++ b/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java
@@ -29,11 +29,11 @@
     // match SELECT DISTINCT? id (AS id)? (, id (AS id)?)*
     static final Pattern SELECT_PATTERN = Pattern.compile(
             "^\\\\s*SELECT\\\\s+((?:DISTINCT\\\\s+)?\\\\w+(?:\\\\.\\\\w+)*)(?:\\\\s+AS\\\\s+\\\\w+)?(\\\\s*,\\\\s*\\\\w+(?:\\\\.\\\\w+)*(?:\\\\s+AS\\\\s+\\\\w+)?)*\\\\s+(.*)",
-            Pattern.CASE_INSENSITIVE);
+            Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
 
     // match FROM
     static final Pattern FROM_PATTERN = Pattern.compile("^\\\\s*FROM\\\\s+.*",
-            Pattern.CASE_INSENSITIVE);
+            Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
 
     private interface NonThrowingCloseable extends AutoCloseable {
         @Override
diff --git a/extensions/panache/hibernate-orm-panache-common/runtime/src/test/java/io/quarkus/hibernate/orm/panache/common/runtime/QueryMatcherTest.java b/extensions/panache/hibernate-orm-panache-common/runtime/src/test/java/io/quarkus/hibernate/orm/panache/common/runtime/QueryMatcherTest.java
index 8f7ec5a5314..95fee841074 100644
--- a/extensions/panache/hibernate-orm-panache-common/runtime/src/test/java/io/quarkus/hibernate/orm/panache/common/runtime/QueryMatcherTest.java
+++ b/extensions/panache/hibernate-orm-panache-common/runtime/src/test/java/io/quarkus/hibernate/orm/panache/common/runtime/QueryMatcherTest.java
@@ -9,22 +9,28 @@ public class QueryMatcherTest {
 
     @Test
     public void testSelectMatcher() {
-        testMatch("from bar", null);
-        testMatch("select foo from bar", "from bar");
-        testMatch("  select   foo   from   bar  ", "from   bar  ");
-        testMatch("select foo as fff from bar", "from bar");
-        testMatch("select foo,bar from bar", "from bar");
-        testMatch("select foo , bar from bar", "from bar");
-        testMatch("select foo as f,bar as b from bar", "from bar");
-        testMatch("select foo as f , bar as b from bar", "from bar");
-
-        testMatch("select foo.bar.gee as f , bar.sup as b from bar", "from bar");
-
-        testMatch("select distinct foo from bar", "from bar");
-        testMatch("select distinct foo,bar from bar", "from bar");
+        testSelectMatch("from bar", null);
+        testSelectMatch("select foo from bar", "from bar");
+        testSelectMatch("  select   foo   from   bar  ", "from   bar  ");
+        testSelectMatch("select foo as fff from bar", "from bar");
+        testSelectMatch("select foo,bar from bar", "from bar");
+        testSelectMatch("select foo , bar from bar", "from bar");
+        testSelectMatch("select foo as f,bar as b from bar", "from bar");
+        testSelectMatch("select foo as f , bar as b from bar", "from bar");
+        testSelectMatch("select foo.bar.gee as f , bar.sup as b from bar", "from bar");
+        testSelectMatch("select distinct foo from bar \\n where field = :value",
+                "from bar \\n where field = :value");
+        testSelectMatch("select distinct foo from bar", "from bar");
+        testSelectMatch("select distinct foo,bar from bar", "from bar");
+        testSelectMatch("select foo from bar where field = :value", "from bar where field = :value");
+        testSelectMatch("select foo from bar \\n where field = :value",
+                "from bar \\n where field = :value");
+        testSelectMatch("select foo from bar \\n where field = :value " +
+                "\\n\\r and fieldTwo :valueTwo \\r\\n :fieldThree = :valueThree",
+                "from bar \\n where field = :value \\n\\r and fieldTwo :valueTwo \\r\\n :fieldThree = :valueThree");
     }
 
-    private void testMatch(String select, String result) {
+    private void testSelectMatch(String select, String result) {
         Matcher matcher = CommonPanacheQueryImpl.SELECT_PATTERN.matcher(select);
         if (result != null) {
             Assertions.assertTrue(matcher.matches());
@@ -33,4 +39,25 @@ private void testMatch(String select, String result) {
             Assertions.assertFalse(matcher.matches());
         }
     }
+
+    @Test
+    public void testFromMatcher() {
+        testFromMatch("from bar");
+        testFromMatch("   from   bar  ");
+        testFromMatch("from bar where field = :value");
+        testFromMatch("from bar where fieldOne = :valueOne and fieldTwo :valueTwo");
+        testFromMatch("from bar where fieldOne = :valueOne \\n and fieldTwo :valueTwo");
+        testFromMatch("from bar where fieldOne = :valueOne \\n\\r and fieldTwo :valueTwo");
+        testFromMatch("from bar where fieldOne = :valueOne \\r\\n and fieldTwo :valueTwo \\n" +
+                "\\n :fieldThree = :valueThree");
+        testFromMatch("from \\n bar where field = :value");
+        testFromMatch("from \\n bar \\n\\r where \\r\\n field = :value");
+        testFromMatch("from \\n bar b \\n\\r where \\r\\n b.field = :value");
+    }
+
+    private void testFromMatch(String query) {
+        Matcher matcher = CommonPanacheQueryImpl.FROM_PATTERN.matcher(query);
+        Assertions.assertTrue(matcher.matches());
+    }
+
 }