@@ -113,11 +113,13 @@ public static ParsedSql parseSqlStatement(final String sql) {
113113 while (j < statement .length && !('}' == statement [j ])) {
114114 j ++;
115115 if (':' == statement [j ] || '{' == statement [j ]) {
116- throw new InvalidDataAccessApiUsageException ("Parameter name contains invalid character '" + statement [j ] + "' at position " + i + " in statement " + sql );
116+ throw new InvalidDataAccessApiUsageException ("Parameter name contains invalid character '" +
117+ statement [j ] + "' at position " + i + " in statement " + sql );
117118 }
118119 }
119120 if (j >= statement .length ) {
120- throw new InvalidDataAccessApiUsageException ("Non-terminated named parameter declaration at position " + i + " in statement " + sql );
121+ throw new InvalidDataAccessApiUsageException (
122+ "Non-terminated named parameter declaration at position " + i + " in statement: " + sql );
121123 }
122124 if (j - i > 3 ) {
123125 parameter = sql .substring (i + 2 , j );
@@ -166,8 +168,9 @@ public static ParsedSql parseSqlStatement(final String sql) {
166168 return parsedSql ;
167169 }
168170
169- private static int addNamedParameter (List <ParameterHolder > parameterList , int totalParameterCount , int escapes , int i , int j ,
170- String parameter ) {
171+ private static int addNamedParameter (
172+ List <ParameterHolder > parameterList , int totalParameterCount , int escapes , int i , int j , String parameter ) {
173+
171174 parameterList .add (new ParameterHolder (parameter , i - escapes , j - escapes ));
172175 totalParameterCount ++;
173176 return totalParameterCount ;
@@ -256,7 +259,7 @@ public static String substituteNamedParameters(ParsedSql parsedSql, SqlParameter
256259 int [] indexes = parsedSql .getParameterIndexes (i );
257260 int startIndex = indexes [0 ];
258261 int endIndex = indexes [1 ];
259- actualSql .append (originalSql . substring ( lastIndex , startIndex ) );
262+ actualSql .append (originalSql , lastIndex , startIndex );
260263 if (paramSource != null && paramSource .hasValue (paramName )) {
261264 Object value = paramSource .getValue (paramName );
262265 if (value instanceof SqlParameterValue ) {
@@ -296,7 +299,7 @@ public static String substituteNamedParameters(ParsedSql parsedSql, SqlParameter
296299 }
297300 lastIndex = endIndex ;
298301 }
299- actualSql .append (originalSql . substring ( lastIndex , originalSql .length () ));
302+ actualSql .append (originalSql , lastIndex , originalSql .length ());
300303 return actualSql .toString ();
301304 }
302305
@@ -409,15 +412,12 @@ public static List<SqlParameter> buildSqlParameterList(ParsedSql parsedSql, SqlP
409412 List <String > paramNames = parsedSql .getParameterNames ();
410413 List <SqlParameter > params = new LinkedList <SqlParameter >();
411414 for (String paramName : paramNames ) {
412- SqlParameter param = new SqlParameter (
413- paramName ,
414- paramSource .getSqlType (paramName ),
415- paramSource .getTypeName (paramName ));
416- params .add (param );
415+ params .add (new SqlParameter (paramName , paramSource .getSqlType (paramName ), paramSource .getTypeName (paramName )));
417416 }
418417 return params ;
419418 }
420419
420+
421421 //-------------------------------------------------------------------------
422422 // Convenience methods operating on a plain SQL String
423423 //-------------------------------------------------------------------------
@@ -464,28 +464,32 @@ public static Object[] buildValueArray(String sql, Map<String, ?> paramMap) {
464464 return buildValueArray (parsedSql , new MapSqlParameterSource (paramMap ), null );
465465 }
466466
467+
467468 private static class ParameterHolder {
468- private String parameterName ;
469- private int startIndex ;
470- private int endIndex ;
469+
470+ private final String parameterName ;
471+
472+ private final int startIndex ;
473+
474+ private final int endIndex ;
471475
472476 public ParameterHolder (String parameterName , int startIndex , int endIndex ) {
473- super ();
474477 this .parameterName = parameterName ;
475478 this .startIndex = startIndex ;
476479 this .endIndex = endIndex ;
477480 }
478481
479482 public String getParameterName () {
480- return parameterName ;
483+ return this . parameterName ;
481484 }
482485
483486 public int getStartIndex () {
484- return startIndex ;
487+ return this . startIndex ;
485488 }
486489
487490 public int getEndIndex () {
488- return endIndex ;
491+ return this . endIndex ;
489492 }
490493 }
494+
491495}
0 commit comments