@@ -110,7 +110,8 @@ public abstract class QueryUtils {
110
110
111
111
private static final String EQUALS_CONDITION_STRING = "%s.%s = :%s" ;
112
112
private static final Pattern ORDER_BY = Pattern .compile ("(order\\ s+by\\ s+)" , CASE_INSENSITIVE );
113
- private static final Pattern ORDER_BY_IN_WINDOW_OR_SUBSELECT = Pattern .compile ("(\\ (\\ s*[a-z0-9 ,.*]*order\\ s+by\\ s+[a-z0-9 ,.]*\\ s*\\ ))" , CASE_INSENSITIVE );
113
+ private static final Pattern ORDER_BY_IN_WINDOW_OR_SUBSELECT = Pattern
114
+ .compile ("(\\ (\\ s*[a-z0-9 ,.*]*order\\ s+by\\ s+[a-z0-9 ,.]*\\ s*\\ ))" , CASE_INSENSITIVE );
114
115
115
116
private static final Pattern NAMED_PARAMETER = Pattern .compile (COLON_NO_DOUBLE_COLON + IDENTIFIER + "|#" + IDENTIFIER ,
116
117
CASE_INSENSITIVE );
@@ -144,6 +145,7 @@ public abstract class QueryUtils {
144
145
ALIAS_MATCH = compile (builder .toString (), CASE_INSENSITIVE );
145
146
146
147
builder = new StringBuilder ();
148
+ builder .append ("\\ s*" );
147
149
builder .append ("(select\\ s+((distinct)?((?s).+?)?)\\ s+)?(from\\ s+" );
148
150
builder .append (IDENTIFIER );
149
151
builder .append ("(?:\\ s+as)?\\ s+)" );
@@ -279,8 +281,8 @@ public static String applySorting(String query, Sort sort, @Nullable String alia
279
281
}
280
282
281
283
/**
282
- * Returns {@code true} if the query has {@code order by} clause.
283
- * The query has {@code order by} clause if there is an {@code order by} which is not part of window clause.
284
+ * Returns {@code true} if the query has {@code order by} clause. The query has {@code order by} clause if there is an
285
+ * {@code order by} which is not part of window clause.
284
286
*
285
287
* @param query the analysed query string
286
288
* @return {@code true} if the query has {@code order by} clause, {@code false} otherwise
@@ -297,9 +299,13 @@ private static boolean hasOrderByClause(String query) {
297
299
* @return the number of occurences of the pattern in the string
298
300
*/
299
301
private static int countOccurences (Pattern pattern , String string ) {
302
+
300
303
Matcher matcher = pattern .matcher (string );
304
+
301
305
int occurences = 0 ;
302
- while (matcher .find ()) occurences ++;
306
+ while (matcher .find ()) {
307
+ occurences ++;
308
+ }
303
309
return occurences ;
304
310
}
305
311
0 commit comments