|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2020 the original author or authors. |
|
|
|
|
* Copyright 2002-2021 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -36,6 +36,7 @@ import org.springframework.util.Assert;
@@ -36,6 +36,7 @@ import org.springframework.util.Assert;
|
|
|
|
|
* |
|
|
|
|
* @author Thomas Risberg |
|
|
|
|
* @author Juergen Hoeller |
|
|
|
|
* @author Yanming Zhou |
|
|
|
|
* @since 2.0 |
|
|
|
|
*/ |
|
|
|
|
public abstract class NamedParameterUtils { |
|
|
|
|
@ -83,7 +84,7 @@ public abstract class NamedParameterUtils {
@@ -83,7 +84,7 @@ public abstract class NamedParameterUtils {
|
|
|
|
|
Assert.notNull(sql, "SQL must not be null"); |
|
|
|
|
|
|
|
|
|
Set<String> namedParameters = new HashSet<>(); |
|
|
|
|
String sqlToUse = sql; |
|
|
|
|
StringBuilder sqlToUse = new StringBuilder(sql); |
|
|
|
|
List<ParameterHolder> parameterList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
char[] statement = sql.toCharArray(); |
|
|
|
|
@ -155,7 +156,7 @@ public abstract class NamedParameterUtils {
@@ -155,7 +156,7 @@ public abstract class NamedParameterUtils {
|
|
|
|
|
int j = i + 1; |
|
|
|
|
if (j < statement.length && statement[j] == ':') { |
|
|
|
|
// escaped ":" should be skipped
|
|
|
|
|
sqlToUse = sqlToUse.substring(0, i - escapes) + sqlToUse.substring(i - escapes + 1); |
|
|
|
|
sqlToUse.deleteCharAt(i - escapes); |
|
|
|
|
escapes++; |
|
|
|
|
i = i + 2; |
|
|
|
|
continue; |
|
|
|
|
@ -174,7 +175,7 @@ public abstract class NamedParameterUtils {
@@ -174,7 +175,7 @@ public abstract class NamedParameterUtils {
|
|
|
|
|
} |
|
|
|
|
i++; |
|
|
|
|
} |
|
|
|
|
ParsedSql parsedSql = new ParsedSql(sqlToUse); |
|
|
|
|
ParsedSql parsedSql = new ParsedSql(sqlToUse.toString()); |
|
|
|
|
for (ParameterHolder ph : parameterList) { |
|
|
|
|
parsedSql.addNamedParameter(ph.getParameterName(), ph.getStartIndex(), ph.getEndIndex()); |
|
|
|
|
} |
|
|
|
|
@ -346,8 +347,14 @@ public abstract class NamedParameterUtils {
@@ -346,8 +347,14 @@ public abstract class NamedParameterUtils {
|
|
|
|
|
String paramName = paramNames.get(i); |
|
|
|
|
try { |
|
|
|
|
SqlParameter param = findParameter(declaredParams, paramName, i); |
|
|
|
|
paramArray[i] = (param != null ? new SqlParameterValue(param, paramSource.getValue(paramName)) : |
|
|
|
|
SqlParameterSourceUtils.getTypedValue(paramSource, paramName)); |
|
|
|
|
Object paramValue = paramSource.getValue(paramName); |
|
|
|
|
if (paramValue instanceof SqlParameterValue) { |
|
|
|
|
paramArray[i] = paramValue; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
paramArray[i] = (param != null ? new SqlParameterValue(param, paramValue) : |
|
|
|
|
SqlParameterSourceUtils.getTypedValue(paramSource, paramName)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
catch (IllegalArgumentException ex) { |
|
|
|
|
throw new InvalidDataAccessApiUsageException( |
|
|
|
|
|