Using Regular expression objects for splitting and replacing in strings. (#1059)

* Where possible, replace .split() and .replace() methods with compiled Regex patterns.
This prevents a regular expression from being compiled multiple times during runtime.

* Forgot making one instance `private static final`.
This commit is contained in:
Koen De Groote
2017-07-06 20:14:51 +12:00
committed by Rob Bygrave
parent 08263c4588
commit 36a5610e25
12 changed files with 68 additions and 24 deletions
@@ -3,6 +3,8 @@ package io.ebeaninternal.server.query;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.el.ElPropertyDeploy;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.persistence.PersistenceException;
import java.util.HashMap;
import java.util.HashSet;
@@ -15,6 +17,8 @@ import java.util.TreeSet;
*/
class SqlTreeAlias {
private static final Pattern TABLE_ALIAS_REPLACE = Pattern.compile("${}", Pattern.LITERAL);
private int counter;
private int manyWhereCounter;
@@ -178,9 +182,9 @@ class SqlTreeAlias {
private String parseRootAlias(String clause) {
if (rootTableAlias == null) {
return clause.replace("${}", "");
return TABLE_ALIAS_REPLACE.matcher(clause).replaceAll("");
} else {
return clause.replace("${}", rootTableAlias + ".");
return TABLE_ALIAS_REPLACE.matcher(clause).replaceAll(Matcher.quoteReplacement(rootTableAlias + "."));
}
}