4141public abstract class NamedParameterUtils {
4242
4343 /**
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.
4645 */
47- private static final char [] PARAMETER_SEPARATORS =
48- new char [] {'"' , '\'' , ':' , '&' , ',' , ';' , '(' , ')' , '|' , '=' , '+' , '-' , '*' , '%' , '/' , '\\' , '<' , '>' , '^' };
46+ private static final String [] START_SKIP = new String [] {"'" , "\" " , "--" , "/*" };
4947
5048 /**
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.
5250 */
53- private static final String [] START_SKIP =
54- new String [] {"'" , "\" " , "--" , "/*" };
51+ private static final String [] STOP_SKIP = new String [] {"'" , "\" " , "\n " , "*/" };
5552
5653 /**
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.
5856 */
59- private static final String [] STOP_SKIP =
60- new String [] {"'" , " \" " , " \n " , "*/" };
57+ private static final char [] PARAMETER_SEPARATORS =
58+ new char [] {'"' , '\'' , ':' , '&' , ',' , ';' , '(' , ')' , '|' , '=' , '+' , '-' , '*' , '%' , '/' , '\\' , '<' , '>' , '^' };
6159
6260
6361 //-------------------------------------------------------------------------
@@ -109,7 +107,7 @@ public static ParsedSql parseSqlStatement(final String sql) {
109107 String parameter = null ;
110108 if (j < statement .length && c == ':' && statement [j ] == '{' ) {
111109 // :{x} style parameter
112- while (j < statement .length && !( '}' == statement [j ]) ) {
110+ while (j < statement .length && '}' != statement [j ]) {
113111 j ++;
114112 if (':' == statement [j ] || '{' == statement [j ]) {
115113 throw new InvalidDataAccessApiUsageException ("Parameter name contains invalid character '" +
@@ -120,7 +118,7 @@ public static ParsedSql parseSqlStatement(final String sql) {
120118 throw new InvalidDataAccessApiUsageException (
121119 "Non-terminated named parameter declaration at position " + i + " in statement: " + sql );
122120 }
123- if (j - i > 3 ) {
121+ if (j - i > 2 ) {
124122 parameter = sql .substring (i + 2 , j );
125123 namedParameterCount = addNewNamedParameter (namedParameters , namedParameterCount , parameter );
126124 totalParameterCount = addNamedParameter (parameterList , totalParameterCount , escapes , i , j + 1 , parameter );
@@ -200,7 +198,7 @@ private static int skipCommentsAndQuotes(char[] statement, int position) {
200198 if (statement [position ] == START_SKIP [i ].charAt (0 )) {
201199 boolean match = true ;
202200 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 )) {
204202 match = false ;
205203 break ;
206204 }
@@ -216,7 +214,7 @@ private static int skipCommentsAndQuotes(char[] statement, int position) {
216214 // last comment not closed properly
217215 return statement .length ;
218216 }
219- if (!( statement [m + n ] == STOP_SKIP [i ].charAt (n ) )) {
217+ if (statement [m + n ] != STOP_SKIP [i ].charAt (n )) {
220218 endMatch = false ;
221219 break ;
222220 }
0 commit comments