|
31 | 31 | import com.google.cloud.spanner.connection.UnitOfWork.CallType; |
32 | 32 | import com.google.common.annotations.VisibleForTesting; |
33 | 33 | import com.google.common.base.Preconditions; |
| 34 | +import com.google.common.base.Splitter; |
34 | 35 | import com.google.common.cache.Cache; |
35 | 36 | import com.google.common.cache.CacheBuilder; |
36 | 37 | import com.google.common.cache.CacheStats; |
|
41 | 42 | import java.util.Collection; |
42 | 43 | import java.util.Collections; |
43 | 44 | import java.util.HashMap; |
| 45 | +import java.util.Iterator; |
44 | 46 | import java.util.Map; |
45 | 47 | import java.util.Objects; |
46 | 48 | import java.util.Set; |
@@ -614,16 +616,20 @@ public boolean isUpdateStatement(String sql) { |
614 | 616 |
|
615 | 617 | private boolean statementStartsWith(String sql, Iterable<String> checkStatements) { |
616 | 618 | Preconditions.checkNotNull(sql); |
617 | | - String[] tokens = sql.split("\\s+", 2); |
618 | | - int checkIndex = 0; |
619 | | - if (supportsExplain() && tokens[0].equalsIgnoreCase("EXPLAIN")) { |
620 | | - checkIndex = 1; |
621 | | - } |
622 | | - if (tokens.length > checkIndex) { |
623 | | - for (String check : checkStatements) { |
624 | | - if (tokens[checkIndex].equalsIgnoreCase(check)) { |
625 | | - return true; |
626 | | - } |
| 619 | + Iterator<String> tokens = Splitter.onPattern("\\s+").split(sql).iterator(); |
| 620 | + if (!tokens.hasNext()) { |
| 621 | + return false; |
| 622 | + } |
| 623 | + String token = tokens.next(); |
| 624 | + if (supportsExplain() && token.equalsIgnoreCase("EXPLAIN")) { |
| 625 | + if (!tokens.hasNext()) { |
| 626 | + return false; |
| 627 | + } |
| 628 | + token = tokens.next(); |
| 629 | + } |
| 630 | + for (String check : checkStatements) { |
| 631 | + if (token.equalsIgnoreCase(check)) { |
| 632 | + return true; |
627 | 633 | } |
628 | 634 | } |
629 | 635 | return false; |
|
0 commit comments