11/*
2- * Copyright 2002-2017 the original author or authors.
2+ * Copyright 2002-2018 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2020import java .util .Collection ;
2121import java .util .HashSet ;
2222import java .util .Iterator ;
23- import java .util .LinkedList ;
2423import java .util .List ;
2524import java .util .Map ;
2625import java .util .Set ;
@@ -232,7 +231,6 @@ private static int skipCommentsAndQuotes(char[] statement, int position) {
232231 // character sequence ending comment or quote not found
233232 return statement .length ;
234233 }
235-
236234 }
237235 }
238236 return position ;
@@ -257,8 +255,11 @@ private static int skipCommentsAndQuotes(char[] statement, int position) {
257255 */
258256 public static String substituteNamedParameters (ParsedSql parsedSql , SqlParameterSource paramSource ) {
259257 String originalSql = parsedSql .getOriginalSql ();
260- StringBuilder actualSql = new StringBuilder ();
261258 List <String > paramNames = parsedSql .getParameterNames ();
259+ if (paramNames .isEmpty ()) {
260+ return originalSql ;
261+ }
262+ StringBuilder actualSql = new StringBuilder (originalSql .length ());
262263 int lastIndex = 0 ;
263264 for (int i = 0 ; i < paramNames .size (); i ++) {
264265 String paramName = paramNames .get (i );
@@ -282,26 +283,26 @@ public static String substituteNamedParameters(ParsedSql parsedSql, SqlParameter
282283 Object entryItem = entryIter .next ();
283284 if (entryItem instanceof Object []) {
284285 Object [] expressionList = (Object []) entryItem ;
285- actualSql .append ("(" );
286+ actualSql .append ('(' );
286287 for (int m = 0 ; m < expressionList .length ; m ++) {
287288 if (m > 0 ) {
288289 actualSql .append (", " );
289290 }
290- actualSql .append ("?" );
291+ actualSql .append ('?' );
291292 }
292- actualSql .append (")" );
293+ actualSql .append (')' );
293294 }
294295 else {
295- actualSql .append ("?" );
296+ actualSql .append ('?' );
296297 }
297298 }
298299 }
299300 else {
300- actualSql .append ("?" );
301+ actualSql .append ('?' );
301302 }
302303 }
303304 else {
304- actualSql .append ("?" );
305+ actualSql .append ('?' );
305306 }
306307 lastIndex = endIndex ;
307308 }
@@ -416,9 +417,10 @@ public static int[] buildSqlTypeArray(ParsedSql parsedSql, SqlParameterSource pa
416417 */
417418 public static List <SqlParameter > buildSqlParameterList (ParsedSql parsedSql , SqlParameterSource paramSource ) {
418419 List <String > paramNames = parsedSql .getParameterNames ();
419- List <SqlParameter > params = new LinkedList <SqlParameter >();
420+ List <SqlParameter > params = new ArrayList <SqlParameter >(paramNames . size () );
420421 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 )));
422424 }
423425 return params ;
424426 }
0 commit comments