Refined TemporaryLobCreator null handling (from 4.3.x)

Issue: SPR-15656
This commit is contained in:
Juergen Hoeller 2017-09-27 15:40:13 +02:00
parent 10139d42fc
commit 75bd516251
4 changed files with 29 additions and 18 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 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.
@ -78,4 +78,5 @@ public class PostgresCallMetaDataProvider extends GenericCallMetaDataProvider {
public boolean byPassReturnParameter(String parameterName) {
return RETURN_VALUE_NAME.equals(parameterName);
}
}

View File

@ -89,24 +89,24 @@ public abstract class RdbmsOperation implements InitializingBean {
/**
* An alternative to the more commonly used setDataSource() when you want to
* use the same JdbcTemplate in multiple RdbmsOperations. This is appropriate if the
* JdbcTemplate has special configuration such as a SQLExceptionTranslator that should
* apply to multiple RdbmsOperation objects.
* An alternative to the more commonly used {@link #setDataSource} when you want to
* use the same {@link JdbcTemplate} in multiple {@code RdbmsOperations}. This is
* appropriate if the {@code JdbcTemplate} has special configuration such as a
* {@link org.springframework.jdbc.support.SQLExceptionTranslator} to be reused.
*/
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
/**
* Return the JdbcTemplate object used by this object.
* Return the {@link JdbcTemplate} used by this operation object.
*/
public JdbcTemplate getJdbcTemplate() {
return this.jdbcTemplate;
}
/**
* Set the JDBC DataSource to obtain connections from.
* Set the JDBC {@link DataSource} to obtain connections from.
* @see org.springframework.jdbc.core.JdbcTemplate#setDataSource
*/
public void setDataSource(DataSource dataSource) {
@ -409,7 +409,7 @@ public abstract class RdbmsOperation implements InitializingBean {
* Validate the named parameters passed to an execute method based on declared parameters.
* Subclasses should invoke this method before every {@code executeQuery()} or
* {@code update()} method.
* @param parameters parameter Map supplied. May be {@code null}.
* @param parameters parameter Map supplied (may be {@code null})
* @throws InvalidDataAccessApiUsageException if the parameters are invalid
*/
protected void validateNamedParameters(@Nullable Map<String, ?> parameters) throws InvalidDataAccessApiUsageException {

View File

@ -60,11 +60,15 @@ public class TemporaryLobCreator implements LobCreator {
public void setBlobAsBytes(PreparedStatement ps, int paramIndex, @Nullable byte[] content)
throws SQLException {
Blob blob = ps.getConnection().createBlob();
blob.setBytes(1, content);
this.temporaryBlobs.add(blob);
ps.setBlob(paramIndex, blob);
if (content != null) {
Blob blob = ps.getConnection().createBlob();
blob.setBytes(1, content);
this.temporaryBlobs.add(blob);
ps.setBlob(paramIndex, blob);
}
else {
ps.setBlob(paramIndex, (Blob) null);
}
if (logger.isDebugEnabled()) {
logger.debug(content != null ? "Copied bytes into temporary BLOB with length " + content.length :
@ -103,11 +107,15 @@ public class TemporaryLobCreator implements LobCreator {
public void setClobAsString(PreparedStatement ps, int paramIndex, @Nullable String content)
throws SQLException {
Clob clob = ps.getConnection().createClob();
clob.setString(1, content);
this.temporaryClobs.add(clob);
ps.setClob(paramIndex, clob);
if (content != null) {
Clob clob = ps.getConnection().createClob();
clob.setString(1, content);
this.temporaryClobs.add(clob);
ps.setClob(paramIndex, clob);
}
else {
ps.setClob(paramIndex, (Clob) null);
}
if (logger.isDebugEnabled()) {
logger.debug(content != null ? "Copied string into temporary CLOB with length " + content.length() :
@ -183,4 +191,5 @@ public class TemporaryLobCreator implements LobCreator {
logger.error("Could not free LOB", ex);
}
}
}

View File

@ -189,6 +189,7 @@ public abstract class AbstractAdaptableMessageListener
/**
* Return the {@link QosSettings} to use when sending a response,
* or {@code null} if the defaults should be used.
* @since 5.0
*/
@Nullable
protected QosSettings getResponseQosSettings() {