Nullability fine-tuning around declaration inconsistencies
Issue: SPR-15720 Issue: SPR-15792
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -19,6 +19,7 @@ package org.springframework.jdbc;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Exception thrown when a ResultSet has been accessed in an invalid fashion.
|
||||
@@ -35,6 +36,7 @@ import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
||||
@SuppressWarnings("serial")
|
||||
public class InvalidResultSetAccessException extends InvalidDataAccessResourceUsageException {
|
||||
|
||||
@Nullable
|
||||
private String sql;
|
||||
|
||||
|
||||
@@ -69,6 +71,7 @@ public class InvalidResultSetAccessException extends InvalidDataAccessResourceUs
|
||||
* Return the SQL that caused the problem.
|
||||
* @return the offending SQL, if known
|
||||
*/
|
||||
@Nullable
|
||||
public String getSql() {
|
||||
return this.sql;
|
||||
}
|
||||
|
||||
@@ -515,6 +515,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||
|
||||
class BatchUpdateStatementCallback implements StatementCallback<int[]>, SqlProvider {
|
||||
|
||||
@Nullable
|
||||
private String currSql;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -21,6 +21,7 @@ import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.jdbc.support.JdbcUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Implementation of RowCallbackHandler. Convenient superclass for callback handlers.
|
||||
@@ -54,11 +55,13 @@ public class RowCountCallbackHandler implements RowCallbackHandler {
|
||||
* Indexed from 0. Type (as in java.sql.Types) for the columns
|
||||
* as returned by ResultSetMetaData object.
|
||||
*/
|
||||
@Nullable
|
||||
private int[] columnTypes;
|
||||
|
||||
/**
|
||||
* Indexed from 0. Column name as returned by ResultSetMetaData object.
|
||||
*/
|
||||
@Nullable
|
||||
private String[] columnNames;
|
||||
|
||||
|
||||
@@ -102,8 +105,9 @@ public class RowCountCallbackHandler implements RowCallbackHandler {
|
||||
* @return the types of the columns as java.sql.Types constants.
|
||||
* <b>Indexed from 0 to n-1.</b>
|
||||
*/
|
||||
@Nullable
|
||||
public final int[] getColumnTypes() {
|
||||
return columnTypes;
|
||||
return this.columnTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,8 +116,9 @@ public class RowCountCallbackHandler implements RowCallbackHandler {
|
||||
* @return the names of the columns.
|
||||
* <b>Indexed from 0 to n-1.</b>
|
||||
*/
|
||||
@Nullable
|
||||
public final String[] getColumnNames() {
|
||||
return columnNames;
|
||||
return this.columnNames;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +127,7 @@ public class RowCountCallbackHandler implements RowCallbackHandler {
|
||||
* @return the number of rows in this ResultSet
|
||||
*/
|
||||
public final int getRowCount() {
|
||||
return rowCount;
|
||||
return this.rowCount;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +137,7 @@ public class RowCountCallbackHandler implements RowCallbackHandler {
|
||||
* @return the number of columns in this result set
|
||||
*/
|
||||
public final int getColumnCount() {
|
||||
return columnCount;
|
||||
return this.columnCount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider {
|
||||
|
||||
@Override
|
||||
public void initializeWithProcedureColumnMetaData(DatabaseMetaData databaseMetaData, @Nullable String catalogName,
|
||||
@Nullable String schemaName, String procedureName) throws SQLException {
|
||||
@Nullable String schemaName, @Nullable String procedureName) throws SQLException {
|
||||
|
||||
this.procedureColumnMetaDataUsed = true;
|
||||
processProcedureColumns(databaseMetaData, catalogName, schemaName, procedureName);
|
||||
|
||||
@@ -71,12 +71,14 @@ public abstract class AbstractJdbcCall {
|
||||
private volatile boolean compiled = false;
|
||||
|
||||
/** The generated string used for call statement */
|
||||
@Nullable
|
||||
private String callString;
|
||||
|
||||
/**
|
||||
* A delegate enabling us to create CallableStatementCreators
|
||||
* efficiently, based on this class's declared parameters.
|
||||
*/
|
||||
@Nullable
|
||||
private CallableStatementCreatorFactory callableStatementFactory;
|
||||
|
||||
|
||||
@@ -222,6 +224,7 @@ public abstract class AbstractJdbcCall {
|
||||
/**
|
||||
* Get the call string that should be used based on parameters and meta data.
|
||||
*/
|
||||
@Nullable
|
||||
public String getCallString() {
|
||||
return this.callString;
|
||||
}
|
||||
@@ -230,6 +233,7 @@ public abstract class AbstractJdbcCall {
|
||||
* Get the {@link CallableStatementCreatorFactory} being used
|
||||
*/
|
||||
protected CallableStatementCreatorFactory getCallableStatementFactory() {
|
||||
Assert.state(this.callableStatementFactory != null, "No CallableStatementCreatorFactory available");
|
||||
return this.callableStatementFactory;
|
||||
}
|
||||
|
||||
@@ -322,7 +326,7 @@ public abstract class AbstractJdbcCall {
|
||||
}
|
||||
|
||||
this.callableStatementFactory =
|
||||
new CallableStatementCreatorFactory(getCallString(), this.callMetaDataContext.getCallParameters());
|
||||
new CallableStatementCreatorFactory(this.callString, this.callMetaDataContext.getCallParameters());
|
||||
|
||||
onCompileInternal();
|
||||
}
|
||||
|
||||
@@ -81,9 +81,11 @@ public abstract class AbstractJdbcInsert {
|
||||
private volatile boolean compiled = false;
|
||||
|
||||
/** The generated string used for insert statement */
|
||||
@Nullable
|
||||
private String insertString;
|
||||
|
||||
/** The SQL type information for the insert columns */
|
||||
@Nullable
|
||||
private int[] insertTypes;
|
||||
|
||||
|
||||
@@ -222,6 +224,7 @@ public abstract class AbstractJdbcInsert {
|
||||
/**
|
||||
* Get the insert string to be used.
|
||||
*/
|
||||
@Nullable
|
||||
public String getInsertString() {
|
||||
return this.insertString;
|
||||
}
|
||||
@@ -229,6 +232,7 @@ public abstract class AbstractJdbcInsert {
|
||||
/**
|
||||
* Get the array of {@link java.sql.Types} to be used for insert.
|
||||
*/
|
||||
@Nullable
|
||||
public int[] getInsertTypes() {
|
||||
return this.insertTypes;
|
||||
}
|
||||
@@ -276,7 +280,7 @@ public abstract class AbstractJdbcInsert {
|
||||
this.insertString = this.tableMetaDataContext.createInsertString(getGeneratedKeyNames());
|
||||
this.insertTypes = this.tableMetaDataContext.createInsertTypes();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Compiled insert object: insert string is [" + getInsertString() + "]");
|
||||
logger.debug("Compiled insert object: insert string is [" + this.insertString + "]");
|
||||
}
|
||||
onCompileInternal();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import javax.sql.DataSource;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -45,6 +46,7 @@ public class JdbcBeanDefinitionReader {
|
||||
|
||||
private final PropertiesBeanDefinitionReader propReader;
|
||||
|
||||
@Nullable
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ public class IsolationLevelDataSourceAdapter extends UserCredentialsDataSourceAd
|
||||
* @see #getCurrentReadOnlyFlag()
|
||||
*/
|
||||
@Override
|
||||
protected Connection doGetConnection(String username, String password) throws SQLException {
|
||||
protected Connection doGetConnection(@Nullable String username, @Nullable String password) throws SQLException {
|
||||
Connection con = super.doGetConnection(username, password);
|
||||
Boolean readOnlyToUse = getCurrentReadOnlyFlag();
|
||||
if (readOnlyToUse != null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -22,6 +22,7 @@ import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -52,6 +53,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class SimpleDriverDataSource extends AbstractDriverBasedDataSource {
|
||||
|
||||
@Nullable
|
||||
private Driver driver;
|
||||
|
||||
|
||||
@@ -117,13 +119,14 @@ public class SimpleDriverDataSource extends AbstractDriverBasedDataSource {
|
||||
* Driver instance.
|
||||
* @see #setDriverClass
|
||||
*/
|
||||
public void setDriver(Driver driver) {
|
||||
public void setDriver(@Nullable Driver driver) {
|
||||
this.driver = driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the JDBC Driver instance to use.
|
||||
*/
|
||||
@Nullable
|
||||
public Driver getDriver() {
|
||||
return this.driver;
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ public class WebSphereDataSourceAdapter extends IsolationLevelDataSourceAdapter
|
||||
* @see com.ibm.websphere.rsadapter.WSDataSource#getConnection(com.ibm.websphere.rsadapter.JDBCConnectionSpec)
|
||||
*/
|
||||
@Override
|
||||
protected Connection doGetConnection(String username, String password) throws SQLException {
|
||||
protected Connection doGetConnection(@Nullable String username, @Nullable String password) throws SQLException {
|
||||
// Create JDBCConnectionSpec using current isolation level value and read-only flag.
|
||||
Object connSpec = createConnectionSpec(
|
||||
getCurrentIsolationLevel(), getCurrentReadOnlyFlag(), username, password);
|
||||
|
||||
@@ -38,8 +38,10 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean {
|
||||
@Nullable
|
||||
private DataSource dataSource;
|
||||
|
||||
@Nullable
|
||||
private DatabasePopulator databasePopulator;
|
||||
|
||||
@Nullable
|
||||
private DatabasePopulator databaseCleaner;
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
@@ -171,6 +171,7 @@ public class Jdbc4SqlXmlHandler implements SqlXmlHandler {
|
||||
*/
|
||||
private static abstract class AbstractJdbc4SqlXmlValue implements SqlXmlValue {
|
||||
|
||||
@Nullable
|
||||
private SQLXML xmlObject;
|
||||
|
||||
@Override
|
||||
@@ -187,11 +188,13 @@ public class Jdbc4SqlXmlHandler implements SqlXmlHandler {
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
try {
|
||||
this.xmlObject.free();
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
throw new DataAccessResourceFailureException("Could not free SQLXML object", ex);
|
||||
if (this.xmlObject != null) {
|
||||
try {
|
||||
this.xmlObject.free();
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
throw new DataAccessResourceFailureException("Could not free SQLXML object", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user