|
1 | 1 | /*
|
2 |
| - * Copyright 2008-2014 the original author or authors. |
| 2 | + * Copyright 2008-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -84,14 +84,17 @@ public abstract class QueryUtils {
|
84 | 84 | private static final String IDENTIFIER = "[\\p{Alnum}._$]+";
|
85 | 85 | private static final String IDENTIFIER_GROUP = String.format("(%s)", IDENTIFIER);
|
86 | 86 |
|
87 |
| - private static final String LEFT_JOIN = "left (outer )?join " + IDENTIFIER + " (as )?" + IDENTIFIER_GROUP; |
88 |
| - private static final Pattern LEFT_JOIN_PATTERN = Pattern.compile(LEFT_JOIN, Pattern.CASE_INSENSITIVE); |
| 87 | + private static final String JOIN = "join " + IDENTIFIER + " (as )?" + IDENTIFIER_GROUP; |
| 88 | + private static final Pattern JOIN_PATTERN = Pattern.compile(JOIN, Pattern.CASE_INSENSITIVE); |
89 | 89 |
|
90 | 90 | private static final String EQUALS_CONDITION_STRING = "%s.%s = :%s";
|
91 | 91 | private static final Pattern ORDER_BY = Pattern.compile(".*order\\s+by\\s+.*", CASE_INSENSITIVE);
|
92 | 92 |
|
93 | 93 | private static final Map<PersistentAttributeType, Class<? extends Annotation>> ASSOCIATION_TYPES;
|
94 | 94 |
|
| 95 | + private static final int QUERY_JOIN_ALIAS_GROUP_INDEX = 2; |
| 96 | + private static final int VARIABLE_NAME_GROUP_INDEX = 4; |
| 97 | + |
95 | 98 | static {
|
96 | 99 |
|
97 | 100 | StringBuilder builder = new StringBuilder();
|
@@ -250,11 +253,11 @@ private static String getOrderClause(Set<String> joinAliases, String alias, Orde
|
250 | 253 | static Set<String> getOuterJoinAliases(String query) {
|
251 | 254 |
|
252 | 255 | Set<String> result = new HashSet<String>();
|
253 |
| - Matcher matcher = LEFT_JOIN_PATTERN.matcher(query); |
| 256 | + Matcher matcher = JOIN_PATTERN.matcher(query); |
254 | 257 |
|
255 | 258 | while (matcher.find()) {
|
256 | 259 |
|
257 |
| - String alias = matcher.group(3); |
| 260 | + String alias = matcher.group(QUERY_JOIN_ALIAS_GROUP_INDEX); |
258 | 261 | if (StringUtils.hasText(alias)) {
|
259 | 262 | result.add(alias);
|
260 | 263 | }
|
@@ -358,7 +361,7 @@ public static String createCountQueryFor(String originalQuery, String countProje
|
358 | 361 |
|
359 | 362 | if (countProjection == null) {
|
360 | 363 |
|
361 |
| - String variable = matcher.matches() ? matcher.group(4) : null; |
| 364 | + String variable = matcher.matches() ? matcher.group(VARIABLE_NAME_GROUP_INDEX) : null; |
362 | 365 | boolean useVariable = variable != null && StringUtils.hasText(variable) && !variable.startsWith("new")
|
363 | 366 | && !variable.startsWith("count(") && !variable.contains(",");
|
364 | 367 |
|
|
0 commit comments