| 1 |
|
package org.codehaus.mojo.sql; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
import org.codehaus.plexus.util.StringUtils; |
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
|
|
|
| 0% |
Uncovered Elements: 63 (63) |
Complexity: 20 |
Complexity Density: 0.57 |
|
| 27 |
|
public class SqlSplitter { |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
public static final int NO_END = -1; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
@param |
| 38 |
|
|
| 39 |
|
@param |
| 40 |
|
|
| 41 |
|
@return |
| 42 |
|
@value |
| 43 |
|
|
|
|
|
| 0% |
Uncovered Elements: 60 (60) |
Complexity: 19 |
Complexity Density: 0.56 |
|
| 44 |
0
|
public static int containsSqlEnd(String line, String delimiter) {... |
| 45 |
|
|
| 46 |
0
|
boolean isComment = false; |
| 47 |
|
|
| 48 |
0
|
boolean isAlphaDelimiter = StringUtils.isAlpha(delimiter); |
| 49 |
|
|
| 50 |
0
|
if (line == null || line.length() == 0) { |
| 51 |
0
|
return NO_END; |
| 52 |
|
} |
| 53 |
|
|
| 54 |
0
|
int pos = 0; |
| 55 |
|
|
| 56 |
0
|
do { |
| 57 |
0
|
if (isComment) { |
| 58 |
0
|
if (line.startsWith("*/", pos)) { |
| 59 |
0
|
isComment = false; |
| 60 |
|
} else { |
| 61 |
0
|
pos++; |
| 62 |
0
|
continue; |
| 63 |
|
} |
| 64 |
|
} |
| 65 |
|
|
| 66 |
0
|
if (line.startsWith("/*", pos)) { |
| 67 |
0
|
isComment = true; |
| 68 |
0
|
pos += 2; |
| 69 |
0
|
continue; |
| 70 |
|
} |
| 71 |
|
|
| 72 |
0
|
if (line.startsWith("--", pos)) { |
| 73 |
0
|
return NO_END; |
| 74 |
|
} |
| 75 |
|
|
| 76 |
0
|
if (line.startsWith("'", pos) || line.startsWith("\"", pos)) { |
| 77 |
0
|
String quoteChar = "" + line.charAt(pos); |
| 78 |
0
|
String quoteEscape = "\\" + quoteChar; |
| 79 |
0
|
pos++; |
| 80 |
|
|
| 81 |
0
|
if (line.length() <= pos) { |
| 82 |
0
|
return NO_END; |
| 83 |
|
} |
| 84 |
|
|
| 85 |
0
|
do { |
| 86 |
0
|
if (line.startsWith(quoteEscape, pos)) { |
| 87 |
0
|
pos += 2; |
| 88 |
|
} |
| 89 |
0
|
} while (!line.startsWith(quoteChar, pos++)); |
| 90 |
|
|
| 91 |
0
|
continue; |
| 92 |
|
} |
| 93 |
|
|
| 94 |
0
|
if (line.startsWith(delimiter, pos)) { |
| 95 |
0
|
if (isAlphaDelimiter) { |
| 96 |
|
|
| 97 |
|
|
| 98 |
0
|
if ((pos == 0 || !isAlpha(line.charAt(pos - 1))) |
| 99 |
|
&& (line.length() == pos + delimiter.length() || !isAlpha(line.charAt(pos |
| 100 |
|
+ delimiter.length())))) { |
| 101 |
0
|
return pos + delimiter.length(); |
| 102 |
|
} |
| 103 |
|
} else { |
| 104 |
0
|
return pos + delimiter.length(); |
| 105 |
|
} |
| 106 |
|
} |
| 107 |
|
|
| 108 |
0
|
pos++; |
| 109 |
|
|
| 110 |
0
|
} while (line.length() >= pos); |
| 111 |
|
|
| 112 |
0
|
return NO_END; |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
|
| 116 |
|
@param |
| 117 |
|
|
| 118 |
|
@return |
| 119 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 120 |
0
|
private static boolean isAlpha(char c) {... |
| 121 |
0
|
return Character.isUpperCase(c) || Character.isLowerCase(c); |
| 122 |
|
} |
| 123 |
|
|
| 124 |
|
} |