1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
import java .util .Collection ;
21
21
import java .util .HashSet ;
22
22
import java .util .Iterator ;
23
- import java .util .LinkedList ;
24
23
import java .util .List ;
25
24
import java .util .Map ;
26
25
import java .util .Set ;
@@ -232,7 +231,6 @@ private static int skipCommentsAndQuotes(char[] statement, int position) {
232
231
// character sequence ending comment or quote not found
233
232
return statement .length ;
234
233
}
235
-
236
234
}
237
235
}
238
236
return position ;
@@ -257,8 +255,11 @@ private static int skipCommentsAndQuotes(char[] statement, int position) {
257
255
*/
258
256
public static String substituteNamedParameters (ParsedSql parsedSql , SqlParameterSource paramSource ) {
259
257
String originalSql = parsedSql .getOriginalSql ();
260
- StringBuilder actualSql = new StringBuilder ();
261
258
List <String > paramNames = parsedSql .getParameterNames ();
259
+ if (paramNames .isEmpty ()) {
260
+ return originalSql ;
261
+ }
262
+ StringBuilder actualSql = new StringBuilder (originalSql .length ());
262
263
int lastIndex = 0 ;
263
264
for (int i = 0 ; i < paramNames .size (); i ++) {
264
265
String paramName = paramNames .get (i );
@@ -282,26 +283,26 @@ public static String substituteNamedParameters(ParsedSql parsedSql, SqlParameter
282
283
Object entryItem = entryIter .next ();
283
284
if (entryItem instanceof Object []) {
284
285
Object [] expressionList = (Object []) entryItem ;
285
- actualSql .append ("(" );
286
+ actualSql .append ('(' );
286
287
for (int m = 0 ; m < expressionList .length ; m ++) {
287
288
if (m > 0 ) {
288
289
actualSql .append (", " );
289
290
}
290
- actualSql .append ("?" );
291
+ actualSql .append ('?' );
291
292
}
292
- actualSql .append (")" );
293
+ actualSql .append (')' );
293
294
}
294
295
else {
295
- actualSql .append ("?" );
296
+ actualSql .append ('?' );
296
297
}
297
298
}
298
299
}
299
300
else {
300
- actualSql .append ("?" );
301
+ actualSql .append ('?' );
301
302
}
302
303
}
303
304
else {
304
- actualSql .append ("?" );
305
+ actualSql .append ('?' );
305
306
}
306
307
lastIndex = endIndex ;
307
308
}
@@ -416,9 +417,10 @@ public static int[] buildSqlTypeArray(ParsedSql parsedSql, SqlParameterSource pa
416
417
*/
417
418
public static List <SqlParameter > buildSqlParameterList (ParsedSql parsedSql , SqlParameterSource paramSource ) {
418
419
List <String > paramNames = parsedSql .getParameterNames ();
419
- List <SqlParameter > params = new LinkedList <SqlParameter >();
420
+ List <SqlParameter > params = new ArrayList <SqlParameter >(paramNames . size () );
420
421
for (String paramName : paramNames ) {
421
- params .add (new SqlParameter (paramName , paramSource .getSqlType (paramName ), paramSource .getTypeName (paramName )));
422
+ params .add (new SqlParameter (
423
+ paramName , paramSource .getSqlType (paramName ), paramSource .getTypeName (paramName )));
422
424
}
423
425
return params ;
424
426
}
0 commit comments