41
41
public abstract class NamedParameterUtils {
42
42
43
43
/**
44
- * Set of characters that qualify as parameter separators,
45
- * indicating that a parameter name in a SQL String has ended.
44
+ * Set of characters that qualify as comment or quotes starting characters.
46
45
*/
47
- private static final char [] PARAMETER_SEPARATORS =
48
- new char [] {'"' , '\'' , ':' , '&' , ',' , ';' , '(' , ')' , '|' , '=' , '+' , '-' , '*' , '%' , '/' , '\\' , '<' , '>' , '^' };
46
+ private static final String [] START_SKIP = new String [] {"'" , "\" " , "--" , "/*" };
49
47
50
48
/**
51
- * Set of characters that qualify as comment or quotes starting characters.
49
+ * Set of characters that at are the corresponding comment or quotes ending characters.
52
50
*/
53
- private static final String [] START_SKIP =
54
- new String [] {"'" , "\" " , "--" , "/*" };
51
+ private static final String [] STOP_SKIP = new String [] {"'" , "\" " , "\n " , "*/" };
55
52
56
53
/**
57
- * Set of characters that at are the corresponding comment or quotes ending characters.
54
+ * Set of characters that qualify as parameter separators,
55
+ * indicating that a parameter name in a SQL String has ended.
58
56
*/
59
- private static final String [] STOP_SKIP =
60
- new String [] {"'" , " \" " , " \n " , "*/" };
57
+ private static final char [] PARAMETER_SEPARATORS =
58
+ new char [] {'"' , '\'' , ':' , '&' , ',' , ';' , '(' , ')' , '|' , '=' , '+' , '-' , '*' , '%' , '/' , '\\' , '<' , '>' , '^' };
61
59
62
60
63
61
//-------------------------------------------------------------------------
@@ -109,7 +107,7 @@ public static ParsedSql parseSqlStatement(final String sql) {
109
107
String parameter = null ;
110
108
if (j < statement .length && c == ':' && statement [j ] == '{' ) {
111
109
// :{x} style parameter
112
- while (j < statement .length && !( '}' == statement [j ]) ) {
110
+ while (j < statement .length && '}' != statement [j ]) {
113
111
j ++;
114
112
if (':' == statement [j ] || '{' == statement [j ]) {
115
113
throw new InvalidDataAccessApiUsageException ("Parameter name contains invalid character '" +
@@ -120,7 +118,7 @@ public static ParsedSql parseSqlStatement(final String sql) {
120
118
throw new InvalidDataAccessApiUsageException (
121
119
"Non-terminated named parameter declaration at position " + i + " in statement: " + sql );
122
120
}
123
- if (j - i > 3 ) {
121
+ if (j - i > 2 ) {
124
122
parameter = sql .substring (i + 2 , j );
125
123
namedParameterCount = addNewNamedParameter (namedParameters , namedParameterCount , parameter );
126
124
totalParameterCount = addNamedParameter (parameterList , totalParameterCount , escapes , i , j + 1 , parameter );
@@ -200,7 +198,7 @@ private static int skipCommentsAndQuotes(char[] statement, int position) {
200
198
if (statement [position ] == START_SKIP [i ].charAt (0 )) {
201
199
boolean match = true ;
202
200
for (int j = 1 ; j < START_SKIP [i ].length (); j ++) {
203
- if (!( statement [position + j ] == START_SKIP [i ].charAt (j ) )) {
201
+ if (statement [position + j ] != START_SKIP [i ].charAt (j )) {
204
202
match = false ;
205
203
break ;
206
204
}
@@ -216,7 +214,7 @@ private static int skipCommentsAndQuotes(char[] statement, int position) {
216
214
// last comment not closed properly
217
215
return statement .length ;
218
216
}
219
- if (!( statement [m + n ] == STOP_SKIP [i ].charAt (n ) )) {
217
+ if (statement [m + n ] != STOP_SKIP [i ].charAt (n )) {
220
218
endMatch = false ;
221
219
break ;
222
220
}
0 commit comments