Nullability fine-tuning based on IntelliJ IDEA 2018.3 inspection
Issue: SPR-15540
This commit is contained in:
@@ -111,25 +111,25 @@ public abstract class NamedParameterUtils {
|
||||
char c = statement[i];
|
||||
if (c == ':' || c == '&') {
|
||||
int j = i + 1;
|
||||
if (j < statement.length && statement[j] == ':' && c == ':') {
|
||||
if (c == ':' && j < statement.length && statement[j] == ':') {
|
||||
// Postgres-style "::" casting operator should be skipped
|
||||
i = i + 2;
|
||||
continue;
|
||||
}
|
||||
String parameter = null;
|
||||
if (j < statement.length && c == ':' && statement[j] == '{') {
|
||||
if (c == ':' && j < statement.length && statement[j] == '{') {
|
||||
// :{x} style parameter
|
||||
while (j < statement.length && statement[j] != '}') {
|
||||
while (statement[j] != '}') {
|
||||
j++;
|
||||
if (j >= statement.length) {
|
||||
throw new InvalidDataAccessApiUsageException("Non-terminated named parameter declaration " +
|
||||
"at position " + i + " in statement: " + sql);
|
||||
}
|
||||
if (statement[j] == ':' || statement[j] == '{') {
|
||||
throw new InvalidDataAccessApiUsageException("Parameter name contains invalid character '" +
|
||||
statement[j] + "' at position " + i + " in statement: " + sql);
|
||||
}
|
||||
}
|
||||
if (j >= statement.length) {
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
"Non-terminated named parameter declaration at position " + i + " in statement: " + sql);
|
||||
}
|
||||
if (j - i > 2) {
|
||||
parameter = sql.substring(i + 2, j);
|
||||
namedParameterCount = addNewNamedParameter(namedParameters, namedParameterCount, parameter);
|
||||
|
||||
@@ -211,7 +211,7 @@ public abstract class RdbmsOperation implements InitializingBean {
|
||||
* Set the column names of the auto-generated keys.
|
||||
* @see java.sql.Connection#prepareStatement(String, String[])
|
||||
*/
|
||||
public void setGeneratedKeysColumnNames(String... names) {
|
||||
public void setGeneratedKeysColumnNames(@Nullable String... names) {
|
||||
if (isCompiled()) {
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
"The column names for the generated keys must be set before the operation is compiled");
|
||||
@@ -230,7 +230,7 @@ public abstract class RdbmsOperation implements InitializingBean {
|
||||
/**
|
||||
* Set the SQL executed by this operation.
|
||||
*/
|
||||
public void setSql(String sql) {
|
||||
public void setSql(@Nullable String sql) {
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,13 +40,6 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public abstract class SqlCall extends RdbmsOperation {
|
||||
|
||||
/**
|
||||
* Object enabling us to create CallableStatementCreators
|
||||
* efficiently, based on this class's declared parameters.
|
||||
*/
|
||||
@Nullable
|
||||
private CallableStatementCreatorFactory callableStatementFactory;
|
||||
|
||||
/**
|
||||
* Flag used to indicate that this call is for a function and to
|
||||
* use the {? = call get_invoice_count(?)} syntax.
|
||||
@@ -54,20 +47,26 @@ public abstract class SqlCall extends RdbmsOperation {
|
||||
private boolean function = false;
|
||||
|
||||
/**
|
||||
* Flag used to indicate that the sql for this call should be used exactly as it is
|
||||
* defined. No need to add the escape syntax and parameter place holders.
|
||||
* Flag used to indicate that the sql for this call should be used exactly as
|
||||
* it is defined. No need to add the escape syntax and parameter place holders.
|
||||
*/
|
||||
private boolean sqlReadyForUse = false;
|
||||
|
||||
/**
|
||||
* Call string as defined in java.sql.CallableStatement.
|
||||
* String of form {call add_invoice(?, ?, ?)}
|
||||
* or {? = call get_invoice_count(?)} if isFunction is set to true
|
||||
* Updated after each parameter is added.
|
||||
* String of form {call add_invoice(?, ?, ?)} or {? = call get_invoice_count(?)}
|
||||
* if isFunction is set to true. Updated after each parameter is added.
|
||||
*/
|
||||
@Nullable
|
||||
private String callString;
|
||||
|
||||
/**
|
||||
* Object enabling us to create CallableStatementCreators
|
||||
* efficiently, based on this class's declared parameters.
|
||||
*/
|
||||
@Nullable
|
||||
private CallableStatementCreatorFactory callableStatementFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor to allow use as a JavaBean.
|
||||
@@ -129,30 +128,32 @@ public abstract class SqlCall extends RdbmsOperation {
|
||||
@Override
|
||||
protected final void compileInternal() {
|
||||
if (isSqlReadyForUse()) {
|
||||
this.callString = getSql();
|
||||
this.callString = resolveSql();
|
||||
}
|
||||
else {
|
||||
StringBuilder callString = new StringBuilder(32);
|
||||
List<SqlParameter> parameters = getDeclaredParameters();
|
||||
int parameterCount = 0;
|
||||
if (isFunction()) {
|
||||
this.callString = "{? = call " + getSql() + "(";
|
||||
callString.append("{? = call ").append(resolveSql()).append('(');
|
||||
parameterCount = -1;
|
||||
}
|
||||
else {
|
||||
this.callString = "{call " + getSql() + "(";
|
||||
callString.append("{call ").append(resolveSql()).append('(');
|
||||
}
|
||||
for (SqlParameter parameter : parameters) {
|
||||
if (!(parameter.isResultsParameter())) {
|
||||
if (!parameter.isResultsParameter()) {
|
||||
if (parameterCount > 0) {
|
||||
this.callString += ", ";
|
||||
callString.append(", ");
|
||||
}
|
||||
if (parameterCount >= 0) {
|
||||
this.callString += "?";
|
||||
callString.append('?');
|
||||
}
|
||||
parameterCount++;
|
||||
}
|
||||
}
|
||||
this.callString += ")}";
|
||||
callString.append(")}");
|
||||
this.callString = callString.toString();
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Compiled stored procedure. Call string is [" + this.callString + "]");
|
||||
|
||||
Reference in New Issue
Block a user